cssClass is correctly filled for new note

This commit is contained in:
azivner 2018-09-01 13:18:55 +02:00
parent bc38172792
commit 792039227f
4 changed files with 29 additions and 9 deletions

View File

@ -99,23 +99,37 @@ class Note extends Entity {
return await repository.getEntities(`SELECT * FROM attributes WHERE isDeleted = 0 AND noteId = ?`, [this.noteId]);
}
/** @returns {Promise<Attribute[]>} all note's attributes, including inherited ones */
async getAttributes() {
/**
* @param {string} [name] - attribute name to filter
* @returns {Promise<Attribute[]>} 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<Attribute[]>} 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<Attribute[]>} 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<Attribute[]>} 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<Attribute[]>} all note's relations (attributes with type relation), including inherited ones
*/
async getRelations(name) {
return (await this.getAttributes(name)).filter(attr => attr.type === RELATION);
}
/**

View File

@ -89,6 +89,8 @@ async function setupProtectedSession() {
$protectedSessionOnButton.addClass('active');
$protectedSessionOffButton.removeClass('active');
}
infoService.showMessage("Protected session has been started.");
}
function ensureDialogIsClosed() {

View File

@ -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

View File

@ -81,6 +81,8 @@ async function createNewNote(parentNoteId, noteData) {
position: attr.position,
isInheritable: attr.isInheritable
}).save();
note.invalidateAttributeCache();
}
}