mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 13:39:01 +01:00 
			
		
		
		
	support for cssClass label on note
This commit is contained in:
		
							parent
							
								
									12d82e3b33
								
							
						
					
					
						commit
						cd9eef32b0
					
				@ -1,6 +1,7 @@
 | 
				
			|||||||
"use strict";
 | 
					"use strict";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const Entity = require('./entity');
 | 
					const Entity = require('./entity');
 | 
				
			||||||
 | 
					const Attribute = require('./attribute');
 | 
				
			||||||
const protectedSessionService = require('../services/protected_session');
 | 
					const protectedSessionService = require('../services/protected_session');
 | 
				
			||||||
const repository = require('../services/repository');
 | 
					const repository = require('../services/repository');
 | 
				
			||||||
const dateUtils = require('../services/date_utils');
 | 
					const dateUtils = require('../services/date_utils');
 | 
				
			||||||
@ -131,6 +132,37 @@ class Note extends Entity {
 | 
				
			|||||||
        return attributes.find(attr => attr.type === 'label' && attr.name === name);
 | 
					        return attributes.find(attr => attr.type === 'label' && attr.name === name);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async getLabelValue(name) {
 | 
				
			||||||
 | 
					        const label = await this.getLabel(name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return label ? label.value : null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async setLabel(name, value = "") {
 | 
				
			||||||
 | 
					        let label = await this.getLabel(name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!label) {
 | 
				
			||||||
 | 
					            label = new Attribute({
 | 
				
			||||||
 | 
					                noteId: this.noteId,
 | 
				
			||||||
 | 
					                type: 'label',
 | 
				
			||||||
 | 
					                name: name
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        label.value = value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await label.save();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async removeLabel(name) {
 | 
				
			||||||
 | 
					        const label = await this.getLabel(name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (label) {
 | 
				
			||||||
 | 
					            label.isDeleted = true;
 | 
				
			||||||
 | 
					            await label.save();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async getRevisions() {
 | 
					    async getRevisions() {
 | 
				
			||||||
        return await repository.getEntities("SELECT * FROM note_revisions WHERE noteId = ?", [this.noteId]);
 | 
					        return await repository.getEntities("SELECT * FROM note_revisions WHERE noteId = ?", [this.noteId]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,7 @@ class NoteShort {
 | 
				
			|||||||
        this.type = row.type;
 | 
					        this.type = row.type;
 | 
				
			||||||
        this.mime = row.mime;
 | 
					        this.mime = row.mime;
 | 
				
			||||||
        this.archived = row.archived;
 | 
					        this.archived = row.archived;
 | 
				
			||||||
 | 
					        this.cssClass = row.cssClass;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    isJson() {
 | 
					    isJson() {
 | 
				
			||||||
 | 
				
			|||||||
@ -115,6 +115,10 @@ async function getExtraClasses(note) {
 | 
				
			|||||||
        extraClasses.push("multiple-parents");
 | 
					        extraClasses.push("multiple-parents");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (note.cssClass) {
 | 
				
			||||||
 | 
					        extraClasses.push(note.cssClass);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    extraClasses.push(note.type);
 | 
					    extraClasses.push(note.type);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return extraClasses.join(" ");
 | 
					    return extraClasses.join(" ");
 | 
				
			||||||
 | 
				
			|||||||
@ -9,6 +9,26 @@ async function getNotes(noteIds) {
 | 
				
			|||||||
      SELECT noteId, title, isProtected, type, mime
 | 
					      SELECT noteId, title, isProtected, type, mime
 | 
				
			||||||
      FROM notes WHERE isDeleted = 0 AND noteId IN (???)`, noteIds);
 | 
					      FROM notes WHERE isDeleted = 0 AND noteId IN (???)`, noteIds);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const cssClassLabels = await sql.getManyRows(`
 | 
				
			||||||
 | 
					      SELECT noteId, value FROM attributes WHERE isDeleted = 0 AND type = 'label' 
 | 
				
			||||||
 | 
					                                             AND name = 'cssClass' AND noteId IN (???)`, noteIds);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (const label of cssClassLabels) {
 | 
				
			||||||
 | 
					        // FIXME: inefficient!
 | 
				
			||||||
 | 
					        const note = notes.find(note => note.noteId === label.noteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!note) {
 | 
				
			||||||
 | 
					            continue;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (note.cssClass) {
 | 
				
			||||||
 | 
					            note.cssClass += " " + label.value;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else {
 | 
				
			||||||
 | 
					            note.cssClass = label.value;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protectedSessionService.decryptNotes(notes);
 | 
					    protectedSessionService.decryptNotes(notes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    notes.forEach(note => note.isProtected = !!note.isProtected);
 | 
					    notes.forEach(note => note.isProtected = !!note.isProtected);
 | 
				
			||||||
 | 
				
			|||||||
@ -26,10 +26,19 @@ async function cloneNoteToParent(noteId, parentNoteId, prefix) {
 | 
				
			|||||||
    return { success: true };
 | 
					    return { success: true };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// this is identical to cloneNoteToParent except for the intention - if cloned note is already in parent,
 | 
					 | 
				
			||||||
// then this is successful result
 | 
					 | 
				
			||||||
async function ensureNoteIsPresentInParent(noteId, parentNoteId, prefix) {
 | 
					async function ensureNoteIsPresentInParent(noteId, parentNoteId, prefix) {
 | 
				
			||||||
    await cloneNoteToParent(noteId, parentNoteId, prefix);
 | 
					    const validationResult = await treeService.validateParentChild(parentNoteId, noteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!validationResult.success) {
 | 
				
			||||||
 | 
					        return validationResult;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    await new Branch({
 | 
				
			||||||
 | 
					        noteId: noteId,
 | 
				
			||||||
 | 
					        parentNoteId: parentNoteId,
 | 
				
			||||||
 | 
					        prefix: prefix,
 | 
				
			||||||
 | 
					        isExpanded: 0
 | 
				
			||||||
 | 
					    }).save();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function ensureNoteIsAbsentFromParent(noteId, parentNoteId) {
 | 
					async function ensureNoteIsAbsentFromParent(noteId, parentNoteId) {
 | 
				
			||||||
 | 
				
			|||||||
@ -10,6 +10,10 @@ async function setEntityConstructor(constructor) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getEntityFromName(entityName, entityId) {
 | 
					async function getEntityFromName(entityName, entityId) {
 | 
				
			||||||
 | 
					    if (!entityName || !entityId) {
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const constructor = entityConstructor.getEntityFromTableName(entityName);
 | 
					    const constructor = entityConstructor.getEntityFromTableName(entityName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return await getEntity(`SELECT * FROM ${constructor.tableName} WHERE ${constructor.primaryKeyName} = ?`, [entityId]);
 | 
					    return await getEntity(`SELECT * FROM ${constructor.tableName} WHERE ${constructor.primaryKeyName} = ?`, [entityId]);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user