mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
code should not rely on fixed branch IDs since they can change after move
This commit is contained in:
parent
e5e0add1a2
commit
5c4db266a4
1
db/migrations/0198__NOOP.sql
Normal file
1
db/migrations/0198__NOOP.sql
Normal file
@ -0,0 +1 @@
|
||||
-- NOOP
|
@ -1,4 +0,0 @@
|
||||
UPDATE branches SET branchId = 'search' WHERE parentNoteId = 'hidden' AND noteId = 'search';
|
||||
-- the IDs are renamed in the 0199 migration
|
||||
UPDATE branches SET branchId = 'globalnotemap' WHERE parentNoteId = 'singles' AND noteId = 'globalnotemap';
|
||||
UPDATE branches SET branchId = 'sqlconsole' WHERE parentNoteId = 'hidden' AND noteId = 'sqlconsole';
|
@ -1,7 +1,6 @@
|
||||
UPDATE notes SET noteId = '_globalNoteMap', title = 'Note Map' WHERE noteId = 'globalnotemap';
|
||||
UPDATE note_contents SET noteId = '_globalNoteMap' WHERE noteId = 'globalnotemap';
|
||||
UPDATE note_revisions SET noteId = '_globalNoteMap' WHERE noteId = 'globalnotemap';
|
||||
UPDATE branches SET branchId = '_globalNoteMap' WHERE branchId = 'globalnotemap';
|
||||
UPDATE branches SET noteId = '_globalNoteMap' WHERE noteId = 'globalnotemap';
|
||||
UPDATE branches SET parentNoteId = '_globalNoteMap' WHERE parentNoteId = 'globalnotemap';
|
||||
UPDATE attributes SET noteId = '_globalNoteMap' WHERE noteId = 'globalnotemap';
|
||||
@ -11,7 +10,6 @@ UPDATE entity_changes SET entityId = '_globalNoteMap' WHERE entityId = 'globalno
|
||||
UPDATE notes SET noteId = '_bulkAction', title = 'Bulk Action' WHERE noteId = 'bulkaction';
|
||||
UPDATE note_contents SET noteId = '_bulkAction' WHERE noteId = 'bulkaction';
|
||||
UPDATE note_revisions SET noteId = '_bulkAction' WHERE noteId = 'bulkaction';
|
||||
UPDATE branches SET branchId = '_bulkAction' WHERE branchId = 'bulkaction';
|
||||
UPDATE branches SET parentNoteId = '_bulkAction' WHERE parentNoteId = 'bulkaction';
|
||||
UPDATE branches SET noteId = '_bulkAction' WHERE noteId = 'bulkaction';
|
||||
UPDATE attributes SET noteId = '_bulkAction' WHERE noteId = 'bulkaction';
|
||||
@ -22,7 +20,6 @@ UPDATE notes SET noteId = '_sqlConsole', title = 'SQL Console History' WHERE not
|
||||
UPDATE note_contents SET noteId = '_sqlConsole' WHERE noteId = 'sqlconsole';
|
||||
UPDATE note_revisions SET noteId = '_sqlConsole' WHERE noteId = 'sqlconsole';
|
||||
UPDATE branches SET noteId = '_sqlConsole' WHERE noteId = 'sqlconsole';
|
||||
UPDATE branches SET branchId = '_sqlConsole' WHERE branchId = 'sqlconsole';
|
||||
UPDATE branches SET parentNoteId = '_sqlConsole' WHERE parentNoteId = 'sqlconsole';
|
||||
UPDATE attributes SET noteId = '_sqlConsole' WHERE noteId = 'sqlconsole';
|
||||
UPDATE attributes SET value = '_sqlConsole' WHERE type = 'relation' AND value = 'sqlconsole';
|
||||
@ -31,8 +28,7 @@ UPDATE entity_changes SET entityId = '_sqlConsole' WHERE entityId = 'sqlconsole'
|
||||
UPDATE notes SET noteId = '_hidden', title = 'Hidden Notes' WHERE noteId = 'hidden';
|
||||
UPDATE note_contents SET noteId = '_hidden' WHERE noteId = 'hidden';
|
||||
UPDATE note_revisions SET noteId = '_hidden' WHERE noteId = 'hidden';
|
||||
UPDATE branches SET noteId = '_hidden' WHERE noteId = 'hidden';
|
||||
UPDATE branches SET branchId = '_hidden', prefix = NULL WHERE branchId = 'hidden';
|
||||
UPDATE branches SET noteId = '_hidden', prefix = NULL WHERE noteId = 'hidden';
|
||||
UPDATE branches SET parentNoteId = '_hidden' WHERE parentNoteId = 'hidden';
|
||||
UPDATE attributes SET noteId = '_hidden' WHERE noteId = 'hidden';
|
||||
UPDATE attributes SET value = '_hidden' WHERE type = 'relation' AND value = 'hidden';
|
||||
@ -42,7 +38,6 @@ UPDATE notes SET noteId = '_search', title = 'Search History' WHERE noteId = 'se
|
||||
UPDATE note_contents SET noteId = '_search' WHERE noteId = 'search';
|
||||
UPDATE note_revisions SET noteId = '_search' WHERE noteId = 'search';
|
||||
UPDATE branches SET noteId = '_search' WHERE noteId = 'search';
|
||||
UPDATE branches SET branchId = '_search' WHERE branchId = 'search';
|
||||
UPDATE branches SET parentNoteId = '_search' WHERE parentNoteId = 'search';
|
||||
UPDATE attributes SET noteId = '_search' WHERE noteId = 'search';
|
||||
UPDATE attributes SET value = '_search' WHERE type = 'relation' AND value = 'search';
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
const Note = require('./note');
|
||||
const AbstractEntity = require("./abstract_entity");
|
||||
const sql = require("../../services/sql");
|
||||
const dateUtils = require("../../services/date_utils");
|
||||
const utils = require("../../services/utils");
|
||||
const TaskContext = require("../../services/task_context");
|
||||
|
@ -57,7 +57,9 @@ async function moveAfterBranch(branchIdsToMove, afterBranchId) {
|
||||
}
|
||||
|
||||
async function moveToParentNote(branchIdsToMove, newParentBranchId) {
|
||||
if (newParentBranchId === '_lbRoot') {
|
||||
const newParentBranch = await froca.getBranch(newParentBranchId);
|
||||
|
||||
if (newParentBranch.noteId === '_lbRoot') {
|
||||
toastService.showError('Cannot move notes here.');
|
||||
return;
|
||||
}
|
||||
|
@ -493,12 +493,12 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
if (opts.type === 'customWidget' && !opts.widgetNoteId) { throw new Error("widgetNoteId is mandatory for launchers of type 'customWidget'"); }
|
||||
|
||||
const parentNoteId = !!opts.isVisible ? '_lbVisibleLaunchers' : '_lbAvailableLaunchers';
|
||||
const actualId = 'al_' + opts.id;
|
||||
const noteId = 'al_' + opts.id;
|
||||
|
||||
const launcherNote =
|
||||
becca.getNote(opts.id) ||
|
||||
specialNotesService.createLauncher({
|
||||
id: actualId,
|
||||
noteId: noteId,
|
||||
parentNoteId: parentNoteId,
|
||||
launcherType: opts.type,
|
||||
}).note;
|
||||
|
@ -121,8 +121,16 @@ function toggleNoteInParent(present, noteId, parentNoteId, prefix) {
|
||||
|
||||
function cloneNoteAfter(noteId, afterBranchId) {
|
||||
if (['_hidden', 'root'].includes(noteId)) {
|
||||
return { success: false, message: 'Cloning the given note is forbidden.' };
|
||||
} else if (afterBranchId === '_hidden') {
|
||||
return { success: false, message: `Cloning the note '${noteId}' is forbidden.` };
|
||||
}
|
||||
|
||||
const afterBranch = becca.getBranch(afterBranchId);
|
||||
|
||||
if (!afterBranch) {
|
||||
return { success: false, message: `Branch '${afterBranchId}' does not exist.` };
|
||||
}
|
||||
|
||||
if (afterBranch.noteId === '_hidden') {
|
||||
return { success: false, message: 'Cannot clone after the hidden branch.' };
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
const becca = require("../becca/becca");
|
||||
const noteService = require("./notes");
|
||||
const log = require("./log");
|
||||
|
||||
const LBTPL_ROOT = "_lbTplRoot";
|
||||
const LBTPL_BASE = "_lbTplBase";
|
||||
@ -248,7 +247,6 @@ function checkHiddenSubtreeRecursively(parentNoteId, item) {
|
||||
|
||||
if (!note) {
|
||||
({note, branch} = noteService.createNewNote({
|
||||
branchId: item.id,
|
||||
noteId: item.id,
|
||||
title: item.title,
|
||||
type: item.type,
|
||||
@ -286,10 +284,9 @@ function checkHiddenSubtreeRecursively(parentNoteId, item) {
|
||||
note.save();
|
||||
}
|
||||
|
||||
if (!branch) {
|
||||
// not sure if there's some better way to recover
|
||||
log.error(`Cannot find launcher branch id='${item.id}', ignoring...`);
|
||||
} else {
|
||||
if (branch) {
|
||||
// in case of launchers the branch ID is not preserved and should not be relied upon - launchers which move between
|
||||
// visible and available will change branch since branch's parent-child relationship is immutable
|
||||
if (item.notePosition !== undefined && branch.notePosition !== item.notePosition) {
|
||||
branch.notePosition = item.notePosition;
|
||||
branch.save();
|
||||
|
@ -166,7 +166,6 @@ function createNewNote(params) {
|
||||
note.setContent(params.content);
|
||||
|
||||
branch = new Branch({
|
||||
branchId: params.branchId,
|
||||
noteId: note.noteId,
|
||||
parentNoteId: params.parentNoteId,
|
||||
notePosition: params.notePosition !== undefined ? params.notePosition : getNewNotePosition(params.parentNoteId),
|
||||
|
@ -139,10 +139,9 @@ function getMonthlyParentNoteId(rootNoteId, prefix) {
|
||||
return monthNote.noteId;
|
||||
}
|
||||
|
||||
function createScriptLauncher(parentNoteId, forceId = null) {
|
||||
function createScriptLauncher(parentNoteId, forceNoteId = null) {
|
||||
const note = noteService.createNewNote({
|
||||
noteId: forceId,
|
||||
branchId: forceId,
|
||||
noteId: forceNoteId,
|
||||
title: "Script Launcher",
|
||||
type: 'launcher',
|
||||
content: '',
|
||||
@ -153,13 +152,12 @@ function createScriptLauncher(parentNoteId, forceId = null) {
|
||||
return note;
|
||||
}
|
||||
|
||||
function createLauncher({parentNoteId, launcherType, id}) {
|
||||
function createLauncher({parentNoteId, launcherType, noteId}) {
|
||||
let note;
|
||||
|
||||
if (launcherType === 'note') {
|
||||
note = noteService.createNewNote({
|
||||
noteId: id,
|
||||
branchId: id,
|
||||
noteId: noteId,
|
||||
title: "Note Launcher",
|
||||
type: 'launcher',
|
||||
content: '',
|
||||
@ -168,11 +166,10 @@ function createLauncher({parentNoteId, launcherType, id}) {
|
||||
|
||||
note.addRelation('template', LBTPL_NOTE_LAUNCHER);
|
||||
} else if (launcherType === 'script') {
|
||||
note = createScriptLauncher(parentNoteId, id);
|
||||
note = createScriptLauncher(parentNoteId, noteId);
|
||||
} else if (launcherType === 'customWidget') {
|
||||
note = noteService.createNewNote({
|
||||
noteId: id,
|
||||
branchId: id,
|
||||
noteId: noteId,
|
||||
title: "Widget Launcher",
|
||||
type: 'launcher',
|
||||
content: '',
|
||||
@ -182,8 +179,8 @@ function createLauncher({parentNoteId, launcherType, id}) {
|
||||
note.addRelation('template', LBTPL_CUSTOM_WIDGET);
|
||||
} else if (launcherType === 'spacer') {
|
||||
note = noteService.createNewNote({
|
||||
noteId: id,
|
||||
branchId: id,
|
||||
noteId: noteId,
|
||||
branchId: noteId,
|
||||
title: "Spacer",
|
||||
type: 'launcher',
|
||||
content: '',
|
||||
|
@ -187,7 +187,7 @@ function sortNotes(parentNoteId, customSortBy = 'title', reverse = false, folder
|
||||
for (const note of notes) {
|
||||
const branch = note.getParentBranches().find(b => b.parentNoteId === parentNoteId);
|
||||
|
||||
if (branch.branchId === '_hidden') {
|
||||
if (branch.noteId === '_hidden') {
|
||||
position = 999_999_999;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user