1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 15:59:41 +02:00

feat(kube): introduce custom templates [EE-1125] (#5434)

* feat(kube): introduce custom templates

refactor(customtemplates): use build option

chore(deps): upgrade yaml parser

feat(customtemplates): add and edit RC to kube templates

fix(kube): show docker icon

fix(custom-templates): save rc

* fix(kube/templates): route to correct routes
This commit is contained in:
Chaim Lev-Ari 2021-09-02 08:28:51 +03:00 committed by GitHub
parent a176ec5ace
commit e4fe4f9a43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 1562 additions and 107 deletions

View file

@ -0,0 +1,6 @@
import controller from './kube-custom-templates-view.controller.js';
export const kubeCustomTemplatesView = {
templateUrl: './kube-custom-templates-view.html',
controller,
};

View file

@ -0,0 +1,79 @@
import _ from 'lodash-es';
export default class KubeCustomTemplatesViewController {
/* @ngInject */
constructor($async, $state, Authentication, CustomTemplateService, FormValidator, ModalService, Notifications) {
Object.assign(this, { $async, $state, Authentication, CustomTemplateService, FormValidator, ModalService, Notifications });
this.state = {
selectedTemplate: null,
formValidationError: '',
actionInProgress: false,
};
this.currentUser = {
isAdmin: false,
id: null,
};
this.isEditAllowed = this.isEditAllowed.bind(this);
this.getTemplates = this.getTemplates.bind(this);
this.validateForm = this.validateForm.bind(this);
this.confirmDelete = this.confirmDelete.bind(this);
this.selectTemplate = this.selectTemplate.bind(this);
}
selectTemplate(template) {
this.$state.go('kubernetes.deploy', { templateId: template.Id });
}
isEditAllowed(template) {
// todo - check if current user is admin/endpointadmin/owner
return this.currentUser.isAdmin || this.currentUser.id === template.CreatedByUserId;
}
getTemplates() {
return this.$async(async () => {
try {
this.templates = await this.CustomTemplateService.customTemplates(3);
} catch (err) {
this.Notifications.error('Failed loading templates', err, 'Unable to load custom templates');
}
});
}
validateForm(accessControlData, isAdmin) {
this.state.formValidationError = '';
const error = this.FormValidator.validateAccessControl(accessControlData, isAdmin);
if (error) {
this.state.formValidationError = error;
return false;
}
return true;
}
confirmDelete(templateId) {
return this.$async(async () => {
const confirmed = await this.ModalService.confirmDeletionAsync('Are you sure that you want to delete this template?');
if (!confirmed) {
return;
}
try {
await this.CustomTemplateService.remove(templateId);
_.remove(this.templates, { Id: templateId });
} catch (err) {
this.Notifications.error('Failure', err, 'Failed to delete template');
}
});
}
$onInit() {
this.getTemplates();
this.currentUser.isAdmin = this.Authentication.isAdmin();
const user = this.Authentication.getUserDetails();
this.currentUser.id = user.ID;
}
}

View file

@ -0,0 +1,25 @@
<rd-header id="view-top">
<rd-header-title title-text="Custom Templates">
<a data-toggle="tooltip" title="Refresh" ui-sref="kubernetes.templates.custom" ui-sref-opts="{reload: true}">
<i class="fa fa-sync" aria-hidden="true"></i>
</a>
</rd-header-title>
<rd-header-content>Custom Templates</rd-header-content>
</rd-header>
<div class="row">
<div class="col-sm-12">
<custom-templates-list
ng-if="$ctrl.templates"
title-text="Templates"
title-icon="fa-rocket"
templates="$ctrl.templates"
table-key="customTemplates"
is-edit-allowed="$ctrl.isEditAllowed"
on-select-click="($ctrl.selectTemplate)"
on-delete-click="($ctrl.confirmDelete)"
create-path="kubernetes.templates.custom.new"
edit-path="kubernetes.templates.custom.edit"
></custom-templates-list>
</div>
</div>