2018-02-01 12:27:52 +00:00
|
|
|
angular.module('portainer.docker')
|
2017-12-06 11:04:02 +00:00
|
|
|
.controller('VolumesDatatableController', ['PaginationService', 'DatatableService',
|
|
|
|
function (PaginationService, DatatableService) {
|
|
|
|
|
|
|
|
var ctrl = this;
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
selectAll: false,
|
|
|
|
orderBy: this.orderBy,
|
|
|
|
paginatedItemLimit: PaginationService.getPaginationLimit(this.tableKey),
|
|
|
|
displayTextFilter: false,
|
|
|
|
selectedItemCount: 0,
|
|
|
|
selectedItems: []
|
|
|
|
};
|
2018-07-11 14:18:44 +00:00
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
this.filters = {
|
|
|
|
usage: {
|
|
|
|
open: false,
|
|
|
|
enabled: false,
|
|
|
|
showUsedVolumes: true,
|
|
|
|
showUnusedVolumes: true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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.selectItem = function(item) {
|
|
|
|
if (item.Checked) {
|
|
|
|
this.state.selectedItemCount++;
|
|
|
|
this.state.selectedItems.push(item);
|
|
|
|
} else {
|
|
|
|
this.state.selectedItems.splice(this.state.selectedItems.indexOf(item), 1);
|
|
|
|
this.state.selectedItemCount--;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.selectAll = function() {
|
|
|
|
for (var i = 0; i < this.state.filteredDataSet.length; i++) {
|
|
|
|
var item = this.state.filteredDataSet[i];
|
|
|
|
if (item.Checked !== this.state.selectAll) {
|
|
|
|
item.Checked = this.state.selectAll;
|
|
|
|
this.selectItem(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.changePaginationLimit = function() {
|
|
|
|
PaginationService.setPaginationLimit(this.tableKey, this.state.paginatedItemLimit);
|
|
|
|
};
|
|
|
|
|
2018-08-22 15:33:06 +00:00
|
|
|
this.applyFilters = function(value) {
|
2017-12-06 11:04:02 +00:00
|
|
|
var volume = value;
|
|
|
|
var filters = ctrl.filters;
|
2018-07-11 14:18:44 +00:00
|
|
|
if ((volume.dangling && filters.usage.showUnusedVolumes)
|
2017-12-06 11:04:02 +00:00
|
|
|
|| (!volume.dangling && filters.usage.showUsedVolumes)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2018-07-11 14:18:44 +00:00
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
this.onUsageFilterChange = function() {
|
|
|
|
var filters = this.filters.usage;
|
|
|
|
var filtered = false;
|
|
|
|
if (!filters.showUsedVolumes || !filters.showUnusedVolumes) {
|
|
|
|
filtered = true;
|
|
|
|
}
|
|
|
|
this.filters.usage.enabled = filtered;
|
|
|
|
DatatableService.setDataTableFilters(this.tableKey, this.filters);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.$onInit = function() {
|
|
|
|
setDefaults(this);
|
|
|
|
|
|
|
|
var storedOrder = DatatableService.getDataTableOrder(this.tableKey);
|
|
|
|
if (storedOrder !== null) {
|
|
|
|
this.state.reverseOrder = storedOrder.reverse;
|
|
|
|
this.state.orderBy = storedOrder.orderBy;
|
|
|
|
}
|
2018-07-11 14:18:44 +00:00
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
var storedFilters = DatatableService.getDataTableFilters(this.tableKey);
|
|
|
|
if (storedFilters !== null) {
|
|
|
|
this.filters = storedFilters;
|
|
|
|
}
|
|
|
|
this.filters.usage.open = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
function setDefaults(ctrl) {
|
|
|
|
ctrl.showTextFilter = ctrl.showTextFilter ? ctrl.showTextFilter : false;
|
|
|
|
ctrl.state.reverseOrder = ctrl.reverseOrder ? ctrl.reverseOrder : false;
|
|
|
|
}
|
|
|
|
}]);
|