From 4f1e6ec70f9f2f92202763dfc74f983a09d84c04 Mon Sep 17 00:00:00 2001 From: azivner Date: Tue, 21 Aug 2018 12:50:43 +0200 Subject: [PATCH] note API additions --- src/entities/note.js | 40 +++++++++++++++++++ .../javascripts/services/note_detail.js | 1 + 2 files changed, 41 insertions(+) diff --git a/src/entities/note.js b/src/entities/note.js index 3ce9288f5..ee793247f 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.js index ed71e5aab..8fba4ff2b 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" });