diff --git a/src/views/admin/components/lists/metadata-list.vue b/src/views/admin/components/lists/metadata-list.vue index 38ca565f4..a4b60782e 100644 --- a/src/views/admin/components/lists/metadata-list.vue +++ b/src/views/admin/components/lists/metadata-list.vue @@ -166,7 +166,7 @@ diff --git a/src/views/admin/components/metadata-types/compound/Compound.vue b/src/views/admin/components/metadata-types/compound/Compound.vue index acd549039..85e08c4f3 100644 --- a/src/views/admin/components/metadata-types/compound/Compound.vue +++ b/src/views/admin/components/metadata-types/compound/Compound.vue @@ -142,7 +142,6 @@ } } } - console.log(currentValue) return _.groupBy(currentValue, 'parent_meta_id'); } }, diff --git a/src/views/admin/components/metadata-types/compound/child-metadata-list.vue b/src/views/admin/components/metadata-types/compound/child-metadata-list.vue index 3b59f442a..3a6dbf5b1 100644 --- a/src/views/admin/components/metadata-types/compound/child-metadata-list.vue +++ b/src/views/admin/components/metadata-types/compound/child-metadata-list.vue @@ -173,7 +173,7 @@ }, props: { isRepositoryLevel: Boolean, - parent: String + parent: Object }, data() { return { @@ -185,7 +185,18 @@ hightlightedMetadatum: '', editForms: {}, metadataSearchCancel: undefined, - childrenMetadata: [] + } + }, + computed: { + childrenMetadata() { + console.log(this.parent.metadata_type_options.children_objects) + if (this.parent && + this.parent.metadata_type_options && + this.parent.metadata_type_options.children_objects.length > 0 + ) + return this.parent.metadata_type_options.children_objects; + else + return []; } }, watch: { @@ -228,7 +239,11 @@ } }, mounted() { - this.isLoadingMetadata = true; + if (this.isRepositoryLevel) + this.collectionId = 'default'; + else + this.collectionId = this.$route.params.collectionId; + this.refreshMetadata(); }, beforeDestroy() { @@ -264,7 +279,7 @@ this.isUpdatingMetadataOrder = true; this.updateChildMetadataOrder({ collectionId: this.collectionId, - parentMetadatumId: this.parent, + parentMetadatumId: this.parent.id, childMetadataOrder: metadataOrder }) .then(() => { @@ -283,7 +298,7 @@ this.isUpdatingMetadataOrder = true; this.updateChildMetadataOrder({ collectionId: this.collectionId, - parentMetadatumId: this.parent, + parentMetadatumId: this.parent.id, childMetadataOrder: metadataOrder }) .then(() => { @@ -300,13 +315,13 @@ status: 'auto-draft', isRepositoryLevel: this.isRepositoryLevel, newIndex: newIndex, - parent: this.parent + parent: this.parent.id }) .then((metadatum) => { if (!this.isRepositoryLevel) this.updateMetadataOrder(); - this.childrenMetadata.splice(newIndex, 1, metadatum); + //this.childrenMetadata.splice(newIndex, 1, metadatum); this.toggleMetadatumEdition(metadatum.id) this.hightlightedMetadatum = ''; @@ -387,22 +402,19 @@ this.$router.push({ query: {}}); }, refreshMetadata() { - + /* + this.isLoadingMetadata = true; + // Cancels previous Request if (this.metadataSearchCancel != undefined) this.metadataSearchCancel.cancel('Metadata search Canceled.'); - if (this.isRepositoryLevel) - this.collectionId = 'default'; - else - this.collectionId = this.$route.params.collectionId; - this.fetchMetadata({ collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true, includeDisabled: true, - parent: this.parent + parent: this.parent.id }).then((resp) => { resp.request .then((metadata) => { @@ -424,6 +436,7 @@ this.metadataSearchCancel = resp.source; }) .catch(() => this.isLoadingMetadata = false); + */ }, isAvailableChildMetadata(to, from, item) { return !['tainacan-compound', 'tainacan-taxonomy', 'tainacan-relationship'].includes(item.id); diff --git a/src/views/admin/js/store/modules/item/mutations.js b/src/views/admin/js/store/modules/item/mutations.js index e8c7a95b4..cb0789a52 100644 --- a/src/views/admin/js/store/modules/item/mutations.js +++ b/src/views/admin/js/store/modules/item/mutations.js @@ -63,7 +63,7 @@ export const cleanItemMetadata = (state) => { } export const setSingleMetadatum = (state, itemMetadatum) => { - + if (itemMetadatum.metadatum.parent <= 0) { let index = state.itemMetadata.findIndex(anItemMetadatum => anItemMetadatum.metadatum.id == itemMetadatum.metadatum.id); if (index >= 0) diff --git a/src/views/admin/js/store/modules/metadata/actions.js b/src/views/admin/js/store/modules/metadata/actions.js index da318346d..1efd40e7d 100644 --- a/src/views/admin/js/store/modules/metadata/actions.js +++ b/src/views/admin/js/store/modules/metadata/actions.js @@ -61,8 +61,8 @@ export const sendMetadatum = ({commit}, {collectionId, name, metadatumType, stat }) .then(res => { let metadatum = res.data; - if (metadatum.parent == undefined || metadatum.parent == null || metadatum.parent <= 0) - commit('setSingleMetadatum', { metadatum: metadatum, index: newIndex }); + commit('setSingleMetadatum', { metadatum: metadatum, index: newIndex }); + resolve(metadatum); }) .catch(error => { @@ -83,8 +83,8 @@ export const updateMetadatum = ({commit}, {collectionId, metadatumId, isReposito axios.tainacan.put(endpoint + '?context=edit', options) .then(res => { let metadatum = res.data; - if (metadatum.parent == undefined || metadatum.parent == null || metadatum.parent <= 0) - commit('setSingleMetadatum', { metadatum: metadatum, index: index }); + commit('setSingleMetadatum', { metadatum: metadatum, index: index }); + resolve(metadatum); }) .catch(error => { diff --git a/src/views/admin/js/store/modules/metadata/mutations.js b/src/views/admin/js/store/modules/metadata/mutations.js index 1006cdf3b..b60d8f6b8 100644 --- a/src/views/admin/js/store/modules/metadata/mutations.js +++ b/src/views/admin/js/store/modules/metadata/mutations.js @@ -8,12 +8,33 @@ export const deleteMetadatum = ( state, metadatum ) => { } export const setSingleMetadatum = (state, {metadatum, index}) => { - if (index != undefined && index != null) - Vue.set( state.metadata, index, metadatum); - else { - const existingIndex = state.metadata.findIndex((aMetadatum) => aMetadatum.id == metadatum.id); - if (existingIndex >= 0) - Vue.set( state.metadata, existingIndex, metadatum) + if (metadatum.parent && metadatum.parent >= 0) { + const existingParentIndex = state.metadata.findIndex((aMetadatum) => aMetadatum.id == metadatum.parent); + if (existingParentIndex >= 0) { + let existingParent = JSON.parse(JSON.stringify(state.metadata[existingParentIndex])); + let existingParentChildrenObject = existingParent.metadata_type_options.children_objects; + + if (index != undefined && index != null) + existingParentChildrenObject.splice(index, 0, metadatum); + else { + const existingIndex = existingParentChildrenObject.findIndex((aMetadatum) => aMetadatum.id == metadatum.id); + if (existingIndex >= 0) + existingParentChildrenObject.splice(existingIndex, 0, metadatum); + else + existingParentChildrenObject.push(metadatum); + } + + existingParent.metadata_type_options.children_objects = existingParentChildrenObject; + Vue.set(state.metadata, existingParentIndex, existingParent) + } + } else { + if (index != undefined && index != null) + Vue.set( state.metadata, index, metadatum); + else { + const existingIndex = state.metadata.findIndex((aMetadatum) => aMetadatum.id == metadatum.id); + if (existingIndex >= 0) + Vue.set( state.metadata, existingIndex, metadatum) + } } }