Skip to content

Commit

Permalink
Doesn't crash if list isn't there
Browse files Browse the repository at this point in the history
  • Loading branch information
stayradiated committed Jun 23, 2012
1 parent d11d3cc commit 6b66338
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 33 deletions.
12 changes: 10 additions & 2 deletions merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,23 @@ mergeDB = function(server, client, callback) {
// server.save(['tasks', id, 'logged']);
} else if (list === 'trash') {
//Remove from list
server.lists.items[old].order.remove(id);
if(server.lists.items.hasOwnProperty(old)) {
if(!server.lists.items[old].hasOwnProperty('deleted')) {
server.lists.items[old].order.remove(id);
}
}
// delete server.tasks[id];
server.tasks[id] = {deleted: 1};
msg('Deleted: ' + id);
// Saves - but doesn't mess with timestamps
// server.save();
} else {
//Remove from list
server.lists.items[old].order.remove(id);
if(server.lists.items.hasOwnProperty(old)) {
if(!server.lists.items[old].hasOwnProperty('deleted')) {
server.lists.items[old].order.remove(id);
}
}
//Move to other list
server.lists.items[list].order.unshift(id);
server.tasks[id].list = list;
Expand Down
70 changes: 39 additions & 31 deletions upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ cleanDB = function(d) {
if(_this.hasOwnProperty('list')) {
if(isNumber(Number(_this.list))) {
o.tasks[i].list = Number(_this.list)
} else if( _this.list === 'today' || _this.list === 'next' || _this.list === 'logbook' || _this.list === 'scheduled') {
} else if( _this.list === 'today' || _this.list === 'next' || _this.list === 'logbook') {
o.tasks[i].list = _this.list
}
}
Expand Down Expand Up @@ -174,36 +174,36 @@ cleanDB = function(d) {
}

// Scheduled
if(_this.hasOwnProperty('type')) {
if(_this.type === 'scheduled') {
if(_this.hasOwnProperty('next')) {
o.tasks[i].type = _this.type
o.tasks[i].next = Number(_this.next)
o.tasks[i].time.type = Number(_this.time.type) || 0
o.tasks[i].time.next = Number(_this.time.next) || 0
}
} else if(_this.type === 'recurring') {
var valid = true
if(!_this.hasOwnProperty('next')) valid = false
if(!_this.hasOwnProperty('ends')) valid = false
if(_this.hasOwnProperty('recurType')) {
if(_this.recurType !== 'daily' || _this.recurType !== 'weekly' || _this.recurType !== 'monthly') valid = false
} else valid = false
if(!_this.hasOwnProperty('recurInterval')) valid = false
if(valid) {
o.tasks[i].type = _this.type
o.tasks[i].next = Number(_this.next)
o.tasks[i].ends = Number(_this.ends)
o.tasks[i].recurType = _this.recurType
o.tasks[i].recurInterval = _this.recurInterval
o.tasks[i].time.type = Number(_this.time.type) || 0
o.tasks[i].time.next = Number(_this.time.next) || 0
o.tasks[i].time.ends = Number(_this.time.ends) || 0
o.tasks[i].time.recurType = Number(_this.time.recurType) || 0
o.tasks[i].time.recurInterval = Number(_this.time.recurInterval) || 0
}
}
}
// if(_this.hasOwnProperty('type')) {
// if(_this.type === 'scheduled') {
// if(_this.hasOwnProperty('next')) {
// o.tasks[i].type = _this.type
// o.tasks[i].next = Number(_this.next)
// o.tasks[i].time.type = Number(_this.time.type) || 0
// o.tasks[i].time.next = Number(_this.time.next) || 0
// }
// } else if(_this.type === 'recurring') {
// var valid = true
// if(!_this.hasOwnProperty('next')) valid = false
// if(!_this.hasOwnProperty('ends')) valid = false
// if(_this.hasOwnProperty('recurType')) {
// if(_this.recurType !== 'daily' || _this.recurType !== 'weekly' || _this.recurType !== 'monthly') valid = false
// } else valid = false
// if(!_this.hasOwnProperty('recurInterval')) valid = false
// if(valid) {
// o.tasks[i].type = _this.type
// o.tasks[i].next = Number(_this.next)
// o.tasks[i].ends = Number(_this.ends)
// o.tasks[i].recurType = _this.recurType
// o.tasks[i].recurInterval = _this.recurInterval
// o.tasks[i].time.type = Number(_this.time.type) || 0
// o.tasks[i].time.next = Number(_this.time.next) || 0
// o.tasks[i].time.ends = Number(_this.time.ends) || 0
// o.tasks[i].time.recurType = Number(_this.time.recurType) || 0
// o.tasks[i].time.recurInterval = Number(_this.time.recurInterval) || 0
// }
// }
// }
}

// Lists
Expand Down Expand Up @@ -270,10 +270,18 @@ cleanDB = function(d) {
// Order
if(_this.hasOwnProperty('order')) {
if(isArray(_this.order)) {

// All tasks in list
for(var j = 0; j < _this.order.length; j++) {
if(o.tasks.hasOwnProperty(_this.order[j])) {
if(!o.tasks[_this.order[j]].hasOwnProperty('deleted')) {

// Push to order
o.lists.items[i].order.push(_this.order[j])

// Update task.list
o.tasks[_this.order[j]].list = i

}
}
}
Expand Down

0 comments on commit 6b66338

Please sign in to comment.