Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into release-candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigok committed Apr 28, 2019
2 parents d1da92f + e60e22f commit 0cbee28
Show file tree
Hide file tree
Showing 185 changed files with 2,989 additions and 1,730 deletions.
7 changes: 6 additions & 1 deletion app/apps/client/admin/appManage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function getApps(instance) {
return APIClient.get(`apps/${ id }?marketplace=true&version=${ FlowRouter.getQueryParam('version') }`)
.catch((e) => {
console.log(e);
toastr.error((e.xhr.responseJSON && e.xhr.responseJSON.error) || e.message);
return Promise.resolve({ app: undefined });
})
.then((remote) => {
Expand Down Expand Up @@ -79,7 +80,11 @@ function getApps(instance) {
instance.ready.set(true);

if (appInfo.remote && appInfo.local) {
return APIClient.get(`apps/${ id }?marketplace=true&update=true&appVersion=${ FlowRouter.getQueryParam('version') }`);
try {
return APIClient.get(`apps/${ id }?marketplace=true&update=true&appVersion=${ FlowRouter.getQueryParam('version') }`);
} catch (e) {
toastr.error((e.xhr.responseJSON && e.xhr.responseJSON.error) || e.message);
}
}

return Promise.resolve(false);
Expand Down
52 changes: 10 additions & 42 deletions app/apps/client/admin/apps.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<template name="apps">
<section class="rc-apps-marketplace">
{{#header sectionName="Apps" hideHelp=true fixedHeight=true fullpage=true}}
{{#if appsDevelopmentMode}}
<button class="rc-button rc-button--small rc-button--primary rc-button--outline" data-button="install">
{{> icon icon="upload" block="rc-icon--default-size"}} {{_ "Upload app"}}
{{#header sectionName="Marketplace" hideHelp=true fixedHeight=true fullpage=true}}
<div class="rc-header__section-button">
<button class="rc-button rc-button--small rc-button--primary" data-button="install_app">
{{> icon icon="cloud-plus" block="rc-icon--default-size"}} {{_ "Marketplace_view_marketplace"}}
</button>
{{/if}}
{{#if appsDevelopmentMode}}
<button class="rc-button rc-button--small rc-button--primary rc-button--outline" data-button="upload_app">
{{> icon icon="upload" block="rc-icon--default-size"}} {{_ "Upload_app"}}
</button>
{{/if}}
</div>
{{/header}}
<div class="rc-table-content">
{{>tabs tabs=tabsData}}

<form class="js-search-form" role="form">
<div class="rc-input">
<div class="rc-input__icon">
Expand Down Expand Up @@ -39,8 +42,6 @@
<th class="rc-table-td">
<div class="table-fake-th">{{_ "Details"}} </div>
</th>
<th class="rc-table-td--small rc-apps-marketplace-price">
</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -84,39 +85,6 @@
</div>
</div>
</td>
<td class="rc-apps-marketplace-price">
{{#if $eq latest._installed true}}
<button class="apps-installer" data-app="{{appId}}">
{{_ "Installed"}}
{{> icon icon="menu" block="rc-icon--default-size"}}
</button>
{{/if}}
{{#if renderDownloadButton latest}}
<div class="rc-apps-marketplace__wrap-actions">
{{#if $eq isPurchased true}}
<button class="js-install apps-installer" data-app="{{appId}}">
{{_ "Purchased"}}
{{> icon block="installer rc-icon--default-size" icon="download"}}
</button>
{{else}}
<button class="js-purchase apps-installer" data-app="{{appId}}">
<span class="rc-app-price">
{{#if $eq price 0}}
{{_ "Free"}}
{{else}}
{{ formatPrice price }}
{{/if}}
</span>
{{> icon block="installer rc-icon--default-size" icon="circled-arrow-down"}}
</button>
{{/if}}
<span class="loading">
Downloading
{{> icon block="rc-icon--default-size rc-icon" icon="loading"}}
</span>
</div>
{{/if}}
</td>
</tr>
{{/each}}
{{#if isLoading}}
Expand Down
177 changes: 17 additions & 160 deletions app/apps/client/admin/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Template } from 'meteor/templating';
import { Tracker } from 'meteor/tracker';
import { settings } from '../../../settings';
import { t, APIClient } from '../../../utils';
import { modal } from '../../../ui-utils';
import { AppEvents } from '../communication';
import { Apps } from '../orchestrator';
import { SideNav } from '../../../ui-utils/client';
Expand All @@ -21,53 +20,24 @@ const sortByColumn = (array, column, inverted) =>
return 1;
});

const tagAlreadyInstalledApps = (installedApps, apps) => {
const installedIds = installedApps.map((app) => app.latest.id);

const tagged = apps.map((app) =>
({
price: app.price,
isPurchased: app.isPurchased,
latest: {
...app.latest,
_installed: installedIds.includes(app.latest.id),
},
})
);

return tagged;
};

const getApps = async (instance) => {
instance.isLoading.set(true);

const data = await APIClient.get('apps?marketplace=true');
const tagged = tagAlreadyInstalledApps(instance.installedApps.get(), data);

if (instance.searchType.get() === 'marketplace') {
instance.apps.set(tagged);
instance.isLoading.set(false);
instance.ready.set(true);
}
};

const getInstalledApps = async (instance) => {
const data = await APIClient.get('apps');
const apps = data.apps.map((app) => ({ latest: app }));
instance.installedApps.set(apps);
try {
const data = await APIClient.get('apps');
const apps = data.apps.map((app) => ({ latest: app }));

if (instance.searchType.get() === 'installed') {
instance.apps.set(apps);
instance.isLoading.set(false);
instance.ready.set(true);
} catch (e) {
toastr.error((e.xhr.responseJSON && e.xhr.responseJSON.error) || e.message);
}

instance.isLoading.set(false);
instance.ready.set(true);
};

Template.apps.onCreated(function() {
const instance = this;
this.ready = new ReactiveVar(false);
this.apps = new ReactiveVar([]);
this.installedApps = new ReactiveVar([]);
this.categories = new ReactiveVar([]);
this.searchText = new ReactiveVar('');
this.searchSortBy = new ReactiveVar('name');
Expand All @@ -76,19 +46,14 @@ Template.apps.onCreated(function() {
this.page = new ReactiveVar(0);
this.end = new ReactiveVar(false);
this.isLoading = new ReactiveVar(true);
this.searchType = new ReactiveVar('marketplace');

const queryTab = FlowRouter.getQueryParam('tab');
if (queryTab) {
if (queryTab.toLowerCase() === 'installed') {
this.searchType.set('installed');
}
}

getInstalledApps(instance);
getApps(instance);

APIClient.get('apps?categories=true').then((data) => instance.categories.set(data));
try {
APIClient.get('apps?categories=true').then((data) => instance.categories.set(data));
} catch (e) {
toastr.error((e.xhr.responseJSON && e.xhr.responseJSON.error) || e.message);
}

instance.onAppAdded = function _appOnAppAdded() {
// ToDo: fix this formatting data to add an app to installedApps array without to fetch all
Expand Down Expand Up @@ -204,59 +169,9 @@ Template.apps.helpers({
sortDirection.set('asc');
};
},
searchType() {
return Template.instance().searchType.get();
},
renderDownloadButton(latest) {
const isMarketplace = Template.instance().searchType.get() === 'marketplace';
const isDownloaded = latest._installed === false;

return isMarketplace && isDownloaded;
},
formatPrice(price) {
return `$${ Number.parseFloat(price).toFixed(2) }`;
},
formatCategories(categories = []) {
return categories.join(', ');
},
tabsData() {
const instance = Template.instance();

const { searchType } = instance;

return {
tabs: [
{
label: t('Marketplace'),
value: 'marketplace',
condition() {
return true;
},
active: searchType.get() === 'marketplace',
},
{
label: t('Installed'),
value: 'installed',
condition() {
return true;
},
active: searchType.get() === 'installed',
},
],
onChange(value) {
instance.apps.set([]);
searchType.set(value);
instance.isLoading.set(true);

if (value === 'marketplace') {
getApps(instance);
} else {
instance.apps.set(instance.installedApps.get());
instance.isLoading.set(false);
}
},
};
},
});

Template.apps.events({
Expand All @@ -267,69 +182,11 @@ Template.apps.events({
FlowRouter.go(`/admin/apps/${ rl.latest.id }?version=${ rl.latest.version }`);
}
},
'click [data-button="install"]'() {
FlowRouter.go('/admin/app/install');
},
'click .js-install'(e, template) {
e.stopPropagation();
const elm = e.currentTarget.parentElement;

elm.classList.add('loading');

APIClient.post('apps/', {
appId: this.latest.id,
marketplace: true,
version: this.latest.version,
})
.then(async () => {
await Promise.all([
getInstalledApps(template),
getApps(template),
]);
elm.classList.remove('loading');
})
.catch((e) => {
toastr.error((e.xhr.responseJSON && e.xhr.responseJSON.error) || e.message);
elm.classList.remove('loading');
});
'click [data-button="install_app"]'() {
FlowRouter.go('marketplace');
},
'click .js-purchase'(e, template) {
e.stopPropagation();

const rl = this;

// play animation
const elm = e.currentTarget.parentElement;

APIClient.get(`apps?buildBuyUrl=true&appId=${ rl.latest.id }`)
.then((data) => {
modal.open({
allowOutsideClick: false,
data,
template: 'iframeModal',
}, () => {
elm.classList.add('loading');
APIClient.post('apps/', {
appId: this.latest.id,
marketplace: true,
version: this.latest.version,
})
.then(async () => {
await Promise.all([
getInstalledApps(template),
getApps(template),
]);
elm.classList.remove('loading');
})
.catch((e) => {
toastr.error((e.xhr.responseJSON && e.xhr.responseJSON.error) || e.message);
elm.classList.remove('loading');
});
});
})
.catch((e) => {
toastr.error((e.xhr.responseJSON && e.xhr.responseJSON.error) || e.message);
});
'click [data-button="upload_app"]'() {
FlowRouter.go('app-install');
},
'keyup .js-search'(e, t) {
t.searchText.set(e.currentTarget.value);
Expand Down
Loading

0 comments on commit 0cbee28

Please sign in to comment.