From 120e058346e8e533763bcccb95bea2f26305f554 Mon Sep 17 00:00:00 2001 From: Philip How Date: Mon, 4 Mar 2013 00:18:04 +0000 Subject: [PATCH 1/4] onlies now reset their value every day --- src/app/scoring.coffee | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/app/scoring.coffee b/src/app/scoring.coffee index f9f13a909c..4726d7baaf 100644 --- a/src/app/scoring.coffee +++ b/src/app/scoring.coffee @@ -216,6 +216,9 @@ cron = (model) -> value = obj.tasks[taskObj.id].value #get updated value absVal = if (completed) then Math.abs(value) else value todoTally += absVal + else if type is 'habit' #reset 'onlies' value to 0 + if taskObj.up==false or taskObj.down==false + batch.set "tasks.#{taskObj.id}.value", 0 # Finished tallying obj.history ?= {}; obj.history.todos ?= []; obj.history.exp ?= [] From 4919cd22b55e4c0c0354f7d47f0f4b64ec75d316 Mon Sep 17 00:00:00 2001 From: Daniel Saewitz Date: Sun, 3 Mar 2013 19:30:53 -0500 Subject: [PATCH 2/4] Move deprecated API back to deprecated --- src/server/api.coffee | 38 +----------------------------------- src/server/deprecated.coffee | 35 +++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 39 deletions(-) diff --git a/src/server/api.coffee b/src/server/api.coffee index 7ab6d75e07..e27a28fc4e 100644 --- a/src/server/api.coffee +++ b/src/server/api.coffee @@ -113,42 +113,6 @@ router.get '/user/tasks', auth, (req, res) -> res.json 200, tasks -### - This is called form deprecated.coffee's score function, and the req.headers are setup properly to handle the login -### -scoreTask = (req, res, next) -> - auth req, res, -> - {taskId, direction} = req.params - {title, service, icon} = req.body - - # Send error responses for improper API call - return res.send(500, ':taskId required') unless taskId - return res.send(500, ":direction must be 'up' or 'down'") unless direction in ['up','down'] - - model = req.getModel() - {user, userObj} = req - - model.ref('_user', user) - - # Create task if doesn't exist - # TODO add service & icon to task - unless model.get("_user.tasks.#{taskId}") - model.refList "_habitList", "_user.tasks", "_user.habitIds" - model.at('_habitList').push - id: taskId - type: 'habit' - text: (title || taskId) - value: 0 - up: true - down: true - notes: "This task was created by a third-party service. Feel free to edit, it won't harm the connection to that service. Additionally, multiple services may piggy-back off this task." - - delta = scoring.score(model, taskId, direction) - result = model.get ('_user.stats') - result.delta = delta - res.send(result) -router.post '/user/tasks/:taskId/:direction', scoreTask - module.exports = router -module.exports.scoreTask = scoreTask # export so deprecated can call it +module.exports.auth = auth # export so deprecated can call it diff --git a/src/server/deprecated.coffee b/src/server/deprecated.coffee index a1c1ff817c..e97d7e6710 100644 --- a/src/server/deprecated.coffee +++ b/src/server/deprecated.coffee @@ -15,10 +15,41 @@ router.get '/:uid/down/:score?', (req, res) -> res.send(500, deprecatedMessage) router.post '/users/:uid/tasks/:taskId/:direction', (req, res) -> res.send(500, deprecatedMessage) # Redirect to new API -router.post '/v1/users/:uid/tasks/:taskId/:direction', (req, res, next) -> +initDeprecated = (req, res, next) -> req.headers['x-api-user'] = req.params.uid req.headers['x-api-key'] = req.body.apiToken - api.scoreTask(req, res, next) + next() + +router.post '/v1/users/:uid/tasks/:taskId/:direction', initDeprecated, api.auth, (req, res) -> + {taskId, direction} = req.params + {title, service, icon} = req.body + + # Send error responses for improper API call + return res.send(500, ':taskId required') unless taskId + return res.send(500, ":direction must be 'up' or 'down'") unless direction in ['up','down'] + + model = req.getModel() + {user, userObj} = req + + model.ref('_user', user) + + # Create task if doesn't exist + # TODO add service & icon to task + unless model.get("_user.tasks.#{taskId}") + model.refList "_habitList", "_user.tasks", "_user.habitIds" + model.at('_habitList').push + id: taskId + type: 'habit' + text: (title || taskId) + value: 0 + up: true + down: true + notes: "This task was created by a third-party service. Feel free to edit, it won't harm the connection to that service. Additionally, multiple services may piggy-back off this task." + + delta = scoring.score(model, taskId, direction) + result = model.get ('_user.stats') + result.delta = delta + res.send(result) router.get '/v1/users/:uid/calendar.ics', (req, res) -> #return next() #disable for now From 30a3e46f20b576000c77611a9f80e987e004bd17 Mon Sep 17 00:00:00 2001 From: Daniel Saewitz Date: Sun, 3 Mar 2013 19:37:54 -0500 Subject: [PATCH 3/4] Move deprecated api back into new --- src/server/api.coffee | 41 ++++++++++++++++++++++++++++++++++-- src/server/deprecated.coffee | 33 ++--------------------------- 2 files changed, 41 insertions(+), 33 deletions(-) diff --git a/src/server/api.coffee b/src/server/api.coffee index e27a28fc4e..8927f6172b 100644 --- a/src/server/api.coffee +++ b/src/server/api.coffee @@ -113,6 +113,43 @@ router.get '/user/tasks', auth, (req, res) -> res.json 200, tasks -module.exports = router -module.exports.auth = auth # export so deprecated can call it +### + This is called form deprecated.coffee's score function, and the req.headers are setup properly to handle the login +### +scoreTask = (req, res, next) -> + {taskId, direction} = req.params + {title, service, icon} = req.body + + # Send error responses for improper API call + return res.send(500, ':taskId required') unless taskId + return res.send(500, ":direction must be 'up' or 'down'") unless direction in ['up','down'] + + model = req.getModel() + {user, userObj} = req + + model.ref('_user', user) + + # Create task if doesn't exist + # TODO add service & icon to task + unless model.get("_user.tasks.#{taskId}") + model.refList "_habitList", "_user.tasks", "_user.habitIds" + model.at('_habitList').push + id: taskId + type: 'habit' + text: (title || taskId) + value: 0 + up: true + down: true + notes: "This task was created by a third-party service. Feel free to edit, it won't harm the connection to that service. Additionally, multiple services may piggy-back off this task." + + delta = scoring.score(model, taskId, direction) + result = model.get ('_user.stats') + result.delta = delta + res.send(result) + +router.post '/user/tasks/:taskId/:direction', auth, scoreTask + +module.exports = router +module.exports.auth = auth +module.exports.scoreTask = scoreTask # export so deprecated can call it diff --git a/src/server/deprecated.coffee b/src/server/deprecated.coffee index e97d7e6710..3fcef2c8a3 100644 --- a/src/server/deprecated.coffee +++ b/src/server/deprecated.coffee @@ -20,36 +20,7 @@ initDeprecated = (req, res, next) -> req.headers['x-api-key'] = req.body.apiToken next() -router.post '/v1/users/:uid/tasks/:taskId/:direction', initDeprecated, api.auth, (req, res) -> - {taskId, direction} = req.params - {title, service, icon} = req.body - - # Send error responses for improper API call - return res.send(500, ':taskId required') unless taskId - return res.send(500, ":direction must be 'up' or 'down'") unless direction in ['up','down'] - - model = req.getModel() - {user, userObj} = req - - model.ref('_user', user) - - # Create task if doesn't exist - # TODO add service & icon to task - unless model.get("_user.tasks.#{taskId}") - model.refList "_habitList", "_user.tasks", "_user.habitIds" - model.at('_habitList').push - id: taskId - type: 'habit' - text: (title || taskId) - value: 0 - up: true - down: true - notes: "This task was created by a third-party service. Feel free to edit, it won't harm the connection to that service. Additionally, multiple services may piggy-back off this task." - - delta = scoring.score(model, taskId, direction) - result = model.get ('_user.stats') - result.delta = delta - res.send(result) +router.post '/v1/users/:uid/tasks/:taskId/:direction', initDeprecated, api.auth, api.scoreTask router.get '/v1/users/:uid/calendar.ics', (req, res) -> #return next() #disable for now @@ -78,4 +49,4 @@ router.get '/v1/users/:uid/calendar.ics', (req, res) -> formattedIcal = ical.toString().replace(/DTSTART\:/g, 'DTSTART;VALUE=DATE:') res.send(200, formattedIcal) -module.exports = router \ No newline at end of file +module.exports = router From 35cea7fcbb086556e26db6e5ab19b719d9478ac2 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Sun, 3 Mar 2013 20:59:14 -0500 Subject: [PATCH 4/4] notification on "onlies" mechanic --- src/app/character.coffee | 3 +++ views/app/alerts.html | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/app/character.coffee b/src/app/character.coffee index 19a64d0fd3..3acbaba2b3 100644 --- a/src/app/character.coffee +++ b/src/app/character.coffee @@ -60,6 +60,9 @@ module.exports.app = (appExports, model) -> appExports.closeAlgosNotification = (e, el) -> user.set('flags.algosNotification', 'hide') + appExports.closeOnliesNotification = (e, el) -> + user.set('flags.onliesNotification', 'hide') + appExports.customizeGender = (e, el) -> user.set 'preferences.gender', $(el).attr('data-value') diff --git a/views/app/alerts.html b/views/app/alerts.html index bb91206ced..a230f65abd 100644 --- a/views/app/alerts.html +++ b/views/app/alerts.html @@ -7,8 +7,20 @@ {#if equal(_user.flags.algosNotification,'show')}
- [x] -

New features! Custom day start, new and better algorithms, authentication enhancements. See details here. + [x] +

New features! Custom day start, new and better algorithms, authentication enhancements. See details here.  "Hey, I had more Exp before this roll-out!" Restore your Exp here.

+ {/} + + {#if equal(_user.flags.onliesNotification, 'show')} +
+ [x] +

+ "Onlies" now gain / lose value just like other habits, and are reset back to 0 at the beginning of each day. +  See details here, and +  chime in with your recommendations on this mechanic. +

+
+ {/} \ No newline at end of file