More updates to itemMetadatum update logic. #17

This commit is contained in:
mateuswetah 2020-03-24 09:22:18 -03:00
parent fc02e2bd59
commit 8045189383
4 changed files with 18 additions and 12 deletions

View File

@ -26,14 +26,14 @@
<template v-for="(childItemMetadata, groupIndex) of childItemMetadataGroups">
<hr
v-if="groupIndex > 0"
:key="groupIndex + '-' + index">
:key="groupIndex">
<tainacan-form-item
v-if="groupIndex > 0"
v-for="(childItemMetadatum, index) of childItemMetadata"
:key="groupIndex + '-' + index"
v-for="(childItemMetadatum, childIndex) of childItemMetadata"
:key="childIndex"
:item-metadatum="childItemMetadatum"
:is-collapsed="childItemMetadatum.collapse"
@changeCollapse="onChangeCollapse($event, groupIndex, index)"/>
@changeCollapse="onChangeCollapse($event, groupIndex, childIndex)"/>
<a
v-if="groupIndex > 0"
@click="removeGroup(groupIndex)"
@ -94,7 +94,7 @@
let currentChildItemMetadataGroups = [];
const parentValues = this.isMultiple ? this.itemMetadatum.value : [ this.itemMetadatum.value ];
if (this.itemMetadatum.metadatum &&
this.itemMetadatum.metadatum.metadata_type_options &&
this.itemMetadatum.metadatum.metadata_type_options.children_objects.length > 0
@ -224,15 +224,17 @@
this.childItemMetadataGroups.push(newEmptyGroup);
},
removeGroup(groupIndex) {
this.currentChildItemMetadataGroups.splice(groupIndex, 1);
let updatedItemMetadatum = JSON.parse(JSON.stringify(this.itemMetadatum))
updatedItemMetadatum.slice(groupIndex, 1);
console.log(JSON.parse(JSON.stringify(this.childItemMetadataGroups)))
this.childItemMetadataGroups.splice(groupIndex, 1);
let updatedItemMetadatumValue = JSON.parse(JSON.stringify(this.itemMetadatum.value))
updatedItemMetadatumValue.splice(groupIndex, 1);
console.log(JSON.parse(JSON.stringify(this.childItemMetadataGroups)))
// If none is the case, the value is update request is sent to the API
eventBusItemMetadata.$emit('input', {
itemId: this.itemMetadatum.item.id,
metadatumId: this.itemMetadatum.metadatum.id,
values: updatedItemMetadatum,
values: updatedItemMetadatumValue,
parentMetaId: this.itemMetadatum.parent_meta_id
});
}

View File

@ -35,7 +35,7 @@ export const eventBusItemMetadata = new Vue({
this.$store.dispatch('item/updateItemMetadatum', {
item_id: itemId,
metadatum_id: metadatumId,
values: Array.isArray(values[0]) ? values[0] : values,
values: values,
parent_meta_id: parentMetaId ? parentMetaId : null
})
.then(() => {

View File

@ -2,7 +2,7 @@ import axios from '../../../axios';
// Actions related to Item's metadata
export const updateItemMetadatum = ({ commit }, { item_id, metadatum_id, values, parent_meta_id }) => {
let body = { values: values }
let body = { value: values }
if (parent_meta_id != undefined && parent_meta_id != null && parent_meta_id != false)
body['parent_meta_id'] = parent_meta_id;

View File

@ -86,9 +86,13 @@ export const setSingleMetadatum = (state, itemMetadatum) => {
};
if (currentParent.metadatum.multiple == 'yes') {
let currrentChildMetadataGroupIndex = currentParentValues.findIndex((metadataGroup) => {
return metadataGroup.findIndex((metadatumValue) => metadatumValue.parent_meta_id == itemMetadatum.parent_meta_id && metadatumValue.metadatum_id == itemMetadatum.metadatum.id) >= 0;
return metadataGroup.findIndex((metadatumValue) => {
return metadatumValue.parent_meta_id == itemMetadatum.parent_meta_id;
}) >= 0;
});
if (currrentChildMetadataGroupIndex >= 0) {
let currrentChildMetadatumIndex = currentParentValues[currrentChildMetadataGroupIndex].findIndex((metadatumValue) => metadatumValue.parent_meta_id == itemMetadatum.parent_meta_id && metadatumValue.metadatum_id == itemMetadatum.metadatum.id);
if (currrentChildMetadatumIndex >= 0)