added "save search to note" button

This commit is contained in:
zadam
2021-06-06 11:01:10 +02:00
parent e48609aa68
commit c886583396
10 changed files with 93 additions and 40 deletions

View File

@@ -12,9 +12,16 @@ const utils = require('../../services/utils');
const path = require('path');
const Attribute = require('../../becca/entities/attribute.js');
const htmlSanitizer = require('../../services/html_sanitizer');
const {formatAttrForSearch} = require("../../services/attribute_formatter.js");
function findClippingNote(todayNote, pageUrl) {
const notes = todayNote.getDescendantNotesWithLabel('pageUrl', pageUrl);
const notes = todayNote.searchNoteInSubtree(
formatAttrForSearch({
type: 'label',
name: "pageUrl",
value: pageUrl
}, true)
);
for (const note of notes) {
if (note.getOwnedLabelValue('clipType') === 'clippings') {

View File

@@ -13,11 +13,11 @@ function getInboxNote(req) {
let inbox;
if (hoistedNote) {
([inbox] = hoistedNote.getDescendantNotesWithLabel('hoistedInbox'));
if (!hoistedNote.isRoot()) {
inbox = hoistedNote.searchNoteInSubtree('#hoistedInbox');
if (!inbox) {
([inbox] = hoistedNote.getDescendantNotesWithLabel('inbox'));
inbox = hoistedNote.searchNoteInSubtree('#inbox');
}
if (!inbox) {
@@ -114,39 +114,35 @@ function getSearchRoot() {
return searchRoot;
}
function saveSearchNote(req) {
const searchNote = becca.getNote(req.body.searchNoteId);
const hoistedNote = getHoistedNote();
let searchHome;
if (!hoistedNote.isRoot()) {
searchHome = hoistedNote.searchNoteInSubtree('#hoistedSearchHome')
|| hoistedNote.searchNoteInSubtree('#searchHome')
|| hoistedNote;
}
else {
const today = dateUtils.localNowDate();
searchHome = hoistedNote.searchNoteInSubtree('#searchHome')
|| dateNoteService.getDateNote(today);
}
return searchNote.cloneTo(searchHome.noteId);
}
function createSearchNote(req) {
const params = req.body;
const searchString = params.searchString || "";
let ancestorNoteId = params.ancestorNoteId;
const hoistedNote = getHoistedNote();
let searchHome = getSearchRoot();
// if (hoistedNote) {
// ([searchHome] = hoistedNote.getDescendantNotesWithLabel('hoistedSearchHome'));
//
// if (!searchHome) {
// ([searchHome] = hoistedNote.getDescendantNotesWithLabel('searchHome'));
// }
//
// if (!searchHome) {
// searchHome = hoistedNote;
// }
//
// if (!ancestorNoteId) {
// ancestorNoteId = hoistedNote.noteId;
// }
// }
// else {
// const today = dateUtils.localNowDate();
//
// searchHome = attributeService.getNoteWithLabel('searchHome')
// || dateNoteService.getDateNote(today);
// }
const ancestorNoteId = params.ancestorNoteId || hoistedNote.noteId;
const {note} = noteService.createNewNote({
parentNoteId: searchHome.noteId,
parentNoteId: getSearchRoot().noteId,
title: 'Search: ' + searchString,
content: "",
type: 'search',
@@ -163,9 +159,7 @@ function createSearchNote(req) {
}
function getHoistedNote() {
return cls.getHoistedNoteId() && cls.getHoistedNoteId() !== 'root'
? becca.getNote(cls.getHoistedNoteId())
: null;
return becca.getNote(cls.getHoistedNoteId());
}
module.exports = {
@@ -175,5 +169,6 @@ module.exports = {
getYearNote,
getDateNotesForMonth,
createSqlConsole,
createSearchNote
createSearchNote,
saveSearchNote
};

View File

@@ -92,7 +92,7 @@ function update(name, value) {
}
function getUserThemes() {
const notes = searchService.findNotes("#appTheme");
const notes = searchService.searchNotes("#appTheme");
const ret = [];
for (const note of notes) {

View File

@@ -212,6 +212,7 @@ function register(app) {
apiRoute(GET, '/api/date-notes/notes-for-month/:month', dateNotesRoute.getDateNotesForMonth);
apiRoute(POST, '/api/sql-console', dateNotesRoute.createSqlConsole);
apiRoute(POST, '/api/search-note', dateNotesRoute.createSearchNote);
apiRoute(POST, '/api/save-search-note', dateNotesRoute.saveSearchNote);
route(GET, '/api/images/:noteId/:filename', [auth.checkApiAuthOrElectron], imageRoute.returnImage);
route(POST, '/api/images', [auth.checkApiAuthOrElectron, uploadMiddleware, csrfMiddleware], imageRoute.uploadImage, apiResultHandler);