2016-04-02 14:40:07 +02:00
|
|
|
define(function () {
|
2016-04-13 18:09:44 +02:00
|
|
|
app.registerController('ProjectEnvironmentCtrl', ['$scope', '$http', '$uibModal', 'Project', '$rootScope', function ($scope, $http, $modal, Project, $rootScope) {
|
2016-04-07 14:49:34 +02:00
|
|
|
$scope.reload = function () {
|
|
|
|
$http.get(Project.getURL() + '/environment').success(function (environment) {
|
|
|
|
$scope.environment = environment;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.remove = function (environment) {
|
|
|
|
$http.delete(Project.getURL() + '/environment/' + environment.id).success(function () {
|
|
|
|
$scope.reload();
|
2016-06-17 22:16:46 +02:00
|
|
|
}).error(function (d) {
|
|
|
|
if (!(d && d.inUse)) {
|
|
|
|
swal('error', 'could not delete environment..', 'error');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
swal({
|
|
|
|
title: 'Environment in use',
|
|
|
|
text: d.error,
|
|
|
|
type: 'error',
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonColor: "#DD6B55",
|
|
|
|
confirmButtonText: 'Mark as removed'
|
|
|
|
}, function () {
|
|
|
|
$http.delete(Project.getURL() + '/environment/' + environment.id + '?setRemoved=1').success(function () {
|
|
|
|
$scope.reload();
|
|
|
|
}).error(function () {
|
|
|
|
swal('error', 'could not delete environment..', 'error');
|
|
|
|
});
|
|
|
|
});
|
2016-04-07 14:49:34 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-13 18:09:44 +02:00
|
|
|
$scope.add = function () {
|
2016-06-14 05:40:16 +02:00
|
|
|
var scope = $rootScope.$new();
|
|
|
|
scope.env = {
|
|
|
|
json: '{}'
|
|
|
|
};
|
|
|
|
|
2016-04-13 18:09:44 +02:00
|
|
|
$modal.open({
|
2016-06-14 05:40:16 +02:00
|
|
|
templateUrl: '/tpl/projects/environment/add.html',
|
|
|
|
scope: scope
|
2016-04-13 18:09:44 +02:00
|
|
|
}).result.then(function (env) {
|
2016-06-25 11:39:55 +02:00
|
|
|
$http.post(Project.getURL() + '/environment', env.environment)
|
2016-04-13 18:09:44 +02:00
|
|
|
.success(function () {
|
|
|
|
$scope.reload();
|
|
|
|
}).error(function (_, status) {
|
|
|
|
swal('Erorr', 'Environment not added: ' + status, 'error');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.editEnvironment = function (env) {
|
|
|
|
var scope = $rootScope.$new();
|
2016-06-14 05:40:16 +02:00
|
|
|
scope.env = env;
|
2016-04-13 18:09:44 +02:00
|
|
|
|
|
|
|
$modal.open({
|
2016-06-14 05:40:16 +02:00
|
|
|
templateUrl: '/tpl/projects/environment/add.html',
|
2016-04-13 18:09:44 +02:00
|
|
|
scope: scope
|
2016-06-17 22:16:46 +02:00
|
|
|
}).result.then(function (opts) {
|
|
|
|
if (opts.remove) {
|
|
|
|
return $scope.remove(env);
|
|
|
|
}
|
|
|
|
|
|
|
|
$http.put(Project.getURL() + '/environment/' + env.id, opts.environment)
|
2016-04-13 18:09:44 +02:00
|
|
|
.success(function () {
|
|
|
|
$scope.reload();
|
|
|
|
}).error(function (_, status) {
|
|
|
|
swal('Erorr', 'Environment not updated: ' + status, 'error');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-07 14:49:34 +02:00
|
|
|
$scope.reload();
|
2016-04-02 14:40:07 +02:00
|
|
|
}]);
|
2016-06-25 11:39:55 +02:00
|
|
|
});
|