mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
new "iconClass" property on note_short, now together with cssClass respecting template relationship, #707
This commit is contained in:
parent
95c37cfdd1
commit
e00ab5dbf9
@ -35,6 +35,8 @@ class NoteShort {
|
|||||||
this.archived = row.archived;
|
this.archived = row.archived;
|
||||||
/** @param {string} */
|
/** @param {string} */
|
||||||
this.cssClass = row.cssClass;
|
this.cssClass = row.cssClass;
|
||||||
|
/** @param {string} */
|
||||||
|
this.iconClass = row.iconClass;
|
||||||
|
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
this.parents = [];
|
this.parents = [];
|
||||||
|
@ -41,7 +41,10 @@ const NOTE_TYPE_ICONS = {
|
|||||||
async function getIcon(note) {
|
async function getIcon(note) {
|
||||||
const hoistedNoteId = await hoistedNoteService.getHoistedNoteId();
|
const hoistedNoteId = await hoistedNoteService.getHoistedNoteId();
|
||||||
|
|
||||||
if (note.noteId === 'root') {
|
if (note.iconClass) {
|
||||||
|
return note.iconClass;
|
||||||
|
}
|
||||||
|
else if (note.noteId === 'root') {
|
||||||
return "bx bx-chevrons-right";
|
return "bx bx-chevrons-right";
|
||||||
}
|
}
|
||||||
else if (note.noteId === hoistedNoteId) {
|
else if (note.noteId === hoistedNoteId) {
|
||||||
|
@ -4,37 +4,66 @@ const sql = require('../../services/sql');
|
|||||||
const optionService = require('../../services/options');
|
const optionService = require('../../services/options');
|
||||||
const protectedSessionService = require('../../services/protected_session');
|
const protectedSessionService = require('../../services/protected_session');
|
||||||
const noteCacheService = require('../../services/note_cache');
|
const noteCacheService = require('../../services/note_cache');
|
||||||
|
const log = require('../../services/log');
|
||||||
|
|
||||||
async function getNotes(noteIds) {
|
async function getNotes(noteIds) {
|
||||||
// we return also deleted notes which have been specifically asked for
|
// we return also deleted notes which have been specifically asked for
|
||||||
const notes = await sql.getManyRows(`
|
const notes = await sql.getManyRows(`
|
||||||
SELECT
|
SELECT
|
||||||
noteId,
|
noteId,
|
||||||
title,
|
title,
|
||||||
isProtected,
|
isProtected,
|
||||||
type,
|
type,
|
||||||
mime,
|
mime,
|
||||||
isDeleted
|
isDeleted
|
||||||
FROM notes
|
FROM notes
|
||||||
WHERE noteId IN (???)`, noteIds);
|
WHERE noteId IN (???)`, noteIds);
|
||||||
|
|
||||||
const cssClassLabels = await sql.getManyRows(`
|
const noteMap = new Map(notes.map(note => [note.noteId, note]));
|
||||||
SELECT noteId, value FROM attributes WHERE isDeleted = 0 AND type = 'label'
|
|
||||||
AND name = 'cssClass' AND noteId IN (???)`, noteIds);
|
|
||||||
|
|
||||||
for (const label of cssClassLabels) {
|
const templateClassLabels = await sql.getManyRows(`
|
||||||
// FIXME: inefficient!
|
SELECT
|
||||||
const note = notes.find(note => note.noteId === label.noteId);
|
templAttr.noteId,
|
||||||
|
attr.name,
|
||||||
|
attr.value
|
||||||
|
FROM attributes templAttr
|
||||||
|
JOIN attributes attr ON attr.noteId = templAttr.value
|
||||||
|
WHERE
|
||||||
|
templAttr.isDeleted = 0
|
||||||
|
AND templAttr.type = 'relation'
|
||||||
|
AND templAttr.name = 'template'
|
||||||
|
AND templAttr.noteId IN (???)
|
||||||
|
AND attr.isDeleted = 0
|
||||||
|
AND attr.type = 'label'
|
||||||
|
AND attr.name IN ('cssClass', 'iconClass')`, noteIds);
|
||||||
|
|
||||||
if (!note) {
|
const noteClassLabels = await sql.getManyRows(`
|
||||||
continue;
|
SELECT
|
||||||
}
|
noteId, name, value
|
||||||
|
FROM attributes
|
||||||
|
WHERE
|
||||||
|
isDeleted = 0
|
||||||
|
AND type = 'label'
|
||||||
|
AND name IN ('cssClass', 'iconClass')
|
||||||
|
AND noteId IN (???)`, noteIds);
|
||||||
|
|
||||||
if (note.cssClass) {
|
// first template ones, then on the note itself so that note class label have priority
|
||||||
note.cssClass += " " + label.value;
|
// over template ones for iconClass (which can be only one)
|
||||||
}
|
const allClassLabels = templateClassLabels.concat(noteClassLabels);
|
||||||
else {
|
|
||||||
note.cssClass = label.value;
|
for (const label of allClassLabels) {
|
||||||
|
const note = noteMap.get(label.noteId);
|
||||||
|
|
||||||
|
if (note) {
|
||||||
|
if (label.name === 'cssClass') {
|
||||||
|
note.cssClass = note.cssClass ? `${note.cssClass} ${label.value}` : label.value;
|
||||||
|
}
|
||||||
|
else if (label.name === 'iconClass') {
|
||||||
|
note.iconClass = label.value;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log.error(`Unrecognized label name ${label.name}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user