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
note API additions
azivner4f1e6ec70f9f
diff --git a/src/entities/note.js b/src/entities/note.jsindex 3ce9288f51..ee793247f1 100644--- a/src/entities/note.js+++ b/src/entities/note.js@@ -231,6 +231,46 @@ class Note extends Entity {async removeLabel(name, value = "") { return await this.removeAttribute(LABEL, name, value); }async removeRelation(name, value = "") { return await this.removeAttribute(RELATION, name, value); }+ async getRelationTarget(name) {+ const relation = await this.getRelation(name);++ return relation ? await repository.getNote(relation.value) : null;+ }++ async findNotesWithAttribute(type, name, value) {+ const params = [this.noteId, name];+ let valueCondition = "";++ if (value !== undefined) {+ params.push(value);+ valueCondition = " AND attributes.value = ?";+ }++ const notes = await repository.getEntities(`+ WITH RECURSIVE+ tree(noteId) AS (+ SELECT ?+ UNION+ SELECT branches.noteId FROM branches+ JOIN tree ON branches.parentNoteId = tree.noteId+ JOIN notes ON notes.noteId = branches.noteId+ WHERE notes.isDeleted = 0+ AND branches.isDeleted = 0+ )+ SELECT notes.* FROM notes+ JOIN tree ON tree.noteId = notes.noteId+ JOIN attributes ON attributes.noteId = notes.noteId+ WHERE attributes.isDeleted = 0+ AND attributes.name = ?+ ${valueCondition}+ ORDER BY noteId, position`, params);++ return notes;+ }++ async findNotesWithLabel(name, value) { return await this.findNotesWithAttribute(LABEL, name, value); }+ async findNotesWithRelation(name, value) { return await this.findNotesWithAttribute(RELATION, name, value); }+async getRevisions() {return await repository.getEntities("SELECT * FROM note_revisions WHERE noteId = ?", [this.noteId]);}diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.jsindex ed71e5aabd..8fba4ff2b2 100644--- a/src/public/javascripts/services/note_detail.js+++ b/src/public/javascripts/services/note_detail.js@@ -299,6 +299,7 @@ async function loadAttributes() {$input.datepicker({changeMonth: true,changeYear: true,+ yearRange: "c-200:c+10",dateFormat: "yy-mm-dd"});