From 93ddcfecd9943eb5e05aaeb6b0174abbb822624f Mon Sep 17 00:00:00 2001 From: Sven Dowideit Date: Tue, 15 Feb 2022 04:30:02 +1000 Subject: [PATCH] fix(templates): show docker-compose app templates when in swarm mode [EE-2117] (#6177) * fix(templates): EE-2117: show docker-compose app templates when in swarm mode and the user selects 'showContainers Signed-off-by: Sven Dowideit * fix(templates): keep original behavior for standalone * fix(templates): display all templates on Swarm * refactor(templates): update method name Co-authored-by: deviantony --- .../template-list/template-list-controller.js | 23 ++++++++++++------- .../template-list/templateList.html | 7 ++++-- .../views/templates/templatesController.js | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/app/portainer/components/template-list/template-list-controller.js b/app/portainer/components/template-list/template-list-controller.js index 1b95ab2df..23554347f 100644 --- a/app/portainer/components/template-list/template-list-controller.js +++ b/app/portainer/components/template-list/template-list-controller.js @@ -16,12 +16,26 @@ function TemplateListController($async, $state, DatatableService, Notifications, DatatableService.setDataTableTextFilters(this.tableKey, this.state.textFilter); }; + this.filterByTemplateType = function (item) { + switch (item.Type) { + case 1: // container + return ctrl.state.showContainerTemplates; + case 2: // swarm stack + return ctrl.showSwarmStacks; + case 3: // docker compose + return !ctrl.showSwarmStacks || (ctrl.showSwarmStacks && ctrl.state.showContainerTemplates); + case 4: // Edge stack templates + return false; + } + return false; + }; + this.updateCategories = function () { var availableCategories = []; for (var i = 0; i < ctrl.templates.length; i++) { var template = ctrl.templates[i]; - if ((template.Type === 1 && ctrl.state.showContainerTemplates) || (template.Type === 2 && ctrl.showSwarmStacks) || (template.Type === 3 && !ctrl.showSwarmStacks)) { + if (this.filterByTemplateType(template)) { availableCategories = availableCategories.concat(template.Categories); } } @@ -37,13 +51,6 @@ function TemplateListController($async, $state, DatatableService, Notifications, return _.includes(item.Categories, ctrl.state.selectedCategory); }; - this.filterByType = function (item) { - if ((item.Type === 1 && ctrl.state.showContainerTemplates) || (item.Type === 2 && ctrl.showSwarmStacks) || (item.Type === 3 && !ctrl.showSwarmStacks)) { - return true; - } - return false; - }; - this.duplicateTemplate = duplicateTemplate.bind(this); this.duplicateTemplateAsync = duplicateTemplateAsync.bind(this); function duplicateTemplate(template) { diff --git a/app/portainer/components/template-list/templateList.html b/app/portainer/components/template-list/templateList.html index 30f91c787..25ef2681b 100644 --- a/app/portainer/components/template-list/templateList.html +++ b/app/portainer/components/template-list/templateList.html @@ -45,7 +45,7 @@
Loading...
-
+
No templates available.
diff --git a/app/portainer/views/templates/templatesController.js b/app/portainer/views/templates/templatesController.js index a9d9964cf..ce3456117 100644 --- a/app/portainer/views/templates/templatesController.js +++ b/app/portainer/views/templates/templatesController.js @@ -259,7 +259,7 @@ angular.module('portainer.app').controller('TemplatesController', [ deployable = endpoint.mode.provider === DOCKER_SWARM_MODE; break; case 3: - deployable = endpoint.mode.provider === DOCKER_STANDALONE; + deployable = endpoint.mode.provider === DOCKER_SWARM_MODE || endpoint.mode.provider === DOCKER_STANDALONE; break; } return deployable;