mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
server-ts: Port services/special_notes
This commit is contained in:
parent
16283d4054
commit
984ce49168
@ -1,4 +1,4 @@
|
|||||||
const specialNotesService = require('../services/special_notes.js');
|
const specialNotesService = require('../services/special_notes');
|
||||||
const dateNotesService = require('../services/date_notes');
|
const dateNotesService = require('../services/date_notes');
|
||||||
const eu = require('./etapi_utils');
|
const eu = require('./etapi_utils');
|
||||||
const mappers = require('./mappers.js');
|
const mappers = require('./mappers.js');
|
||||||
|
@ -4,7 +4,7 @@ const imageType = require('image-type');
|
|||||||
const imageService = require('../../services/image');
|
const imageService = require('../../services/image');
|
||||||
const noteService = require('../../services/notes');
|
const noteService = require('../../services/notes');
|
||||||
const { sanitizeAttributeName } = require('../../services/sanitize_attribute_name');
|
const { sanitizeAttributeName } = require('../../services/sanitize_attribute_name');
|
||||||
const specialNotesService = require('../../services/special_notes.js');
|
const specialNotesService = require('../../services/special_notes');
|
||||||
|
|
||||||
function uploadImage(req) {
|
function uploadImage(req) {
|
||||||
const file = req.file;
|
const file = req.file;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
const dateNoteService = require('../../services/date_notes');
|
const dateNoteService = require('../../services/date_notes');
|
||||||
const sql = require('../../services/sql');
|
const sql = require('../../services/sql');
|
||||||
const cls = require('../../services/cls');
|
const cls = require('../../services/cls');
|
||||||
const specialNotesService = require('../../services/special_notes.js');
|
const specialNotesService = require('../../services/special_notes');
|
||||||
const becca = require('../../becca/becca');
|
const becca = require('../../becca/becca');
|
||||||
|
|
||||||
function getInboxNote(req) {
|
function getInboxNote(req) {
|
||||||
|
@ -48,7 +48,7 @@ const senderRoute = require('./api/sender.js');
|
|||||||
const filesRoute = require('./api/files.js');
|
const filesRoute = require('./api/files.js');
|
||||||
const searchRoute = require('./api/search');
|
const searchRoute = require('./api/search');
|
||||||
const bulkActionRoute = require('./api/bulk_action.js');
|
const bulkActionRoute = require('./api/bulk_action.js');
|
||||||
const specialNotesRoute = require('./api/special_notes.js');
|
const specialNotesRoute = require('./api/special_notes');
|
||||||
const noteMapRoute = require('./api/note_map.js');
|
const noteMapRoute = require('./api/note_map.js');
|
||||||
const clipperRoute = require('./api/clipper.js');
|
const clipperRoute = require('./api/clipper.js');
|
||||||
const similarNotesRoute = require('./api/similar_notes.js');
|
const similarNotesRoute = require('./api/similar_notes.js');
|
||||||
@ -67,7 +67,7 @@ const etapiAttachmentRoutes = require('../etapi/attachments.js');
|
|||||||
const etapiAttributeRoutes = require('../etapi/attributes');
|
const etapiAttributeRoutes = require('../etapi/attributes');
|
||||||
const etapiBranchRoutes = require('../etapi/branches.js');
|
const etapiBranchRoutes = require('../etapi/branches.js');
|
||||||
const etapiNoteRoutes = require('../etapi/notes.js');
|
const etapiNoteRoutes = require('../etapi/notes.js');
|
||||||
const etapiSpecialNoteRoutes = require('../etapi/special_notes.js');
|
const etapiSpecialNoteRoutes = require('../etapi/special_notes');
|
||||||
const etapiSpecRoute = require('../etapi/spec.js');
|
const etapiSpecRoute = require('../etapi/spec.js');
|
||||||
const etapiBackupRoute = require('../etapi/backup');
|
const etapiBackupRoute = require('../etapi/backup');
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ const SearchContext = require('./search/search_context');
|
|||||||
const becca = require('../becca/becca');
|
const becca = require('../becca/becca');
|
||||||
const ws = require('./ws');
|
const ws = require('./ws');
|
||||||
const SpacedUpdate = require('./spaced_update');
|
const SpacedUpdate = require('./spaced_update');
|
||||||
const specialNotesService = require('./special_notes.js');
|
const specialNotesService = require('./special_notes');
|
||||||
const branchService = require('./branches');
|
const branchService = require('./branches');
|
||||||
const exportService = require('./export/zip');
|
const exportService = require('./export/zip');
|
||||||
const syncMutex = require('./sync_mutex');
|
const syncMutex = require('./sync_mutex');
|
||||||
|
@ -155,6 +155,7 @@ function getAndValidateParent(params: GetValidateParams) {
|
|||||||
interface NoteParams {
|
interface NoteParams {
|
||||||
/** optionally can force specific noteId */
|
/** optionally can force specific noteId */
|
||||||
noteId?: string;
|
noteId?: string;
|
||||||
|
branchId?: string;
|
||||||
parentNoteId: string;
|
parentNoteId: string;
|
||||||
templateNoteId?: string;
|
templateNoteId?: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
@ -1,16 +1,20 @@
|
|||||||
const attributeService = require('./attributes');
|
import attributeService = require('./attributes');
|
||||||
const dateNoteService = require('./date_notes');
|
import dateNoteService = require('./date_notes');
|
||||||
const becca = require('../becca/becca');
|
import becca = require('../becca/becca');
|
||||||
const noteService = require('./notes');
|
import noteService = require('./notes');
|
||||||
const dateUtils = require('./date_utils');
|
import dateUtils = require('./date_utils');
|
||||||
const log = require('./log');
|
import log = require('./log');
|
||||||
const hoistedNoteService = require('./hoisted_note');
|
import hoistedNoteService = require('./hoisted_note');
|
||||||
const searchService = require('./search/services/search');
|
import searchService = require('./search/services/search');
|
||||||
const SearchContext = require('./search/search_context');
|
import SearchContext = require('./search/search_context');
|
||||||
const {LBTPL_NOTE_LAUNCHER, LBTPL_CUSTOM_WIDGET, LBTPL_SPACER, LBTPL_SCRIPT} = require('./hidden_subtree');
|
import hiddenSubtree = require('./hidden_subtree');
|
||||||
|
const { LBTPL_NOTE_LAUNCHER, LBTPL_CUSTOM_WIDGET, LBTPL_SPACER, LBTPL_SCRIPT } = hiddenSubtree;
|
||||||
|
|
||||||
function getInboxNote(date) {
|
function getInboxNote(date: string) {
|
||||||
const workspaceNote = hoistedNoteService.getWorkspaceNote();
|
const workspaceNote = hoistedNoteService.getWorkspaceNote();
|
||||||
|
if (!workspaceNote) {
|
||||||
|
throw new Error("Unable to find workspace note");
|
||||||
|
}
|
||||||
|
|
||||||
let inbox;
|
let inbox;
|
||||||
|
|
||||||
@ -48,8 +52,9 @@ function createSqlConsole() {
|
|||||||
return note;
|
return note;
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveSqlConsole(sqlConsoleNoteId) {
|
function saveSqlConsole(sqlConsoleNoteId: string) {
|
||||||
const sqlConsoleNote = becca.getNote(sqlConsoleNoteId);
|
const sqlConsoleNote = becca.getNote(sqlConsoleNoteId);
|
||||||
|
if (!sqlConsoleNote) throw new Error(`Unable to find SQL console note ID: ${sqlConsoleNoteId}`);
|
||||||
const today = dateUtils.localNowDate();
|
const today = dateUtils.localNowDate();
|
||||||
|
|
||||||
const sqlConsoleHome =
|
const sqlConsoleHome =
|
||||||
@ -59,7 +64,7 @@ function saveSqlConsole(sqlConsoleNoteId) {
|
|||||||
const result = sqlConsoleNote.cloneTo(sqlConsoleHome.noteId);
|
const result = sqlConsoleNote.cloneTo(sqlConsoleHome.noteId);
|
||||||
|
|
||||||
for (const parentBranch of sqlConsoleNote.getParentBranches()) {
|
for (const parentBranch of sqlConsoleNote.getParentBranches()) {
|
||||||
if (parentBranch.parentNote.hasAncestor('_hidden')) {
|
if (parentBranch.parentNote?.hasAncestor('_hidden')) {
|
||||||
parentBranch.markAsDeleted();
|
parentBranch.markAsDeleted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,7 +72,7 @@ function saveSqlConsole(sqlConsoleNoteId) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createSearchNote(searchString, ancestorNoteId) {
|
function createSearchNote(searchString: string, ancestorNoteId: string) {
|
||||||
const {note} = noteService.createNewNote({
|
const {note} = noteService.createNewNote({
|
||||||
parentNoteId: getMonthlyParentNoteId('_search', 'search'),
|
parentNoteId: getMonthlyParentNoteId('_search', 'search'),
|
||||||
title: `Search: ${searchString}`,
|
title: `Search: ${searchString}`,
|
||||||
@ -88,6 +93,9 @@ function createSearchNote(searchString, ancestorNoteId) {
|
|||||||
|
|
||||||
function getSearchHome() {
|
function getSearchHome() {
|
||||||
const workspaceNote = hoistedNoteService.getWorkspaceNote();
|
const workspaceNote = hoistedNoteService.getWorkspaceNote();
|
||||||
|
if (!workspaceNote) {
|
||||||
|
throw new Error("Unable to find workspace note");
|
||||||
|
}
|
||||||
|
|
||||||
if (!workspaceNote.isRoot()) {
|
if (!workspaceNote.isRoot()) {
|
||||||
return workspaceNote.searchNoteInSubtree('#workspaceSearchHome')
|
return workspaceNote.searchNoteInSubtree('#workspaceSearchHome')
|
||||||
@ -101,14 +109,18 @@ function getSearchHome() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveSearchNote(searchNoteId) {
|
function saveSearchNote(searchNoteId: string) {
|
||||||
const searchNote = becca.getNote(searchNoteId);
|
const searchNote = becca.getNote(searchNoteId);
|
||||||
|
if (!searchNote) {
|
||||||
|
throw new Error("Unable to find search note");
|
||||||
|
}
|
||||||
|
|
||||||
const searchHome = getSearchHome();
|
const searchHome = getSearchHome();
|
||||||
|
|
||||||
const result = searchNote.cloneTo(searchHome.noteId);
|
const result = searchNote.cloneTo(searchHome.noteId);
|
||||||
|
|
||||||
for (const parentBranch of searchNote.getParentBranches()) {
|
for (const parentBranch of searchNote.getParentBranches()) {
|
||||||
if (parentBranch.parentNote.hasAncestor('_hidden')) {
|
if (parentBranch.parentNote?.hasAncestor('_hidden')) {
|
||||||
parentBranch.markAsDeleted();
|
parentBranch.markAsDeleted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,7 +128,7 @@ function saveSearchNote(searchNoteId) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMonthlyParentNoteId(rootNoteId, prefix) {
|
function getMonthlyParentNoteId(rootNoteId: string, prefix: string) {
|
||||||
const month = dateUtils.localNowDate().substring(0, 7);
|
const month = dateUtils.localNowDate().substring(0, 7);
|
||||||
const labelName = `${prefix}MonthNote`;
|
const labelName = `${prefix}MonthNote`;
|
||||||
|
|
||||||
@ -138,7 +150,7 @@ function getMonthlyParentNoteId(rootNoteId, prefix) {
|
|||||||
return monthNote.noteId;
|
return monthNote.noteId;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createScriptLauncher(parentNoteId, forceNoteId = null) {
|
function createScriptLauncher(parentNoteId: string, forceNoteId?: string) {
|
||||||
const note = noteService.createNewNote({
|
const note = noteService.createNewNote({
|
||||||
noteId: forceNoteId,
|
noteId: forceNoteId,
|
||||||
title: "Script Launcher",
|
title: "Script Launcher",
|
||||||
@ -151,7 +163,13 @@ function createScriptLauncher(parentNoteId, forceNoteId = null) {
|
|||||||
return note;
|
return note;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createLauncher({parentNoteId, launcherType, noteId}) {
|
interface LauncherConfig {
|
||||||
|
parentNoteId: string;
|
||||||
|
launcherType: string;
|
||||||
|
noteId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createLauncher({ parentNoteId, launcherType, noteId }: LauncherConfig) {
|
||||||
let note;
|
let note;
|
||||||
|
|
||||||
if (launcherType === 'note') {
|
if (launcherType === 'note') {
|
||||||
@ -197,10 +215,10 @@ function createLauncher({parentNoteId, launcherType, noteId}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetLauncher(noteId) {
|
function resetLauncher(noteId: string) {
|
||||||
const note = becca.getNote(noteId);
|
const note = becca.getNote(noteId);
|
||||||
|
|
||||||
if (note.isLaunchBarConfig()) {
|
if (note?.isLaunchBarConfig()) {
|
||||||
if (note) {
|
if (note) {
|
||||||
if (noteId === '_lbRoot') {
|
if (noteId === '_lbRoot') {
|
||||||
// deleting hoisted notes are not allowed, so we just reset the children
|
// deleting hoisted notes are not allowed, so we just reset the children
|
||||||
@ -228,7 +246,13 @@ function resetLauncher(noteId) {
|
|||||||
* Another use case was for script-packages (e.g. demo Task manager) which could this way register automatically/easily
|
* Another use case was for script-packages (e.g. demo Task manager) which could this way register automatically/easily
|
||||||
* into the launchbar - for this it's recommended to use backend API's createOrUpdateLauncher()
|
* into the launchbar - for this it's recommended to use backend API's createOrUpdateLauncher()
|
||||||
*/
|
*/
|
||||||
function createOrUpdateScriptLauncherFromApi(opts) {
|
function createOrUpdateScriptLauncherFromApi(opts: {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
action: string;
|
||||||
|
icon?: string;
|
||||||
|
shortcut?: string;
|
||||||
|
}) {
|
||||||
if (opts.id && !/^[a-z0-9]+$/i.test(opts.id)) {
|
if (opts.id && !/^[a-z0-9]+$/i.test(opts.id)) {
|
||||||
throw new Error(`Launcher ID can be alphanumeric only, '${opts.id}' given`);
|
throw new Error(`Launcher ID can be alphanumeric only, '${opts.id}' given`);
|
||||||
}
|
}
|
||||||
@ -263,7 +287,7 @@ function createOrUpdateScriptLauncherFromApi(opts) {
|
|||||||
return launcherNote;
|
return launcherNote;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export = {
|
||||||
getInboxNote,
|
getInboxNote,
|
||||||
createSqlConsole,
|
createSqlConsole,
|
||||||
saveSqlConsole,
|
saveSqlConsole,
|
Loading…
x
Reference in New Issue
Block a user