From 66f7c1da9a06b6ad949503364ed040041f1097f2 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Thu, 7 May 2020 15:54:12 -0300 Subject: [PATCH] Adjustments to new logic of creating and removing groups into item metadata --- .../metadata-types/compound/Compound.vue | 25 ++++++++++++------- .../admin/js/store/modules/item/mutations.js | 5 ++-- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/views/admin/components/metadata-types/compound/Compound.vue b/src/views/admin/components/metadata-types/compound/Compound.vue index 8441e3c8b..15d60c75e 100644 --- a/src/views/admin/components/metadata-types/compound/Compound.vue +++ b/src/views/admin/components/metadata-types/compound/Compound.vue @@ -255,22 +255,29 @@ value: '', value_as_html: '', value_as_string: '', - collapse: false + collapse: true }; newEmptyGroup.push(childObject) } - } + } - this.isCreatingGroup = true; + this.childItemMetadataGroups.push(newEmptyGroup); + + this.isCreatingGroup = false; }); }, removeGroup(groupIndex) { - this.isRemovingGroup = true; - eventBusItemMetadata.$emit('remove_group', { - itemId: this.itemMetadatum.item.id, - metadatumId: this.itemMetadatum.metadatum.id, - parentMetaId: this.itemMetadatum.value[groupIndex][0].parent_meta_id - }); + + if (this.itemMetadatum.value && this.itemMetadatum.value[groupIndex] && this.itemMetadatum.value[groupIndex][0]) { + this.isRemovingGroup = true; + eventBusItemMetadata.$emit('remove_group', { + itemId: this.itemMetadatum.item.id, + metadatumId: this.itemMetadatum.metadatum.id, + parentMetaId: this.itemMetadatum.value[groupIndex][0].parent_meta_id + }); + } else { + this.childItemMetadataGroups.splice(groupIndex, 1); + } } } } diff --git a/src/views/admin/js/store/modules/item/mutations.js b/src/views/admin/js/store/modules/item/mutations.js index aec4a08d9..e9e90425e 100644 --- a/src/views/admin/js/store/modules/item/mutations.js +++ b/src/views/admin/js/store/modules/item/mutations.js @@ -102,6 +102,7 @@ export const setSingleMetadatum = (state, itemMetadatum) => { } else { currentParentValues.push([childMetadatumValue]) } + } else { let currrentChildMetadatumIndex = currentParentValues.findIndex((metadatumValue) => metadatumValue.parent_meta_id == itemMetadatum.parent_meta_id && metadatumValue.metadatum_id == itemMetadatum.metadatum.id); if (currrentChildMetadatumIndex >= 0) @@ -130,8 +131,8 @@ export const deleteChildItemMetadata = (state, { parentMetadatumId, parentMetaId if (currentChildMetadataGroupIndex >= 0) currentParentValues.splice(currentChildMetadataGroupIndex, 1); - - currentParent.value = currentParentValues; + + currentParent.value = JSON.parse(JSON.stringify(currentParentValues)); Vue.set(state.itemMetadata, parentIndex, currentParent); } }