allow refreshing saved note, closes #304

This commit is contained in:
azivner 2019-01-08 23:32:03 +01:00
parent 05aee884b6
commit c8ec86e537
4 changed files with 22 additions and 3 deletions

View File

@ -1,7 +1,9 @@
import noteDetailService from "./note_detail.js"; import noteDetailService from "./note_detail.js";
import treeService from "./tree.js";
const $searchString = $("#search-string"); const $searchString = $("#search-string");
const $component = $('#note-detail-search'); const $component = $('#note-detail-search');
const $refreshButton = $('#note-detail-search-refresh-results-button');
function getContent() { function getContent() {
return JSON.stringify({ return JSON.stringify({
@ -25,6 +27,8 @@ function show() {
$searchString.on('input', noteDetailService.noteChanged); $searchString.on('input', noteDetailService.noteChanged);
} }
$refreshButton.click(() => treeService.reload());
export default { export default {
getContent, getContent,
show, show,

View File

@ -352,6 +352,7 @@ function clearSelectedNodes() {
} }
async function treeInitialized() { async function treeInitialized() {
// - is used in mobile to indicate that we don't want to activate any note after load
if (startNotePath === '-') { if (startNotePath === '-') {
return; return;
} }
@ -363,7 +364,6 @@ async function treeInitialized() {
startNotePath = null; startNotePath = null;
} }
// - is used in mobile to indicate that we don't want to activate any note after load
if (startNotePath) { if (startNotePath) {
const node = await activateNote(startNotePath); const node = await activateNote(startNotePath);
@ -438,6 +438,16 @@ function initFancyTree(tree) {
$span.append(unhoistButton); $span.append(unhoistButton);
} }
},
// this is done to automatically lazy load all expanded search notes after tree load
loadChildren: function(event, data) {
data.node.visit(function(subNode){
// Load all lazy/unloaded child nodes
// (which will trigger `loadChildren` recursively)
if( subNode.isUndefined() && subNode.isExpanded() ) {
subNode.load();
}
});
} }
}); });

View File

@ -86,7 +86,7 @@ async function prepareNode(branch) {
extraClasses: await getExtraClasses(note), extraClasses: await getExtraClasses(note),
icon: await getIcon(note), icon: await getIcon(note),
refKey: note.noteId, refKey: note.noteId,
expanded: (note.type !== 'search' && branch.isExpanded) || hoistedNoteId === note.noteId expanded: branch.isExpanded || hoistedNoteId === note.noteId
}; };
if (note.hasChildren() || note.type === 'search') { if (note.hasChildren() || note.type === 'search') {

View File

@ -1,7 +1,12 @@
<div id="note-detail-search" class="note-detail-component"> <div id="note-detail-search" class="note-detail-component">
<div style="display: flex; align-items: center;"> <div style="display: flex; align-items: center;">
<strong>Search string: &nbsp; &nbsp;</strong> <strong>Search string: &nbsp; &nbsp;</strong>
<textarea rows="4" cols="50" id="search-string"></textarea> <textarea rows="4" cols="40" id="search-string"></textarea>
<span>
&nbsp; &nbsp;
<button type="button" class="btn btn-primary" id="note-detail-search-refresh-results-button">Refresh tree</button>
</span>
</div> </div>
<br /> <br />