From 5ea0dfe713efabed95e4ea4dc51ddfa5fc02d674 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Fri, 8 Feb 2013 20:48:31 -0500 Subject: [PATCH] move idList back to root-level, is what's causing the sort bug - see https://github.com/codeparty/racer/pull/73 --- migrations/20130208_idLists_to_typeIds.js | 18 ++++++++++++++++++ src/app/browser.coffee | 2 ++ src/app/character.coffee | 23 +++++++++++------------ src/app/index.coffee | 2 +- src/app/tasks.coffee | 8 ++++---- src/server/serverRoutes.coffee | 2 +- 6 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 migrations/20130208_idLists_to_typeIds.js diff --git a/migrations/20130208_idLists_to_typeIds.js b/migrations/20130208_idLists_to_typeIds.js new file mode 100644 index 0000000000..2b1311c636 --- /dev/null +++ b/migrations/20130208_idLists_to_typeIds.js @@ -0,0 +1,18 @@ +// move idList back to root-level, is what's causing the sort bug - see https://github.com/codeparty/racer/pull/73 + +// We could just delete user.idLists, since it's re-created on refresh. However, users's first refresh will scare them +// since everything will dissappear - second refresh will bring everything back. +db.users.find().forEach(function(user){ + db.users.update( + {_id:user._id}, + { + $set:{ + 'habitIds':user.idLists.habit, + 'dailyIds':user.idLists.daily, + 'todoIds':user.idLists.todo, + 'rewardIds':user.idLists.reward + } + //$unset:{idLists:true} // run this after the code has been pushed + } + ) +}) \ No newline at end of file diff --git a/src/app/browser.coffee b/src/app/browser.coffee index e6897b0f1e..edf8734a10 100644 --- a/src/app/browser.coffee +++ b/src/app/browser.coffee @@ -4,6 +4,8 @@ module.exports.resetDom = (model) -> window.DERBY.app.dom.clear() window.DERBY.app.view.render(model) model.fn '_tnl', '_user.stats.lvl', (lvl) -> (lvl*100)/5 + _.each ['habit', 'daily', 'todo', 'reward'], (type) -> + model.refList "_#{type}List", "_user.tasks", "_user.{type}Ids" module.exports.app = (appExports, model) -> loadJavaScripts(model) diff --git a/src/app/character.coffee b/src/app/character.coffee index 2643672440..5d556b6997 100644 --- a/src/app/character.coffee +++ b/src/app/character.coffee @@ -49,7 +49,7 @@ module.exports.app = (appExports, model) -> batch.startTransaction() taskTypes = ['habit', 'daily', 'todo', 'reward'] batch.set 'tasks', {} - _.each taskTypes, (type) -> batch.set "idLists.#{type}", [] + _.each taskTypes, (type) -> batch.set "#{type}Ids", [] batch.set 'balance', 2 if user.get('balance') < 2 #only if they haven't manually bought tokens revive(batch) batch.commit() @@ -91,11 +91,10 @@ userSchema = party: { current: null, invitation: null } items: { weapon: 0, armor: 0, head: 0, shield: 0 } preferences: { gender: 'm', skin: 'white', hair: 'blond', armorSet: 'v1' } - idLists: - habit: [] - daily: [] - todo: [] - reward: [] + habitIds: [] + dailyIds: [] + todoIds: [] + rewardIds: [] apiToken: null # set in newUserObject below lastCron: 'new' #this will be replaced with `+new Date` on first run balance: 2 @@ -127,10 +126,10 @@ module.exports.newUserObject = -> guid = task.id = derby.uuid() newUser.tasks[guid] = task switch task.type - when 'habit' then newUser.idLists.habit.push guid - when 'daily' then newUser.idLists.daily.push guid - when 'todo' then newUser.idLists.todo.push guid - when 'reward' then newUser.idLists.reward.push guid + when 'habit' then newUser.habitIds.push guid + when 'daily' then newUser.dailyIds.push guid + when 'todo' then newUser.todoIds.push guid + when 'reward' then newUser.rewardIds.push guid return newUser module.exports.updateUser = (batch) -> @@ -146,13 +145,13 @@ module.exports.updateUser = (batch) -> # 1. remove duplicates # 2. restore missing zombie tasks back into list taskIds = _.pluck( _.where(tasks, {type:type}), 'id') - union = _.union obj.idLists[type], taskIds + union = _.union obj[type + 'Ids'], taskIds # 2. remove empty (grey) tasks preened = _.filter(union, (val) -> _.contains(taskIds, val)) # There were indeed issues found, set the new list - batch.set("idLists.#{type}", preened) # if _.difference(preened, userObj[path]).length != 0 + batch.set("#{type}Ids", preened) # if _.difference(preened, userObj[path]).length != 0 module.exports.BatchUpdate = BatchUpdate = (model) -> user = model.at("_user") diff --git a/src/app/index.coffee b/src/app/index.coffee index aaa56075db..056a67002b 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -54,7 +54,7 @@ get '/', (page, model, next) -> # refLists _.each ['habit', 'daily', 'todo', 'reward'], (type) -> - model.refList "_#{type}List", "_user.tasks", "_user.idLists.#{type}" + model.refList "_#{type}List", "_user.tasks", "_user.#{type}Ids" # tnl function model.fn '_tnl', '_user.stats.lvl', (lvl) -> diff --git a/src/app/tasks.coffee b/src/app/tasks.coffee index 18469bb251..afcc5f5896 100644 --- a/src/app/tasks.coffee +++ b/src/app/tasks.coffee @@ -95,14 +95,14 @@ module.exports.app = (appExports, model) -> # fix when query subscriptions implemented properly $('[rel=tooltip]').tooltip('hide') - ids = user.get("idLists.#{type}") + ids = user.get("#{type}Ids") ids.splice(ids.indexOf(id),1) user.del('tasks.'+id) - user.set("idLists.#{type}", ids) + user.set("#{type}Ids", ids) appExports.clearCompleted = (e, el) -> - todoIds = user.get('idLists.todo') + todoIds = user.get('todoIds') removed = false _.each model.get('_todoList'), (task) -> if task.completed @@ -110,7 +110,7 @@ module.exports.app = (appExports, model) -> user.del('tasks.'+task.id) todoIds.splice(todoIds.indexOf(task.id), 1) if removed - user.set('idLists.todo', todoIds) + user.set('todoIds', todoIds) appExports.toggleDay = (e, el) -> task = model.at(e.target) diff --git a/src/server/serverRoutes.coffee b/src/server/serverRoutes.coffee index 126720ef67..7f53e8d186 100644 --- a/src/server/serverRoutes.coffee +++ b/src/server/serverRoutes.coffee @@ -50,7 +50,7 @@ module.exports = (expressApp, root, derby) -> # Create task if doesn't exist # TODO add service & icon to task unless model.get("_user.tasks.#{taskId}") - model.refList "_habitList", "_user.tasks", "_user.idLists.habit" + model.refList "_habitList", "_user.tasks", "_user.habitIds" model.at('_habitList').push { id: taskId type: 'habit'