From f7bc57458ecf35ea9f18ee147432e0293cef6a8d Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Tue, 17 Mar 2020 11:53:16 -0300 Subject: [PATCH] Renames remaining references of item metadatum store variables for itemMetadata. #17. --- .../components/edition/item-edition-form.vue | 15 +++---- .../metadata-types/compound/Compound.vue | 13 ++++-- .../metadata-types/tainacan-form-item.vue | 8 ++-- src/views/admin/js/event-bus-item-metadata.js | 2 +- .../admin/js/store/modules/item/actions.js | 43 ++++++------------- .../admin/js/store/modules/item/getters.js | 4 +- .../admin/js/store/modules/item/index.js | 2 +- .../admin/js/store/modules/item/mutations.js | 22 +++++----- src/views/admin/pages/singles/item-page.vue | 8 ++-- 9 files changed, 53 insertions(+), 64 deletions(-) diff --git a/src/views/admin/components/edition/item-edition-form.vue b/src/views/admin/components/edition/item-edition-form.vue index 83cae2074..235de6f3c 100644 --- a/src/views/admin/components/edition/item-edition-form.vue +++ b/src/views/admin/components/edition/item-edition-form.vue @@ -823,7 +823,7 @@ export default { return this.getCollection() }, metadatumList() { - return JSON.parse(JSON.stringify(this.getMetadata())); + return JSON.parse(JSON.stringify(this.getItemMetadata())); }, lastUpdated() { return this.getLastUpdated(); @@ -849,7 +849,7 @@ export default { this.$userPrefs.set('sequence_' + this.sequenceId + '_position', this.itemPosition); // Clear form variables - this.cleanMetadata(); + this.cleanItemMetadata(); eventBusItemMetadata.clearAllErrors(); this.formErrorMessage = ''; @@ -871,7 +871,7 @@ export default { }, created(){ // Obtains collection ID - this.cleanMetadata(); + this.cleanItemMetadata(); eventBusItemMetadata.clearAllErrors(); this.formErrorMessage = ''; this.collectionId = this.$route.params.collectionId; @@ -957,10 +957,9 @@ export default { 'sendItem', 'updateItem', 'updateItemDocument', - 'fetchMetadata', - 'sendMetadatum', + 'fetchItemMetadata', 'fetchItem', - 'cleanMetadata', + 'cleanItemMetadata', 'sendAttachments', 'fetchAttachments', 'deletePermanentlyAttachment', @@ -970,7 +969,7 @@ export default { 'removeAttachmentFromItem' ]), ...mapGetters('item',[ - 'getMetadata', + 'getItemMetadata', 'getTotalAttachments', 'getLastUpdated' ]), @@ -1101,7 +1100,7 @@ export default { }, loadMetadata() { // Obtains Item Metadatum - this.fetchMetadata(this.itemId).then((metadata) => { + this.fetchItemMetadata(this.itemId).then((metadata) => { this.metadataCollapses = []; if (this.isOnSequenceEdit && this.$route.query.collapses) { diff --git a/src/views/admin/components/metadata-types/compound/Compound.vue b/src/views/admin/components/metadata-types/compound/Compound.vue index 63a0e1095..911efa9a3 100644 --- a/src/views/admin/components/metadata-types/compound/Compound.vue +++ b/src/views/admin/components/metadata-types/compound/Compound.vue @@ -10,8 +10,7 @@ class="tainacan-icon tainacan-icon-1-25em"/> - import { mapActions } from 'vuex'; + export default { props: { itemMetadatum: Object, @@ -49,11 +49,18 @@ this.itemMetadatum.metadatum.metadata_type_options.children_objects.length > 0 ) { for (let child of this.itemMetadatum.metadatum.metadata_type_options.children_objects) { + let values = []; + + if (Array.isArray(this.itemMetadatum.value)) + values = this.itemMetadatum.value.map((aValue) => aValue[child.id] ? aValue[child.id].value : []) + else + values = this.itemMetadatum.value[child.id] ? this.itemMetadatum.value[child.id].value : [] + this.children.push({ parent_meta_id: this.itemMetadatum.value[child.id] ? this.itemMetadatum.value[child.id].parent_meta_id : 0, item: this.itemMetadatum.item, metadatum: child, - value: this.itemMetadatum.value[child.id] ? this.itemMetadatum.value[child.id].value : [], + value: values, value_as_html: this.itemMetadatum.value[child.id] ? this.itemMetadatum.value[child.id].value_as_html : '', value_as_string: this.itemMetadatum.value[child.id] ? this.itemMetadatum.value[child.id].value_as_string : '' }); diff --git a/src/views/admin/components/metadata-types/tainacan-form-item.vue b/src/views/admin/components/metadata-types/tainacan-form-item.vue index bf29ae055..2476006b2 100644 --- a/src/views/admin/components/metadata-types/tainacan-form-item.vue +++ b/src/views/admin/components/metadata-types/tainacan-form-item.vue @@ -174,7 +174,7 @@ let currentValues = []; // An array of terms - if (this.values[0].constructor.name == 'Object') + if (this.values.length && this.values[0].constructor.name == 'Object') currentValues = this.values.map(term => term.value) else currentValues = this.values; @@ -193,16 +193,16 @@ // A single term value case 'Object': - if (this.values[0] == this.itemMetadatum.value.id) + if (this.values.length && this.values[0] == this.itemMetadatum.value.id) return; break; // Any single metadatum value that is not a term default: - if (this.values[0] == this.itemMetadatum.value) + if (this.values.length && this.values[0] == this.itemMetadatum.value) return; } - + // If none is the case, the value is update request is sent to the API eventBusItemMetadata.$emit('input', { itemId: this.itemMetadatum.item.id, diff --git a/src/views/admin/js/event-bus-item-metadata.js b/src/views/admin/js/event-bus-item-metadata.js index d496b0e0c..a2a81dc35 100644 --- a/src/views/admin/js/event-bus-item-metadata.js +++ b/src/views/admin/js/event-bus-item-metadata.js @@ -33,7 +33,7 @@ export const eventBusItemMetadata = new Vue({ values = onlyValues; } - this.$store.dispatch('item/updateMetadata', { + this.$store.dispatch('item/updateItemMetadatum', { item_id: itemId, metadatum_id: metadatumId, values: Array.isArray(values[0]) ? values[0] : values, diff --git a/src/views/admin/js/store/modules/item/actions.js b/src/views/admin/js/store/modules/item/actions.js index 3a78aa329..cd3146085 100644 --- a/src/views/admin/js/store/modules/item/actions.js +++ b/src/views/admin/js/store/modules/item/actions.js @@ -1,24 +1,7 @@ import axios from '../../../axios'; -// Actions related to Item's metadatum -export const sendMetadatum = ( { commit }, { item_id, metadatum_id, values }) => { - return new Promise( (resolve, reject) => { - axios.tainacan.post('/item/'+item_id+'/metadata/'+metadatum_id, { - values: values - }) - .then( res => { - const metadatum = res.data - commit('setSingleMetadatum', metadatum); - commit('setLastUpdated'); - resolve( metadatum ); - }) - .catch(error => { - reject( error); - }); - }); -}; - -export const updateMetadata = ({ commit }, { item_id, metadatum_id, values, parent_meta_id }) => { +// Actions related to Item's metadata +export const updateItemMetadatum = ({ commit }, { item_id, metadatum_id, values, parent_meta_id }) => { let body = { values: values } if (parent_meta_id != undefined && parent_meta_id != null && parent_meta_id != false) @@ -27,10 +10,10 @@ export const updateMetadata = ({ commit }, { item_id, metadatum_id, values, pare return new Promise((resolve, reject) => { axios.tainacan.patch(`/item/${item_id}/metadata/${metadatum_id}`, body) .then( res => { - let metadatum = res.data; - commit('setSingleMetadatum', metadatum); + let itemMetadatum = res.data; + commit('setSingleMetadatum', itemMetadatum); commit('setLastUpdated'); - resolve(metadatum) + resolve(itemMetadatum) }) .catch( error => { reject(error.response.data.errors); @@ -38,14 +21,14 @@ export const updateMetadata = ({ commit }, { item_id, metadatum_id, values, pare }); }; -export const fetchMetadata = ({ commit }, item_id) => { - commit('cleanMetadata'); +export const fetchItemMetadata = ({ commit }, item_id) => { + commit('cleanItemMetadata'); return new Promise((resolve, reject) => { - axios.tainacan.get('/item/'+item_id+'/metadata') + axios.tainacan.get('/item/' + item_id + '/metadata') .then(res => { - let metadata = res.data; - commit('setMetadata', metadata); - resolve( metadata ); + let itemMetadata = res.data; + commit('setItemMetadata', itemMetadata); + resolve( itemMetadata ); }) .catch(error => { reject( error ); @@ -53,8 +36,8 @@ export const fetchMetadata = ({ commit }, item_id) => { }); }; -export const cleanMetadata = ({ commit }) => { - commit('cleanMetadata'); +export const cleanItemMetadata = ({ commit }) => { + commit('cleanItemMetadata'); }; export const cleanLastUpdated = ({ commit }) => { diff --git a/src/views/admin/js/store/modules/item/getters.js b/src/views/admin/js/store/modules/item/getters.js index 26b666db3..6262e99db 100644 --- a/src/views/admin/js/store/modules/item/getters.js +++ b/src/views/admin/js/store/modules/item/getters.js @@ -1,5 +1,5 @@ -export const getMetadata = state => { - return state.metadata; +export const getItemMetadata = state => { + return state.itemMetadata; } export const getItem = state => { diff --git a/src/views/admin/js/store/modules/item/index.js b/src/views/admin/js/store/modules/item/index.js index daaa77bd2..f18c57bf8 100644 --- a/src/views/admin/js/store/modules/item/index.js +++ b/src/views/admin/js/store/modules/item/index.js @@ -4,7 +4,7 @@ import * as mutations from './mutations'; const state = { item: [], - metadata: [], + itemMetadata: [], error: [], itemTitle: '', attachment: {}, diff --git a/src/views/admin/js/store/modules/item/mutations.js b/src/views/admin/js/store/modules/item/mutations.js index ef8614405..47caed916 100644 --- a/src/views/admin/js/store/modules/item/mutations.js +++ b/src/views/admin/js/store/modules/item/mutations.js @@ -26,7 +26,7 @@ export const setAttachments = ( state, attachments ) => { state.attachments = attachments; } -export const removeAttatchmentFromItem = (state, attachmentId) => { +export const removeAttatchmentFromItem = (state, attachmentId) => { let indexOfRemoved = state.attachments.findIndex((anAttachment) => anAttachment.id == attachmentId); if (indexOfRemoved >= 0) @@ -54,35 +54,35 @@ export const cleanItemTitle = ( state ) => { state.itemTitle = ''; } -export const setMetadata = ( state, metadata) => { - state.metadata = metadata; +export const setItemMetadata = ( state, itemMetadata) => { + state.itemMetadata = itemMetadata; } -export const cleanMetadata = (state) => { - state.metadata = []; +export const cleanItemMetadata = (state) => { + state.itemMetadata = []; } export const setSingleMetadatum = (state, itemMetadatum) => { if (itemMetadatum.metadatum.parent <= 0) { - let index = state.metadata.findIndex(anItemMetadatum => anItemMetadatum.metadatum.id == itemMetadatum.metadatum.id); + let index = state.itemMetadata.findIndex(anItemMetadatum => anItemMetadatum.metadatum.id == itemMetadatum.metadatum.id); if (index >= 0) - Vue.set( state.metadata, index, itemMetadatum ); + Vue.set( state.itemMetadata, index, itemMetadatum ); else - state.metadata.push( itemMetadatum ); + state.itemMetadata.push( itemMetadatum ); } else { - let parentIndex = state.metadata.findIndex(anItemMetadatum => anItemMetadatum.metadatum.id == itemMetadatum.metadatum.parent); + let parentIndex = state.itemMetadata.findIndex(anItemMetadatum => anItemMetadatum.metadatum.id == itemMetadatum.metadatum.parent); if (parentIndex >= 0) { - let currentParent = state.metadata[parentIndex]; + let currentParent = state.itemMetadata[parentIndex]; currentParent.value[itemMetadatum.metadatum.id] = { parent_meta_id: itemMetadatum.parent_meta_id ? itemMetadatum.parent_meta_id : 0, value: itemMetadatum.value ? itemMetadatum.value : [], value_as_html: itemMetadatum.value_as_html ? itemMetadatum.value_as_html : '', value_as_string: itemMetadatum.value_as_string ? itemMetadatum.value_as_string : '' }; - Vue.set(state.metadata, parentIndex, currentParent); + Vue.set(state.itemMetadata, parentIndex, currentParent); } } } diff --git a/src/views/admin/pages/singles/item-page.vue b/src/views/admin/pages/singles/item-page.vue index 3d808a836..3eb78e8d1 100644 --- a/src/views/admin/pages/singles/item-page.vue +++ b/src/views/admin/pages/singles/item-page.vue @@ -354,7 +354,7 @@ return this.getItem(); }, metadatumList() { - return JSON.parse(JSON.stringify(this.getMetadata())); + return JSON.parse(JSON.stringify(this.getItemMetadata())); }, totalAttachments() { return this.getTotalAttachments(); @@ -386,11 +386,11 @@ methods: { ...mapActions('item', [ 'fetchItem', - 'fetchMetadata', + 'fetchItemMetadata', ]), ...mapGetters('item', [ 'getItem', - 'getMetadata', + 'getItemMetadata', 'getTotalAttachments' ]), ...mapGetters('collection', [ @@ -398,7 +398,7 @@ ]), loadMetadata() { // Obtains Item Metadatum - this.fetchMetadata(this.itemId).then(() => { + this.fetchItemMetadata(this.itemId).then(() => { this.isLoading = false; }); },