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
|
|
|
|
2021-01-28 10:07:35 -08:00
|
|
|
angular.module('Application').controller('AppsController', ['$scope', '$translate', '$interval', '$location', 'Client', function ($scope, $translate, $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
|
2021-02-16 20:10:11 +01:00
|
|
|
var GROUP_ACCESS_UNSET = { _unset: true, name: 'No Group Filter' }; // dummy record for the single select filter
|
2019-05-20 23:40:02 +02:00
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.installedApps = Client.getInstalledApps();
|
2019-04-12 11:06:56 +02:00
|
|
|
$scope.tags = Client.getAppTags();
|
2020-09-26 17:50:23 +02:00
|
|
|
$scope.states = [
|
|
|
|
|
{ state: '', label: 'All States' },
|
|
|
|
|
{ state: 'running', label: 'Running' },
|
2020-10-06 13:01:01 -07:00
|
|
|
{ state: 'stopped', label: 'Stopped' },
|
|
|
|
|
{ state: 'not_responding', label: 'Not Responding' }
|
2020-09-26 17:50:23 +02:00
|
|
|
];
|
|
|
|
|
$scope.selectedState = $scope.states[0];
|
2019-04-12 11:06:56 +02:00
|
|
|
$scope.selectedTags = [];
|
2021-02-16 20:10:11 +01:00
|
|
|
$scope.selectedGroup = GROUP_ACCESS_UNSET;
|
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 = '';
|
2021-02-16 20:10:11 +01:00
|
|
|
$scope.groups = [ GROUP_ACCESS_UNSET ];
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2020-12-15 15:48:25 +01:00
|
|
|
$translate(['apps.stateFilterHeader', 'apps.domainsFilterHeader', 'app.states.running', 'app.states.stopped', 'app.states.notResponding']).then(function (tr) {
|
|
|
|
|
if (tr['apps.domainsFilterHeader']) ALL_DOMAINS_DOMAIN.domain = tr['apps.domainsFilterHeader'];
|
|
|
|
|
if (tr['apps.stateFilterHeader']) $scope.states[0].label = tr['apps.stateFilterHeader'];
|
|
|
|
|
if (tr['app.states.running']) $scope.states[1].label = tr['app.states.running'];
|
|
|
|
|
if (tr['app.states.stopped']) $scope.states[2].label = tr['app.states.stopped'];
|
|
|
|
|
if (tr['app.states.notResponding']) $scope.states[3].label = tr['app.states.notResponding'];
|
|
|
|
|
});
|
|
|
|
|
|
2020-01-06 16:23:31 +01:00
|
|
|
$scope.$watch('selectedTags', function (newVal, oldVal) {
|
|
|
|
|
if (newVal === oldVal) return;
|
|
|
|
|
|
|
|
|
|
localStorage.selectedTags = newVal.join(',');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$scope.$watch('selectedDomain', function (newVal, oldVal) {
|
|
|
|
|
if (newVal === oldVal) return;
|
|
|
|
|
|
|
|
|
|
if (newVal._alldomains) localStorage.removeItem('selectedDomain');
|
|
|
|
|
else localStorage.selectedDomain = newVal.domain;
|
|
|
|
|
});
|
|
|
|
|
|
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');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-10 18:00:50 +02:00
|
|
|
$scope.appInfo = {
|
|
|
|
|
app: {},
|
|
|
|
|
message: '',
|
|
|
|
|
|
|
|
|
|
show: function (app) {
|
|
|
|
|
$scope.appInfo.app = app;
|
|
|
|
|
$scope.appInfo.message = app.manifest.postInstallMessage;
|
|
|
|
|
|
2020-06-30 10:34:07 +02:00
|
|
|
$('#appinfoPostinstallMessage').collapse('hide');
|
2020-06-10 18:00:50 +02:00
|
|
|
$('#appInfoModal').modal('show');
|
|
|
|
|
|
|
|
|
|
return false; // prevent propagation and default
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
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 () {
|
2020-04-28 15:52:04 +02:00
|
|
|
setTimeout(function () { $('#appSearch').focus(); }, 1);
|
|
|
|
|
|
2020-01-07 12:17:40 +01:00
|
|
|
// refresh the new list immediately when switching from another view (appstore)
|
|
|
|
|
Client.refreshInstalledApps(function () {
|
|
|
|
|
var refreshAppsTimer = $interval(Client.refreshInstalledApps.bind(Client, function () {}), 5000);
|
|
|
|
|
$scope.$on('$destroy', function () {
|
|
|
|
|
$interval.cancel(refreshAppsTimer);
|
|
|
|
|
});
|
2020-04-28 15:52:04 +02:00
|
|
|
});
|
2020-01-07 12:17:40 +01:00
|
|
|
|
2020-04-28 15:52:04 +02:00
|
|
|
if (!$scope.user.isAtLeastAdmin) return;
|
2020-01-07 12:17:40 +01:00
|
|
|
|
2020-04-28 15:52:04 +02:00
|
|
|
// load local settings and apply tag filter
|
|
|
|
|
if (localStorage.selectedTags) {
|
|
|
|
|
if (!$scope.tags.length) localStorage.removeItem('selectedTags');
|
|
|
|
|
else $scope.selectedTags = localStorage.selectedTags.split(',');
|
|
|
|
|
}
|
2020-01-07 12:17:40 +01:00
|
|
|
|
2021-02-16 20:10:11 +01:00
|
|
|
Client.getGroups(function (error, result) {
|
|
|
|
|
if (error) Client.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.groups = [ GROUP_ACCESS_UNSET ].concat(result);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-28 15:52:04 +02:00
|
|
|
Client.getDomains(function (error, result) {
|
|
|
|
|
if (error) Client.error(error);
|
2020-01-07 12:17:40 +01:00
|
|
|
|
2020-04-28 15:52:04 +02:00
|
|
|
$scope.domains = result;
|
|
|
|
|
$scope.filterDomains = [ALL_DOMAINS_DOMAIN].concat(result);
|
2020-01-07 12:17:40 +01:00
|
|
|
|
2020-04-28 15:52:04 +02:00
|
|
|
if (localStorage.selectedDomain) $scope.selectedDomain = $scope.filterDomains.find(function (d) { return d.domain === localStorage.selectedDomain; }) || ALL_DOMAINS_DOMAIN;
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-06-24 23:06:12 -07:00
|
|
|
$('.collapse').on('shown.bs.collapse', function(){
|
|
|
|
|
$(this).parent().find('.fa-angle-right').removeClass('fa-angle-right').addClass('fa-angle-down');
|
|
|
|
|
}).on('hidden.bs.collapse', function(){
|
|
|
|
|
$(this).parent().find('.fa-angle-down').removeClass('fa-angle-down').addClass('fa-angle-right');
|
|
|
|
|
});
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$('.modal-backdrop').remove();
|
|
|
|
|
}]);
|