From e58b8e6c40e6665f9a30249bf8e94995f9a6f3cc Mon Sep 17 00:00:00 2001 From: azivner Date: Tue, 22 Aug 2017 21:23:10 -0400 Subject: [PATCH] last note viewed is displayed after loading the app. Doesn't work well with cloned notes yet, also scrolling to the item in the tree doesn't work yet. --- src/notes.py | 2 ++ src/tree.py | 10 ++++++---- static/js/tree.js | 13 ++++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/notes.py b/src/notes.py index fe0050601..c734185af 100644 --- a/src/notes.py +++ b/src/notes.py @@ -10,6 +10,8 @@ from sql import delete, execute, insert, getResults, getSingleResult, commit class Notes(Resource): def get(self, note_id): + execute("update options set opt_value = ? where opt_name = 'start_node'", [note_id]) + return { 'detail': getSingleResult("select * from notes where note_id = ?", [note_id]), 'formatting': getResults("select * from formatting where note_id = ? order by note_offset", [note_id]), diff --git a/src/tree.py b/src/tree.py index 42a855783..e16618083 100644 --- a/src/tree.py +++ b/src/tree.py @@ -1,8 +1,6 @@ from flask_restful import Resource -from sql import getResults -from flask_restful import Resource -from sql import getResults +from sql import getResults, getSingleResult class Tree(Resource): @@ -35,4 +33,8 @@ class Tree(Resource): parent['children'].append(note) parent['folder'] = True - return rootNotes + retObject = {} + retObject['notes'] = rootNotes + retObject['start_note_id'] = getSingleResult('select * from options where opt_name = "start_node"')['opt_value']; + + return retObject diff --git a/static/js/tree.js b/static/js/tree.js index c42b2cb00..de65e7d51 100644 --- a/static/js/tree.js +++ b/static/js/tree.js @@ -1,5 +1,8 @@ $(function(){ - $.get(baseUrl + 'tree').then(notes => { + $.get(baseUrl + 'tree').then(resp => { + const notes = resp.notes; + const startNoteId = resp.start_note_id; + function copyTitle(notes) { for (let note of notes) { note.title = note.note_title; @@ -33,6 +36,7 @@ $(function(){ } $("#tree").fancytree({ + autoScroll: true, extensions: ["hotkeys"], source: notes, activate: function(event, data){ @@ -47,6 +51,13 @@ $(function(){ collapse: function(event, data) { setExpanded(data.node.key, false); }, + init: function(event, data) { + console.log("Activating..."); + + if (startNoteId) { + data.tree.activateKey(startNoteId); + } + }, hotkeys: { keydown: { "insert": function(node) {