move idList back to root-level, is what's causing the sort bug - see https://github.com/codeparty/racer/pull/73

This commit is contained in:
Tyler Renelle
2013-02-08 20:48:31 -05:00
parent 648032228a
commit 5ea0dfe713
6 changed files with 37 additions and 18 deletions
+2
View File
@@ -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)
+11 -12
View File
@@ -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")
+1 -1
View File
@@ -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) ->
+4 -4
View File
@@ -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)
+1 -1
View File
@@ -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'