From 378987e61c07467d13230e8b823138a41bc7b622 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 13 Feb 2021 20:07:08 +0100 Subject: [PATCH] added icon to note title row --- src/public/app/entities/note_short.js | 35 +++++++++++++++-- .../layouts/desktop_extra_window_layout.js | 5 ++- .../app/layouts/desktop_main_window_layout.js | 5 ++- src/public/app/widgets/note_icon.js | 34 +++++++++++++++++ src/public/app/widgets/note_title.js | 4 +- src/public/app/widgets/note_tree.js | 38 ++----------------- 6 files changed, 80 insertions(+), 41 deletions(-) create mode 100644 src/public/app/widgets/note_icon.js diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.js index a35e1399d..202aa2771 100644 --- a/src/public/app/entities/note_short.js +++ b/src/public/app/entities/note_short.js @@ -1,6 +1,7 @@ import server from '../services/server.js'; -import Attribute from './attribute.js'; import noteAttributeCache from "../services/note_attribute_cache.js"; +import ws from "../services/ws.js"; +import options from "../services/options.js"; const LABEL = 'label'; const RELATION = 'relation'; @@ -266,7 +267,7 @@ class NoteShort { return this.getAttributes(LABEL, name); } - getIcon(isFolder = false) { + getIcon() { const iconClassLabels = this.getLabels('iconClass'); const workspaceIconClass = this.getWorkspaceIconClass(); @@ -280,7 +281,7 @@ class NoteShort { return "bx bx-chevrons-right"; } else if (this.type === 'text') { - if (isFolder) { + if (this.isFolder()) { return "bx bx-folder"; } else { @@ -295,6 +296,34 @@ class NoteShort { } } + isFolder() { + return this.type === 'search' + || this.getFilteredChildBranches().length > 0; + } + + getFilteredChildBranches() { + let childBranches = this.getChildBranches(); + + if (!childBranches) { + ws.logError(`No children for ${parentNote}. This shouldn't happen.`); + return; + } + + if (options.is("hideIncludedImages_main")) { + const imageLinks = this.getRelations('imageLink'); + + // image is already visible in the parent note so no need to display it separately in the book + childBranches = childBranches.filter(branch => !imageLinks.find(rel => rel.value === branch.noteId)); + } + + // we're not checking hideArchivedNotes since that would mean we need to lazy load the child notes + // which would seriously slow down everything. + // we check this flag only once user chooses to expand the parent. This has the negative consequence that + // note may appear as folder but not contain any children when all of them are archived + + return childBranches; + } + /** * @param {string} [name] - relation name to filter * @returns {Attribute[]} all note's relations (attributes with type relation), including inherited ones diff --git a/src/public/app/layouts/desktop_extra_window_layout.js b/src/public/app/layouts/desktop_extra_window_layout.js index e6f91cfc8..a9adc7105 100644 --- a/src/public/app/layouts/desktop_extra_window_layout.js +++ b/src/public/app/layouts/desktop_extra_window_layout.js @@ -20,6 +20,7 @@ import SqlResultWidget from "../widgets/sql_result.js"; import FilePropertiesWidget from "../widgets/type_property_widgets/file_properties.js"; import ImagePropertiesWidget from "../widgets/type_property_widgets/image_properties.js"; import NotePropertiesWidget from "../widgets/type_property_widgets/note_properties.js"; +import NoteIconWidget from "../widgets/note_icon.js"; export default class DesktopExtraWindowLayout { constructor(customWidgets) { @@ -42,8 +43,10 @@ export default class DesktopExtraWindowLayout { .filling() .child(new FlexContainer('column').id('center-pane').filling() .child(new FlexContainer('row').class('title-row') + .css('align-items: center;') + .cssBlock('.title-row > * { margin: 5px; }') .overflowing() - .cssBlock('.title-row > * { margin: 5px 5px 0 5px; }') + .child(new NoteIconWidget()) .child(new NoteTitleWidget()) .child(new NoteTypeWidget().hideInZenMode()) .child(new NoteActionsWidget().hideInZenMode()) diff --git a/src/public/app/layouts/desktop_main_window_layout.js b/src/public/app/layouts/desktop_main_window_layout.js index 734d1dd9e..36979c419 100644 --- a/src/public/app/layouts/desktop_main_window_layout.js +++ b/src/public/app/layouts/desktop_main_window_layout.js @@ -31,6 +31,7 @@ import SqlTableSchemasWidget from "../widgets/sql_table_schemas.js"; import FilePropertiesWidget from "../widgets/type_property_widgets/file_properties.js"; import ImagePropertiesWidget from "../widgets/type_property_widgets/image_properties.js"; import NotePropertiesWidget from "../widgets/type_property_widgets/note_properties.js"; +import NoteIconWidget from "../widgets/note_icon.js"; const RIGHT_PANE_CSS = ` + + +`; + +export default class NoteIconWidget extends TabAwareWidget { + doRender() { + this.$widget = $(TPL); + this.$icon = this.$widget.find('span'); + this.contentSized(); + } + + async refreshWithNote(note) { + this.$icon.removeClass().addClass(note.getIcon()) + } +} diff --git a/src/public/app/widgets/note_title.js b/src/public/app/widgets/note_title.js index 816e83a0d..23f031fc9 100644 --- a/src/public/app/widgets/note_title.js +++ b/src/public/app/widgets/note_title.js @@ -9,11 +9,10 @@ const TPL = `