Delete playbook

This commit is contained in:
Matej Kramny 2014-08-25 00:24:40 +01:00
parent f5c9f996ef
commit 34cc4a7c7d
5 changed files with 22 additions and 8 deletions

View File

@ -13,11 +13,7 @@ var schema = mongoose.Schema({
name: String,
password: String,
private_key: String,
public_key: String,
playbook: {
type: ObjectId,
ref: 'Playbook'
},
public_key: String
});
schema.index({

View File

@ -20,6 +20,9 @@ html
ul.nav
h2.text-center: a(ui-sref="homepage") Semaphore
button.btn.btn-block.btn-default(ui-sref="addPlaybook") Add Playbook
button.btn.btn-block.btn-default(ui-sref="credentials.list") Credentials
br
li(ng-repeat="playbook in playbooks")
a(ui-sref="playbook.view({ playbook_id: playbook._id })") {{ playbook.name }}

View File

@ -1,3 +1,4 @@
h1 {{ playbook.data.name }}
button.btn.btn-danger.pull-right(ng-click="delete()") Delete
pre: code: {{ playbook }}

View File

@ -1,7 +1,16 @@
define([
'app'
], function(app) {
app.registerController('PlaybookCtrl', ['$scope', function($scope) {
app.registerController('PlaybookCtrl', ['$scope', '$state', '$rootScope', '$http', function($scope, $state, $rootScope, $http) {
console.log($scope.playbook);
$scope.delete = function () {
$scope.playbook.delete();
$http.get('/playbooks').success(function(data, status) {
$rootScope.playbooks = data;
});
$state.transitionTo('homepage');
}
}]);
});

View File

@ -22,10 +22,15 @@ define([
$scope.playbook = playbook;
},
resolve: {
playbook: function (Playbook, $stateParams, $q) {
playbook: function (Playbook, $stateParams, $q, $state) {
var deferred = $q.defer();
var playbook = new Playbook($stateParams.playbook_id, function (err, errStatus) {
if (err && errStatus == 404) {
$state.transitionTo('homepage');
return deferred.reject();
}
deferred.resolve(playbook);
});