Finished _todoList/_completedList transfering. instead of remove/push

on lists, just splice/push to todoIds and completedIds
This commit is contained in:
Tyler Renelle 2012-07-27 22:29:02 -04:00
parent 33c5acf5ec
commit 05121a2d18
2 changed files with 25 additions and 22 deletions

View file

@ -74,7 +74,6 @@ view.fn("silver", function(num) {
get('/:uidParam?', function(page, model, _arg) {
var uidParam;
uidParam = _arg.uidParam;
console.log(Scoring);
return model.fetch('users', function(err, users) {
var guid, newUser, task, user, userId, _i, _len, _ref1;
if ((uidParam != null) && users.get(uidParam)) {
@ -130,8 +129,10 @@ get('/:uidParam?', function(page, model, _arg) {
getHabits = function(page, model, userId) {
return model.subscribe("users." + userId, function(err, user) {
console.log(userId, 'userId');
console.log(err, 'err');
console.log({
userId: userId,
err: err
}, "app/index.coffee: model.subscribe");
model.ref('_user', user);
model.set('_items', {
armor: content.items.armor[parseInt(user.get('items.armor')) + 1],
@ -198,7 +199,7 @@ ready(function(model) {
}
tour.start();
model.on('set', '_user.tasks.*.completed', function(i, completed, previous, isLocal, passed) {
var direction, from, ids, index, task, to, _ref3;
var direction, from, fromIds, task, to, toIds, _ref3, _ref4;
if (passed.cron != null) {
return;
}
@ -218,14 +219,14 @@ ready(function(model) {
direction: direction()
});
if (task.get('type') === 'todo') {
_ref3 = direction() === 'up' ? ['_todoList', '_completedList'] : ['_completedList', '_todoList'], from = _ref3[0], to = _ref3[1];
ids = _.map(model.get(from), function(obj) {
return obj.id;
});
index = ids.indexOf(i);
return model.push(to, task.get(), function() {
return model.remove(from, index);
});
_ref3 = direction() === 'up' ? ['todo', 'completed'] : ['completed', 'todo'], from = _ref3[0], to = _ref3[1];
_ref4 = ["_user." + from + "Ids", "_user." + to + "Ids"], from = _ref4[0], to = _ref4[1];
fromIds = model.get(from);
fromIds.splice(fromIds.indexOf(i), 1);
model.set(from, fromIds);
toIds = model.get(to);
toIds.push(i);
return model.set(to, toIds);
}
});
exports.addTask = function(e, el, next) {

View file

@ -44,7 +44,6 @@ view.fn "silver", (num) ->
# ========== ROUTES ==========
get '/:uidParam?', (page, model, {uidParam}) ->
console.log Scoring
model.fetch 'users', (err, users) ->
@ -89,9 +88,8 @@ get '/:uidParam?', (page, model, {uidParam}) ->
getHabits = (page, model, userId) ->
model.subscribe "users.#{userId}", (err, user) ->
console.log userId, 'userId' # = 26c48325-2fea-4e2e-a60f-a5fa28d7b410
console.log err, 'err' # = Unauthorized: No access control declared for path users.26c48325-2fea-4e2e-a60f-a5fa28d7b410 ???
console.log {userId:userId, err:err}, "app/index.coffee: model.subscribe"
# => {userId: 26c48325-2fea-4e2e-a60f-a5fa28d7b410, err: Unauthorized: No access control declared for path users.26c48325-2fea-4e2e-a60f-a5fa28d7b410 }
model.ref '_user', user
@ -177,12 +175,16 @@ ready (model) ->
# Then move the todos to/from _todoList/_completedList
if task.get('type') == 'todo'
[from, to] = if (direction()=='up') then ['_todoList', '_completedList'] else ['_completedList', '_todoList']
ids = _.map model.get(from), (obj) ->
obj.id
index = ids.indexOf(i)
model.push to, task.get(), () ->
model.remove from, index
[from, to] = if (direction()=='up') then ['todo', 'completed'] else ['completed', 'todo']
[from, to] = ["_user.#{from}Ids", "_user.#{to}Ids"]
# Remove from source (just remove the id from id-list)
fromIds = model.get(from)
fromIds.splice(fromIds.indexOf(i), 1)
model.set from, fromIds
# Push to target (just the id to id-list)
toIds = model.get(to)
toIds.push i
model.set to, toIds
exports.addTask = (e, el, next) ->
type = $(el).attr('data-task-type')