Add make list button, don't "pop" cards on sync if they haven't changed

master v1.1.0
Skylar Ittner 5 years ago
parent f62d935431
commit f5be364d96

@ -243,10 +243,10 @@ class Note {
var text = this.getText().split('\n'); var text = this.getText().split('\n');
for (var i = 0; i < text.length; i++) { for (var i = 0; i < text.length; i++) {
if (text[i].match(/^[^\s\=\#\-<](.+)/)) { if (text[i].match(/^[^\s\=\#\-<](.+)/)) {
if (text.length > i && text[i + 1].match(/^[\=-](.+)/)) { // if (text.length > i && text[i + 1].match(/^[\=-](.+)/)) {
// Don't do it if the next line makes this one a heading // // Don't do it if the next line makes this one a heading
continue; // continue;
} // }
text[i] = "- [ ] " + text[i]; text[i] = "- [ ] " + text[i];
} }
} }
@ -299,6 +299,7 @@ class Note {
if (this.getColor() != othernote.getColor()) { if (this.getColor() != othernote.getColor()) {
return false; return false;
} }
return true;
} }
} }

@ -157,7 +157,9 @@ class Notes {
console.log("local note that's overwriting it: ", note); console.log("local note that's overwriting it: ", note);
notesToSaveRemote.push(note); notesToSaveRemote.push(note);
} else { } 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 // They aren't the same, let's trust the server
notesToSaveLocal.push(remnote); notesToSaveLocal.push(remnote);
} }

@ -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) { for (i in window.shuffleInstance.items) {
window.shuffleInstance.remove(window.shuffleInstance.items[i]); window.shuffleInstance.remove(window.shuffleInstance.items[i]);
} }
@ -100,6 +119,7 @@ function loadNotesToCards(notes, callback) {
} }
function loadCards(callback) { function loadCards(callback) {
var oldnotes = NOTES.getAll().slice();
NOTES.syncAll(function (notes) { NOTES.syncAll(function (notes) {
if ($("#offline-indicator").css("display") != "none") { if ($("#offline-indicator").css("display") != "none") {
app.toast.create({ app.toast.create({
@ -108,10 +128,11 @@ function loadCards(callback) {
}).open(); }).open();
} }
$("#offline-indicator").css("display", "none"); $("#offline-indicator").css("display", "none");
loadNotesToCards(notes, callback); console.log("Comparing: ", notes, oldnotes);
loadNotesToCards(notes, oldnotes, callback);
}, function (notes) { }, function (notes) {
$("#offline-indicator").css("display", ""); $("#offline-indicator").css("display", "");
loadNotesToCards(notes, callback); loadNotesToCards(notes, oldnotes, callback);
}); });
} }
@ -133,10 +154,15 @@ function favoriteNote(id) {
note.setModified(); note.setModified();
$("#notecard-" + id).attr("data-favorite", note.getFavorite() ? "1" : "0"); $("#notecard-" + id).attr("data-favorite", note.getFavorite() ? "1" : "0");
note.saveNote(); note.saveNote();
NOTES.syncAll();
} }
function makeList(id) { function makeList(id) {
var note = NOTES.get(id);
note.toChecklist();
note.setModified();
note.saveNote();
app.ptr.refresh();
} }
function deleteNote(id) { function deleteNote(id) {
@ -144,8 +170,10 @@ function deleteNote(id) {
var note = NOTES.get(id); var note = NOTES.get(id);
note.deleteme(); note.deleteme();
NOTES.set(note); NOTES.set(note);
window.shuffleInstance.remove(document.getElementById("notecard-" + id)); window.shuffleInstance.remove(document.getElementById("notecard-col-" + id));
loadCards(); $("#notecard-col-" + id).remove();
window.shuffleInstance.layout();
NOTES.syncAll();
}); });
} }
@ -190,6 +218,7 @@ $("#app").on("click", "#colorpicker .colorpicker-color", function () {
note.setColor(color); note.setColor(color);
note.setModified(); note.setModified();
note.saveNote(); note.saveNote();
NOTES.syncAll();
$("#notecard-" + noteid).data("bg", note.getColor()); $("#notecard-" + noteid).data("bg", note.getColor());
$("#notecard-" + noteid).data("fg", note.getTextColor()); $("#notecard-" + noteid).data("fg", note.getTextColor());
$("#notecard-" + noteid).attr("data-bg", note.getColor()); $("#notecard-" + noteid).attr("data-bg", note.getColor());
@ -226,13 +255,13 @@ function openNoteActionMenu(notecard) {
favoriteNote(noteid); favoriteNote(noteid);
} }
}, },
// { {
// text: "Make a List", text: "Make a List",
// icon: '<i class="fas fa-tasks fa-fw"></i>', icon: '<i class="fas fa-tasks fa-fw"></i>',
// onClick: function () { onClick: function () {
// makeList(noteid); makeList(noteid);
// } }
// }, },
{ {
text: "Delete", text: "Delete",
color: "red", color: "red",
@ -256,7 +285,7 @@ function openNoteActionMenu(notecard) {
'<li><a class="list-button item-link edit-note-btn" data-note="' + noteid + '"><i class="fas fa-edit fa-fw"></i> Edit</a></li>' + '<li><a class="list-button item-link edit-note-btn" data-note="' + noteid + '"><i class="fas fa-edit fa-fw"></i> Edit</a></li>' +
'<li><a class="list-button item-link color-note-btn" data-note="' + noteid + '"><i class="fas fa-palette fa-fw"></i> Color</a></li>' + '<li><a class="list-button item-link color-note-btn" data-note="' + noteid + '"><i class="fas fa-palette fa-fw"></i> Color</a></li>' +
'<li><a class="list-button item-link favorite-note-btn" data-note="' + noteid + '"><i class="fas fa-star-half-alt fa-fw"></i> Favorite</a></li>' + '<li><a class="list-button item-link favorite-note-btn" data-note="' + noteid + '"><i class="fas fa-star-half-alt fa-fw"></i> Favorite</a></li>' +
//'<li><a class="list-button item-link listify-note-btn" data-note="' + noteid + '"><i class="fas fa-tasks fa-fw"></i> Make a List</a></li>' + '<li><a class="list-button item-link listify-note-btn" data-note="' + noteid + '"><i class="fas fa-tasks fa-fw"></i> Make a List</a></li>' +
'<li><a class="list-button item-link delete-note-btn text-color-red" data-note="' + noteid + '"><i class="fas fa-trash fa-fw"></i> Delete</a></li>' + '<li><a class="list-button item-link delete-note-btn text-color-red" data-note="' + noteid + '"><i class="fas fa-trash fa-fw"></i> Delete</a></li>' +
'</ul>' + '</ul>' +
'</div>' + '</div>' +
@ -278,4 +307,10 @@ $(".view-main").on("click", ".notecard .editbtn", function () {
$(".view-main").on("contextmenu", ".notecard", function () { $(".view-main").on("contextmenu", ".notecard", function () {
return openNoteActionMenu($(this)); return openNoteActionMenu($(this));
});
// Re-layout notes when any images load
$("img").on("load", function () {
console.log("Image loaded, redoing layout...");
window.shuffleInstance.layout();
}); });
Loading…
Cancel
Save