if search note would end up outside of current hoisting, save it under the hoisted note, closes #1694

This commit is contained in:
zadam 2021-02-26 23:33:22 +01:00
parent d476dfc53b
commit 3fe87259e2

View file

@ -5,6 +5,8 @@ const sql = require('../../services/sql');
const dateUtils = require('../../services/date_utils');
const noteService = require('../../services/notes');
const attributeService = require('../../services/attributes');
const cls = require('../../services/cls');
const repository = require('../../services/repository');
function getInboxNote(req) {
return attributeService.getNoteWithLabel('inbox')
@ -62,13 +64,27 @@ function createSqlConsole() {
function createSearchNote(req) {
const params = req.body;
const searchString = params.searchString || "";
let ancestorNoteId = params.ancestorNoteId;
const today = dateUtils.localNowDate();
const searchHome =
let searchHome =
attributeService.getNoteWithLabel('searchHome')
|| dateNoteService.getDateNote(today);
if (cls.getHoistedNoteId() && cls.getHoistedNoteId() !== 'root') {
const hoistedNote = repository.getNote(cls.getHoistedNoteId());
if (!hoistedNote.getDescendantNoteIds().includes(searchHome.noteId)) {
// otherwise the note would be saved outside of the hoisted context which is weird
searchHome = hoistedNote;
}
if (!ancestorNoteId) {
ancestorNoteId = cls.getHoistedNoteId();
}
}
const {note} = noteService.createNewNote({
parentNoteId: searchHome.noteId,
title: 'Search: ' + searchString,
@ -79,8 +95,8 @@ function createSearchNote(req) {
note.setLabel('searchString', searchString);
if (params.ancestorNoteId) {
note.setRelation('ancestor', params.ancestorNoteId);
if (ancestorNoteId) {
note.setRelation('ancestor', ancestorNoteId);
}
return note;