diff --git a/src/js/client.js b/src/js/client.js index 2dd87a219..950d5dc9a 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -2002,7 +2002,7 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N }); }; - Client.prototype.getAppsFast = function (callback) { + Client.prototype.getAppstoreAppsFast = function (callback) { if (this._appstoreAppCache.length !== 0) return callback(null, this._appstoreAppCache); this.getAppstoreApps(callback); diff --git a/src/views/appstore.js b/src/views/appstore.js index 9a4bfbb9d..d7d551e89 100644 --- a/src/views/appstore.js +++ b/src/views/appstore.js @@ -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; }); }