1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29:41 +02:00
portainer/app/kubernetes/components/datatables/volumes-datatable/volumesDatatableController.js
Chaim Lev-Ari 1830a80a61
feat(k8s/resource-pool): add the ability to mark/unmark resource pool as system (#5360)
* feat(k8s/resource-pool): add the ability to mark/unmark resource pool as system

fix(kube/ns): check label to see if namespace is system

refactor(k8s/namespaces): rename variables

feat(kubernetes): toggle system state in the server (#5361)

fix(app/resource-pool): UI fixes

feat(app/resource-pool): add confirmation modal when unamrking system namespace

* refactor(app): review changes

* feat(app/namespaces): introduce store to retrieve namespace system status without changing all the kubernetes models

refactor(app/namespaces): remove unused code first introduced for system tagging

fix(app/namespaces): cache namespaces to retrieve system status regardless of namespace reference format

refactor(app): migrate namespace store from helper to a separate singleton

refactor(app): remove KubernetesNamespaceHelper from DI cycle

* refactor(app): normalize usage of KubernetesNamespaceHelper functions

* refactor(app/k8s): change namespace store to functions instead of class

Co-authored-by: LP B <xAt0mZ@users.noreply.github.com>
2021-08-26 16:00:59 +02:00

90 lines
2.8 KiB
JavaScript

import angular from 'angular';
import KubernetesVolumeHelper from 'Kubernetes/helpers/volumeHelper';
import KubernetesNamespaceHelper from 'Kubernetes/helpers/namespaceHelper';
// TODO: review - refactor to use `extends GenericDatatableController`
class KubernetesVolumesDatatableController {
/* @ngInject */
constructor($async, $controller, Authentication, DatatableService) {
this.$async = $async;
this.$controller = $controller;
this.Authentication = Authentication;
this.DatatableService = DatatableService;
this.onInit = this.onInit.bind(this);
this.allowSelection = this.allowSelection.bind(this);
this.isDisplayed = this.isDisplayed.bind(this);
}
onSettingsShowSystemChange() {
this.DatatableService.setDataTableSettings(this.tableKey, this.settings);
}
disableRemove(item) {
return this.isSystemNamespace(item) || this.isUsed(item);
}
isUsed(item) {
return KubernetesVolumeHelper.isUsed(item);
}
isSystemNamespace(item) {
return KubernetesNamespaceHelper.isSystemNamespace(item.ResourcePool.Namespace.Name);
}
isDisplayed(item) {
return !this.isSystemNamespace(item) || this.settings.showSystem;
}
isExternalVolume(item) {
return KubernetesVolumeHelper.isExternalVolume(item);
}
allowSelection(item) {
return !this.disableRemove(item);
}
async onInit() {
this.setDefaults();
this.prepareTableFromDataset();
this.isAdmin = this.Authentication.isAdmin();
this.settings.showSystem = false;
this.state.orderBy = this.orderBy;
var storedOrder = this.DatatableService.getDataTableOrder(this.tableKey);
if (storedOrder !== null) {
this.state.reverseOrder = storedOrder.reverse;
this.state.orderBy = storedOrder.orderBy;
}
var textFilter = this.DatatableService.getDataTableTextFilters(this.tableKey);
if (textFilter !== null) {
this.state.textFilter = textFilter;
this.onTextFilterChange();
}
var storedFilters = this.DatatableService.getDataTableFilters(this.tableKey);
if (storedFilters !== null) {
this.filters = storedFilters;
}
if (this.filters && this.filters.state) {
this.filters.state.open = false;
}
var storedSettings = this.DatatableService.getDataTableSettings(this.tableKey);
if (storedSettings !== null) {
this.settings = storedSettings;
this.settings.open = false;
}
this.onSettingsRepeaterChange();
}
$onInit() {
const ctrl = angular.extend({}, this.$controller('GenericDatatableController'), this);
angular.extend(this, ctrl);
return this.$async(this.onInit);
}
}
export default KubernetesVolumesDatatableController;
angular.module('portainer.kubernetes').controller('KubernetesVolumesDatatableController', KubernetesVolumesDatatableController);