summaryrefslogtreecommitdiff
path: root/modules/todo/todo.js
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-02-25 09:55:13 +0100
committertomsmeding <tom.smeding@gmail.com>2017-02-25 09:55:13 +0100
commit823d072ad49e30832d167e4c04bdf1b64b5a5336 (patch)
tree1f18ac0404ce2fe09de7d6889eb7aa4af97f80ca /modules/todo/todo.js
parent54e0f34a0430fb3dd5dfe46f1a01e61a22e822e3 (diff)
todo: Shift ahead repeating items
Diffstat (limited to 'modules/todo/todo.js')
-rw-r--r--modules/todo/todo.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/modules/todo/todo.js b/modules/todo/todo.js
index 66433d9..8fabc63 100644
--- a/modules/todo/todo.js
+++ b/modules/todo/todo.js
@@ -52,6 +52,18 @@ var naccounts=0;
})();
+function shiftDate(date,repweeks){
+ var Y=date.getFullYear(),
+ M=date.getMonth(),
+ D=date.getDate(),
+ h=date.getHours(),
+ m=date.getMinutes(),
+ s=date.getSeconds(),
+ ms=date.getMilliseconds();
+ return new Date(Y,M,D+7*repweeks,h,m,s,ms);
+}
+
+
function sendUnauth(res){
res.set("WWW-Authenticate","Basic realm=Authorization required");
return res.sendStatus(401);
@@ -161,6 +173,33 @@ module.exports=function(app,io,_moddir){
if(fail)res.status(404).send("Unknown id");
else res.status(200).end();
});
+ app.post("/todo/task/shiftahead",function(req,res){
+ var id=+req.body;
+ var i;
+ var fail=false;
+ var usertasks=tasks[req.authuser];
+ var now;
+ if(id<0||~~id!=id||isNaN(id)||!usertasks){
+ fail=true;
+ } else {
+ for(i=0;i<usertasks.length;i++)if(usertasks[i].id==id)break;
+ if(i==usertasks.length)fail=true;
+ else if(usertasks[i].repweeks==0){
+ res.status(400).send("Can't shiftahead a non-repeating task");
+ return;
+ } else {
+ now=new Date();
+ while(usertasks[i].date<now){ // First move up to now
+ usertasks[i].date=shiftDate(usertasks[i].date,usertasks[i].repweeks);
+ }
+ // Then for the actual shiftahead:
+ usertasks[i].date=shiftDate(usertasks[i].date,usertasks[i].repweeks);
+ persist.setItemSync("tasks",tasks);
+ }
+ }
+ if(fail)res.status(404).send("Unknown id");
+ else res.status(200).end();
+ });
app.post("/todo/task",function(req,res){
var obj;
try {