From f5be364d966d38ed1c644275819bf78034673fa7 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Wed, 23 Jan 2019 22:49:34 -0700 Subject: [PATCH] Add make list button, don't "pop" cards on sync if they haven't changed --- www/js/Note.class.js | 9 ++++--- www/js/Notes.class.js | 4 ++- www/js/home.js | 63 +++++++++++++++++++++++++++++++++---------- 3 files changed, 57 insertions(+), 19 deletions(-) diff --git a/www/js/Note.class.js b/www/js/Note.class.js index d82a587..55f929f 100644 --- a/www/js/Note.class.js +++ b/www/js/Note.class.js @@ -243,10 +243,10 @@ class Note { var text = this.getText().split('\n'); for (var i = 0; i < text.length; i++) { if (text[i].match(/^[^\s\=\#\-<](.+)/)) { - if (text.length > i && text[i + 1].match(/^[\=-](.+)/)) { - // Don't do it if the next line makes this one a heading - continue; - } +// if (text.length > i && text[i + 1].match(/^[\=-](.+)/)) { +// // Don't do it if the next line makes this one a heading +// continue; +// } text[i] = "- [ ] " + text[i]; } } @@ -299,6 +299,7 @@ class Note { if (this.getColor() != othernote.getColor()) { return false; } + return true; } } \ No newline at end of file diff --git a/www/js/Notes.class.js b/www/js/Notes.class.js index 034a725..bc6eb01 100644 --- a/www/js/Notes.class.js +++ b/www/js/Notes.class.js @@ -157,7 +157,9 @@ class Notes { console.log("local note that's overwriting it: ", note); notesToSaveRemote.push(note); } else { - if (note.compareTo(remnote) != true) { + if (note.compareTo(remnote) == true) { + notesListFinal.push(note); + } else { // They aren't the same, let's trust the server notesToSaveLocal.push(remnote); } diff --git a/www/js/home.js b/www/js/home.js index 2e3c93e..7ce4658 100644 --- a/www/js/home.js +++ b/www/js/home.js @@ -50,7 +50,26 @@ $(".view-main").on("click", ".parsedown-task-list", function (e) { }); -function loadNotesToCards(notes, callback) { +function loadNotesToCards(notes, oldnotes, callback) { + if (notes.length == oldnotes.length) { + var allSame = true; + var allPresent = true; + for (var n in notes) { + if (!notes[n].compareTo(oldnotes[n])) { + allSame = false; + } + if (document.getElementById('notecard-col-' + notes[n].getID()) === null) { + allPresent = false; + } + } + if (allSame && allPresent) { + window.shuffleInstance.layout(); + if (typeof callback == 'function') { + callback(); + } + return; + } + } for (i in window.shuffleInstance.items) { window.shuffleInstance.remove(window.shuffleInstance.items[i]); } @@ -100,6 +119,7 @@ function loadNotesToCards(notes, callback) { } function loadCards(callback) { + var oldnotes = NOTES.getAll().slice(); NOTES.syncAll(function (notes) { if ($("#offline-indicator").css("display") != "none") { app.toast.create({ @@ -108,10 +128,11 @@ function loadCards(callback) { }).open(); } $("#offline-indicator").css("display", "none"); - loadNotesToCards(notes, callback); + console.log("Comparing: ", notes, oldnotes); + loadNotesToCards(notes, oldnotes, callback); }, function (notes) { $("#offline-indicator").css("display", ""); - loadNotesToCards(notes, callback); + loadNotesToCards(notes, oldnotes, callback); }); } @@ -133,10 +154,15 @@ function favoriteNote(id) { note.setModified(); $("#notecard-" + id).attr("data-favorite", note.getFavorite() ? "1" : "0"); note.saveNote(); + NOTES.syncAll(); } function makeList(id) { - + var note = NOTES.get(id); + note.toChecklist(); + note.setModified(); + note.saveNote(); + app.ptr.refresh(); } function deleteNote(id) { @@ -144,8 +170,10 @@ function deleteNote(id) { var note = NOTES.get(id); note.deleteme(); NOTES.set(note); - window.shuffleInstance.remove(document.getElementById("notecard-" + id)); - loadCards(); + window.shuffleInstance.remove(document.getElementById("notecard-col-" + id)); + $("#notecard-col-" + id).remove(); + window.shuffleInstance.layout(); + NOTES.syncAll(); }); } @@ -190,6 +218,7 @@ $("#app").on("click", "#colorpicker .colorpicker-color", function () { note.setColor(color); note.setModified(); note.saveNote(); + NOTES.syncAll(); $("#notecard-" + noteid).data("bg", note.getColor()); $("#notecard-" + noteid).data("fg", note.getTextColor()); $("#notecard-" + noteid).attr("data-bg", note.getColor()); @@ -226,13 +255,13 @@ function openNoteActionMenu(notecard) { favoriteNote(noteid); } }, -// { -// text: "Make a List", -// icon: '', -// onClick: function () { -// makeList(noteid); -// } -// }, + { + text: "Make a List", + icon: '', + onClick: function () { + makeList(noteid); + } + }, { text: "Delete", color: "red", @@ -256,7 +285,7 @@ function openNoteActionMenu(notecard) { '
  • Edit
  • ' + '
  • Color
  • ' + '
  • Favorite
  • ' + - //'
  • Make a List
  • ' + + '
  • Make a List
  • ' + '
  • Delete
  • ' + '' + '' + @@ -278,4 +307,10 @@ $(".view-main").on("click", ".notecard .editbtn", function () { $(".view-main").on("contextmenu", ".notecard", function () { return openNoteActionMenu($(this)); +}); + +// Re-layout notes when any images load +$("img").on("load", function () { + console.log("Image loaded, redoing layout..."); + window.shuffleInstance.layout(); }); \ No newline at end of file