From 3261fea67fbfdd6dddc7d5578863870cad986d70 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 25 Jul 2020 23:32:46 +0200 Subject: [PATCH] added promotedAttributesExpanded option --- src/public/app/widgets/attribute_list.js | 24 ++++++++++++++----- src/public/app/widgets/promoted_attributes.js | 2 +- src/routes/api/options.js | 3 ++- src/services/options_init.js | 3 ++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/public/app/widgets/attribute_list.js b/src/public/app/widgets/attribute_list.js index 177391a1b..5ce43a30f 100644 --- a/src/public/app/widgets/attribute_list.js +++ b/src/public/app/widgets/attribute_list.js @@ -120,11 +120,11 @@ export default class AttributeListWidget extends TabAwareWidget { this.$allAttrWrapper = this.$widget.find('.all-attr-wrapper'); this.$promotedExpander.on('click', async () => { - if (this.$allAttrWrapper.is(":visible")) { - this.$allAttrWrapper.slideUp(200); - } else { - this.$allAttrWrapper.slideDown(200); - } + const collapse = this.$allAttrWrapper.is(":visible"); + + await options.save('promotedAttributesExpanded', !collapse); + + this.triggerEvent(`promotedAttributesCollapsedStateChanged`, {collapse}); }); this.$ownedAndInheritedWrapper = this.$widget.find('.owned-and-inherited-wrapper'); @@ -165,7 +165,7 @@ export default class AttributeListWidget extends TabAwareWidget { const hasPromotedAttrs = this.promotedAttributesWidget.getPromotedAttributes().length > 0; if (hasPromotedAttrs) { - this.$allAttrWrapper.show(); + this.$allAttrWrapper.toggle(options.is('promotedAttributesExpanded')); this.$ownedAndInheritedWrapper.hide(); this.$inheritedAttributesWrapper.hide(); } @@ -240,4 +240,16 @@ export default class AttributeListWidget extends TabAwareWidget { this.$ownedAndInheritedWrapper.slideDown(200); } } + + /** + * This event is used to synchronize collapsed state of all the tab-cached widgets since they are all rendered + * separately but should behave uniformly for the user. + */ + promotedAttributesCollapsedStateChangedEvent({collapse}) { + if (collapse) { + this.$allAttrWrapper.slideUp(200); + } else { + this.$allAttrWrapper.slideDown(200); + } + } } diff --git a/src/public/app/widgets/promoted_attributes.js b/src/public/app/widgets/promoted_attributes.js index c5c4cf341..b89730342 100644 --- a/src/public/app/widgets/promoted_attributes.js +++ b/src/public/app/widgets/promoted_attributes.js @@ -44,7 +44,7 @@ export default class PromotedAttributesWidget extends TabAwareWidget { this.$container.empty(); const promotedAttributes = this.getPromotedAttributes(); - const attributes = note.getAttributes();console.log(this.note.getAttributes()); + const attributes = note.getAttributes(); const cells = []; diff --git a/src/routes/api/options.js b/src/routes/api/options.js index 76291b91f..8bd5579aa 100644 --- a/src/routes/api/options.js +++ b/src/routes/api/options.js @@ -38,7 +38,8 @@ const ALLOWED_OPTIONS = new Set([ 'leftPaneVisible', 'rightPaneVisible', 'nativeTitleBarVisible', - 'attributeListExpanded' + 'attributeListExpanded', + 'promotedAttributesExpanded' ]); function getOptions() { diff --git a/src/services/options_init.js b/src/services/options_init.js index 8913303dc..9303b9466 100644 --- a/src/services/options_init.js +++ b/src/services/options_init.js @@ -85,7 +85,8 @@ const defaultOptions = [ { name: 'eraseNotesAfterTimeInSeconds', value: '604800', isSynced: true }, // default is 7 days { name: 'hideArchivedNotes_main', value: 'false', isSynced: false }, { name: 'hideIncludedImages_main', value: 'true', isSynced: false }, - { name: 'attributeListExpanded', value: 'false', isSynced: false } + { name: 'attributeListExpanded', value: 'false', isSynced: false }, + { name: 'promotedAttributesExpanded', value: 'false', isSynced: true } ]; function initStartupOptions() {