From c9b2ff05e9578ebffa29d509cc4fb5ab24742c35 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 29 Mar 2020 22:15:09 +0200 Subject: [PATCH] book notes don't display images as separate children if the image is included in the parent text note, #892 --- package-lock.json | 2 +- .../javascripts/widgets/note_actions.js | 11 +-- .../javascripts/widgets/type_widgets/book.js | 80 +++++++++++-------- .../javascripts/widgets/type_widgets/text.js | 10 +-- src/public/stylesheets/style.css | 2 + 5 files changed, 53 insertions(+), 52 deletions(-) diff --git a/package-lock.json b/package-lock.json index d8d768703..3b425515d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "trilium", - "version": "0.40.6", + "version": "0.40.7", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/public/javascripts/widgets/note_actions.js b/src/public/javascripts/widgets/note_actions.js index 6bf0569aa..37216a720 100644 --- a/src/public/javascripts/widgets/note_actions.js +++ b/src/public/javascripts/widgets/note_actions.js @@ -10,6 +10,7 @@ const TPL = ` .note-actions .dropdown-item[disabled], .note-actions .dropdown-item[disabled]:hover { color: var(--muted-text-color) !important; background-color: transparent !important; + pointer-events: none; /* makes it unclickable */ } @@ -64,14 +65,4 @@ export default class NoteActionsWidget extends TabAwareWidget { this.$exportNoteButton.attr('disabled', 'disabled'); } } - - triggerEvent(e, eventName) { - const $item = $(e.target).closest('dropdown-item'); - - if ($item.is('[disabled]')) { - return; - } - - this.triggerEvent(eventName); - } } \ No newline at end of file diff --git a/src/public/javascripts/widgets/type_widgets/book.js b/src/public/javascripts/widgets/type_widgets/book.js index 13ba4a55b..159be7e7b 100644 --- a/src/public/javascripts/widgets/type_widgets/book.js +++ b/src/public/javascripts/widgets/type_widgets/book.js @@ -158,46 +158,62 @@ export default class BookTypeWidget extends TypeWidget { this.$help.show(); } + const imageLinks = note.getRelations('imageLink'); + for (const childNote of childNotes) { - const childNotePath = this.notePath + '/' + childNote.noteId; - - const $content = $('
') - .css("max-height", ZOOMS[this.zoomLevel].height); - - const $card = $('
') - .attr('data-note-id', childNote.noteId) - .css("flex-basis", ZOOMS[this.zoomLevel].width) - .append($('
').append(await linkService.createNoteLink(childNotePath, {showTooltip: false}))) - .append($content); - - try { - const {type, renderedContent} = await noteContentRenderer.getRenderedContent(childNote); - - $card.addClass("type-" + type); - $content.append(renderedContent); - } - catch (e) { - console.log(`Caught error while rendering note ${note.noteId} of type ${note.type}: ${e.message}, stack: ${e.stack}`); - - $content.append("rendering error"); + // image is already visible in the parent note so no need to display it separately in the book + if (imageLinks.find(rel => rel.value === childNote.noteId)) { + continue; } - const childCount = childNote.getChildNoteIds().length; - - if (childCount > 0) { - const label = `${childCount} child${childCount > 1 ? 'ren' : ''}`; - - $card.append($('
') - .append($(`+ Show ${label}`)) - .append($(`- Hide ${label}`).hide()) - .append($('
')) - ); - } + const $card = await this.renderNote(childNote); $container.append($card); } } + async renderNote(note) { + const notePath = this.notePath + '/' + note.noteId; + + const $content = $('
') + .css("max-height", ZOOMS[this.zoomLevel].height); + + const $card = $('
') + .attr('data-note-id', note.noteId) + .css("flex-basis", ZOOMS[this.zoomLevel].width) + .append($('
').append(await linkService.createNoteLink(notePath, {showTooltip: false}))) + .append($content); + + try { + const {type, renderedContent} = await noteContentRenderer.getRenderedContent(note); + + $card.addClass("type-" + type); + $content.append(renderedContent); + } catch (e) { + console.log(`Caught error while rendering note ${note.noteId} of type ${note.type}: ${e.message}, stack: ${e.stack}`); + + $content.append("rendering error"); + } + + const imageLinks = note.getRelations('imageLink'); + + const childCount = note.getChildNoteIds() + .filter(childNoteId => !imageLinks.find(rel => rel.value === childNoteId)) + .length; + + if (childCount > 0) { + const label = `${childCount} child${childCount > 1 ? 'ren' : ''}`; + + $card.append($('
') + .append($(`+ Show ${label}`)) + .append($(`- Hide ${label}`).hide()) + .append($('
')) + ); + } + + return $card; + } + /** @return {boolean} true if this is "auto book" activated (empty text note) and not explicit book note */ isAutoBook() { return this.note.type !== 'book'; diff --git a/src/public/javascripts/widgets/type_widgets/text.js b/src/public/javascripts/widgets/type_widgets/text.js index ce621faaa..5fc8e488d 100644 --- a/src/public/javascripts/widgets/type_widgets/text.js +++ b/src/public/javascripts/widgets/type_widgets/text.js @@ -155,15 +155,7 @@ export default class TextTypeWidget extends TypeWidget { // if content is only tags/whitespace (typically

 

), then just make it empty // this is important when setting new note to code - return this.isContentEmpty(content) ? '' : content; - } - - isContentEmpty(content) { - content = content.toLowerCase(); - - return jQuery(content).text().trim() === '' - && !content.includes("