From b697e7bdf122f7e58de872d65cb88248e71c122c Mon Sep 17 00:00:00 2001 From: Tobias Leugger Date: Sat, 26 Jan 2013 11:33:51 +0100 Subject: [PATCH 1/5] Getting rid of the completedList and completedIds, instead only using the 'completed' attribute of the todo task. This fixes some issues were a task was at the same time in the todoIds and completedIds. --- src/app/index.coffee | 29 +++++++++++------------------ src/app/schema.coffee | 1 - views/app/index.html | 12 ++++++++++-- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/app/index.coffee b/src/app/index.coffee index 9d59ab1499..bb60c11bda 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -16,7 +16,7 @@ _ = require('underscore') setupListReferences = (model) -> # Setup Task Lists - taskTypes = ['habit', 'daily', 'todo', 'completed', 'reward'] + taskTypes = ['habit', 'daily', 'todo', 'reward'] _.each taskTypes, (type) -> model.refList "_#{type}List", "_user.tasks", "_user.#{type}Ids" # ========== ROUTES ========== @@ -145,19 +145,6 @@ ready (model) -> task = user.at("tasks.#{i}") scoring.score(i, direction()) - # Then move the todos to/from _todoList/_completedList - if task.get('type') == 'todo' - [from, to] = if (direction()=='up') then ['todo', 'completed'] else ['completed', 'todo'] - [from, to] = ["#{from}Ids", "#{to}Ids"] - # Remove from source (just remove the id from id-list) - fromIds = user.get(from) - fromIds.splice(fromIds.indexOf(i), 1) - user.set from, fromIds - # Push to target (just the id to id-list) - toIds = user.get(to) - toIds.push i - user.set to, toIds - exports.addTask = (e, el, next) -> type = $(el).attr('data-task-type') list = model.at "_#{type}List" @@ -210,9 +197,15 @@ ready (model) -> task.remove() exports.clearCompleted = (e, el) -> - _.each model.get('_completedList'), (task) -> - user.del('tasks.'+task.id) - user.set('completedIds', []) + todoIds = user.get('todoIds') + removed = false + _.each model.get('_todoList'), (task) -> + if task.completed + removed = true + user.del('tasks.'+task.id) + todoIds.splice(todoIds.indexOf(task.id), 1) + if removed + user.set('todoIds', todoIds) exports.toggleDay = (e, el) -> task = model.at(e.target) @@ -303,7 +296,7 @@ ready (model) -> exports.reset = (e, el) -> userObj = user.get() - taskTypes = ['habit', 'daily', 'todo', 'completed', 'reward'] + taskTypes = ['habit', 'daily', 'todo', 'reward'] userObj.tasks = {} _.each taskTypes, (type) -> userObj["#{type}Ids"] = [] userObj.balance = 2 if userObj.balance < 2 #only if they haven't manually bought tokens diff --git a/src/app/schema.coffee b/src/app/schema.coffee index da0b48d7fb..245bba9438 100644 --- a/src/app/schema.coffee +++ b/src/app/schema.coffee @@ -12,7 +12,6 @@ module.exports.userSchema = -> habitIds: [] dailyIds: [] todoIds: [] - completedIds: [] rewardIds: [] for task in content.defaultTasks diff --git a/views/app/index.html b/views/app/index.html index 0d3c894633..f01e42a2a4 100644 --- a/views/app/index.html +++ b/views/app/index.html @@ -210,13 +210,21 @@
    - {#each _todoList as :task}{/} + {#each _todoList as :task} + {#if not(:task.completed)} + + {/} + {/}
    - {#each _completedList as :task}{/} + {#each _todoList as :task} + {#if :task.completed} + + {/} + {/}
Clear Completed
From 61b848bf4f3c0aaf0c2a9fe1ef2c19782067cedb Mon Sep 17 00:00:00 2001 From: Tobias Leugger Date: Sun, 27 Jan 2013 18:55:46 +0100 Subject: [PATCH 2/5] Updating the task list cleanup to not restore the completedIds list. Fixing the mocha test to not check for the completedIds. --- src/app/index.coffee | 5 +---- test/user.mocha.coffee | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/app/index.coffee b/src/app/index.coffee index bb60c11bda..c8092ce971 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -59,15 +59,12 @@ get '/', (page, model, next) -> ## Task List Cleanup # FIXME temporary hack to fix lists (Need to figure out why these are happening) # FIXME consolidate these all under user.listIds so we can set them en-masse - _.each ['habit','daily','todo', 'completed', 'reward'], (type) -> + _.each ['habit','daily','todo','reward'], (type) -> path = "#{type}Ids" # 1. remove duplicates # 2. restore missing zombie tasks back into list where = {type:type} - if type in ['completed', 'todo'] - where.type = 'todo' - where.completed = if type == 'completed' then true else false taskIds = _.pluck( _.where(userObj.tasks, where), 'id') union = _.union userObj[path], taskIds diff --git a/test/user.mocha.coffee b/test/user.mocha.coffee index 868786c14c..33b1917014 100644 --- a/test/user.mocha.coffee +++ b/test/user.mocha.coffee @@ -84,7 +84,6 @@ describe 'User', -> expect(_.size(user.habitIds)).to.eql 3 expect(_.size(user.dailyIds)).to.eql 3 expect(_.size(user.todoIds)).to.eql 1 - expect(_.size(user.completedIds)).to.eql 0 expect(_.size(user.rewardIds)).to.eql 2 ##### Habits ##### From bfe85ad6a8d08538bf11b14e7aa321bdac0faf63 Mon Sep 17 00:00:00 2001 From: Nicholas Terwoord Date: Sun, 27 Jan 2013 21:36:34 -0500 Subject: [PATCH 3/5] HTML entities & and < are not handled correctly - Instead of using `view.escapeHTML`, just check if todo is blank via RegEx --- src/app/index.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/index.coffee b/src/app/index.coffee index 9d59ab1499..3f39d87e91 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -162,8 +162,10 @@ ready (model) -> type = $(el).attr('data-task-type') list = model.at "_#{type}List" newModel = model.at('_new' + type.charAt(0).toUpperCase() + type.slice(1)) + text = newModel.get() # Don't add a blank todo - return unless text = view.escapeHtml newModel.get() + return if /^(\s)*$/.test(text) + newModel.set '' switch type From 50692c371dfb47082aff040307b42905f8fc0b0d Mon Sep 17 00:00:00 2001 From: Nicholas Terwoord Date: Sun, 27 Jan 2013 22:21:03 -0500 Subject: [PATCH 4/5] Changed button colors - By default, unpressed buttons are now a gray color --- styles/app/index.styl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/styles/app/index.styl b/styles/app/index.styl index 0c6cbd4475..a95d1edeea 100644 --- a/styles/app/index.styl +++ b/styles/app/index.styl @@ -43,6 +43,16 @@ html,body,p,h1,ul,li,table,tr,th,td color: #005580 background-color: #DEE5F2 +.dailys + .repeat-days > .btn:not(.active) + background-color: #aaa; + background-image: -moz-linear-gradient(top, #eee, #aaa); + background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#eee), to(#aaa)); + background-image: -webkit-linear-gradient(top, #eee, #aaa); + background-image: -o-linear-gradient(top, #eee, #aaa); + background-image: linear-gradient(to bottom, #eee, #aaa); + background-repeat: repeat-x; + .help-icon float:right; From 933741422483605ef2d166474c1e254d840fdf52 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Mon, 28 Jan 2013 15:09:10 -0500 Subject: [PATCH 5/5] add completed/todo merge migration a la @toebu --- migrations/20130128_merge_completed_todo_ids.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 migrations/20130128_merge_completed_todo_ids.js diff --git a/migrations/20130128_merge_completed_todo_ids.js b/migrations/20130128_merge_completed_todo_ids.js new file mode 100644 index 0000000000..d362a4b771 --- /dev/null +++ b/migrations/20130128_merge_completed_todo_ids.js @@ -0,0 +1,15 @@ +db.users.find({ completedIds: { $exists: true } }).forEach(function(user) { + var newTodoIds = user.todoIds; + user.completedIds.forEach(function(value) { + if (newTodoIds.indexOf(value) === -1) { + newTodoIds.push(value) + } + }); + db.users.update( + { _id: user._id }, + { + $set: { todoIds: newTodoIds }, + $unset: { completedIds: 1 } + } + ); +}); \ No newline at end of file