From 21d3b0c9d8daa4706b8a4610739eaf25643e1018 Mon Sep 17 00:00:00 2001 From: azivner Date: Mon, 12 Nov 2018 23:34:22 +0100 Subject: [PATCH] implemented mirror relations --- src/entities/attribute.js | 21 +++++++- src/public/javascripts/dialogs/attributes.js | 2 + src/public/javascripts/services/attributes.js | 21 ++++---- .../javascripts/services/note_autocomplete.js | 16 ++++-- src/public/javascripts/services/tree.js | 7 ++- src/public/javascripts/services/tree_cache.js | 2 +- src/public/stylesheets/style.css | 9 ++++ src/routes/api/attributes.js | 21 +++++++- src/services/consistency_checks.js | 14 +++++ src/services/events.js | 2 + src/services/handlers.js | 53 ++++++++++++++++++- src/services/repository.js | 21 ++++---- src/views/dialogs/attributes.ejs | 6 +++ 13 files changed, 164 insertions(+), 31 deletions(-) diff --git a/src/entities/attribute.js b/src/entities/attribute.js index c12f39a20..a40964b9f 100644 --- a/src/entities/attribute.js +++ b/src/entities/attribute.js @@ -40,10 +40,20 @@ class Attribute extends Entity { } } + /** + * @returns {Promise} + */ async getNote() { - return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]); + if (!this.__note) { + this.__note = await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]); + } + + return this.__note; } + /** + * @returns {Promise} + */ async getTargetNote() { if (this.type !== 'relation') { throw new Error(`Attribute ${this.attributeId} is not relation`); @@ -53,9 +63,16 @@ class Attribute extends Entity { return null; } - return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.value]); + if (!this.__targetNote) { + this.__targetNote = await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.value]); + } + + return this.__targetNote; } + /** + * @return {boolean} + */ isDefinition() { return this.type === 'label-definition' || this.type === 'relation-definition'; } diff --git a/src/public/javascripts/dialogs/attributes.js b/src/public/javascripts/dialogs/attributes.js index 6d04b0a3b..c01b2ea81 100644 --- a/src/public/javascripts/dialogs/attributes.js +++ b/src/public/javascripts/dialogs/attributes.js @@ -71,6 +71,7 @@ function AttributesModel() { attr.relationDefinition = (attr.type === 'relation-definition' && attr.value) ? attr.value : { multiplicityType: "singlevalue", + mirrorRelation: "", isPromoted: true }; @@ -189,6 +190,7 @@ function AttributesModel() { }, relationDefinition: { multiplicityType: "singlevalue", + mirrorRelation: "", isPromoted: true } })); diff --git a/src/public/javascripts/services/attributes.js b/src/public/javascripts/services/attributes.js index 785fae1cb..d1ba1cc04 100644 --- a/src/public/javascripts/services/attributes.js +++ b/src/public/javascripts/services/attributes.js @@ -60,7 +60,7 @@ async function showAttributes() { const $inputCell = $("").append($("
").addClass("input-group").append($input)); const $actionCell = $(""); - const $multiplicityCell = $(""); + const $multiplicityCell = $("").addClass("multiplicity"); $tr .append($labelCell) @@ -148,9 +148,14 @@ async function showAttributes() { // ideally we'd use link instead of button which would allow tooltip preview, but // we can't guarantee updating the link in the a element const $openButton = $("