Files
backroad/app/kubernetes/components/datatables/applications-datatable/applicationsDatatableController.js
Matt Hook d8793b2c96 feat(helm/views): helm release and application views EE-1236 (#5529)
* feat(helm): add helm chart backport to ce EE-1409 (#5425)

* EE-1311 Helm Chart Backport from EE

* backport to ce

Co-authored-by: Matt Hook <hookenz@gmail.com>

* Pull in all changes from tech review in EE-943

* added helm to sidebar after rebase, sync CE with EE

* removed redundant handler (not used) - to match EE

* feat(helm) display helm charts - backend EE-1236

* copy over components for new applications view EE-1236

* Add new applications datatable component

* Add more migrated files

* removed test not applicable to CE

* baclkported EE app data table code to CE

* removed redundant helm repo url

* resolved conflicts, updated code

* using endpoint middleware

* PR review fixes

* using constants, openapi updated

Co-authored-by: Richard Wei <54336863+WaysonWei@users.noreply.github.com>
Co-authored-by: zees-dev <dev.786zshan@gmail.com>
2021-09-02 16:22:51 +12:00

147 lines
5.2 KiB
JavaScript

import { KubernetesApplicationDeploymentTypes, KubernetesApplicationTypes } from 'Kubernetes/models/application/models';
import KubernetesApplicationHelper from 'Kubernetes/helpers/application';
import KubernetesNamespaceHelper from 'Kubernetes/helpers/namespaceHelper';
import { KubernetesConfigurationTypes } from 'Kubernetes/models/configuration/models';
angular.module('portainer.docker').controller('KubernetesApplicationsDatatableController', [
'$scope',
'$controller',
'DatatableService',
'Authentication',
function ($scope, $controller, DatatableService, Authentication) {
angular.extend(this, $controller('GenericDatatableController', { $scope: $scope }));
const ctrl = this;
this.settings = Object.assign(this.settings, {
showSystem: false,
});
this.state = Object.assign(this.state, {
expandAll: false,
expandedItems: [],
});
this.expandAll = function () {
this.state.expandAll = !this.state.expandAll;
this.state.filteredDataSet.forEach((item) => this.expandItem(item, this.state.expandAll));
};
this.expandItem = function (item, expanded) {
item.Expanded = expanded;
if (item.Expanded && !this.state.expandedItems.includes(item.Id)) {
this.state.expandedItems = [...this.state.expandedItems, item.Id];
} else {
this.state.expandedItems = this.state.expandedItems.filter((id) => id !== item.Id);
}
DatatableService.setDataTableExpandedItems(this.tableKey, this.state.expandedItems);
};
function expandPreviouslyExpandedItem(item, storedExpandedItems) {
const expandedItem = storedExpandedItems.some((storedId) => storedId === item.Id);
if (expandedItem) {
ctrl.expandItem(item, true);
}
}
this.expandItems = function (storedExpandedItems) {
let expandedItemCount = 0;
this.state.expandedItems = storedExpandedItems;
for (let i = 0; i < this.dataset.length; i++) {
const item = this.dataset[i];
expandPreviouslyExpandedItem(item, storedExpandedItems);
if (item.Expanded) {
++expandedItemCount;
}
}
if (expandedItemCount === this.dataset.length) {
this.state.expandAll = true;
}
};
this.onDataRefresh = function () {
const storedExpandedItems = DatatableService.getDataTableExpandedItems(this.tableKey);
if (storedExpandedItems !== null) {
this.expandItems(storedExpandedItems);
}
};
this.onSettingsShowSystemChange = function () {
DatatableService.setDataTableSettings(this.tableKey, this.settings);
};
this.isExternalApplication = function (item) {
return KubernetesApplicationHelper.isExternalApplication(item);
};
this.isSystemNamespace = function (item) {
// if all charts in a helm app/release are in the system namespace
if (item.KubernetesApplications && item.KubernetesApplications.length > 0) {
return item.KubernetesApplications.some((app) => KubernetesNamespaceHelper.isSystemNamespace(app.ResourcePool));
}
return KubernetesNamespaceHelper.isSystemNamespace(item.ResourcePool);
};
this.isDisplayed = function (item) {
return !ctrl.isSystemNamespace(item) || ctrl.settings.showSystem;
};
this.getPublishUrl = function (item) {
// Map all ingress rules in published ports to their respective URLs
const publishUrls = item.PublishedPorts.flatMap((pp) => pp.IngressRules).map(({ Host, IP, Path }) => `http://${Host || IP}${Path}`);
// Return the first URL
return publishUrls.length > 0 ? publishUrls[0] : '';
};
this.hasConfigurationSecrets = function (item) {
return item.Configurations && item.Configurations.some((config) => config.Data && config.Type === KubernetesConfigurationTypes.SECRET);
};
/**
* Do not allow applications in system namespaces to be selected
*/
this.allowSelection = function (item) {
return !this.isSystemNamespace(item);
};
this.$onInit = function () {
this.isAdmin = Authentication.isAdmin();
this.KubernetesApplicationDeploymentTypes = KubernetesApplicationDeploymentTypes;
this.KubernetesApplicationTypes = KubernetesApplicationTypes;
this.setDefaults();
this.prepareTableFromDataset();
this.state.orderBy = this.orderBy;
var storedOrder = DatatableService.getDataTableOrder(this.tableKey);
if (storedOrder !== null) {
this.state.reverseOrder = storedOrder.reverse;
this.state.orderBy = storedOrder.orderBy;
}
var textFilter = DatatableService.getDataTableTextFilters(this.tableKey);
if (textFilter !== null) {
this.state.textFilter = textFilter;
this.onTextFilterChange();
}
var storedFilters = DatatableService.getDataTableFilters(this.tableKey);
if (storedFilters !== null) {
this.filters = storedFilters;
}
if (this.filters && this.filters.state) {
this.filters.state.open = false;
}
var storedSettings = DatatableService.getDataTableSettings(this.tableKey);
if (storedSettings !== null) {
this.settings = storedSettings;
this.settings.open = false;
}
this.onSettingsRepeaterChange();
};
},
]);