basic implementation of saved searches finished, closes #83

This commit is contained in:
azivner 2018-03-12 23:27:21 -04:00
parent e5c0acbb43
commit f1b0b3bcdb
2 changed files with 28 additions and 3 deletions

View File

@ -654,14 +654,28 @@ const noteTree = (function() {
$tree.contextmenu(contextMenu.contextMenuSettings);
}
async function loadSearchNote(noteId) {
const note = await server.get('notes/' + noteId);
async function loadSearchNote(searchNoteId) {
const note = await server.get('notes/' + searchNoteId);
const json = JSON.parse(note.detail.content);
const noteIds = await server.get('notes?search=' + encodeURIComponent(json.searchString));
console.log("Found: ", noteIds);
for (const noteId of noteIds) {
const noteTreeId = "virt" + randomString(10);
notesTreeMap[noteTreeId] = {
noteTreeId: noteTreeId,
noteId: noteId,
parentNoteId: searchNoteId,
prefix: '',
virtual: true
};
setParentChildRelation(noteTreeId, searchNoteId, noteId);
}
return prepareNoteTreeInner(searchNoteId);
}
function getTree() {

View File

@ -219,4 +219,15 @@ function toObject(array, fn) {
}
return obj;
}
function randomString(len) {
let text = "";
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (let i = 0; i < len; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}