Get subscription first and then get apps
This commit is contained in:
+28
-32
@@ -284,20 +284,31 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$loca
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
onSubscribed();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function getAppList(callback) {
|
||||
Client.getAppstoreApps(function (error, apps) {
|
||||
if (error) return callback(error);
|
||||
function onSubscribed() {
|
||||
Client.getAppstoreApps(function (error) {
|
||||
if (error) return console.error(error);
|
||||
|
||||
// ensure we have a tags property for further use
|
||||
apps.forEach(function (app) {
|
||||
if (!app.manifest.tags) app.manifest.tags = [];
|
||||
// start with featured apps listing. this also sets $scope.apps accordingly
|
||||
$scope.showCategory(null, 'featured');
|
||||
|
||||
// domains is required since we populate the dropdown with domains[0]
|
||||
Client.getDomains(function (error, result) {
|
||||
if (error) console.error(error);
|
||||
|
||||
$scope.domains = result;
|
||||
|
||||
// show install app dialog immediately if an app id was passed in the query
|
||||
// hashChangeListener calls $apply, so make sure we don't double digest here
|
||||
setTimeout(hashChangeListener, 1);
|
||||
|
||||
setTimeout(function () { $('#appstoreSearch').focus(); }, 1000);
|
||||
});
|
||||
|
||||
return callback(null, apps);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -431,8 +442,12 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$loca
|
||||
|
||||
function getSubscription(callback) {
|
||||
Client.getSubscription(function (error, subscription) {
|
||||
if (error) { // error.statusCode will be 402
|
||||
$scope.validSubscription = false;
|
||||
if (error) {
|
||||
if (error.statusCode === 402) { // not setup yet
|
||||
$scope.validSubscription = false;
|
||||
} else {
|
||||
return callback(error);
|
||||
}
|
||||
} else {
|
||||
$scope.subscription = subscription;
|
||||
}
|
||||
@@ -450,37 +465,18 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$loca
|
||||
function init() {
|
||||
$scope.ready = false;
|
||||
|
||||
getAppList(function (error, apps) {
|
||||
getSubscription(function (error) {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
return $timeout(init, 1000);
|
||||
}
|
||||
|
||||
$scope.apps = apps;
|
||||
|
||||
fetchUsers();
|
||||
fetchGroups();
|
||||
|
||||
// start with featured apps listing
|
||||
$scope.showCategory(null, 'featured');
|
||||
if ($scope.validSubscription) onSubscribed();
|
||||
|
||||
// domains is required since we populate the dropdown with domains[0]
|
||||
Client.getDomains(function (error, result) {
|
||||
if (error) console.error(error);
|
||||
|
||||
$scope.domains = result;
|
||||
|
||||
// show install app dialog immediately if an app id was passed in the query
|
||||
// hashChangeListener calls $apply, so make sure we don't double digest here
|
||||
setTimeout(hashChangeListener, 1);
|
||||
|
||||
getSubscription(function (error) {
|
||||
if (error) console.error(error);
|
||||
$scope.ready = true;
|
||||
|
||||
setTimeout(function () { $('#appstoreSearch').focus(); }, 1000);
|
||||
});
|
||||
});
|
||||
$scope.ready = true;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user