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
pull/4889/head
Maxime Bajeux 2021-02-23 00:52:18 +01:00 committed by GitHub
parent 44b6aaedc8
commit c84da11a91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 24 deletions

View File

@ -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
}

View File

@ -55,7 +55,7 @@
<button
type="button"
class="btn btn-primary btn-sm"
ng-disabled="$ctrl.state.actionInProgress || !$ctrl.formValues.name"
ng-disabled="$ctrl.state.actionInProgress || !$ctrl.formValues.name || $ctrl.state.provider !== $ctrl.template.Type"
ng-click="$ctrl.createTemplate()"
button-spinner="$ctrl.state.actionInProgress"
>
@ -63,7 +63,10 @@
<span ng-show="$ctrl.state.actionInProgress">Deployment in progress...</span>
</button>
<button type="button" class="btn btn-sm btn-default" ng-click="$ctrl.unselectTemplate($ctrl.template)">Hide</button>
<span class="text-danger" ng-if="$ctrl.state.formValidationError" style="margin-left: 5px;">{{ $ctrl.state.formValidationError }}</span>
<div class="cols-sm-12 small text-danger" ng-if="$ctrl.state.formValidationError" style="margin-left: 5px; margin-top: 5px;">{{ $ctrl.state.formValidationError }}</div>
<div class="cols-sm-12 small text-danger" ng-if="$ctrl.state.provider !== $ctrl.template.Type" style="margin-left: 5px; margin-top: 5px;"
>This template type cannot be deployed on this endpoint.</div
>
</div>
</div>
<!-- !actions -->

View File

@ -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);

View File

@ -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(),