From 792039227f9ab3538f7eea86fb96583132aa9e44 Mon Sep 17 00:00:00 2001 From: azivner Date: Sat, 1 Sep 2018 13:18:55 +0200 Subject: [PATCH] cssClass is correctly filled for new note --- src/entities/note.js | 32 +++++++++++++------ .../javascripts/services/protected_session.js | 2 ++ src/routes/api/notes.js | 2 ++ src/services/notes.js | 2 ++ 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/entities/note.js b/src/entities/note.js index 09bfb3482..4c2c09aec 100644 --- a/src/entities/note.js +++ b/src/entities/note.js @@ -99,23 +99,37 @@ class Note extends Entity { return await repository.getEntities(`SELECT * FROM attributes WHERE isDeleted = 0 AND noteId = ?`, [this.noteId]); } - /** @returns {Promise} all note's attributes, including inherited ones */ - async getAttributes() { + /** + * @param {string} [name] - attribute name to filter + * @returns {Promise} all note's attributes, including inherited ones + */ + async getAttributes(name) { if (!this.__attributeCache) { await this.loadAttributesToCache(); } - return this.__attributeCache; + if (name) { + return this.__attributeCache.filter(attr => attr.name === name); + } + else { + return this.__attributeCache; + } } - /** @returns {Promise} all note's labels (attributes with type label), including inherited ones */ - async getLabels() { - return (await this.getAttributes()).filter(attr => attr.type === LABEL); + /** + * @param {string} [name] - label name to filter + * @returns {Promise} all note's labels (attributes with type label), including inherited ones + */ + async getLabels(name) { + return (await this.getAttributes(name)).filter(attr => attr.type === LABEL); } - /** @returns {Promise} all note's relations (attributes with type relation), including inherited ones */ - async getRelations() { - return (await this.getAttributes()).filter(attr => attr.type === RELATION); + /** + * @param {string} [name] - relation name to filter + * @returns {Promise} all note's relations (attributes with type relation), including inherited ones + */ + async getRelations(name) { + return (await this.getAttributes(name)).filter(attr => attr.type === RELATION); } /** diff --git a/src/public/javascripts/services/protected_session.js b/src/public/javascripts/services/protected_session.js index 60a91e65a..d8924e1e8 100644 --- a/src/public/javascripts/services/protected_session.js +++ b/src/public/javascripts/services/protected_session.js @@ -89,6 +89,8 @@ async function setupProtectedSession() { $protectedSessionOnButton.addClass('active'); $protectedSessionOffButton.removeClass('active'); } + + infoService.showMessage("Protected session has been started."); } function ensureDialogIsClosed() { diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js index 97cddb8bd..ccb5f75b6 100644 --- a/src/routes/api/notes.js +++ b/src/routes/api/notes.js @@ -26,6 +26,8 @@ async function createNote(req) { const { note, branch } = await noteService.createNewNote(parentNoteId, newNote, req); + note.cssClass = (await note.getLabels("cssClass")).map(label => label.value).join(" "); + return { note, branch diff --git a/src/services/notes.js b/src/services/notes.js index 3b79712fa..62c2b52ee 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -81,6 +81,8 @@ async function createNewNote(parentNoteId, noteData) { position: attr.position, isInheritable: attr.isInheritable }).save(); + + note.invalidateAttributeCache(); } }