2019-03-21 05:46:49 +00:00
|
|
|
import _ from 'lodash-es';
|
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
angular.module('portainer.docker').controller('JobsDatatableController', [
|
|
|
|
'$scope',
|
|
|
|
'$controller',
|
|
|
|
'$q',
|
|
|
|
'$state',
|
|
|
|
'PaginationService',
|
|
|
|
'DatatableService',
|
|
|
|
'ContainerService',
|
|
|
|
'ModalService',
|
|
|
|
'Notifications',
|
|
|
|
function ($scope, $controller, $q, $state, PaginationService, DatatableService, ContainerService, ModalService, Notifications) {
|
|
|
|
angular.extend(this, $controller('GenericDatatableController', { $scope: $scope }));
|
|
|
|
|
|
|
|
var ctrl = this;
|
|
|
|
|
|
|
|
this.filters = {
|
|
|
|
state: {
|
|
|
|
open: false,
|
|
|
|
enabled: false,
|
|
|
|
values: [],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
this.applyFilters = function (value) {
|
|
|
|
var container = value;
|
|
|
|
var filters = ctrl.filters;
|
|
|
|
for (var i = 0; i < filters.state.values.length; i++) {
|
|
|
|
var filter = filters.state.values[i];
|
|
|
|
if (container.Status === filter.label && filter.display) {
|
|
|
|
return true;
|
2018-10-28 06:06:50 +00:00
|
|
|
}
|
2020-04-10 21:54:53 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.onStateFilterChange = function () {
|
|
|
|
var filters = this.filters.state.values;
|
|
|
|
var filtered = false;
|
|
|
|
for (var i = 0; i < filters.length; i++) {
|
|
|
|
var filter = filters[i];
|
|
|
|
if (!filter.display) {
|
|
|
|
filtered = true;
|
2018-10-28 06:06:50 +00:00
|
|
|
}
|
2020-04-10 21:54:53 +00:00
|
|
|
}
|
|
|
|
this.filters.state.enabled = filtered;
|
|
|
|
DatatableService.setDataTableFilters(this.tableKey, this.filters);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.prepareTableFromDataset = function () {
|
|
|
|
var availableStateFilters = [];
|
|
|
|
for (var i = 0; i < this.dataset.length; i++) {
|
|
|
|
var item = this.dataset[i];
|
|
|
|
availableStateFilters.push({
|
|
|
|
label: item.Status,
|
|
|
|
display: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.filters.state.values = _.uniqBy(availableStateFilters, 'label');
|
|
|
|
};
|
|
|
|
|
|
|
|
this.updateStoredFilters = function (storedFilters) {
|
|
|
|
var datasetFilters = this.filters.state.values;
|
|
|
|
|
|
|
|
for (var i = 0; i < datasetFilters.length; i++) {
|
|
|
|
var filter = datasetFilters[i];
|
|
|
|
var existingFilter = _.find(storedFilters, ['label', filter.label]);
|
|
|
|
if (existingFilter && !existingFilter.display) {
|
|
|
|
filter.display = existingFilter.display;
|
|
|
|
this.filters.state.enabled = true;
|
2018-10-28 06:06:50 +00:00
|
|
|
}
|
2020-04-10 21:54:53 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function confirmPurgeJobs() {
|
|
|
|
return showConfirmationModal();
|
|
|
|
|
|
|
|
function showConfirmationModal() {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
ModalService.confirm({
|
|
|
|
title: 'Are you sure ?',
|
|
|
|
message: 'Clearing job history will remove all stopped jobs containers.',
|
|
|
|
buttons: {
|
|
|
|
confirm: {
|
|
|
|
label: 'Purge',
|
|
|
|
className: 'btn-danger',
|
2018-10-28 06:06:50 +00:00
|
|
|
},
|
2020-04-10 21:54:53 +00:00
|
|
|
},
|
|
|
|
callback: function onConfirm(confirmed) {
|
|
|
|
deferred.resolve(confirmed);
|
|
|
|
},
|
|
|
|
});
|
2018-10-28 06:06:50 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
return deferred.promise;
|
2018-10-28 06:06:50 +00:00
|
|
|
}
|
2020-04-10 21:54:53 +00:00
|
|
|
}
|
2018-10-28 06:06:50 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
this.purgeAction = function () {
|
|
|
|
confirmPurgeJobs().then(function success(confirmed) {
|
|
|
|
if (!confirmed) {
|
|
|
|
return $q.when();
|
|
|
|
}
|
|
|
|
ContainerService.prune({ label: ['io.portainer.job.endpoint'] })
|
|
|
|
.then(function success() {
|
2018-11-07 03:06:27 +00:00
|
|
|
Notifications.success('Success', 'Job history cleared');
|
2018-10-28 06:06:50 +00:00
|
|
|
$state.reload();
|
2020-04-10 21:54:53 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2018-10-28 06:06:50 +00:00
|
|
|
Notifications.error('Failure', err.message, 'Unable to clear job history');
|
|
|
|
});
|
2020-04-10 21:54:53 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
this.$onInit = function () {
|
|
|
|
this.setDefaults();
|
|
|
|
this.prepareTableFromDataset();
|
|
|
|
|
|
|
|
this.state.orderBy = this.orderBy;
|
|
|
|
var storedOrder = DatatableService.getDataTableOrder(this.tableKey);
|
|
|
|
if (storedOrder !== null) {
|
|
|
|
this.state.reverseOrder = storedOrder.reverse;
|
|
|
|
this.state.orderBy = storedOrder.orderBy;
|
|
|
|
}
|
2018-10-28 06:06:50 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
var textFilter = DatatableService.getDataTableTextFilters(this.tableKey);
|
|
|
|
if (textFilter !== null) {
|
|
|
|
this.state.textFilter = textFilter;
|
|
|
|
this.onTextFilterChange();
|
|
|
|
}
|
2019-07-02 15:51:17 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
var storedFilters = DatatableService.getDataTableFilters(this.tableKey);
|
|
|
|
if (storedFilters !== null) {
|
|
|
|
this.filters = storedFilters;
|
|
|
|
this.updateStoredFilters(storedFilters.state.values);
|
|
|
|
}
|
|
|
|
if (this.filters && this.filters.state) {
|
|
|
|
this.filters.state.open = false;
|
|
|
|
}
|
2019-07-22 10:54:59 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
var storedSettings = DatatableService.getDataTableSettings(this.tableKey);
|
|
|
|
if (storedSettings !== null) {
|
|
|
|
this.settings = storedSettings;
|
|
|
|
this.settings.open = false;
|
|
|
|
}
|
|
|
|
this.onSettingsRepeaterChange();
|
|
|
|
};
|
|
|
|
},
|
|
|
|
]);
|