From b986e9335600693003eb128242227782ca6be52b Mon Sep 17 00:00:00 2001 From: azivner Date: Tue, 15 Aug 2017 21:29:12 -0400 Subject: [PATCH] support for cloned notes including updating clones. Creating clones is not supported. Renaming is handled a bit differently - all clones and original share the same name, while in Notecase desktop each clone has separate name. --- src/tree.py | 10 +++++++++- static/js/note.js | 4 +++- static/js/tree.js | 9 +++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/tree.py b/src/tree.py index c38066327..42a855783 100644 --- a/src/tree.py +++ b/src/tree.py @@ -7,7 +7,15 @@ from sql import getResults class Tree(Resource): def get(self): - notes = getResults("select notes_tree.*, notes.note_title from notes_tree join notes on notes.note_id = notes_tree.note_id order by note_pid, note_pos") + notes = getResults("select " + "notes_tree.*, " + "COALESCE(clone.note_title, notes.note_title) as note_title, " + "notes.note_clone_id, " + "case when notes.note_clone_id is null or notes.note_clone_id = '' then 0 else 1 end as is_clone " + "from notes_tree " + "join notes on notes.note_id = notes_tree.note_id " + "left join notes as clone on notes.note_clone_id = clone.note_id " + "order by note_pid, note_pos") rootNotes = [] notesMap = {} diff --git a/static/js/note.js b/static/js/note.js index cfaae36ca..23411617d 100644 --- a/static/js/note.js +++ b/static/js/note.js @@ -28,8 +28,10 @@ function noteChanged() { note.detail.note_title = title; + const note_id = note.detail.is_clone ? note.detail.note_clone_id : note.detail.note_id; + $.ajax({ - url: baseUrl + 'notes/' + note.detail.note_id, + url: baseUrl + 'notes/' + note_id, type: 'PUT', data: JSON.stringify(note), contentType: "application/json", diff --git a/static/js/tree.js b/static/js/tree.js index beb401eb2..2968164ca 100644 --- a/static/js/tree.js +++ b/static/js/tree.js @@ -3,6 +3,11 @@ $(function(){ function copyTitle(notes) { for (let note of notes) { note.title = note.note_title; + + if (note.is_clone) { + note.title += " (clone)"; + } + note.key = note.note_id; note.expanded = note.is_expanded; @@ -31,8 +36,8 @@ $(function(){ extensions: ["hotkeys"], source: notes, activate: function(event, data){ - var node = data.node.data; - var noteId = node.note_id; + const node = data.node.data; + const noteId = node.is_clone ? node.note_clone_id : node.note_id; loadNote(noteId); },