From cea268a1e08a3dfcc4b6dc673727e0c1c4b275b5 Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Tue, 8 Oct 2019 14:00:39 -0500 Subject: [PATCH] Better dummy management, fixes #313 --- .../javascripts/app/controllers/editor.js | 5 +++++ .../javascripts/app/controllers/notes.js | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/app/controllers/editor.js b/app/assets/javascripts/app/controllers/editor.js index 749745dce..d384a931e 100644 --- a/app/assets/javascripts/app/controllers/editor.js +++ b/app/assets/javascripts/app/controllers/editor.js @@ -398,6 +398,11 @@ angular.module('app') } this.deleteNote = async function(permanently) { + if(this.note.dummy) { + alert("This note is a placeholder and cannot be deleted. To remove from your list, simply navigate to a different note."); + return; + } + let run = () => { $timeout(() => { if(this.note.locked) { diff --git a/app/assets/javascripts/app/controllers/notes.js b/app/assets/javascripts/app/controllers/notes.js index 74606dc72..3ba466548 100644 --- a/app/assets/javascripts/app/controllers/notes.js +++ b/app/assets/javascripts/app/controllers/notes.js @@ -380,6 +380,10 @@ angular.module('app') } this.selectNote = async function(note, viaClick = false) { + if(this.selectedNote === note) { + return; + } + if(!note) { this.selectionMade()(null); return; @@ -388,7 +392,7 @@ angular.module('app') let run = () => { $timeout(() => { let dummyNote; - if(this.selectedNote && this.selectedNote != note && this.selectedNote.dummy) { + if(this.selectedNote && this.selectedNote != note && this.selectedNote.dummy == true) { // remove dummy dummyNote = this.selectedNote; } @@ -404,7 +408,7 @@ angular.module('app') // There needs to be a long timeout after setting selection before removing the dummy // Otherwise, you'll click a note, remove this one, and strangely, the click event registers for a lower cell - if(dummyNote) { + if(dummyNote && dummyNote.dummy == true) { $timeout(() => { modelManager.removeItemLocally(dummyNote); _.pull(this.notes, dummyNote); @@ -431,14 +435,17 @@ angular.module('app') } this.createNewNote = function() { + if(this.selectedNote && this.selectedNote.dummy) { + return; + } // The "Note X" counter is based off this.notes.length, but sometimes, what you see in the list is only a subset. // We can use this.visibleNotes().length, but that only accounts for non-paginated results, so first 15 or so. - var title = "Note" + (this.notes ? (" " + (this.notes.length + 1)) : ""); + let title = "Note" + (this.notes ? (" " + (this.notes.length + 1)) : ""); let newNote = modelManager.createItem({content_type: "Note", content: {text: "", title: title}}); + newNote.client_updated_at = new Date(); newNote.dummy = true; - this.newNote = newNote; - this.selectNote(this.newNote); - this.addNew()(this.newNote); + this.selectNote(newNote); + this.addNew()(newNote); } this.noteFilter = {text : ''};