Merge branch 'master' into custom-search-dialog

This commit is contained in:
zadam 2022-05-15 20:35:26 +02:00
commit 1d8664927d
6 changed files with 37 additions and 8 deletions

View File

@ -43,7 +43,6 @@ export default class Entrypoints extends Component {
const inboxNote = await dateNoteService.getInboxNote();
const {note} = await server.post(`notes/${inboxNote.noteId}/children?target=into`, {
title: 'new note',
content: '',
type: 'text',
isProtected: inboxNote.isProtected && protectedSessionHolder.isProtectedSessionAvailable()

View File

@ -28,8 +28,6 @@ async function createNote(parentNotePath, options = {}) {
[options.title, options.content] = parseSelectedHtml(window.cutToNote.getSelectedHtml());
}
const newNoteName = options.title || "new note";
const parentNoteId = treeService.getNoteIdFromNotePath(parentNotePath);
if (options.type === 'mermaid' && !options.content) {
@ -41,7 +39,7 @@ async function createNote(parentNotePath, options = {}) {
}
const {note, branch} = await server.post(`notes/${parentNoteId}/children?target=${options.target}&targetBranchId=${options.targetBranchId || ""}`, {
title: newNoteName,
title: options.title,
content: options.content || "",
isProtected: options.isProtected,
type: options.type,

View File

@ -219,6 +219,15 @@ const ATTR_HELP = {
"shareDisallowRobotIndexing": `will forbid robot indexing of this note via <code>X-Robots-Tag: noindex</code> header`,
"displayRelations": "comma delimited names of relations which should be displayed. All other ones will be hidden.",
"hideRelations": "comma delimited names of relations which should be hidden. All other ones will be displayed.",
"titleTemplate": `default title of notes created as children of this note. The value is evaluated as JavaScript string
and thus can be enriched with dynamic content via the injected <code>now</code> and <code>parentNote</code> variables. Examples:
<ul>
<li><code>\${parentNote.getLabelValue('authorName')}'s literary works</code></li>
<li><code>Log for \${now.format('YYYY-MM-DD HH:mm:ss')}</code></li>
</ul>
See <a href="https://github.com/zadam/trilium/wiki/Default-note-title">wiki with details</a>, API docs for <a href="https://zadam.github.io/trilium/backend_api/Note.html">parentNote</a> and <a href="https://day.js.org/docs/en/display/format">now</a> for details.`
},
"relation": {
"runOnNoteCreation": "executes when note is created on backend",

View File

@ -50,6 +50,7 @@ module.exports = [
{ type: 'label', name: 'shareDisallowRobotIndexing' },
{ type: 'label', name: 'displayRelations' },
{ type: 'label', name: 'hideRelations' },
{ type: 'label', name: 'titleTemplate' },
// relation names
{ type: 'relation', name: 'internalLink' },

View File

@ -17,7 +17,7 @@ const becca = require('../becca/becca');
const Branch = require('../becca/entities/branch');
const Note = require('../becca/entities/note');
const Attribute = require('../becca/entities/attribute');
const TaskContext = require("./task_context.js");
const dayjs = require("dayjs");
function getNewNotePosition(parentNoteId) {
const note = becca.notes[parentNoteId];
@ -79,6 +79,28 @@ function copyChildAttributes(parentNote, childNote) {
}
}
function getNewNoteTitle(parentNote) {
let title = "new note";
const titleTemplate = parentNote.getLabelValue('titleTemplate');
if (titleTemplate !== null) {
try {
const now = dayjs(cls.getLocalNowDateTime() || new Date());
// "officially" injected values:
// - now
// - parentNote
title = eval('`' + titleTemplate + '`');
} catch (e) {
log.error(`Title template of note '${parentNote.noteId}' failed with: ${e.message}`);
}
}
return title;
}
/**
* Following object properties are mandatory:
* - {string} parentNoteId
@ -104,8 +126,7 @@ function createNewNote(params) {
}
if (params.title === null || params.title === undefined) {
// empty title is allowed since it's possible to create such in the UI
throw new Error(`Note title must be set`);
params.title = getNewNoteTitle(parentNote);
}
if (params.content === null || params.content === undefined) {

View File

@ -153,10 +153,11 @@ function setDbAsInitialized() {
function optimize() {
log.info("Optimizing database");
const start = Date.now();
sql.execute("PRAGMA optimize");
log.info("Optimization finished.");
log.info(`Optimization finished in ${Date.now() - start}ms.`);
}
dbReady.then(() => {