mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-23 12:30:41 +01:00
Add playbooks via GUI
This commit is contained in:
parent
7c466863f2
commit
2e60b91c63
1
Vagrantfile
vendored
1
Vagrantfile
vendored
@ -5,6 +5,7 @@ VAGRANTFILE_API_VERSION = "2"
|
||||
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
config.vm.box = "hashicorp/precise32"
|
||||
config.vm.network :forwarded_port, guest: 3000, host: 3000
|
||||
|
||||
config.vm.provider "virtualbox" do |vb|
|
||||
# vb.gui = true
|
||||
|
@ -11,6 +11,7 @@ exports.router = function(app) {
|
||||
]);
|
||||
|
||||
templates.add('homepage')
|
||||
templates.add('abstract')
|
||||
templates.setup();
|
||||
|
||||
app.get('/', layout);
|
||||
|
64
lib/routes/playbook/playbook.js
Normal file
64
lib/routes/playbook/playbook.js
Normal file
@ -0,0 +1,64 @@
|
||||
var models = require('../../models')
|
||||
var mongoose = require('mongoose')
|
||||
var express = require('express')
|
||||
|
||||
exports.unauthorized = function (app, template) {
|
||||
template([
|
||||
'view'
|
||||
], {
|
||||
prefix: 'playbook'
|
||||
});
|
||||
}
|
||||
|
||||
exports.httpRouter = function (app) {
|
||||
}
|
||||
|
||||
exports.router = function (app) {
|
||||
var playbook = express.Router();
|
||||
|
||||
playbook.get('/', view)
|
||||
.put('/', save)
|
||||
.delete('/', remove)
|
||||
|
||||
app.param('playbook_id', getPlaybook)
|
||||
app.use('/playbook/:playbook_id', playbook);
|
||||
}
|
||||
|
||||
function getPlaybook (req, res, next, id) {
|
||||
models.Playbook.findOne({
|
||||
_id: id
|
||||
}, function (err, playbook) {
|
||||
if (err || !playbook) {
|
||||
return res.send(404);
|
||||
}
|
||||
|
||||
req.playbook = playbook;
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
function view (req, res) {
|
||||
res.send(req.playbook);
|
||||
}
|
||||
|
||||
function save (req, res) {
|
||||
req.playbook.name = req.body.name;
|
||||
req.playbook.location = req.body.location;
|
||||
|
||||
if (req.body.vault_password.length > 0) {
|
||||
req.playbook.vault_password = req.body.vault_password;
|
||||
}
|
||||
|
||||
try {
|
||||
req.playbook.credential = mongoose.Types.ObjectId(req.body.credential);
|
||||
} catch (e) {}
|
||||
|
||||
req.playbook.save();
|
||||
res.send(201);
|
||||
}
|
||||
|
||||
function remove (req, res) {
|
||||
req.playbook.remove(function (err) {
|
||||
res.send(201);
|
||||
})
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
var models = require('../../models')
|
||||
var mongoose = require('mongoose')
|
||||
|
||||
var playbook = require('./playbook')
|
||||
|
||||
exports.unauthorized = function (app, template) {
|
||||
template([
|
||||
@ -6,19 +9,39 @@ exports.unauthorized = function (app, template) {
|
||||
], {
|
||||
prefix: 'playbook'
|
||||
});
|
||||
|
||||
playbook.unauthorized(app, template);
|
||||
}
|
||||
|
||||
exports.httpRouter = function () {
|
||||
|
||||
exports.httpRouter = function (app) {
|
||||
playbook.httpRouter(app);
|
||||
}
|
||||
|
||||
exports.router = function (app) {
|
||||
app.get('/playbooks', getPlaybooks)
|
||||
.post('/playbooks', addPlaybook)
|
||||
|
||||
playbook.router(app);
|
||||
}
|
||||
|
||||
function getPlaybooks (req, res) {
|
||||
models.Playbook.find({
|
||||
}, function (err, playbooks) {
|
||||
}).sort('-created').exec(function (err, playbooks) {
|
||||
res.send(playbooks)
|
||||
})
|
||||
}
|
||||
|
||||
function addPlaybook (req, res) {
|
||||
var playbook = new models.Playbook({
|
||||
name: req.body.name,
|
||||
location: req.body.location,
|
||||
vault_password: req.body.vault_password
|
||||
})
|
||||
try {
|
||||
playbook.credential = mongoose.Types.ObjectId(req.body.credential)
|
||||
} catch (e) {}
|
||||
|
||||
playbook.save(function () {
|
||||
res.send(201);
|
||||
})
|
||||
}
|
1
lib/views/abstract.jade
Normal file
1
lib/views/abstract.jade
Normal file
@ -0,0 +1 @@
|
||||
ui-view(autoscroll="false")
|
@ -22,7 +22,7 @@ html
|
||||
button.btn.btn-block.btn-default(ui-sref="addPlaybook") Add Playbook
|
||||
|
||||
li(ng-repeat="playbook in playbooks")
|
||||
a(ui-sref="playbook({ pid: playbook._id })") {{ playbook.name }}
|
||||
a(ui-sref="playbook.view({ playbook_id: playbook._id })") {{ playbook.name }}
|
||||
|
||||
.col-sm-9.col-lg-10
|
||||
block content
|
||||
|
@ -1 +1,21 @@
|
||||
h1 Add Playbook
|
||||
h1 Add Playbook
|
||||
|
||||
form.form-horizontal
|
||||
.form-group
|
||||
label.control-label.col-sm-4 Name
|
||||
.col-sm-7
|
||||
input.form-control(type="text" placeholder="Playbook Name" ng-model="playbook.data.name")
|
||||
|
||||
.form-group
|
||||
label.control-label.col-sm-4 Location
|
||||
.col-sm-7
|
||||
input.form-control(type="text" placeholder="Git Location" ng-model="playbook.data.location")
|
||||
|
||||
.form-group
|
||||
label.control-label.col-sm-4 Vault Password
|
||||
.col-sm-7
|
||||
input.form-control(type="text" placeholder="Vault Password" ng-model="playbook.data.vault_password")
|
||||
|
||||
.form-group
|
||||
.col-sm-7.col-sm-offset-4
|
||||
button.btn.btn-default(ng-click="playbook.add()") Add
|
3
lib/views/playbook/view.jade
Normal file
3
lib/views/playbook/view.jade
Normal file
@ -0,0 +1,3 @@
|
||||
h1 {{ playbook.data.name }}
|
||||
|
||||
pre: code: {{ playbook }}
|
8
public/js/controllers/playbook/add.js
Normal file
8
public/js/controllers/playbook/add.js
Normal file
@ -0,0 +1,8 @@
|
||||
define([
|
||||
'app',
|
||||
'factories/playbook'
|
||||
], function(app) {
|
||||
app.registerController('AddPlaybookCtrl', ['$scope', 'Playbook', function($scope, Playbook) {
|
||||
$scope.playbook = new Playbook();
|
||||
}]);
|
||||
});
|
7
public/js/controllers/playbook/playbook.js
Normal file
7
public/js/controllers/playbook/playbook.js
Normal file
@ -0,0 +1,7 @@
|
||||
define([
|
||||
'app'
|
||||
], function(app) {
|
||||
app.registerController('PlaybookCtrl', ['$scope', function($scope) {
|
||||
console.log($scope.playbook);
|
||||
}]);
|
||||
});
|
40
public/js/factories/playbook.js
Normal file
40
public/js/factories/playbook.js
Normal file
@ -0,0 +1,40 @@
|
||||
define(['app'], function (app) {
|
||||
app.registerFactory('Playbook', ['$http', function ($http) {
|
||||
var Playbook = function (id, cb) {
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.id = id;
|
||||
|
||||
this.get(cb);
|
||||
}
|
||||
|
||||
Playbook.prototype.save = function () {
|
||||
$http.put('/playbook/'+this.data._id, this.data);
|
||||
}
|
||||
|
||||
Playbook.prototype.add = function () {
|
||||
$http.post('/playbooks', this.data);
|
||||
}
|
||||
|
||||
Playbook.prototype.delete = function () {
|
||||
$http.delete('/playbook/'+this.data._id, this.data);
|
||||
}
|
||||
|
||||
Playbook.prototype.get = function (cb) {
|
||||
var self = this;
|
||||
|
||||
$http.get('/playbook/'+this.id)
|
||||
.success(function (data, status) {
|
||||
self.data = data;
|
||||
cb();
|
||||
})
|
||||
.error(function (data, status) {
|
||||
cb(data, status);
|
||||
})
|
||||
}
|
||||
|
||||
return Playbook;
|
||||
}])
|
||||
})
|
@ -1,12 +1,46 @@
|
||||
define([
|
||||
'app'
|
||||
'app',
|
||||
'factories/playbook'
|
||||
], function(app) {
|
||||
app.config(function($stateProvider) {
|
||||
app.config(function($stateProvider, $couchPotatoProvider) {
|
||||
$stateProvider
|
||||
.state('addPlaybook', {
|
||||
url: '/add',
|
||||
pageTitle: 'Add Playbook',
|
||||
templateUrl: "/view/playbook/add"
|
||||
templateUrl: "/view/playbook/add",
|
||||
controller: 'AddPlaybookCtrl',
|
||||
resolve: {
|
||||
dummy: $couchPotatoProvider.resolve(['controllers/playbook/add'])
|
||||
}
|
||||
})
|
||||
|
||||
.state('playbook', {
|
||||
abstract: true,
|
||||
url: '/playbook/:playbook_id',
|
||||
templateUrl: '/view/abstract',
|
||||
controller: function ($scope, playbook) {
|
||||
$scope.playbook = playbook;
|
||||
},
|
||||
resolve: {
|
||||
playbook: function (Playbook, $stateParams, $q) {
|
||||
var deferred = $q.defer();
|
||||
|
||||
var playbook = new Playbook($stateParams.playbook_id, function (err, errStatus) {
|
||||
deferred.resolve(playbook);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
.state('playbook.view', {
|
||||
url: '/',
|
||||
controller: 'PlaybookCtrl',
|
||||
templateUrl: '/view/playbook/view',
|
||||
resolve: {
|
||||
dummy: $couchPotatoProvider.resolve(['controllers/playbook/playbook'])
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user