search can be triggered from URL, closes #385

This commit is contained in:
azivner 2019-01-25 22:18:34 +01:00
parent b59c175c2e
commit a87f4d8653
3 changed files with 29 additions and 10 deletions

View file

@ -121,6 +121,8 @@ $("#export-note-button").click(function () {
macInit.init();
searchNotesService.init(); // should be in front of treeService since that one manipulates address bar hash
treeService.showTree();
entrypoints.registerEntrypoints();

View file

@ -76,6 +76,15 @@ async function saveSearch() {
await treeService.activateNote(noteId);
}
function init() {
const hashValue = treeService.getHashValueFromAddress();
if (hashValue.startsWith("search=")) {
showSearch();
doSearch(hashValue.substr(7));
}
}
$searchInput.keyup(e => {
const searchText = $searchInput.val();
@ -100,5 +109,6 @@ export default {
toggleSearch,
resetSearch,
showSearch,
doSearch
doSearch,
init
};

View file

@ -483,16 +483,20 @@ async function reload() {
await getTree().reload(notes);
}
function getNotePathFromAddress() {
return document.location.hash.substr(1); // strip initial #
function isNotePathInAddress() {
return getHashValueFromAddress().startsWith("root");
}
function getHashValueFromAddress() {
return document.location.hash ? document.location.hash.substr(1) : ""; // strip initial #
}
async function loadTree() {
const resp = await server.get('tree');
startNotePath = resp.startNotePath;
if (document.location.hash) {
startNotePath = getNotePathFromAddress();
if (isNotePathInAddress()) {
startNotePath = getHashValueFromAddress();
}
return await treeBuilder.prepareTree(resp.notes, resp.branches, resp.relations);
@ -707,13 +711,15 @@ utils.bindShortcut('ctrl+p', createNoteInto);
utils.bindShortcut('ctrl+.', scrollToCurrentNote);
$(window).bind('hashchange', function() {
const notePath = getNotePathFromAddress();
if (isNotePathInAddress()) {
const notePath = getHashValueFromAddress();
if (notePath !== '-' && getCurrentNotePath() !== notePath) {
console.debug("Switching to " + notePath + " because of hash change");
activateNote(notePath);
}
}
});
utils.bindShortcut('alt+c', () => collapseTree()); // don't use shortened form since collapseTree() accepts argument
@ -745,5 +751,6 @@ export default {
showTree,
loadTree,
treeInitialized,
setExpandedToServer
setExpandedToServer,
getHashValueFromAddress
};