handle local deletion relationships
This commit is contained in:
@@ -107,6 +107,10 @@ class Item {
|
|||||||
// must override
|
// must override
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isBeingRemovedLocally() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
removeAllRelationships() {
|
removeAllRelationships() {
|
||||||
// must override
|
// must override
|
||||||
this.setDirty(true);
|
this.setDirty(true);
|
||||||
|
|||||||
@@ -56,6 +56,13 @@ class Note extends Item {
|
|||||||
this.tags = [];
|
this.tags = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isBeingRemovedLocally() {
|
||||||
|
this.tags.forEach(function(tag){
|
||||||
|
_.pull(tag.notes, this);
|
||||||
|
}.bind(this))
|
||||||
|
super.isBeingRemovedLocally();
|
||||||
|
}
|
||||||
|
|
||||||
static filterDummyNotes(notes) {
|
static filterDummyNotes(notes) {
|
||||||
var filtered = notes.filter(function(note){return note.dummy == false || note.dummy == null});
|
var filtered = notes.filter(function(note){return note.dummy == false || note.dummy == null});
|
||||||
return filtered;
|
return filtered;
|
||||||
|
|||||||
@@ -55,6 +55,13 @@ class Tag extends Item {
|
|||||||
this.notes = [];
|
this.notes = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isBeingRemovedLocally() {
|
||||||
|
this.notes.forEach(function(note){
|
||||||
|
_.pull(note.tags, this);
|
||||||
|
}.bind(this))
|
||||||
|
super.isBeingRemovedLocally();
|
||||||
|
}
|
||||||
|
|
||||||
get content_type() {
|
get content_type() {
|
||||||
return "Tag";
|
return "Tag";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,6 @@ class ModelManager {
|
|||||||
|
|
||||||
this.notifySyncObserversOfModels(models);
|
this.notifySyncObserversOfModels(models);
|
||||||
|
|
||||||
// this.sortItems();
|
|
||||||
return models;
|
return models;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +132,9 @@ class ModelManager {
|
|||||||
}
|
}
|
||||||
} else if(item.content_type == "Note") {
|
} else if(item.content_type == "Note") {
|
||||||
if(!_.find(this.notes, {uuid: item.uuid})) {
|
if(!_.find(this.notes, {uuid: item.uuid})) {
|
||||||
this.notes.unshift(item);
|
this.notes.splice(_.sortedLastIndexBy(this.notes, item, function(item){
|
||||||
|
return -item.created_at;
|
||||||
|
}), 0, item);
|
||||||
}
|
}
|
||||||
} else if(item.content_type == "Extension") {
|
} else if(item.content_type == "Extension") {
|
||||||
if(!_.find(this._extensions, {uuid: item.uuid})) {
|
if(!_.find(this._extensions, {uuid: item.uuid})) {
|
||||||
@@ -170,14 +171,6 @@ class ModelManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sortItems() {
|
|
||||||
Item.sortItemsByDate(this.notes);
|
|
||||||
|
|
||||||
this.tags.forEach(function(tag){
|
|
||||||
Item.sortItemsByDate(tag.notes);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
addItemSyncObserver(id, type, callback) {
|
addItemSyncObserver(id, type, callback) {
|
||||||
this.itemSyncObservers.push({id: id, type: type, callback: callback});
|
this.itemSyncObservers.push({id: id, type: type, callback: callback});
|
||||||
}
|
}
|
||||||
@@ -223,10 +216,13 @@ class ModelManager {
|
|||||||
removeItemLocally(item) {
|
removeItemLocally(item) {
|
||||||
_.pull(this.items, item);
|
_.pull(this.items, item);
|
||||||
|
|
||||||
|
item.isBeingRemovedLocally();
|
||||||
|
|
||||||
if(item.content_type == "Tag") {
|
if(item.content_type == "Tag") {
|
||||||
_.pull(this.tags, item);
|
_.pull(this.tags, item);
|
||||||
} else if(item.content_type == "Note") {
|
} else if(item.content_type == "Note") {
|
||||||
_.pull(this.notes, item);
|
_.pull(this.notes, item);
|
||||||
|
|
||||||
} else if(item.content_type == "Extension") {
|
} else if(item.content_type == "Extension") {
|
||||||
_.pull(this._extensions, item);
|
_.pull(this._extensions, item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,8 +107,6 @@ class SyncManager {
|
|||||||
|
|
||||||
var allDirtyItems = this.modelManager.getDirtyItems();
|
var allDirtyItems = this.modelManager.getDirtyItems();
|
||||||
|
|
||||||
console.log("Syncing dirty items", allDirtyItems);
|
|
||||||
|
|
||||||
// we want to write all dirty items to disk only if the user is offline, or if the sync op fails
|
// we want to write all dirty items to disk only if the user is offline, or if the sync op fails
|
||||||
// if the sync op succeeds, these items will be written to disk by handling the "saved_items" response from the server
|
// if the sync op succeeds, these items will be written to disk by handling the "saved_items" response from the server
|
||||||
if(this.authManager.offline()) {
|
if(this.authManager.offline()) {
|
||||||
@@ -147,11 +145,7 @@ class SyncManager {
|
|||||||
request.sync_token = this.syncToken;
|
request.sync_token = this.syncToken;
|
||||||
request.cursor_token = this.cursorToken;
|
request.cursor_token = this.cursorToken;
|
||||||
|
|
||||||
console.log("Syncing with token", request.sync_token, request.cursor_token);
|
|
||||||
|
|
||||||
request.post().then(function(response) {
|
request.post().then(function(response) {
|
||||||
console.log("Sync completion", response.plain());
|
|
||||||
|
|
||||||
this.modelManager.clearDirtyItems(subItems);
|
this.modelManager.clearDirtyItems(subItems);
|
||||||
this.syncStatus.error = null;
|
this.syncStatus.error = null;
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
%div{"infinite-scroll" => "ctrl.paginate()", "can-load" => "true", "threshold" => "200"}
|
%div{"infinite-scroll" => "ctrl.paginate()", "can-load" => "true", "threshold" => "200"}
|
||||||
.note{"ng-repeat" => "note in ctrl.tag.notes | limitTo:ctrl.notesToDisplay | filter: ctrl.filterNotes",
|
.note{"ng-repeat" => "note in ctrl.tag.notes | limitTo:ctrl.notesToDisplay | filter: ctrl.filterNotes",
|
||||||
"ng-click" => "ctrl.selectNote(note)"}
|
"ng-click" => "ctrl.selectNote(note)", "ng-class" => "{'selected' : ctrl.selectedNote == note}"}
|
||||||
.name{"ng-if" => "note.title"}
|
.name{"ng-if" => "note.title"}
|
||||||
{{note.title}}
|
{{note.title}}
|
||||||
.note-preview
|
.note-preview
|
||||||
|
|||||||
Reference in New Issue
Block a user