diff --git a/src/js/appstore.js b/src/js/appstore.js index bdca66512..463002f37 100644 --- a/src/js/appstore.js +++ b/src/js/appstore.js @@ -19,12 +19,12 @@ angular.module('Application').service('AppStore', ['$http', '$base64', 'Client', this._appsCache = []; } - AppStore.prototype.getApps = function (callback) { + AppStore.prototype.getApps = function (unstable, callback) { if (Client.getConfig().apiServerOrigin === null) return callback(new AppStoreError(420, 'Enhance Your Calm')); var that = this; - $http.get(Client.getConfig().apiServerOrigin + '/api/v1/apps', { params: { boxVersion: Client.getConfig().version, unstable: true } }).success(function (data, status) { + $http.get(Client.getConfig().apiServerOrigin + '/api/v1/apps', { params: { boxVersion: Client.getConfig().version, unstable: unstable } }).success(function (data, status) { if (status !== 200) return callback(new AppStoreError(status, data)); angular.copy(data.apps, that._appsCache); @@ -35,56 +35,21 @@ angular.module('Application').service('AppStore', ['$http', '$base64', 'Client', }); }; - AppStore.prototype.getAppsFast = function (callback) { + AppStore.prototype.getAppsFast = function (unstable, callback) { if (Client.getConfig().apiServerOrigin === null) return callback(new AppStoreError(420, 'Enhance Your Calm')); if (this._appsCache.length !== 0) return callback(null, this._appsCache); - this.getApps(callback); - }; - - AppStore.prototype.getAppById = function (appId, callback) { - var that = this; - - // check cache - for (var app in this._appsCache) { - if (this._appsCache[app].id === appId) return callback(null, this._appsCache[app]); - } - - this.getApps(function (error) { - if (error) return callback(error); - - // recheck cache - for (var app in that._appsCache) { - if (that._appsCache[app].id === appId) return callback(null, that._appsCache[app]); - } - - callback(new AppStoreError(404, 'Not found')); - }); + this.getApps(unstable, callback); }; AppStore.prototype.getAppByIdAndVersion = function (appId, version, callback) { if (Client.getConfig().apiServerOrigin === null) return callback(new AppStoreError(420, 'Enhance Your Calm')); - // check cache - for (var app in this._appsCache) { - if (this._appsCache[app].id === appId && this._appsCache[app].manifest.version === version) return callback(null, this._appsCache[app]); - } + var url = Client.getConfig().apiServerOrigin + '/api/v1/apps/' + appId; + if (version && version !== 'latest') url += '/versions/' + version; - $http.get(Client.getConfig().apiServerOrigin + '/api/v1/apps/' + appId + '/versions/' + version).success(function (data, status) { - if (status !== 200) return callback(new AppStoreError(status, data)); - return callback(null, data); - }).error(function (data, status) { - return callback(new AppStoreError(status, data)); - }); - }; - - AppStore.prototype.getAppById = function (appId, callback) { - if (Client.getConfig().apiServerOrigin === null) return callback(new AppStoreError(420, 'Enhance Your Calm')); - - // do not check cache, always get the latest - - $http.get(Client.getConfig().apiServerOrigin + '/api/v1/apps/' + appId).success(function (data, status) { + $http.get(url).success(function (data, status) { if (status !== 200) return callback(new AppStoreError(status, data)); return callback(null, data); }).error(function (data, status) { diff --git a/src/views/appstore.js b/src/views/appstore.js index 0f717f2f3..c00501579 100644 --- a/src/views/appstore.js +++ b/src/views/appstore.js @@ -22,6 +22,7 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$loca $scope.validAppstoreAccount = false; $scope.appstoreConfig = null; $scope.spacesSuffix = ''; + $scope.unstableApps = false; $scope.showView = function (view) { // wait for dialog to be fully closed to avoid modal behavior breakage when moving to a different view already @@ -328,15 +329,22 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$loca }; function getAppList(callback) { - AppStore.getApps(function (error, apps) { - if (error) return callback(error); + Client.getUnstableAppsConfig(function (error, unstable) { + if (error) console.error('Error getting unstable apps config. Falling back to only stable apps.', error); - // ensure we have a tags property for further use - apps.forEach(function (app) { - if (!app.manifest.tags) app.manifest.tags = []; + // stash this for search lookups + $scope.unstableApps = error ? false : unstable; + + AppStore.getApps($scope.unstableApps, function (error, apps) { + if (error) return callback(error); + + // ensure we have a tags property for further use + apps.forEach(function (app) { + if (!app.manifest.tags) app.manifest.tags = []; + }); + + return callback(null, apps); }); - - return callback(null, apps); }); } @@ -346,7 +354,7 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$loca $scope.category = ''; - AppStore.getAppsFast(function (error, apps) { + AppStore.getAppsFast($scope.unstableApps, function (error, apps) { if (error) return $timeout($scope.search, 1000); var token = $scope.searchString.toUpperCase(); @@ -368,7 +376,7 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$loca $scope.cachedCategory = $scope.category; - AppStore.getAppsFast(function (error, apps) { + AppStore.getAppsFast($scope.unstableApps, function (error, apps) { if (error) return $timeout($scope.showCategory.bind(null, event), 1000); if (!$scope.category) { @@ -431,27 +439,15 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$loca var version = $location.search().version; if (appId) { - if (version) { - AppStore.getAppByIdAndVersion(appId, version, function (error, result) { - if (error) { - $scope.showAppNotFound(appId, version); - console.error(error); - return; - } + AppStore.getAppByIdAndVersion(appId, version || 'latest', function (error, result) { + if (error) { + $scope.showAppNotFound(appId, version); + console.error(error); + return; + } - $scope.appInstall.show(result); - }); - } else { - AppStore.getAppById(appId, function (error, result) { - if (error) { - $scope.showAppNotFound(appId, null); - console.error(error); - return; - } - - $scope.appInstall.show(result); - }); - } + $scope.appInstall.show(result); + }); } else { $scope.appInstall.reset(); }