Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
date notes are now created with template relations
zadam45ee959c11a3
diff --git a/src/entities/note.js b/src/entities/note.jsindex 8524d9a69e..b2f7a4b112 100644--- a/src/entities/note.js+++ b/src/entities/note.js@@ -195,6 +195,8 @@ class Note extends Entity {/*** @returns {Promise<Attribute[]>} attributes belonging to this specific note (excludes inherited attributes)+ *+ * This method can be significantly faster than the getAttributes()*/async getOwnedAttributes(type, name) {let query = `SELECT * FROM attributes WHERE isDeleted = 0 AND noteId = ?`;@@ -215,6 +217,8 @@ class Note extends Entity {/*** @returns {Promise<Attribute>} attribute belonging to this specific note (excludes inherited attributes)+ *+ * This method can be significantly faster than the getAttribute()*/async getOwnedAttribute(type, name) {const attrs = await this.getOwnedAttributes(type, name);diff --git a/src/public/javascripts/services/note_type.js b/src/public/javascripts/services/note_type.jsindex bb9f6d035a..da95a5a7bf 100644--- a/src/public/javascripts/services/note_type.js+++ b/src/public/javascripts/services/note_type.js@@ -35,6 +35,9 @@ export default class NoteTypeContext {() => ["file", "image", "search"].includes(this.ctx.note.type));this.$noteTypeDesc.text(await this.findTypeTitle(this.ctx.note.type, this.ctx.note.mime));++ this.$executeScriptButton.toggle(this.ctx.note.mime.startsWith('application/javascript'));+ this.$renderButton.toggle(this.ctx.note.type === 'render');}/** actual body is rendered lazily on note-type button click */@@ -87,9 +90,6 @@ export default class NoteTypeContext {this.$noteTypeDropdown.append($mimeLink);}-- this.$executeScriptButton.toggle(this.ctx.note.mime.startsWith('application/javascript'));- this.$renderButton.toggle(this.ctx.note.type === 'render');}async findTypeTitle(type, mime) {diff --git a/src/services/attributes.js b/src/services/attributes.jsindex ff6a5e4872..8f4102b27b 100644--- a/src/services/attributes.js+++ b/src/services/attributes.js@@ -72,6 +72,15 @@ async function createLabel(noteId, name, value = "") {});}+async function createRelation(noteId, name, targetNoteId) {+ return await createAttribute({+ noteId: noteId,+ type: 'relation',+ name: name,+ value: targetNoteId+ });+}+async function createAttribute(attribute) {return await new Attribute(attribute).save();}@@ -114,6 +123,7 @@ module.exports = {getNotesWithLabels,getNoteWithLabel,createLabel,+ createRelation,createAttribute,getAttributeNames,isAttributeType,diff --git a/src/services/date_notes.js b/src/services/date_notes.jsindex 89d282179d..7887b4b40d 100644--- a/src/services/date_notes.js+++ b/src/services/date_notes.js@@ -67,6 +67,12 @@ async function getYearNote(dateStr, rootNote) {await attributeService.createLabel(yearNote.noteId, YEAR_LABEL, yearStr);await attributeService.createLabel(yearNote.noteId, 'sorted');++ const yearTemplateAttr = await rootNote.getOwnedAttribute('relation', 'yearTemplate');++ if (yearTemplateAttr) {+ await attributeService.createRelation(yearNote.noteId, 'template', yearTemplateAttr.value);+ }}return yearNote;@@ -83,6 +89,10 @@ async function getMonthNoteTitle(rootNote, monthNumber, dateObj) {/** @return {Promise<Note>} */async function getMonthNote(dateStr, rootNote) {+ if (!rootNote) {+ rootNote = await getRootCalendarNote();+ }+const monthStr = dateStr.substr(0, 7);const monthNumber = dateStr.substr(5, 2);@@ -103,6 +113,12 @@ async function getMonthNote(dateStr, rootNote) {await attributeService.createLabel(monthNote.noteId, MONTH_LABEL, monthStr);await attributeService.createLabel(monthNote.noteId, 'sorted');++ const monthTemplateAttr = await rootNote.getOwnedAttribute('relation', 'monthTemplate');++ if (monthTemplateAttr) {+ await attributeService.createRelation(monthNote.noteId, 'template', monthTemplateAttr.value);+ }}return monthNote;@@ -141,6 +157,12 @@ async function getDateNote(dateStr) {}await attributeService.createLabel(dateNote.noteId, DATE_LABEL, dateStr.substr(0, 10));++ const dateTemplateAttr = await rootNote.getOwnedAttribute('relation', 'dateTemplate');++ if (dateTemplateAttr) {+ await attributeService.createRelation(dateNote.noteId, 'template', dateTemplateAttr.value);+ }}return dateNote;