Create and Edit crontabs
parent
035d432b7a
commit
b73c16c8c4
19
app.js
19
app.js
|
@ -8,6 +8,12 @@ var routes = require("./routes").routes;
|
|||
// set the view engine to ejs
|
||||
app.set('view engine', 'ejs');
|
||||
|
||||
var bodyParser = require('body-parser')
|
||||
app.use( bodyParser.json() ); // to support JSON-encoded bodies
|
||||
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
|
||||
extended: true
|
||||
}));
|
||||
|
||||
// include all folders
|
||||
app.use(express.static(__dirname + '/public'));
|
||||
app.use(express.static(__dirname + '/public/css'));
|
||||
|
@ -21,7 +27,6 @@ app.get(routes.root, function(req, res) {
|
|||
//crontab.create_new("/usr/bin/find", "0 2 12 * *");
|
||||
//crontab.create_new("/sbin/ping -c 1 192.168.0.1 > /dev/null", "* * * * *");
|
||||
crontab.crontabs( function(docs){
|
||||
console.log(docs);
|
||||
res.render('index', {
|
||||
routes : routes,
|
||||
crontabs : JSON.stringify(docs)
|
||||
|
@ -29,8 +34,16 @@ app.get(routes.root, function(req, res) {
|
|||
});
|
||||
})
|
||||
|
||||
app.get(routes.save, function(req, res) {
|
||||
res.render('index');
|
||||
app.post(routes.save, function(req, res) {
|
||||
// new job
|
||||
if(req.body._id == -1){
|
||||
crontab.create_new(req.body.name, req.body.command, req.body.schedule);
|
||||
}
|
||||
// edit job
|
||||
else{
|
||||
crontab.update(req.body);
|
||||
}
|
||||
res.end();
|
||||
})
|
||||
|
||||
app.listen(app.get('port'), function() {
|
||||
|
|
|
@ -11,7 +11,7 @@ crontab = function(name, command, schedule, stopped){
|
|||
data.name = name;
|
||||
data.command = command;
|
||||
data.schedule = schedule;
|
||||
data.stopped = stopped;
|
||||
if(stopped != null) data.stopped = stopped;
|
||||
data.timestamp = (new Date()).toString();
|
||||
return data;
|
||||
}
|
||||
|
@ -21,12 +21,14 @@ exports.create_new = function(name, command, schedule){
|
|||
db.insert(tab);
|
||||
}
|
||||
|
||||
exports.update = function(data){
|
||||
db.update({_id: data._id}, crontab(data.name, data.command, data.schedule, null));
|
||||
}
|
||||
exports.crontabs = function(callback){
|
||||
db.find({}, function(err, docs){
|
||||
callback(docs);
|
||||
});
|
||||
}
|
||||
|
||||
exports.set_crontab = function(){
|
||||
exports.crontabs( function(tabs){
|
||||
var crontab_string = "";
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
"dependencies": {
|
||||
"express": "latest",
|
||||
"ejs": "latest",
|
||||
"nedb": "latest"
|
||||
"nedb": "latest",
|
||||
"body-parser": "latest"
|
||||
},
|
||||
"engines": {
|
||||
"node": "latest"
|
||||
|
|
|
@ -52,7 +52,6 @@ function editJob(_id){
|
|||
// if macro not used
|
||||
if(job.schedule.indexOf("@") != 0){
|
||||
var components = job.schedule.split(" ");
|
||||
console.log(components);
|
||||
$("#job-minute").val(components[0]);
|
||||
$("#job-hour").val(components[1]);
|
||||
$("#job-day").val(components[2]);
|
||||
|
@ -63,10 +62,34 @@ function editJob(_id){
|
|||
job_command = job.command;
|
||||
job_string();
|
||||
}
|
||||
|
||||
$("#job-save").click(function(){
|
||||
// TODO good old boring validations
|
||||
$.post("/save", {name: $("#job-name").val(), command: job_command , schedule: schedule, _id: _id}, function(){
|
||||
location.reload();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function newJob(){
|
||||
schedule = ""
|
||||
job_command = ""
|
||||
$("#job-minute").val("*");
|
||||
$("#job-hour").val("*");
|
||||
$("#job-day").val("*");
|
||||
$("#job-month").val("*");
|
||||
$("#job-week").val("*");
|
||||
|
||||
$("#job").modal("show");
|
||||
$("#job-name").val("");
|
||||
$("#job-command").val("");
|
||||
job_string();
|
||||
$("#job-save").click(function(){
|
||||
// TODO good old boring validations
|
||||
$.post("/save", {name: $("#job-name").val(), command: job_command , schedule: schedule, _id: -1}, function(){
|
||||
location.reload();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -82,3 +105,4 @@ function set_schedule(){
|
|||
schedule = $("#job-minute").val() + " " +$("#job-hour").val() + " " +$("#job-day").val() + " " +$("#job-month").val() + " " +$("#job-week").val();
|
||||
job_string();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
exports.routes = {
|
||||
"root" : "/",
|
||||
"downloads" : "/downloads",
|
||||
"save" : "/save"
|
||||
"save" : "/save",
|
||||
"crontab" : "/crontab"
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||
<button type="button" class="btn btn-primary" data-dismiss="modal">Save</button>
|
||||
<button type="button" class="btn btn-primary" data-dismiss="modal" id="job-save">Save</button>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
|
|
Loading…
Reference in New Issue