')
.attr('data-note-id', note.noteId)
.append(
$('
')
.append($expander)
.append(await linkService.createNoteLink(notePath, {showTooltip: false}))
);
$expander.on('click', () => this.toggleContent($card, note, !$card.hasClass("expanded")));
await this.toggleContent($card, note, this.parentNote.hasLabel('expanded'));
return $card;
}
async toggleContent($card, note, expand) {
if (this.viewType === 'list' && ((expand && $card.hasClass("expanded")) || (!expand && !$card.hasClass("expanded")))) {
return;
}
const $expander = $card.find('> .note-book-title .note-expander');
if (expand || this.viewType === 'grid') {
$card.addClass("expanded");
$expander.addClass("bx-chevron-down").removeClass("bx-chevron-right");
}
else {
$card.removeClass("expanded");
$expander.addClass("bx-chevron-right").removeClass("bx-chevron-down");
}
if ((expand || this.viewType === 'grid') && $card.find('.note-book-content').length === 0) {
$card.append(await this.renderNoteContent(note));
}
}
async renderNoteContent(note) {
const $content = $('
');
try {
const {renderedContent, type} = await noteContentRenderer.getRenderedContent(note);
$content.append(renderedContent);
$content.addClass("type-" + type);
} catch (e) {
console.log(`Caught error while rendering note ${note.noteId} of type ${note.type}: ${e.message}, stack: ${e.stack}`);
$content.append("rendering error");
}
if (this.viewType === 'list') {
const imageLinks = note.getRelations('imageLink');
const childNotes = (await note.getChildNotes())
.filter(childNote => !imageLinks.find(rel => rel.value === childNote.noteId));
for (const childNote of childNotes) {
$content.append(await this.renderNote(childNote));
}
}
return $content;
}
}
export default NoteListRenderer;