From 768f1aa663e9091b8c71df6ab9bf0fe42312c1c9 Mon Sep 17 00:00:00 2001 From: LP B Date: Fri, 8 Jul 2022 04:15:23 +0200 Subject: [PATCH] fix(k8s/app-templates): display moustache variables fields when deploying from app template (#7184) --- app/kubernetes/views/deploy/deploy.html | 2 +- .../stacks/create/createStackController.js | 41 ++++++++++++++++--- .../views/stacks/create/createstack.html | 22 ++++++---- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/app/kubernetes/views/deploy/deploy.html b/app/kubernetes/views/deploy/deploy.html index 203ac0e5b..f55d395af 100644 --- a/app/kubernetes/views/deploy/deploy.html +++ b/app/kubernetes/views/deploy/deploy.html @@ -90,7 +90,7 @@ > { + if (!template || ($scope.state.selectedTemplateId === templateId && $scope.state.selectedTemplate === template)) { + return; + } + try { $scope.state.selectedTemplateId = templateId; $scope.state.selectedTemplate = template; const fileContent = await CustomTemplateService.customTemplateFile(templateId); - $scope.onChangeFileContent(fileContent); + $scope.state.templateContent = fileContent; + onChangeFileContent(fileContent); + + if (template.Variables && template.Variables.length > 0) { + const variables = Object.fromEntries(template.Variables.map((variable) => [variable.name, ''])); + onChangeTemplateVariables(variables); + } } catch (err) { - this.Notifications.error('Failure', err, 'Unable to retrieve Custom Template file'); + Notifications.error('Failure', err, 'Unable to retrieve Custom Template file'); } }); } + function onChangeTemplateVariables(value) { + onChangeFormValues({ Variables: value }); + + if (!$scope.isTemplateVariablesEnabled) { + return; + } + const rendered = renderTemplate($scope.state.templateContent, $scope.formValues.Variables, $scope.state.selectedTemplate.Variables); + onChangeFormValues({ StackFileContent: rendered }); + } + async function initView() { var endpointMode = $scope.applicationState.endpoint.mode; $scope.state.StackType = 2; @@ -328,8 +354,11 @@ angular initView(); - function onChangeFormValues(newValues) { - $scope.formValues = newValues; + function onChangeFormValues(values) { + $scope.formValues = { + ...$scope.formValues, + ...values, + }; } } ); diff --git a/app/portainer/views/stacks/create/createstack.html b/app/portainer/views/stacks/create/createstack.html index 135e8cafe..d8cb2c633 100644 --- a/app/portainer/views/stacks/create/createstack.html +++ b/app/portainer/views/stacks/create/createstack.html @@ -128,13 +128,21 @@ path-placeholder="docker-compose.yml" > - +
+ + + +