From 20a1e71100aee3a687b919b861e941de7a70c575 Mon Sep 17 00:00:00 2001 From: azivner Date: Sun, 11 Jun 2017 15:10:34 -0400 Subject: [PATCH] respect if note is supposed to be expanded or not and save expanded state --- app.py | 8 ++++++++ frontend/.gitignore | 2 ++ frontend/index.html | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/app.py b/app.py index fbc7e4fff..7dc4b8f03 100644 --- a/app.py +++ b/app.py @@ -211,6 +211,14 @@ class MoveToNote(Resource): api.add_resource(MoveToNote, '/notes//moveTo/') +class ExpandedNote(Resource): + def put(self, note_id, expanded): + execute("update notes_tree set is_expanded = ? where note_id = ?", [expanded, note_id]) + + conn.commit() + +api.add_resource(ExpandedNote, '/notes//expanded/') + 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") diff --git a/frontend/.gitignore b/frontend/.gitignore index c369a4d90..ee6226ac0 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -3,3 +3,5 @@ node_modules/ dist/ npm-debug.log yarn-error.log +app.pyc +demo.ncdb \ No newline at end of file diff --git a/frontend/index.html b/frontend/index.html index eedaf49ae..f07952ebb 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -235,6 +235,7 @@ for (let note of notes) { note.title = note.note_title; note.key = note.note_id; + note.expanded = note.is_expanded; if (note.children && note.children.length > 0) { copyTitle(note.children); @@ -244,6 +245,19 @@ copyTitle(notes); + function setExpanded(note_id, is_expanded) { + expanded_num = is_expanded ? 1 : 0; + + $.ajax({ + url: baseUrl + 'notes/' + note_id + '/expanded/' + expanded_num, + type: 'PUT', + contentType: "application/json", + success: function(result) { + + } + }); + } + $("#tree").fancytree({ extensions: ["hotkeys"], source: notes, @@ -253,6 +267,12 @@ loadNote(noteId); }, + expand: function(event, data) { + setExpanded(data.node.key, true); + }, + collapse: function(event, data) { + setExpanded(data.node.key, false); + }, hotkeys: { keydown: { "insert": function(node) {