2019-08-12 14:26:44 +00:00
|
|
|
import _ from 'lodash-es';
|
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
angular.module('portainer.docker').controller('NetworksDatatableController', [
|
|
|
|
'$scope',
|
|
|
|
'$controller',
|
|
|
|
'NetworkHelper',
|
|
|
|
'DatatableService',
|
|
|
|
function ($scope, $controller, NetworkHelper, DatatableService) {
|
|
|
|
angular.extend(this, $controller('GenericDatatableController', { $scope: $scope }));
|
2019-07-02 15:51:17 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
this.disableRemove = function (item) {
|
|
|
|
return NetworkHelper.isSystemNetwork(item);
|
|
|
|
};
|
2019-02-25 01:25:48 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
this.state = Object.assign(this.state, {
|
|
|
|
expandedItems: [],
|
|
|
|
});
|
2019-02-25 01:25:48 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
/**
|
|
|
|
* Do not allow system networks to be selected
|
|
|
|
*/
|
|
|
|
this.allowSelection = function (item) {
|
|
|
|
return !this.disableRemove(item);
|
|
|
|
};
|
2019-08-12 14:26:44 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
this.$onInit = function () {
|
|
|
|
this.setDefaults();
|
|
|
|
this.prepareTableFromDataset();
|
2019-07-02 15:51:17 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
this.state.orderBy = this.orderBy;
|
|
|
|
var storedOrder = DatatableService.getDataTableOrder(this.tableKey);
|
|
|
|
if (storedOrder !== null) {
|
|
|
|
this.state.reverseOrder = storedOrder.reverse;
|
|
|
|
this.state.orderBy = storedOrder.orderBy;
|
|
|
|
}
|
2019-07-02 15:51:17 +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;
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
};
|
2019-08-12 14:26:44 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
this.expandItem = function (item, expanded) {
|
|
|
|
item.Expanded = expanded;
|
|
|
|
};
|
2019-08-12 14:26:44 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
this.itemCanExpand = function (item) {
|
|
|
|
return item.Subs.length > 0;
|
|
|
|
};
|
2019-08-12 14:26:44 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
this.hasExpandableItems = function () {
|
|
|
|
return _.filter(this.state.filteredDataSet, (item) => this.itemCanExpand(item)).length;
|
|
|
|
};
|
2019-08-12 14:26:44 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
this.expandAll = function () {
|
|
|
|
this.state.expandAll = !this.state.expandAll;
|
|
|
|
_.forEach(this.state.filteredDataSet, (item) => {
|
|
|
|
if (this.itemCanExpand(item)) {
|
|
|
|
this.expandItem(item, this.state.expandAll);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
},
|
|
|
|
]);
|