2018-01-22 13:01:38 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
2019-01-22 10:54:03 +01:00
|
|
|
/* global angular:false */
|
|
|
|
|
/* global $:false */
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2019-01-22 10:54:03 +01:00
|
|
|
angular.module('Application').controller('AppsController', ['$scope', '$location', '$timeout', '$interval', 'Client', function ($scope, $location, $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.HOST_PORT_MIN = 1024;
|
|
|
|
|
$scope.HOST_PORT_MAX = 65535;
|
|
|
|
|
$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.groups = [];
|
|
|
|
|
$scope.users = [];
|
2019-05-07 10:11:54 -07:00
|
|
|
$scope.backupsEnabled = true;
|
2019-03-20 09:53:10 -07:00
|
|
|
$scope.disableIndexingTemplate = '# Disable search engine indexing\n\nUser-agent: *\nDisallow: /';
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-06-14 15:46:55 +02:00
|
|
|
$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 () {
|
2018-06-15 13:39:30 +02:00
|
|
|
if (!$scope.appPostInstallConfirm.confirmed) return;
|
|
|
|
|
|
2018-06-14 15:46:55 +02:00
|
|
|
$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 = {
|
2019-09-07 09:24:39 +02:00
|
|
|
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');
|
2018-06-14 15:46:55 +02:00
|
|
|
$('#appPostInstallConfirmModal').modal('hide');
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
// reset update dialog
|
|
|
|
|
$scope.appUpdate.error = {};
|
|
|
|
|
$scope.appUpdate.app = {};
|
|
|
|
|
$scope.appUpdate.manifest = {};
|
|
|
|
|
|
2018-06-14 15:46:55 +02:00
|
|
|
// post install confirmation dialog
|
|
|
|
|
$scope.appPostInstallConfirm.app = {};
|
|
|
|
|
$scope.appPostInstallConfirm.message = '';
|
|
|
|
|
$scope.appPostInstallConfirm.confirmed = false;
|
2018-01-22 13:01:38 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function fetchUsers() {
|
|
|
|
|
Client.getUsers(function (error, users) {
|
|
|
|
|
if (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
return $timeout(fetchUsers, 5000);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-05 12:14:20 +01:00
|
|
|
// ensure we have something to work with in the access restriction dropdowns
|
|
|
|
|
users.forEach(function (user) { user.display = user.username || user.email; });
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.users = users;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fetchGroups() {
|
|
|
|
|
Client.getGroups(function (error, groups) {
|
|
|
|
|
if (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
return $timeout(fetchUsers, 5000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.groups = groups;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getBackupConfig() {
|
|
|
|
|
Client.getBackupConfig(function (error, backupConfig) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
2019-05-07 10:11:54 -07:00
|
|
|
$scope.backupEnabled = backupConfig.provider !== 'noop';
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-25 10:42:31 +01:00
|
|
|
function refreshInstalledApps() {
|
|
|
|
|
Client.refreshInstalledApps();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
Client.onReady(function () {
|
2019-03-25 10:42:31 +01:00
|
|
|
refreshInstalledApps(); // refresh the new list immediately when switching from another view (appstore)
|
2018-06-26 10:19:50 -07:00
|
|
|
|
2019-05-04 18:40:10 -07:00
|
|
|
if ($scope.user.admin) {
|
2018-06-25 18:06:17 -07:00
|
|
|
fetchUsers();
|
|
|
|
|
fetchGroups();
|
|
|
|
|
getDomains();
|
2019-05-07 10:11:54 -07:00
|
|
|
getBackupConfig();
|
2018-06-25 18:06:17 -07:00
|
|
|
}
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2019-03-25 10:42:31 +01:00
|
|
|
var refreshAppsTimer = $interval(refreshInstalledApps, 5000);
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-06-25 18:06:17 -07: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();
|
|
|
|
|
}]);
|