Files
cloudron-box/src/views/apps.js
T

142 lines
4.2 KiB
JavaScript
Raw Normal View History

2018-01-22 13:01:38 -08:00
'use strict';
/* global angular:false */
/* global $:false */
2018-01-22 13:01:38 -08:00
2019-09-13 17:19:53 +02:00
angular.module('Application').controller('AppsController', ['$scope', '$timeout', '$interval', 'Client', function ($scope, $timeout, $interval, Client) {
2019-05-20 23:40:02 +02:00
var ALL_DOMAINS_DOMAIN = { _alldomains: true, domain: 'All Domains' }; // dummy record for the single select filter
2018-01-22 13:01:38 -08:00
$scope.installedApps = Client.getInstalledApps();
2019-04-12 11:06:56 +02:00
$scope.tags = Client.getAppTags();
$scope.selectedTags = [];
2019-05-20 23:40:02 +02:00
$scope.selectedDomain = ALL_DOMAINS_DOMAIN;
$scope.filterDomains = [ ALL_DOMAINS_DOMAIN ];
2018-01-22 13:01:38 -08:00
$scope.config = Client.getConfig();
$scope.user = Client.getUserInfo();
$scope.domains = [];
$scope.appPostInstallConfirm = {
app: {},
message: '',
confirmed: false,
show: function (app) {
$scope.reset();
$scope.appPostInstallConfirm.app = app;
$scope.appPostInstallConfirm.message = app.manifest.postInstallMessage;
$('#appPostInstallConfirmModal').modal('show');
return false; // prevent propagation and default
},
submit: function () {
if (!$scope.appPostInstallConfirm.confirmed) return;
$scope.appPostInstallConfirm.app.pendingPostInstallConfirmation = false;
delete localStorage['confirmPostInstall_' + $scope.appPostInstallConfirm.app.id];
$('#appPostInstallConfirmModal').modal('hide');
}
};
2018-01-22 13:01:38 -08:00
$scope.appError = {
app: null,
2019-09-05 17:50:10 -07:00
show: function (app) {
$scope.reset();
$scope.appError.app = app;
$('#appErrorModal').modal('show');
return false; // prevent propagation and default
}
2018-01-22 13:01:38 -08:00
};
$scope.appUpdate = {
busy: false,
error: {},
app: {},
manifest: {},
2019-08-29 11:33:22 -07:00
portBindings: {},
show: function (app, updateManifest) {
$scope.reset();
$scope.appUpdate.app = app;
$scope.appUpdate.manifest = angular.copy(updateManifest);
$('#appUpdateModal').modal('show');
},
submit: function () {
$scope.appUpdate.busy = true;
Client.updateApp($scope.appUpdate.app.id, $scope.appUpdate.manifest, function (error) {
if (error) {
Client.error(error);
} else {
$scope.appUpdate.app = {};
$('#appUpdateModal').modal('hide');
}
$scope.appUpdate.busy = false;
Client.refreshAppCache($scope.appUpdate.app.id); // reflect the new app state immediately
});
}
2018-01-22 13:01:38 -08:00
};
$scope.reset = function () {
// close all dialogs
$('#appErrorModal').modal('hide');
$('#appUpdateModal').modal('hide');
$('#appPostInstallConfirmModal').modal('hide');
2018-01-22 13:01:38 -08:00
// reset update dialog
$scope.appUpdate.error = {};
$scope.appUpdate.app = {};
$scope.appUpdate.manifest = {};
// post install confirmation dialog
$scope.appPostInstallConfirm.app = {};
$scope.appPostInstallConfirm.message = '';
$scope.appPostInstallConfirm.confirmed = false;
2018-01-22 13:01:38 -08:00
};
function getDomains() {
Client.getDomains(function (error, result) {
if (error) {
console.error(error);
return $timeout(getDomains, 5000);
}
$scope.domains = result;
2019-05-20 23:40:02 +02:00
$scope.filterDomains = [ALL_DOMAINS_DOMAIN].concat(result);
2018-01-22 13:01:38 -08:00
});
}
Client.onReady(function () {
2019-09-13 19:06:50 +02:00
Client.refreshInstalledApps(); // refresh the new list immediately when switching from another view (appstore)
2018-06-26 10:19:50 -07:00
2019-09-13 19:06:50 +02:00
if ($scope.user.admin) getDomains();
2018-01-22 13:01:38 -08:00
2019-09-13 19:06:50 +02:00
var refreshAppsTimer = $interval(Client.refreshInstalledApps.bind(Client), 5000);
2018-01-22 13:01:38 -08:00
$scope.$on('$destroy', function () {
$interval.cancel(refreshAppsTimer);
2018-01-22 13:01:38 -08:00
});
});
// setup all the dialog focus handling
2019-09-13 17:07:45 +02:00
['appUpdateModal', 'appErrorModal'].forEach(function (id) {
2018-01-22 13:01:38 -08:00
$('#' + id).on('shown.bs.modal', function () {
$(this).find("[autofocus]:first").focus();
});
});
$('.modal-backdrop').remove();
}]);