From 345ff4d1825b696b30f2bd4d00e151ece3c744bf Mon Sep 17 00:00:00 2001 From: Denis Gukov Date: Tue, 24 Oct 2017 14:43:54 +0500 Subject: [PATCH] feat(template): hidden templates --- public/html/projects/templates/list.pug | 12 +++-- public/js/controllers/projects/templates.js | 52 +++++++++++++++++++-- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/public/html/projects/templates/list.pug b/public/html/projects/templates/list.pug index a0fb27891..3c8951e5a 100644 --- a/public/html/projects/templates/list.pug +++ b/public/html/projects/templates/list.pug @@ -1,5 +1,7 @@ h3 Task Templates - button.btn.btn-success.btn-xs.pull-right(ng-click="add()") New Template + button.btn.btn-success.btn-xs.pull-right(ng-click="add()" style="margin-left: 5px;") New Template + button.btn.btn-default.btn-xs.pull-right(ng-if="allShown" ng-click="hideHidden()") Hide Hidden + button.btn.btn-default.btn-xs.pull-right(ng-if="!allShown" ng-click="showAll()") Show Hidden table.table.table-hover thead: tr @@ -10,7 +12,7 @@ table.table.table-hover th Environment th Repository th   - tbody: tr(ng-repeat="tpl in templates" ng-click="update(tpl)" style="cursor: pointer;") + tbody: tr(ng-repeat="tpl in templates" ng-click="update(tpl)" style="cursor: pointer;" ng-if="!tpl.hidden || allShown") td {{ tpl.alias }} td {{ tpl.playbook }} td {{ sshKeysAssoc[tpl.ssh_key_id].name }} @@ -18,5 +20,7 @@ table.table.table-hover td {{ environmentAssoc[tpl.environment_id].name }} td {{ reposAssoc[tpl.repository_id].name }} td: .pull-right - button.btn.btn-info.btn-xs(ng-click="copy(tpl); $event.stopPropagation();") copy - button.btn.btn-success.btn-xs(ng-click="run(tpl); $event.stopPropagation();", style="margin-left: 5px;") run + button.btn.btn-default.btn-xs(ng-if="!tpl.hidden" ng-click="hideTemplate(tpl); $event.stopPropagation();") hide + button.btn.btn-default.btn-xs(ng-if="tpl.hidden" ng-click="showTemplate(tpl); $event.stopPropagation();") show + button.btn.btn-info.btn-xs(ng-click="copy(tpl); $event.stopPropagation();" style="margin-left: 5px;") copy + button.btn.btn-success.btn-xs(ng-click="run(tpl); $event.stopPropagation();" style="margin-left: 5px;") run diff --git a/public/js/controllers/projects/templates.js b/public/js/controllers/projects/templates.js index 97bfffa16..2bc3f8ac7 100644 --- a/public/js/controllers/projects/templates.js +++ b/public/js/controllers/projects/templates.js @@ -1,5 +1,5 @@ define(['controllers/projects/taskRunner'], function () { - app.registerController('ProjectTemplatesCtrl', ['$scope', '$http', '$uibModal', 'Project', '$rootScope', function ($scope, $http, $modal, Project, $rootScope) { + app.registerController('ProjectTemplatesCtrl', ['$scope', '$http', '$uibModal', 'Project', '$rootScope', '$window', function ($scope, $http, $modal, Project, $rootScope, $window) { $http.get(Project.getURL() + '/keys?type=ssh').success(function (keys) { $scope.sshKeys = keys; @@ -39,8 +39,27 @@ define(['controllers/projects/taskRunner'], function () { }); }); + function getHiddenTemplates() { + try { + return JSON.parse($window.localStorage.getItem('hidden-templates') || '[]') + } catch(e) { + return []; + } + } + + function setHiddenTemplates(hiddenTemplates) { + $window.localStorage.setItem('hidden-templates', JSON.stringify(hiddenTemplates)); + } + $scope.reload = function () { $http.get(Project.getURL() + '/templates?sort=alias&order=asc').success(function (templates) { + var hiddenTemplates = getHiddenTemplates(); + for (var i in templates) { + var template = templates[i]; + if (hiddenTemplates.indexOf(template.id) !== -1) { + template.hidden = true; + } + } $scope.templates = templates; }); } @@ -96,7 +115,7 @@ define(['controllers/projects/taskRunner'], function () { swal('error', 'could not add template:' + status, 'error'); }); }).closed.then(function () { - $scope.reload(); + $scope.reload(); }); } @@ -126,6 +145,33 @@ define(['controllers/projects/taskRunner'], function () { }) } + $scope.showAll = function() { + $scope.allShown = true; + } + + $scope.hideHidden = function() { + $scope.allShown = false; + } + + $scope.hideTemplate = function(template) { + var hiddenTemplates = getHiddenTemplates(); + if (hiddenTemplates.indexOf(template.id) === -1) { + hiddenTemplates.push(template.id); + } + setHiddenTemplates(hiddenTemplates); + template.hidden = true; + } + + $scope.showTemplate = function(template) { + var hiddenTemplates = getHiddenTemplates(); + var i = hiddenTemplates.indexOf(template.id); + if (i !== -1) { + hiddenTemplates.splice(i, 1); + } + setHiddenTemplates(hiddenTemplates); + delete template.hidden; + } + $scope.copy = function (template) { var tpl = angular.copy(template); tpl.id = null; @@ -152,4 +198,4 @@ define(['controllers/projects/taskRunner'], function () { $scope.reload(); }]); -}); \ No newline at end of file +});