2016-04-17 02:20:23 +02:00
|
|
|
define(['controllers/projects/taskRunner'], function () {
|
2016-04-11 12:02:10 +02:00
|
|
|
app.registerController('ProjectTemplatesCtrl', ['$scope', '$http', '$uibModal', 'Project', '$rootScope', function ($scope, $http, $modal, Project, $rootScope) {
|
|
|
|
$http.get(Project.getURL() + '/keys?type=ssh').success(function (keys) {
|
|
|
|
$scope.sshKeys = keys;
|
|
|
|
|
|
|
|
$scope.sshKeysAssoc = {};
|
|
|
|
keys.forEach(function (k) {
|
2016-06-17 22:16:46 +02:00
|
|
|
if (k.removed) k.name = '[removed] - ' + k.name;
|
2016-04-11 12:02:10 +02:00
|
|
|
$scope.sshKeysAssoc[k.id] = k;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$http.get(Project.getURL() + '/inventory').success(function (inv) {
|
|
|
|
$scope.inventory = inv;
|
|
|
|
|
|
|
|
$scope.inventoryAssoc = {};
|
|
|
|
inv.forEach(function (i) {
|
2016-06-17 22:16:46 +02:00
|
|
|
if (i.removed) i.name = '[removed] - ' + i.name;
|
2016-04-11 12:02:10 +02:00
|
|
|
$scope.inventoryAssoc[i.id] = i;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$http.get(Project.getURL() + '/repositories').success(function (repos) {
|
|
|
|
$scope.repos = repos;
|
|
|
|
|
|
|
|
$scope.reposAssoc = {};
|
|
|
|
repos.forEach(function (i) {
|
2016-06-17 22:16:46 +02:00
|
|
|
if (i.removed) i.name = '[removed] - ' + i.name;
|
|
|
|
|
2016-04-11 12:02:10 +02:00
|
|
|
$scope.reposAssoc[i.id] = i;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$http.get(Project.getURL() + '/environment').success(function (env) {
|
|
|
|
$scope.environment = env;
|
|
|
|
|
|
|
|
$scope.environmentAssoc = {};
|
|
|
|
env.forEach(function (i) {
|
2016-06-17 22:16:46 +02:00
|
|
|
if (i.removed) i.name = '[removed] - ' + i.name;
|
|
|
|
|
2016-04-11 12:02:10 +02:00
|
|
|
$scope.environmentAssoc[i.id] = i;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-04-07 14:49:34 +02:00
|
|
|
$scope.reload = function () {
|
|
|
|
$http.get(Project.getURL() + '/templates').success(function (templates) {
|
|
|
|
$scope.templates = templates;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-16 21:42:57 +02:00
|
|
|
$scope.remove = function (template) {
|
|
|
|
$http.delete(Project.getURL() + '/templates/' + template.id).success(function () {
|
2016-04-07 14:49:34 +02:00
|
|
|
$scope.reload();
|
|
|
|
}).error(function () {
|
|
|
|
swal('error', 'could not delete template..', 'error');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-11 12:02:10 +02:00
|
|
|
$scope.add = function () {
|
|
|
|
var scope = $rootScope.$new();
|
|
|
|
scope.keys = $scope.sshKeys;
|
|
|
|
scope.inventory = $scope.inventory;
|
|
|
|
scope.repositories = $scope.repos;
|
|
|
|
scope.environment = $scope.environment;
|
|
|
|
|
|
|
|
$modal.open({
|
|
|
|
templateUrl: '/tpl/projects/templates/add.html',
|
|
|
|
scope: scope
|
2016-06-17 22:16:46 +02:00
|
|
|
}).result.then(function (opts) {
|
|
|
|
var tpl = opts.template;
|
2016-04-11 12:02:10 +02:00
|
|
|
$http.post(Project.getURL() + '/templates', tpl).success(function () {
|
|
|
|
$scope.reload();
|
|
|
|
}).error(function (_, status) {
|
|
|
|
swal('error', 'could not add template:' + status, 'error');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-06-17 22:16:46 +02:00
|
|
|
$scope.update = function (template) {
|
|
|
|
var scope = $rootScope.$new();
|
|
|
|
scope.tpl = template;
|
|
|
|
scope.keys = $scope.sshKeys;
|
|
|
|
scope.inventory = $scope.inventory;
|
|
|
|
scope.repositories = $scope.repos;
|
|
|
|
scope.environment = $scope.environment;
|
|
|
|
|
|
|
|
$modal.open({
|
|
|
|
templateUrl: '/tpl/projects/templates/add.html',
|
|
|
|
scope: scope
|
|
|
|
}).result.then(function (opts) {
|
|
|
|
if (opts.remove) {
|
|
|
|
return $scope.remove(template);
|
|
|
|
}
|
|
|
|
|
|
|
|
var tpl = opts.template;
|
|
|
|
$http.put(Project.getURL() + '/templates/' + template.id, tpl).success(function () {
|
|
|
|
$scope.reload();
|
|
|
|
}).error(function (_, status) {
|
|
|
|
swal('error', 'could not add template:' + status, 'error');
|
|
|
|
});
|
2017-02-15 07:20:57 +01:00
|
|
|
}).closed.then(function () {
|
|
|
|
$scope.reload();
|
2016-06-17 22:16:46 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-17 02:20:23 +02:00
|
|
|
$scope.run = function (tpl) {
|
|
|
|
$modal.open({
|
|
|
|
templateUrl: '/tpl/projects/createTaskModal.html',
|
|
|
|
controller: 'CreateTaskCtrl',
|
|
|
|
resolve: {
|
|
|
|
Project: function () {
|
|
|
|
return Project;
|
|
|
|
},
|
|
|
|
Template: function () {
|
|
|
|
return tpl;
|
|
|
|
}
|
|
|
|
}
|
2016-05-08 11:36:17 +02:00
|
|
|
}).result.then(function (task) {
|
|
|
|
var scope = $rootScope.$new();
|
|
|
|
scope.task = task;
|
|
|
|
scope.project = Project;
|
|
|
|
|
|
|
|
$modal.open({
|
|
|
|
templateUrl: '/tpl/projects/taskModal.html',
|
|
|
|
controller: 'TaskCtrl',
|
|
|
|
scope: scope,
|
|
|
|
size: 'lg'
|
|
|
|
});
|
2016-04-17 02:20:23 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-04-07 14:49:34 +02:00
|
|
|
$scope.reload();
|
2016-04-02 14:40:07 +02:00
|
|
|
}]);
|
|
|
|
});
|