2018-06-11 13:13:19 +00:00
|
|
|
angular.module('portainer.docker')
|
|
|
|
.controller('ServiceTasksDatatableController', ['DatatableService',
|
|
|
|
function (DatatableService) {
|
|
|
|
var ctrl = this;
|
|
|
|
|
|
|
|
this.state = {
|
2018-10-31 02:50:38 +00:00
|
|
|
orderBy: this.orderBy,
|
|
|
|
showQuickActionStats: true,
|
|
|
|
showQuickActionLogs: true,
|
|
|
|
showQuickActionConsole: true,
|
|
|
|
showQuickActionInspect: true
|
2018-06-11 13:13:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.filters = {
|
|
|
|
state: {
|
|
|
|
open: false,
|
|
|
|
enabled: false,
|
|
|
|
values: []
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-22 15:33:06 +00:00
|
|
|
this.applyFilters = function(item) {
|
2018-06-11 13:13:19 +00:00
|
|
|
var filters = ctrl.filters;
|
|
|
|
for (var i = 0; i < filters.state.values.length; i++) {
|
|
|
|
var filter = filters.state.values[i];
|
|
|
|
if (item.Status.State === filter.label && filter.display) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.filters.state.enabled = filtered;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.changeOrderBy = function(orderField) {
|
|
|
|
this.state.reverseOrder = this.state.orderBy === orderField ? !this.state.reverseOrder : false;
|
|
|
|
this.state.orderBy = orderField;
|
|
|
|
DatatableService.setDataTableOrder(this.tableKey, orderField, this.state.reverseOrder);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.prepareTableFromDataset = function() {
|
|
|
|
var availableStateFilters = [];
|
|
|
|
for (var i = 0; i < this.dataset.length; i++) {
|
|
|
|
var item = this.dataset[i];
|
|
|
|
availableStateFilters.push({ label: item.Status.State, display: true });
|
|
|
|
}
|
|
|
|
this.filters.state.values = _.uniqBy(availableStateFilters, 'label');
|
|
|
|
};
|
|
|
|
|
|
|
|
this.$onInit = function() {
|
|
|
|
setDefaults(this);
|
|
|
|
this.prepareTableFromDataset();
|
|
|
|
|
|
|
|
var storedOrder = DatatableService.getDataTableOrder(this.tableKey);
|
|
|
|
if (storedOrder !== null) {
|
|
|
|
this.state.reverseOrder = storedOrder.reverse;
|
|
|
|
this.state.orderBy = storedOrder.orderBy;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function setDefaults(ctrl) {
|
|
|
|
ctrl.state.reverseOrder = ctrl.reverseOrder ? ctrl.reverseOrder : false;
|
|
|
|
}
|
|
|
|
}]);
|