From 75071dfadea0f6f7a4bfef961bf8a2aacddbb8a8 Mon Sep 17 00:00:00 2001
From: Richard Wei <54336863+WaysonWei@users.noreply.github.com>
Date: Thu, 30 Sep 2021 15:53:03 +1300
Subject: [PATCH] feat(k8s): add filter for k8s application type EE-1627
(#5733)
* add filter for k8s application type
---
.../applicationsDatatable.html | 24 +++++++++++++++++--
.../applicationsDatatableController.js | 22 +++++++++++++++++
2 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/app/kubernetes/components/datatables/applications-datatable/applicationsDatatable.html b/app/kubernetes/components/datatables/applications-datatable/applicationsDatatable.html
index 20e35dd01..942fadf75 100644
--- a/app/kubernetes/components/datatables/applications-datatable/applicationsDatatable.html
+++ b/app/kubernetes/components/datatables/applications-datatable/applicationsDatatable.html
@@ -135,12 +135,32 @@
-
+ |
Application Type
+
+ Filter
+ Filter
+
+
|
Status
@@ -160,7 +180,7 @@
|
diff --git a/app/kubernetes/components/datatables/applications-datatable/applicationsDatatableController.js b/app/kubernetes/components/datatables/applications-datatable/applicationsDatatableController.js
index a635285ab..cbb423cfb 100644
--- a/app/kubernetes/components/datatables/applications-datatable/applicationsDatatableController.js
+++ b/app/kubernetes/components/datatables/applications-datatable/applicationsDatatableController.js
@@ -2,6 +2,7 @@ import { KubernetesApplicationDeploymentTypes, KubernetesApplicationTypes } from
import KubernetesApplicationHelper from 'Kubernetes/helpers/application';
import KubernetesNamespaceHelper from 'Kubernetes/helpers/namespaceHelper';
import { KubernetesConfigurationTypes } from 'Kubernetes/models/configuration/models';
+import _ from 'lodash-es';
angular.module('portainer.docker').controller('KubernetesApplicationsDatatableController', [
'$scope',
@@ -22,6 +23,14 @@ angular.module('portainer.docker').controller('KubernetesApplicationsDatatableCo
expandedItems: [],
});
+ this.filters = {
+ state: {
+ open: false,
+ enabled: false,
+ values: [],
+ },
+ };
+
this.expandAll = function () {
this.state.expandAll = !this.state.expandAll;
this.state.filteredDataSet.forEach((item) => this.expandItem(item, this.state.expandAll));
@@ -114,6 +123,19 @@ angular.module('portainer.docker').controller('KubernetesApplicationsDatatableCo
return !this.isSystemNamespace(item);
};
+ this.applyFilters = function (item) {
+ return ctrl.filters.state.values.some((filter) => item.ApplicationType === filter.type && filter.display);
+ };
+
+ this.onStateFilterChange = function () {
+ this.filters.state.enabled = this.filters.state.values.some((filter) => !filter.display);
+ };
+
+ this.prepareTableFromDataset = function () {
+ const availableTypeFilters = this.dataset.map((item) => ({ type: item.ApplicationType, display: true }));
+ this.filters.state.values = _.uniqBy(availableTypeFilters, 'type');
+ };
+
this.$onInit = function () {
this.isAdmin = Authentication.isAdmin();
this.KubernetesApplicationDeploymentTypes = KubernetesApplicationDeploymentTypes;