Solves child metadatum form not updating 'saved' label. #17.

This commit is contained in:
mateuswetah 2020-03-17 16:50:10 -03:00
parent f7bc57458e
commit 2e0dc2b40c
9 changed files with 41 additions and 10 deletions

View File

@ -280,6 +280,7 @@ export default {
}
},
beforeRouteLeave ( to, from, next ) {
let hasUnsavedForms = false;
for (let editForm in this.editForms) {
if (!this.editForms[editForm].saved)

View File

@ -36,6 +36,11 @@
childrenMetadataCollapses: [],
}
},
watch: {
itemMetadatum() {
this.createChildInputs();
}
},
created() {
this.createChildInputs();
},
@ -44,18 +49,22 @@
'fetchChildrenMetadata'
]),
createChildInputs() {
this.children = [];
if (this.itemMetadatum.metadatum &&
this.itemMetadatum.metadatum.metadata_type_options &&
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))
if (Array.isArray(this.itemMetadatum.value)) {
// console.log(this.itemMetadatum.value)
values = this.itemMetadatum.value.map((aValue) => aValue[child.id] ? aValue[child.id].value : [])
else
} else
values = this.itemMetadatum.value[child.id] ? this.itemMetadatum.value[child.id].value : []
//console.log(this.itemMetadatum.value[child.id] ? this.itemMetadatum.value[child.id].parent_meta_id : 0)
this.children.push({
parent_meta_id: this.itemMetadatum.value[child.id] ? this.itemMetadatum.value[child.id].parent_meta_id : 0,
item: this.itemMetadatum.item,

View File

@ -205,6 +205,7 @@
}
},
beforeRouteLeave ( to, from, next ) {
let hasUnsavedForms = false;
for (let editForm in this.editForms) {
if (!this.editForms[editForm].saved)
@ -357,7 +358,7 @@
},
editMetadatum(metadatum) {
this.openedMetadatumId = metadatum.id;
// First time opening
if (this.editForms[this.openedMetadatumId] == undefined) {
this.editForms[this.openedMetadatumId] = JSON.parse(JSON.stringify(metadatum));
@ -374,6 +375,7 @@
this.formWithErrors = '';
delete this.editForms[this.openedMetadatumId];
this.openedMetadatumId = '';
this.refreshMetadata();
this.$router.push({ query: {}});
},
onEditionCanceled() {
@ -404,6 +406,7 @@
.then((metadata) => {
this.isLoadingMetadata = false;
this.childrenMetadata = 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);

View File

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

View File

@ -278,7 +278,8 @@
isRepositoryLevel: this.isRepositoryLevel,
isContextEdit: false,
includeDisabled: false,
isAdvancedSearch: true
isAdvancedSearch: true,
parent: '0'
}).then((resp) => {
resp.request
.then((metadata) => {

View File

@ -10,9 +10,8 @@ export const eventBusItemMetadata = new Vue({
errors() {
this.$emit('hasErrorsOnForm', this.errors.length > 0);
for (let error of this.errors) {
for (let error of this.errors)
this.$emit('updateErrorMessageOf#' + error.metadatum_id, error);
}
}
},
created() {

View File

@ -6,7 +6,7 @@ export const updateItemMetadatum = ({ commit }, { item_id, metadatum_id, values,
if (parent_meta_id != undefined && parent_meta_id != null && parent_meta_id != false)
body['parent_meta_id'] = parent_meta_id;
return new Promise((resolve, reject) => {
axios.tainacan.patch(`/item/${item_id}/metadata/${metadatum_id}`, body)
.then( res => {

View File

@ -76,12 +76,27 @@ export const setSingleMetadatum = (state, itemMetadatum) => {
if (parentIndex >= 0) {
let currentParent = state.itemMetadata[parentIndex];
currentParent.value[itemMetadatum.metadatum.id] = {
let updatedParent = {
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 : ''
};
if (Array.isArray(currentParent.value)) {
let metadatumIndex = currentParent.value.findIndex((aValue) => aValue.parent_meta_id == itemMetadatum.parent_meta_id);
if (metadatumIndex >= 0)
currentParent.value[metadatumIndex][itemMetadatum.metadatum.id] = updatedParent;
else {
const parentObject = {}
parentObject[itemMetadatum.metadatum.id] = updatedParent;
currentParent.value.push(parentObject);
}
} else {
currentParent.value['' + itemMetadatum.metadatum.id] = updatedParent;
}
console.log(currentParent)
Vue.set(state.itemMetadata, parentIndex, currentParent);
}
}

View File

@ -62,6 +62,9 @@ export default {
created() {
this.isRepositoryLevel = (this.$route.params.collectionId === undefined);
},
beforeRouteLeave ( to, from, next ) {
next();
},
methods: {
...mapGetters('collection', [
'getCollection',