Handle case where currently selected note is deleted by a remote sync
This commit is contained in:
@@ -40,6 +40,26 @@ angular.module('app')
|
|||||||
this.loadTagsString();
|
this.loadTagsString();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
modelManager.addItemSyncObserver("component-manager", "Note", (allItems, validItems, deletedItems, source) => {
|
||||||
|
if(!this.note) { return; }
|
||||||
|
if(!ModelManager.isMappingSourceRetrieved(source)) {return;}
|
||||||
|
|
||||||
|
var matchingNote = allItems.find((item) => {
|
||||||
|
return item.uuid == this.note.uuid;
|
||||||
|
});
|
||||||
|
|
||||||
|
if(!matchingNote) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(matchingNote.deleted) {
|
||||||
|
$rootScope.notifyDelete();
|
||||||
|
} else {
|
||||||
|
// Update tags
|
||||||
|
this.loadTagsString();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.noteDidChange = function(note, oldNote) {
|
this.noteDidChange = function(note, oldNote) {
|
||||||
this.setNote(note, oldNote);
|
this.setNote(note, oldNote);
|
||||||
this.reloadComponentContext();
|
this.reloadComponentContext();
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ angular.module('app')
|
|||||||
this.$apply(fn);
|
this.$apply(fn);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.notifyDelete = function() {
|
$rootScope.notifyDelete = function() {
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
$rootScope.$broadcast("noteDeleted");
|
$rootScope.$broadcast("noteDeleted");
|
||||||
}.bind(this), 0);
|
}.bind(this), 0);
|
||||||
@@ -242,7 +242,7 @@ angular.module('app')
|
|||||||
|
|
||||||
if(note.dummy) {
|
if(note.dummy) {
|
||||||
modelManager.removeItemLocally(note);
|
modelManager.removeItemLocally(note);
|
||||||
$scope.notifyDelete();
|
$rootScope.notifyDelete();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,11 +250,11 @@ angular.module('app')
|
|||||||
if(authManager.offline()) {
|
if(authManager.offline()) {
|
||||||
// when deleting items while ofline, we need to explictly tell angular to refresh UI
|
// when deleting items while ofline, we need to explictly tell angular to refresh UI
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
$scope.notifyDelete();
|
$rootScope.notifyDelete();
|
||||||
$scope.safeApply();
|
$scope.safeApply();
|
||||||
}, 50);
|
}, 50);
|
||||||
} else {
|
} else {
|
||||||
$scope.notifyDelete();
|
$rootScope.notifyDelete();
|
||||||
}
|
}
|
||||||
}, null, "deleteNote");
|
}, null, "deleteNote");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ angular.module('app')
|
|||||||
this.onNoteRemoval = function() {
|
this.onNoteRemoval = function() {
|
||||||
let visibleNotes = this.visibleNotes();
|
let visibleNotes = this.visibleNotes();
|
||||||
if(this.selectedIndex < visibleNotes.length) {
|
if(this.selectedIndex < visibleNotes.length) {
|
||||||
this.selectNote(visibleNotes[this.selectedIndex]);
|
this.selectNote(visibleNotes[Math.max(this.selectedIndex, 0)]);
|
||||||
} else {
|
} else {
|
||||||
this.selectNote(visibleNotes[visibleNotes.length - 1]);
|
this.selectNote(visibleNotes[visibleNotes.length - 1]);
|
||||||
}
|
}
|
||||||
@@ -190,11 +190,14 @@ angular.module('app')
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.selectNote = function(note, viaClick = false) {
|
this.selectNote = function(note, viaClick = false) {
|
||||||
if(!note) { return; }
|
if(!note) {
|
||||||
|
this.createNewNote();
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.selectedNote = note;
|
this.selectedNote = note;
|
||||||
note.conflict_of = null; // clear conflict
|
note.conflict_of = null; // clear conflict
|
||||||
this.selectionMade()(note);
|
this.selectionMade()(note);
|
||||||
this.selectedIndex = this.visibleNotes().indexOf(note);
|
this.selectedIndex = Math.max(this.visibleNotes().indexOf(note), 0);
|
||||||
|
|
||||||
if(viaClick && this.isFiltering()) {
|
if(viaClick && this.isFiltering()) {
|
||||||
desktopManager.searchText(this.noteFilter.text);
|
desktopManager.searchText(this.noteFilter.text);
|
||||||
|
|||||||
@@ -10,6 +10,14 @@ class ModelManager {
|
|||||||
ModelManager.MappingSourceRemoteActionRetrieved = "MappingSourceRemoteActionRetrieved"; /* aciton-based Extensions like note history */
|
ModelManager.MappingSourceRemoteActionRetrieved = "MappingSourceRemoteActionRetrieved"; /* aciton-based Extensions like note history */
|
||||||
ModelManager.MappingSourceFileImport = "MappingSourceFileImport";
|
ModelManager.MappingSourceFileImport = "MappingSourceFileImport";
|
||||||
|
|
||||||
|
ModelManager.isMappingSourceRetrieved = (source) => {
|
||||||
|
return [
|
||||||
|
ModelManager.MappingSourceRemoteRetrieved,
|
||||||
|
ModelManager.MappingSourceComponentRetrieved,
|
||||||
|
ModelManager.MappingSourceRemoteActionRetrieved
|
||||||
|
].includes(source);
|
||||||
|
}
|
||||||
|
|
||||||
this.storageManager = storageManager;
|
this.storageManager = storageManager;
|
||||||
this.notes = [];
|
this.notes = [];
|
||||||
this.tags = [];
|
this.tags = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user