Files
cloudron-box/webadmin/views/appstore.js
T
Girish Ramakrishnan 669f0d2eca Fix typo
2014-10-04 00:12:43 -07:00

70 lines
2.0 KiB
JavaScript

/* exported AppStoreController */
'use strict';
var AppStoreController = function ($scope, $location, Client, AppStore) {
$scope.LOADING = 1;
$scope.ERROR = 2;
$scope.LOADED = 3;
$scope.loadStatus = $scope.LOADING;
$scope.loadError = '';
$scope.apps = [];
$scope.refresh = function () {
Client.refreshInstalledApps(function (error) {
if (error) {
$scope.loadStatus = $scope.ERROR;
$scope.loadError = error.message;
return;
}
AppStore.getApps(function (error, apps) {
if (error) {
$scope.loadStatus = $scope.ERROR;
$scope.loadError = error.message;
return;
}
for (var app in apps) {
var found = false;
for (var i = 0; i < $scope.apps.length; ++i) {
if (apps[app].id === $scope.apps[i].id) {
found = true;
break;
}
}
if (!found) $scope.apps.push(apps[app]);
}
$scope.apps.forEach(function (app, index) {
if (Client._installedApps) app.installed = Client._installedApps.some(function (a) { return a.appStoreId === app.id; });
if (!apps[app.id]) $scope.apps.splice(index, 1);
});
$scope.loadStatus = $scope.LOADED;
});
});
};
$scope.installApp = function (app) {
$location.path('/app/' + app.id + '/install');
};
$scope.openApp = function (app) {
for (var i = 0; i < Client._installedApps.length; i++) {
if (Client._installedApps[i].appStoreId === app.id) {
window.open('https://' + Client._installedApps[i].fqdn);
break;
}
}
};
Client.onConfig(function (config) {
if (!config.appServerUrl) return;
$scope.refresh();
});
};