diff --git a/apps/client/src/widgets/ribbon_widgets/book_properties.ts b/apps/client/src/widgets/ribbon_widgets/book_properties.ts index 71030dbcc..9dd25c3ee 100644 --- a/apps/client/src/widgets/ribbon_widgets/book_properties.ts +++ b/apps/client/src/widgets/ribbon_widgets/book_properties.ts @@ -45,31 +45,12 @@ const TPL = /*html*/`
- - - - `; export default class BookPropertiesWidget extends NoteContextAwareWidget { private $viewTypeSelect!: JQuery; - private $expandChildrenButton!: JQuery; - private $collapseAllButton!: JQuery; private $propertiesContainer!: JQuery; private labelsToWatch: string[] = []; @@ -100,33 +81,6 @@ export default class BookPropertiesWidget extends NoteContextAwareWidget { this.$viewTypeSelect = this.$widget.find(".view-type-select"); this.$viewTypeSelect.on("change", () => this.toggleViewType(String(this.$viewTypeSelect.val()))); - this.$expandChildrenButton = this.$widget.find(".expand-children-button"); - this.$expandChildrenButton.on("click", async () => { - if (!this.noteId || !this.note) { - return; - } - - if (!this.note?.isLabelTruthy("expanded")) { - await attributeService.addLabel(this.noteId, "expanded"); - } - - this.triggerCommand("refreshNoteList", { noteId: this.noteId }); - }); - - this.$collapseAllButton = this.$widget.find(".collapse-all-button"); - this.$collapseAllButton.on("click", async () => { - if (!this.noteId || !this.note) { - return; - } - - // owned is important - we shouldn't remove inherited expanded labels - for (const expandedAttr of this.note.getOwnedLabels("expanded")) { - await attributeService.removeAttributeById(this.noteId, expandedAttr.attributeId); - } - - this.triggerCommand("refreshNoteList", { noteId: this.noteId }); - }); - this.$propertiesContainer = this.$widget.find(".book-properties-container"); } @@ -139,15 +93,15 @@ export default class BookPropertiesWidget extends NoteContextAwareWidget { this.$viewTypeSelect.val(viewType); - this.$expandChildrenButton.toggle(viewType === "list"); - this.$collapseAllButton.toggle(viewType === "list"); - this.$propertiesContainer.empty(); const bookPropertiesData = bookPropertiesConfig[viewType]; if (bookPropertiesData) { for (const property of bookPropertiesData.properties) { - this.$propertiesContainer.append(renderBookProperty(property, note)); + this.$propertiesContainer.append(renderBookProperty(property, { + note: this.note, + triggerCommand: this.triggerCommand.bind(this) + })); this.labelsToWatch.push(property.bindToLabel); } } diff --git a/apps/client/src/widgets/ribbon_widgets/book_properties_config.ts b/apps/client/src/widgets/ribbon_widgets/book_properties_config.ts index ff4372da3..30d893268 100644 --- a/apps/client/src/widgets/ribbon_widgets/book_properties_config.ts +++ b/apps/client/src/widgets/ribbon_widgets/book_properties_config.ts @@ -1,17 +1,34 @@ +import { t } from "i18next"; import FNote from "../../entities/fnote"; import attributes from "../../services/attributes"; import { ViewTypeOptions } from "../../services/note_list_renderer" +import NoteContextAwareWidget from "../note_context_aware_widget"; + +type BookProperty = CheckBoxProperty | ButtonProperty; interface BookConfig { - properties: BookProperty[] + properties: BookProperty[]; } -interface BookProperty { - label: string; +interface CheckBoxProperty { type: "checkbox", + label: string; bindToLabel: string } +interface ButtonProperty { + type: "button", + label: string; + title?: string; + icon?: string; + onClick: (context: BookContext) => void; +} + +interface BookContext { + note: FNote; + triggerCommand: NoteContextAwareWidget["triggerCommand"]; +} + export const bookPropertiesConfig: Record = { calendar: { properties: [ @@ -26,16 +43,49 @@ export const bookPropertiesConfig: Record = { bindToLabel: "calendar:weekNumbers" } ] + }, + list: { + properties: [ + { + label: t("book_properties.collapse"), + title: t("book_properties.collapse_all_notes"), + type: "button", + icon: "bx bx-layer-minus", + async onClick({ note, triggerCommand }) { + const { noteId } = note; + + // owned is important - we shouldn't remove inherited expanded labels + for (const expandedAttr of note.getOwnedLabels("expanded")) { + await attributes.removeAttributeById(noteId, expandedAttr.attributeId); + } + + triggerCommand("refreshNoteList", { noteId: noteId }); + }, + }, + { + label: t("book_properties.expand"), + title: t("book_properties.expand_all_children"), + type: "button", + icon: "bx bx-move-vertical", + async onClick({ note, triggerCommand }) { + const { noteId } = note; + if (!note.isLabelTruthy("expanded")) { + await attributes.addLabel(noteId, "expanded"); + } + + triggerCommand("refreshNoteList", { noteId }); + }, + } + ] } }; -export function renderBookProperty(property: BookProperty, note: FNote) { +export function renderBookProperty(property: BookProperty, context: BookContext) { const $container = $("
"); - const $label = $("