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-09-18 15:54:19 +02:00
|
|
|
angular.module('Application').controller('AppsController', ['$scope', '$timeout', '$interval', '$location', 'Client', function ($scope, $timeout, $interval, $location, 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 = [];
|
2020-01-06 15:27:31 +01:00
|
|
|
$scope.appSearch = '';
|
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.appPostInstallConfirm.app = app;
|
|
|
|
|
$scope.appPostInstallConfirm.message = app.manifest.postInstallMessage;
|
2019-09-18 18:10:51 +02:00
|
|
|
$scope.appPostInstallConfirm.confirmed = false;
|
2018-06-14 15:46:55 +02:00
|
|
|
|
|
|
|
|
$('#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');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-18 18:10:51 +02:00
|
|
|
$scope.showAppConfigure = function (app, view) {
|
|
|
|
|
$location.path('/app/' + app.id + '/' + view);
|
2018-01-22 13:01:38 -08:00
|
|
|
};
|
|
|
|
|
|
2019-09-18 18:10:51 +02:00
|
|
|
Client.onReady(function () {
|
2019-10-11 14:55:19 -07:00
|
|
|
Client.refreshInstalledApps(function () {}); // refresh the new list immediately when switching from another view (appstore)
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2019-10-11 14:55:19 -07:00
|
|
|
var refreshAppsTimer = $interval(Client.refreshInstalledApps.bind(Client, function () {}), 5000);
|
2019-09-18 18:18:43 +02:00
|
|
|
$scope.$on('$destroy', function () {
|
|
|
|
|
$interval.cancel(refreshAppsTimer);
|
|
|
|
|
});
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2019-09-18 18:10:51 +02:00
|
|
|
if (!$scope.user.admin) return;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
Client.getDomains(function (error, result) {
|
2019-09-24 19:56:31 +02:00
|
|
|
if (error) Client.error(error);
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
$scope.domains = result;
|
2019-05-20 23:40:02 +02:00
|
|
|
$scope.filterDomains = [ALL_DOMAINS_DOMAIN].concat(result);
|
2020-01-06 15:27:31 +01:00
|
|
|
|
|
|
|
|
setTimeout(function () { $('#appSearch').focus(); }, 1000);
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.modal-backdrop').remove();
|
|
|
|
|
}]);
|