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('ServicesDatatableController', [
|
|
|
|
'$scope',
|
|
|
|
'$controller',
|
|
|
|
'DatatableService',
|
|
|
|
'EndpointProvider',
|
|
|
|
function ($scope, $controller, DatatableService, EndpointProvider) {
|
|
|
|
angular.extend(this, $controller('GenericDatatableController', { $scope: $scope }));
|
|
|
|
|
|
|
|
var ctrl = this;
|
|
|
|
|
|
|
|
this.state = Object.assign(this.state, {
|
|
|
|
expandAll: false,
|
|
|
|
expandedItems: [],
|
|
|
|
publicURL: EndpointProvider.endpointPublicURL(),
|
|
|
|
});
|
2018-06-11 13:13:19 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
this.expandAll = function () {
|
|
|
|
this.state.expandAll = !this.state.expandAll;
|
|
|
|
for (var i = 0; i < this.state.filteredDataSet.length; i++) {
|
|
|
|
var item = this.state.filteredDataSet[i];
|
|
|
|
this.expandItem(item, this.state.expandAll);
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
2020-04-10 21:54:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.expandItem = function (item, expanded) {
|
|
|
|
item.Expanded = expanded;
|
|
|
|
if (item.Expanded) {
|
|
|
|
if (this.state.expandedItems.indexOf(item.Id) === -1) {
|
|
|
|
this.state.expandedItems.push(item.Id);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var index = this.state.expandedItems.indexOf(item.Id);
|
|
|
|
if (index > -1) {
|
|
|
|
this.state.expandedItems.splice(index, 1);
|
|
|
|
}
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
2020-04-10 21:54:53 +00:00
|
|
|
DatatableService.setDataTableExpandedItems(this.tableKey, this.state.expandedItems);
|
|
|
|
};
|
2018-06-11 13:13:19 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
function expandPreviouslyExpandedItem(item, storedExpandedItems) {
|
|
|
|
var expandedItem = _.find(storedExpandedItems, function (storedId) {
|
|
|
|
return item.Id === storedId;
|
|
|
|
});
|
2018-06-11 13:13:19 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
if (expandedItem) {
|
|
|
|
ctrl.expandItem(item, true);
|
|
|
|
}
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
this.expandItems = function (storedExpandedItems) {
|
|
|
|
var expandedItemCount = 0;
|
|
|
|
this.state.expandedItems = storedExpandedItems;
|
2018-06-11 13:13:19 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
for (var i = 0; i < this.dataset.length; i++) {
|
|
|
|
var item = this.dataset[i];
|
|
|
|
expandPreviouslyExpandedItem(item, storedExpandedItems);
|
|
|
|
if (item.Expanded) {
|
|
|
|
++expandedItemCount;
|
|
|
|
}
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
if (expandedItemCount === this.dataset.length) {
|
|
|
|
this.state.expandAll = true;
|
|
|
|
}
|
|
|
|
};
|
2018-06-11 13:13:19 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
this.$onInit = function () {
|
|
|
|
this.setDefaults();
|
|
|
|
this.prepareTableFromDataset();
|
2018-06-11 13:13:19 +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;
|
|
|
|
}
|
2018-06-11 13:13:19 +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();
|
|
|
|
}
|
2018-06-11 13:13:19 +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-02 15:51:17 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
var storedExpandedItems = DatatableService.getDataTableExpandedItems(this.tableKey);
|
|
|
|
if (storedExpandedItems !== null) {
|
|
|
|
this.expandItems(storedExpandedItems);
|
|
|
|
}
|
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();
|
|
|
|
};
|
|
|
|
},
|
|
|
|
]);
|