Skip to content

Commit

Permalink
feat(template): hidden templates
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Oct 24, 2017
1 parent f48c7fa commit 345ff4d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
12 changes: 8 additions & 4 deletions public/html/projects/templates/list.pug
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,13 +12,15 @@ 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 }}
td {{ inventoryAssoc[tpl.inventory_id].name }}
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
52 changes: 49 additions & 3 deletions public/js/controllers/projects/templates.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;
});
}
Expand Down Expand Up @@ -96,7 +115,7 @@ define(['controllers/projects/taskRunner'], function () {
swal('error', 'could not add template:' + status, 'error');
});
}).closed.then(function () {
$scope.reload();
$scope.reload();
});
}

Expand Down Expand Up @@ -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;
Expand All @@ -152,4 +198,4 @@ define(['controllers/projects/taskRunner'], function () {

$scope.reload();
}]);
});
});

0 comments on commit 345ff4d

Please sign in to comment.