From ae909d107941bf2f7d805f41e049b86f474123cf Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 12 Aug 2020 00:02:19 +0200 Subject: [PATCH] fix saving & refreshing attributes across compoments --- src/public/app/widgets/attribute_editor.js | 6 +++++ src/public/app/widgets/attribute_list.js | 3 ++- .../widgets/collapsible_widgets/calendar.js | 6 ++--- src/public/app/widgets/promoted_attributes.js | 22 +++++++++---------- src/public/stylesheets/calendar.css | 3 ++- src/routes/api/attributes.js | 2 +- src/services/note_cache/note_cache_loader.js | 5 ++++- 7 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/public/app/widgets/attribute_editor.js b/src/public/app/widgets/attribute_editor.js index 8f97a986c..0418480ba 100644 --- a/src/public/app/widgets/attribute_editor.js +++ b/src/public/app/widgets/attribute_editor.js @@ -432,4 +432,10 @@ export default class AttributeEditorWidget extends TabAwareWidget { updateAttributeList(attributes) { this.renderOwnedAttributes(attributes, false); } + + entitiesReloadedEvent({loadResults}) { + if (loadResults.getAttributes(this.componentId).find(attr => attr.isAffecting(this.note))) { + this.refresh(); + } + } } diff --git a/src/public/app/widgets/attribute_list.js b/src/public/app/widgets/attribute_list.js index bb5d4c3a9..b8a003771 100644 --- a/src/public/app/widgets/attribute_list.js +++ b/src/public/app/widgets/attribute_list.js @@ -162,9 +162,10 @@ export default class AttributeListWidget extends TabAwareWidget { } async refreshWithNote(note) { - const hasPromotedAttrs = this.promotedAttributesWidget.getPromotedAttributes().length > 0; + const hasPromotedAttrs = this.promotedAttributesWidget.getPromotedDefinitionAttributes().length > 0; if (hasPromotedAttrs) { + this.$promotedExpander.show(); this.$allAttrWrapper.toggle(options.is('promotedAttributesExpanded')); this.$ownedAndInheritedWrapper.hide(); this.$inheritedAttributesWrapper.hide(); diff --git a/src/public/app/widgets/collapsible_widgets/calendar.js b/src/public/app/widgets/collapsible_widgets/calendar.js index 63913f7e4..da7746026 100644 --- a/src/public/app/widgets/collapsible_widgets/calendar.js +++ b/src/public/app/widgets/collapsible_widgets/calendar.js @@ -10,9 +10,7 @@ const TPL = `
-
- March 2017 -
+
@@ -161,4 +159,4 @@ export default class CalendarWidget extends CollapsibleWidget { 'December' ][monthIndex]; } -} \ No newline at end of file +} diff --git a/src/public/app/widgets/promoted_attributes.js b/src/public/app/widgets/promoted_attributes.js index b89730342..9fc8414bd 100644 --- a/src/public/app/widgets/promoted_attributes.js +++ b/src/public/app/widgets/promoted_attributes.js @@ -43,26 +43,26 @@ export default class PromotedAttributesWidget extends TabAwareWidget { async refreshWithNote(note) { this.$container.empty(); - const promotedAttributes = this.getPromotedAttributes(); - const attributes = note.getAttributes(); + const promotedDefAttrs = this.getPromotedDefinitionAttributes(); + const ownedAttributes = note.getOwnedAttributes(); - const cells = []; - - if (promotedAttributes.length === 0) { + if (promotedDefAttrs.length === 0) { this.toggleInt(false); return; } - for (const definitionAttr of promotedAttributes) { - const definitionType = definitionAttr.name.startsWith('label:') ? 'label' : 'relation'; - const valueName = definitionAttr.name.substr(definitionType.length + 1); + const cells = []; - let valueAttrs = attributes.filter(el => el.name === valueName && el.type === definitionType); + for (const definitionAttr of promotedDefAttrs) { + const valueType = definitionAttr.name.startsWith('label:') ? 'label' : 'relation'; + const valueName = definitionAttr.name.substr(valueType.length + 1); + + let valueAttrs = ownedAttributes.filter(el => el.name === valueName && el.type === valueType); if (valueAttrs.length === 0) { valueAttrs.push({ attributeId: "", - type: definitionType, + type: valueType, name: valueName, value: "" }); @@ -85,7 +85,7 @@ export default class PromotedAttributesWidget extends TabAwareWidget { this.toggleInt(true); } - getPromotedAttributes() { + getPromotedDefinitionAttributes() { if (this.note.hasLabel('hidePromotedAttributes')) { return []; } diff --git a/src/public/stylesheets/calendar.css b/src/public/stylesheets/calendar.css index f3e3dadb5..8190a1278 100755 --- a/src/public/stylesheets/calendar.css +++ b/src/public/stylesheets/calendar.css @@ -61,6 +61,7 @@ .calendar-widget .calendar-date { align-items: center; + color: var(--main-text-color); background-color: var(--main-background-color); display: flex; flex-direction: column; @@ -90,4 +91,4 @@ .calendar-widget .calendar-date:not(.calendar-date-active) { cursor: pointer; -} \ No newline at end of file +} diff --git a/src/routes/api/attributes.js b/src/routes/api/attributes.js index a7246d08a..64ebc53de 100644 --- a/src/routes/api/attributes.js +++ b/src/routes/api/attributes.js @@ -89,7 +89,7 @@ function updateNoteAttributes(req) { const note = repository.getNote(noteId); - let existingAttrs = note.getAttributes(); + let existingAttrs = note.getOwnedAttributes(); let position = 0; diff --git a/src/services/note_cache/note_cache_loader.js b/src/services/note_cache/note_cache_loader.js index 8fc4e74d4..1d0f17342 100644 --- a/src/services/note_cache/note_cache_loader.js +++ b/src/services/note_cache/note_cache_loader.js @@ -121,7 +121,10 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED } delete noteCache.attributes[attributeId]; - delete noteCache.attributeIndex[`${attr.type}-${attr.name}`]; + + if (attr) { + delete noteCache.attributeIndex[`${attr.type}-${attr.name}`]; + } } else if (attributeId in noteCache.attributes) { const attr = noteCache.attributes[attributeId];