From c84da11a91e0477c60034c01ed499d10153d41ce Mon Sep 17 00:00:00 2001 From: Maxime Bajeux Date: Tue, 23 Feb 2021 00:52:18 +0100 Subject: [PATCH] feat(custom-templates): switching a template to standalone makes it disappear in swarm mode (#4829) * feat(custom-templates): switching a template to standalone makes it disappear in swarm mode * feat(custom-template): disable deploy button and add an error message * fix(custom-template): invert variable * fix(custom-templates): put the warning message below the button --- .../customtemplates/customtemplate_list.go | 23 +------------------ .../stackFromTemplateForm.html | 7 ++++-- .../customTemplatesViewController.js | 2 ++ .../views/templates/templatesController.js | 1 + 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/api/http/handler/customtemplates/customtemplate_list.go b/api/http/handler/customtemplates/customtemplate_list.go index b33cb8297..c9f4d3d30 100644 --- a/api/http/handler/customtemplates/customtemplate_list.go +++ b/api/http/handler/customtemplates/customtemplate_list.go @@ -4,9 +4,8 @@ import ( "net/http" httperror "github.com/portainer/libhttp/error" - "github.com/portainer/libhttp/request" "github.com/portainer/libhttp/response" - "github.com/portainer/portainer/api" + portainer "github.com/portainer/portainer/api" "github.com/portainer/portainer/api/http/security" "github.com/portainer/portainer/api/internal/authorization" ) @@ -17,8 +16,6 @@ func (handler *Handler) customTemplateList(w http.ResponseWriter, r *http.Reques return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve custom templates from the database", err} } - stackType, _ := request.RetrieveNumericQueryParameter(r, "type", true) - resourceControls, err := handler.DataStore.ResourceControl().ResourceControls() if err != nil { return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve resource controls from the database", err} @@ -26,8 +23,6 @@ func (handler *Handler) customTemplateList(w http.ResponseWriter, r *http.Reques customTemplates = authorization.DecorateCustomTemplates(customTemplates, resourceControls) - customTemplates = filterTemplatesByEngineType(customTemplates, portainer.StackType(stackType)) - securityContext, err := security.RetrieveRestrictedRequestContext(r) if err != nil { return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve info from request context", err} @@ -49,19 +44,3 @@ func (handler *Handler) customTemplateList(w http.ResponseWriter, r *http.Reques return response.JSON(w, customTemplates) } - -func filterTemplatesByEngineType(templates []portainer.CustomTemplate, stackType portainer.StackType) []portainer.CustomTemplate { - if stackType == 0 { - return templates - } - - filteredTemplates := []portainer.CustomTemplate{} - - for _, template := range templates { - if template.Type == stackType { - filteredTemplates = append(filteredTemplates, template) - } - } - - return filteredTemplates -} diff --git a/app/portainer/components/forms/stack-from-template-form/stackFromTemplateForm.html b/app/portainer/components/forms/stack-from-template-form/stackFromTemplateForm.html index a7aac8910..336ccb8a4 100644 --- a/app/portainer/components/forms/stack-from-template-form/stackFromTemplateForm.html +++ b/app/portainer/components/forms/stack-from-template-form/stackFromTemplateForm.html @@ -55,7 +55,7 @@ - {{ $ctrl.state.formValidationError }} +
{{ $ctrl.state.formValidationError }}
+
This template type cannot be deployed on this endpoint.
diff --git a/app/portainer/views/custom-templates/custom-templates-view/customTemplatesViewController.js b/app/portainer/views/custom-templates/custom-templates-view/customTemplatesViewController.js index ff456add3..fa50213ba 100644 --- a/app/portainer/views/custom-templates/custom-templates-view/customTemplatesViewController.js +++ b/app/portainer/views/custom-templates/custom-templates-view/customTemplatesViewController.js @@ -40,6 +40,7 @@ class CustomTemplatesViewController { formValidationError: '', actionInProgress: false, isEditorVisible: false, + provider: 0, }; this.currentUser = { @@ -231,6 +232,7 @@ class CustomTemplatesViewController { apiVersion, } = applicationState; + this.state.provider = endpointMode.provider === 'DOCKER_STANDALONE' ? 2 : 1; this.getTemplates(endpointMode); this.getNetworks(endpointMode.provider, apiVersion); diff --git a/app/portainer/views/templates/templatesController.js b/app/portainer/views/templates/templatesController.js index 1b27ae9af..34f90a9d6 100644 --- a/app/portainer/views/templates/templatesController.js +++ b/app/portainer/views/templates/templatesController.js @@ -254,6 +254,7 @@ angular.module('portainer.app').controller('TemplatesController', [ var endpointMode = $scope.applicationState.endpoint.mode; var apiVersion = $scope.applicationState.endpoint.apiVersion; + this.state.provider = endpointMode.provider === 'DOCKER_STANDALONE' ? 2 : 1; $q.all({ templates: TemplateService.templates(),