diff --git a/.gitignore b/.gitignore index c3c1388..16b5a70 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.swp node_modules +crontabs/*.db diff --git a/app.js b/app.js index d9065b9..afda546 100755 --- a/app.js +++ b/app.js @@ -1,5 +1,9 @@ var express = require('express'); var app = express(); +var crontab = require("./crontab"); + +// include the routes +var routes = require("./routes").routes; // set the view engine to ejs app.set('view engine', 'ejs'); @@ -8,11 +12,23 @@ app.set('view engine', 'ejs'); app.use(express.static(__dirname + '/public')); app.use(express.static(__dirname + '/public/css')); app.use(express.static(__dirname + '/public/js')); + +//set port app.set('port', (process.env.PORT || 8000)); -app.get('/', function(req, res) { - res.render('index'); - //res.sendFile('index.htm'); +app.get(routes.root, function(req, res) { + // get all the crontabs + crontab.crontabs( function(docs){ + console.log(docs); + res.render('index', { + routes : routes, + crontabs : docs + }); + }); +}) + +app.get(routes.save, function(req, res) { + res.render('index'); }) app.listen(app.get('port'), function() { diff --git a/crontab.js b/crontab.js new file mode 100644 index 0000000..a7a7909 --- /dev/null +++ b/crontab.js @@ -0,0 +1,29 @@ +//load database +var Datastore = require('nedb'); +var db = new Datastore({ filename: __dirname + '/crontabs/crontab.db' }); +db.loadDatabase(function (err) { +}); + +crontab = function(command, schedule, stopped){ + var data = {}; + data.command = command; + data.schedule = schedule; + data.stopped = stopped; + data.timestamp = (new Date()).toString(); + return data; +} + +exports.create_new = function(command, schedule){ + var tab = crontab(command, schedule, false); + db.insert(tab); +} + +exports.crontabs = function(callback){ + var finished = false; + db.find({}, function(err, docs){ + finished = true; + callback(docs); + }); +} + + diff --git a/crontabs/README.md b/crontabs/README.md new file mode 100644 index 0000000..6adc7ad --- /dev/null +++ b/crontabs/README.md @@ -0,0 +1 @@ +This folder will have all the crontab database files diff --git a/package.json b/package.json index f561275..68751d7 100755 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ }, "dependencies": { "express": "latest", - "ejs": "latest" + "ejs": "latest", + "nedb": "latest" }, "engines": { "node": "latest" diff --git a/routes.js b/routes.js new file mode 100644 index 0000000..fcf12cb --- /dev/null +++ b/routes.js @@ -0,0 +1,5 @@ +exports.routes = { + "root" : "/", + "downloads" : "/downloads", + "save" : "/save" +} diff --git a/views/index.ejs b/views/index.ejs index 023ec31..5a7bda2 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -6,38 +6,7 @@ - +<% include navbar %>

Jobs

@@ -47,26 +16,33 @@ - - - - - - + <% crontabs.forEach(function(crontab){ %> + <% if (!crontab.stopped) { %> + + + + + + + <% } else { %> + + + + + + + <% } %> + <% }); %> + + - - - - - -
Last Modified
Sample testing ascasdcas - Edit - Stop - -
<%= crontab.command %><%= crontab.schedule %><%= crontab.timestamp %> + Edit + Stop + +
<%= crontab.command %><%= crontab.schedule %><%= crontab.timestamp %> + Start + +
/var/spool/cron/crontab -s -l -d testing ascasdcas - Start - -
New Backup diff --git a/views/navbar.ejs b/views/navbar.ejs new file mode 100644 index 0000000..e1b66c9 --- /dev/null +++ b/views/navbar.ejs @@ -0,0 +1,32 @@ +