mirror of
https://github.com/zadam/trilium.git
synced 2025-02-24 15:05:31 +08:00
if search note would end up outside of current hoisting, save it under the hoisted note, closes #1694
This commit is contained in:
parent
d476dfc53b
commit
3fe87259e2
1 changed files with 19 additions and 3 deletions
|
@ -5,6 +5,8 @@ const sql = require('../../services/sql');
|
||||||
const dateUtils = require('../../services/date_utils');
|
const dateUtils = require('../../services/date_utils');
|
||||||
const noteService = require('../../services/notes');
|
const noteService = require('../../services/notes');
|
||||||
const attributeService = require('../../services/attributes');
|
const attributeService = require('../../services/attributes');
|
||||||
|
const cls = require('../../services/cls');
|
||||||
|
const repository = require('../../services/repository');
|
||||||
|
|
||||||
function getInboxNote(req) {
|
function getInboxNote(req) {
|
||||||
return attributeService.getNoteWithLabel('inbox')
|
return attributeService.getNoteWithLabel('inbox')
|
||||||
|
@ -62,13 +64,27 @@ function createSqlConsole() {
|
||||||
function createSearchNote(req) {
|
function createSearchNote(req) {
|
||||||
const params = req.body;
|
const params = req.body;
|
||||||
const searchString = params.searchString || "";
|
const searchString = params.searchString || "";
|
||||||
|
let ancestorNoteId = params.ancestorNoteId;
|
||||||
|
|
||||||
const today = dateUtils.localNowDate();
|
const today = dateUtils.localNowDate();
|
||||||
|
|
||||||
const searchHome =
|
let searchHome =
|
||||||
attributeService.getNoteWithLabel('searchHome')
|
attributeService.getNoteWithLabel('searchHome')
|
||||||
|| dateNoteService.getDateNote(today);
|
|| 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({
|
const {note} = noteService.createNewNote({
|
||||||
parentNoteId: searchHome.noteId,
|
parentNoteId: searchHome.noteId,
|
||||||
title: 'Search: ' + searchString,
|
title: 'Search: ' + searchString,
|
||||||
|
@ -79,8 +95,8 @@ function createSearchNote(req) {
|
||||||
|
|
||||||
note.setLabel('searchString', searchString);
|
note.setLabel('searchString', searchString);
|
||||||
|
|
||||||
if (params.ancestorNoteId) {
|
if (ancestorNoteId) {
|
||||||
note.setRelation('ancestor', params.ancestorNoteId);
|
note.setRelation('ancestor', ancestorNoteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return note;
|
return note;
|
||||||
|
|
Loading…
Reference in a new issue