Renames remaining references of item metadatum store variables for itemMetadata. #17.

This commit is contained in:
mateuswetah 2020-03-17 11:53:16 -03:00
parent 0dedce8f2f
commit f7bc57458e
9 changed files with 53 additions and 64 deletions

View File

@ -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) {

View File

@ -10,8 +10,7 @@
class="tainacan-icon tainacan-icon-1-25em"/>
</span>
</a>
<component
:is="'tainacan-form-item'"
<tainacan-form-item
v-for="(child, index) in children"
:key="index"
:item-metadatum="child"
@ -23,6 +22,7 @@
<script>
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 : ''
});

View File

@ -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,13 +193,13 @@
// 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;
}

View File

@ -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,

View File

@ -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 }) => {

View File

@ -1,5 +1,5 @@
export const getMetadata = state => {
return state.metadata;
export const getItemMetadata = state => {
return state.itemMetadata;
}
export const getItem = state => {

View File

@ -4,7 +4,7 @@ import * as mutations from './mutations';
const state = {
item: [],
metadata: [],
itemMetadata: [],
error: [],
itemTitle: '',
attachment: {},

View File

@ -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);
}
}
}

View File

@ -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;
});
},