Updates child metadata reordering logic. #17.
This commit is contained in:
parent
3bc2b2ec96
commit
85d7f5b899
|
@ -163,7 +163,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { mapActions, mapGetters } from 'vuex';
|
||||
import { mapActions } from 'vuex';
|
||||
import MetadatumEditionForm from '../../edition/metadatum-edition-form.vue';
|
||||
import CustomDialog from '../../other/custom-dialog.vue';
|
||||
|
||||
|
@ -200,9 +200,6 @@
|
|||
},
|
||||
immediate: true
|
||||
},
|
||||
updateChildrenMetadata(value) {
|
||||
this.updateChildrenMetadata(value, this.parent);
|
||||
}
|
||||
},
|
||||
beforeRouteLeave ( to, from, next ) {
|
||||
|
||||
|
@ -246,12 +243,7 @@
|
|||
'fetchMetadata',
|
||||
'sendMetadatum',
|
||||
'deleteMetadatum',
|
||||
'updateChildrenMetadata',
|
||||
'updateCollectionMetadataOrder',
|
||||
'cleanChildrenMetadata'
|
||||
]),
|
||||
...mapGetters('metadata',[
|
||||
'getChildrenMetadata'
|
||||
'updateChildMetadataOrder'
|
||||
]),
|
||||
handleChange(event) {
|
||||
if (event.added) {
|
||||
|
@ -268,11 +260,18 @@
|
|||
for (let metadatum of this.childrenMetadata)
|
||||
if (metadatum != undefined)
|
||||
metadataOrder.push({ 'id': metadatum.id, 'enabled': metadatum.enabled });
|
||||
/*
|
||||
|
||||
this.isUpdatingMetadataOrder = true;
|
||||
this.updateCollectionMetadataOrder({ collectionId: this.collectionId, metadataOrder: metadataOrder, parent: this.parent })
|
||||
.then(() => this.isUpdatingMetadataOrder = false)
|
||||
.catch(() => this.isUpdatingMetadataOrder = false);*/
|
||||
this.updateChildMetadataOrder({
|
||||
collectionId: this.collectionId,
|
||||
parentMetadatumId: this.parent,
|
||||
childMetadataOrder: metadataOrder
|
||||
})
|
||||
.then(() => {
|
||||
this.refreshMetadata();
|
||||
this.isUpdatingMetadataOrder = false;
|
||||
})
|
||||
.catch(() => this.isUpdatingMetadataOrder = false);
|
||||
},
|
||||
onChangeEnable($event, index) {
|
||||
let metadataOrder = [];
|
||||
|
@ -281,14 +280,17 @@
|
|||
metadataOrder.push({'id': metadatum.id, 'enabled': metadatum.enabled});
|
||||
|
||||
metadataOrder[index].enabled = $event;
|
||||
/*
|
||||
this.isUpdatingMetadataOrder = true;
|
||||
this.updateCollectionMetadataOrder({ collectionId: this.collectionId, metadataOrder: metadataOrder, parent: this.parent })
|
||||
this.updateChildMetadataOrder({
|
||||
collectionId: this.collectionId,
|
||||
parentMetadatumId: this.parent,
|
||||
childMetadataOrder: metadataOrder
|
||||
})
|
||||
.then(() => {
|
||||
this.childrenMetadata[index].enabled = $event;
|
||||
this.refreshMetadata();
|
||||
this.isUpdatingMetadataOrder = false;
|
||||
})
|
||||
.catch(() => this.isUpdatingMetadataOrder = false);*/
|
||||
.catch(() => this.isUpdatingMetadataOrder = false);
|
||||
},
|
||||
addNewMetadatum(newMetadatum, newIndex) {
|
||||
this.sendMetadatum({
|
||||
|
@ -406,7 +408,7 @@
|
|||
.then((metadata) => {
|
||||
this.isLoadingMetadata = false;
|
||||
this.childrenMetadata = metadata;
|
||||
|
||||
console.log(metadata)
|
||||
// Checks URL as router watcher would not wait for list to load
|
||||
if (this.$route.query.edit != undefined) {
|
||||
let existingMetadataIndex = this.childrenMetadata.findIndex((metadatum) => metadatum.id == this.$route.query.edit);
|
||||
|
|
|
@ -27,9 +27,7 @@ export const fetchMetadata = ({commit}, {collectionId, isRepositoryLevel, isCont
|
|||
.then((res) => {
|
||||
let metadata = res.data;
|
||||
if (!isAdvancedSearch) {
|
||||
if (parent && parent > 0)
|
||||
commit('setChildrenMetadata', { metadata, parent });
|
||||
else
|
||||
if (parent == undefined || parent == null || parent <= 0)
|
||||
commit('setMetadata', metadata);
|
||||
}
|
||||
|
||||
|
@ -63,9 +61,7 @@ export const sendMetadatum = ({commit}, {collectionId, name, metadatumType, stat
|
|||
})
|
||||
.then(res => {
|
||||
let metadatum = res.data;
|
||||
if (metadatum.parent && metadatum.parent > 0)
|
||||
commit('setSingleChildMetadatum', { metadatum: metadatum, index: newIndex });
|
||||
else
|
||||
if (metadatum.parent == undefined || metadatum.parent == null || metadatum.parent <= 0)
|
||||
commit('setSingleMetadatum', { metadatum: metadatum, index: newIndex });
|
||||
resolve(metadatum);
|
||||
})
|
||||
|
@ -87,9 +83,7 @@ export const updateMetadatum = ({commit}, {collectionId, metadatumId, isReposito
|
|||
axios.tainacan.put(endpoint + '?context=edit', options)
|
||||
.then(res => {
|
||||
let metadatum = res.data;
|
||||
if (metadatum.parent && metadatum.parent > 0)
|
||||
commit('setSingleChildMetadatum', { metadatum: metadatum, index: index });
|
||||
else
|
||||
if (metadatum.parent == undefined || metadatum.parent == null || metadatum.parent <= 0)
|
||||
commit('setSingleMetadatum', { metadatum: metadatum, index: index });
|
||||
resolve(metadatum);
|
||||
})
|
||||
|
@ -126,10 +120,6 @@ export const updateMetadata = ({commit}, metadata) => {
|
|||
commit('setMetadata', metadata);
|
||||
};
|
||||
|
||||
export const updateChildrenMetadata = ({commit}, { metadata, parent }) => {
|
||||
commit('setChildrenMetadata', metadata, parent);
|
||||
};
|
||||
|
||||
export const deleteMetadatum = ({commit}, {collectionId, metadatumId, isRepositoryLevel}) => {
|
||||
let endpoint = '';
|
||||
if (!isRepositoryLevel)
|
||||
|
@ -141,9 +131,7 @@ export const deleteMetadatum = ({commit}, {collectionId, metadatumId, isReposito
|
|||
axios.tainacan.delete(endpoint)
|
||||
.then(res => {
|
||||
const metadatum = res.data;
|
||||
if (metadatum.parent && metadatum.parent > 0)
|
||||
commit('deleteChildrenMetadatum', metadatum);
|
||||
else
|
||||
if (metadatum.parent == undefined || metadatum.parent == null || metadatum.parent <= 0)
|
||||
commit('deleteMetadatum', metadatum);
|
||||
resolve(res.data);
|
||||
}).catch((error) => {
|
||||
|
@ -158,28 +146,11 @@ export const cleanMetadata = ({commit}) => {
|
|||
commit('cleanMetadata');
|
||||
};
|
||||
|
||||
export const cleanChildrenMetadata = ({commit}, parent) => {
|
||||
commit('cleanChildrenMetadata', parent );
|
||||
};
|
||||
|
||||
export const updateCollectionMetadataOrder = ({ commit, state }, {collectionId, metadataOrder, parent}) => {
|
||||
|
||||
let allMetadataOrder = [];
|
||||
|
||||
if (parent && parent > 0) {
|
||||
allMetadataOrder = state.metadataOrder;
|
||||
console.log(allMetadataOrder)
|
||||
const parentMetadataIndex = allMetadataOrder.find((metadatumOrder) => metadatumOrder.id == parent);
|
||||
if (parentMetadataIndex >= 0)
|
||||
allMetadataOrder[parentMetadataIndex]['children_metadata_order'] = metadataOrder;
|
||||
|
||||
} else {
|
||||
allMetadataOrder = metadataOrder;
|
||||
}
|
||||
export const updateCollectionMetadataOrder = ({ commit }, {collectionId, metadataOrder}) => {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.tainacan.patch('/collections/' + collectionId + '/metadata_order?context=edit', {
|
||||
metadata_order: allMetadataOrder
|
||||
metadata_order: metadataOrder
|
||||
}).then(res => {
|
||||
commit('collection/setCollection', res.data, { root: true });
|
||||
commit('updateMetadataOrderFromCollection', res.data.metadata_order);
|
||||
|
@ -191,6 +162,26 @@ export const updateCollectionMetadataOrder = ({ commit, state }, {collectionId,
|
|||
});
|
||||
}
|
||||
|
||||
export const updateChildMetadataOrder = ({ commit }, {collectionId, parentMetadatumId, childMetadataOrder }) => {
|
||||
|
||||
const body = {
|
||||
'metadata_type_options': {
|
||||
'children_order': childMetadataOrder
|
||||
}
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.tainacan.put('/collection/' + collectionId + '/metadata/' + parentMetadatumId + '?context=edit', body)
|
||||
.then(res => {
|
||||
const updatedParentMetadatum = res.data;
|
||||
commit('setSingleMetadatum', { metadatum: updatedParentMetadatum });
|
||||
resolve(updatedParentMetadatum);
|
||||
}).catch(error => {
|
||||
reject(error.response);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export const fetchMetadatumTypes = ({commit}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.tainacan.get('/metadata-types')
|
||||
|
|
|
@ -2,10 +2,6 @@ export const getMetadata = state => {
|
|||
return state.metadata;
|
||||
}
|
||||
|
||||
export const getChildrenMetadata = state => {
|
||||
return state.childrenMetadata;
|
||||
}
|
||||
|
||||
export const getMetadatumTypes = state => {
|
||||
return state.metadatumTypes;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import * as mutations from './mutations';
|
|||
|
||||
const state = {
|
||||
metadata: [],
|
||||
childrenMetadata: {},
|
||||
metadatumTypes: [],
|
||||
metadatumMappers: []
|
||||
};
|
||||
|
|
|
@ -7,32 +7,20 @@ export const deleteMetadatum = ( state, metadatum ) => {
|
|||
}
|
||||
}
|
||||
|
||||
export const deleteChildrenMetadatum = ( state, metadatum ) => {
|
||||
let index = state.childrenMetadata[metadatum.parent].findIndex(deletedMetadatum => deletedMetadatum.id == metadatum.id);
|
||||
if (index >= 0) {
|
||||
state.childrenMetadata[metadatum.parent].splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
export const setSingleMetadatum = (state, {metadatum, index}) => {
|
||||
Vue.set( state.metadata, index, metadatum);
|
||||
}
|
||||
|
||||
export const setSingleChildMetadatum = (state, {metadatum, index}) => {
|
||||
if (metadatum.id && metadatum.parent)
|
||||
Vue.set( state.childrenMetadata[metadatum.parent], index, metadatum);
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
export const setMetadata = (state, metadata) => {
|
||||
state.metadata = metadata;
|
||||
}
|
||||
|
||||
export const setChildrenMetadata = (state, {metadata, parent}) => {
|
||||
const updatedChildrenMetadata = state.childrenMetadata;
|
||||
updatedChildrenMetadata[parent] = metadata;
|
||||
state.childrenMetadata = updatedChildrenMetadata;
|
||||
}
|
||||
|
||||
export const updateMetadataOrderFromCollection = (state, metadataOrder) => {
|
||||
for (let i = 0; i < state.metadata.length; i++) {
|
||||
let updatedMetadatumIndex = metadataOrder.findIndex(aMetadatum => aMetadatum.id == state.metadata[i].id);
|
||||
|
@ -51,8 +39,4 @@ export const setMetadatumMappers = (state, metadatumMappers) => {
|
|||
|
||||
export const cleanMetadata = (state) => {
|
||||
state.metadata = [];
|
||||
}
|
||||
|
||||
export const cleanChildrenMetadata = (state, parent) => {
|
||||
state.childrenMetadata[parent] = [];
|
||||
}
|
Loading…
Reference in New Issue