1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-07 14:55:27 +02:00

feat(edge/templates): introduce edge app templates [EE-6209] (#10480)

This commit is contained in:
Chaim Lev-Ari 2023-11-14 14:54:44 +02:00 committed by GitHub
parent 95d96e1164
commit e1e90c9c1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
58 changed files with 1142 additions and 365 deletions

View file

@ -38,6 +38,17 @@ export const ngModule = angular
'isVariablesNamesFromParent',
])
)
.component(
'appTemplatesList',
r2a(withUIRouter(withCurrentUser(AppTemplatesList)), [
'onSelect',
'templates',
'selectedId',
'disabledTypes',
'fixedCategories',
'hideDuplicate',
])
)
.component(
'customTemplatesList',
r2a(withUIRouter(withCurrentUser(CustomTemplatesList)), [
@ -54,15 +65,6 @@ export const ngModule = angular
.component(
'customTemplatesTypeSelector',
r2a(TemplateTypeSelector, ['onChange', 'value'])
)
.component(
'appTemplatesList',
r2a(withUIRouter(withCurrentUser(AppTemplatesList)), [
'onSelect',
'templates',
'selectedId',
'showSwarmStacks',
])
);
withFormValidation(

View file

@ -118,7 +118,7 @@ export const ngModule = angular
)
.component(
'fallbackImage',
r2a(FallbackImage, ['src', 'fallbackIcon', 'alt', 'size', 'className'])
r2a(FallbackImage, ['src', 'fallbackIcon', 'alt', 'className'])
)
.component('prIcon', r2a(Icon, ['className', 'icon', 'mode', 'size', 'spin']))
.component(

View file

@ -5,6 +5,7 @@ import { getTemplateVariables, intersectVariables } from '@/react/portainer/cust
import { isBE } from '@/react/portainer/feature-flags/feature-flags.service';
import { editor, upload, git } from '@@/BoxSelector/common-options/build-methods';
import { confirmWebEditorDiscard } from '@@/modals/confirm';
import { fetchFilePreview } from '@/react/portainer/templates/app-templates/queries/useFetchTemplateInfoMutation';
class CreateCustomTemplateViewController {
/* @ngInject */
@ -218,38 +219,43 @@ class CreateCustomTemplateViewController {
}
async $onInit() {
const applicationState = this.StateManager.getState();
return this.$async(async () => {
const applicationState = this.StateManager.getState();
this.state.endpointMode = applicationState.endpoint.mode;
let stackType = 0;
if (this.state.endpointMode.provider === 'DOCKER_STANDALONE') {
this.isDockerStandalone = true;
stackType = 2;
} else if (this.state.endpointMode.provider === 'DOCKER_SWARM_MODE') {
stackType = 1;
}
this.formValues.Type = stackType;
const { fileContent, type } = this.$state.params;
this.formValues.FileContent = fileContent;
if (type) {
this.formValues.Type = +type;
}
try {
this.templates = await this.CustomTemplateService.customTemplates([1, 2]);
} catch (err) {
this.Notifications.error('Failure loading', err, 'Failed loading custom templates');
}
this.state.loading = false;
this.$window.onbeforeunload = () => {
if (this.state.Method === 'editor' && this.formValues.FileContent && this.state.isEditorDirty) {
return '';
this.state.endpointMode = applicationState.endpoint.mode;
let stackType = 0;
if (this.state.endpointMode.provider === 'DOCKER_STANDALONE') {
this.isDockerStandalone = true;
stackType = 2;
} else if (this.state.endpointMode.provider === 'DOCKER_SWARM_MODE') {
stackType = 1;
}
};
this.formValues.Type = stackType;
const { appTemplateId, type } = this.$state.params;
if (type) {
this.formValues.Type = +type;
}
if (appTemplateId) {
this.formValues.FileContent = await fetchFilePreview(appTemplateId);
}
try {
this.templates = await this.CustomTemplateService.customTemplates([1, 2]);
} catch (err) {
this.Notifications.error('Failure loading', err, 'Failed loading custom templates');
}
this.state.loading = false;
this.$window.onbeforeunload = () => {
if (this.state.Method === 'editor' && this.formValues.FileContent && this.state.isEditorDirty) {
return '';
}
};
});
}
$onDestroy() {

View file

@ -270,9 +270,4 @@
<!-- container-form -->
</div>
<app-templates-list
templates="templates"
on-select="(selectTemplate)"
selected-id="state.selectedTemplate.Id"
show-swarm-stacks="applicationState.endpoint.mode.provider === 'DOCKER_SWARM_MODE' && applicationState.endpoint.mode.role === 'MANAGER' && applicationState.endpoint.apiVersion >= 1.25"
></app-templates-list>
<app-templates-list templates="templates" on-select="(selectTemplate)" selected-id="state.selectedTemplate.Id" disabled-types="disabledTypes"></app-templates-list>

View file

@ -1,4 +1,5 @@
import _ from 'lodash-es';
import { TemplateType } from '@/react/portainer/templates/app-templates/types';
import { AccessControlFormData } from '../../components/accessControlForm/porAccessControlFormModel';
angular.module('portainer.app').controller('TemplatesController', [
@ -48,6 +49,8 @@ angular.module('portainer.app').controller('TemplatesController', [
actionInProgress: false,
};
$scope.enabledTypes = [TemplateType.Container, TemplateType.ComposeStack];
$scope.formValues = {
network: '',
name: '',
@ -282,6 +285,10 @@ angular.module('portainer.app').controller('TemplatesController', [
var apiVersion = $scope.applicationState.endpoint.apiVersion;
const endpointId = +$state.params.endpointId;
const showSwarmStacks = endpointMode.provider === 'DOCKER_SWARM_MODE' && endpointMode.role === 'MANAGER' && apiVersion >= 1.25;
$scope.disabledTypes = !showSwarmStacks ? [TemplateType.SwarmStack] : [];
$q.all({
templates: TemplateService.templates(endpointId),
volumes: VolumeService.getVolumes(),