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

View file

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