From 9bc35041d52041b9dcd34fb590070d3cc78108fd Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Tue, 25 Oct 2016 11:28:04 +0200 Subject: Add TODO module --- modules/todo/todo.html | 236 +++++++++++++++++++++++++++++++++++++++++++++++++ modules/todo/todo.js | 86 ++++++++++++++++++ 2 files changed, 322 insertions(+) create mode 100644 modules/todo/todo.html create mode 100644 modules/todo/todo.js (limited to 'modules/todo') diff --git a/modules/todo/todo.html b/modules/todo/todo.html new file mode 100644 index 0000000..ae13163 --- /dev/null +++ b/modules/todo/todo.html @@ -0,0 +1,236 @@ + + + + +TODO + + + + +

TODO

+
+

+ + + + diff --git a/modules/todo/todo.js b/modules/todo/todo.js new file mode 100644 index 0000000..3a86e68 --- /dev/null +++ b/modules/todo/todo.js @@ -0,0 +1,86 @@ +"use strict"; + +// {"key":"tasks","value":[{"id":1,"subject":"kaas rep","repweeks":0,"date":"2016-10-25T07:46:54.493Z"},{"id":2,"subject":"kaas","repweeks":0,"date":"2016-10-27T07:46:54.493Z"}]} + +var cmn=require("../$common.js"), + persist=require("node-persist"); + +var moddir=null; + +persist=persist.create({ + dir:"persist/todo", + continuous:false, + interval:false +}); +persist.initSync(); + +//tasks: [{id: Int,subject: String,repweeks: Int,date: Date}] +//repweeks==0 implies no repetition +var nextid=persist.getItemSync("nextid"); +if(nextid==null)nextid=1; +var tasks=persist.getItemSync("tasks"); +(function(){ + if(!tasks){ + tasks=[]; + persist.setItemSync("tasks",tasks); + } else { + for(var task of tasks){ + task.date=new Date(task.date); + if(nextid<=task.id)nextid=task.id+1; + } + persist.setItemSync("nextid",nextid); + } +})(); + + +module.exports=function(app,io,_moddir){ + moddir=_moddir; + // app.all(["/todo","/todo/*"],cmn.authgen()); + app.get("/todo",function(req,res){ + res.sendFile(moddir+"/todo.html"); + }); + app.get("/todo/list",function(req,res){ + res.json(tasks); + }); + app.delete("/todo/task",function(req,res){ + var id=+req.body; + var i; + var fail=false; + if(id<0||~~id!=id||isNaN(id)){ + fail=true; + } else { + for(i=0;i