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 ) { beforeRouteLeave ( to, from, next ) {
let hasUnsavedForms = false; let hasUnsavedForms = false;
for (let editForm in this.editForms) { for (let editForm in this.editForms) {
if (!this.editForms[editForm].saved) if (!this.editForms[editForm].saved)

View File

@ -36,6 +36,11 @@
childrenMetadataCollapses: [], childrenMetadataCollapses: [],
} }
}, },
watch: {
itemMetadatum() {
this.createChildInputs();
}
},
created() { created() {
this.createChildInputs(); this.createChildInputs();
}, },
@ -44,6 +49,8 @@
'fetchChildrenMetadata' 'fetchChildrenMetadata'
]), ]),
createChildInputs() { createChildInputs() {
this.children = [];
if (this.itemMetadatum.metadatum && if (this.itemMetadatum.metadatum &&
this.itemMetadatum.metadatum.metadata_type_options && this.itemMetadatum.metadatum.metadata_type_options &&
this.itemMetadatum.metadatum.metadata_type_options.children_objects.length > 0 this.itemMetadatum.metadatum.metadata_type_options.children_objects.length > 0
@ -51,11 +58,13 @@
for (let child of this.itemMetadatum.metadatum.metadata_type_options.children_objects) { for (let child of this.itemMetadatum.metadatum.metadata_type_options.children_objects) {
let values = []; 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 : []) 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 : [] 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({ this.children.push({
parent_meta_id: this.itemMetadatum.value[child.id] ? this.itemMetadatum.value[child.id].parent_meta_id : 0, parent_meta_id: this.itemMetadatum.value[child.id] ? this.itemMetadatum.value[child.id].parent_meta_id : 0,
item: this.itemMetadatum.item, item: this.itemMetadatum.item,

View File

@ -205,6 +205,7 @@
} }
}, },
beforeRouteLeave ( to, from, next ) { beforeRouteLeave ( to, from, next ) {
let hasUnsavedForms = false; let hasUnsavedForms = false;
for (let editForm in this.editForms) { for (let editForm in this.editForms) {
if (!this.editForms[editForm].saved) if (!this.editForms[editForm].saved)
@ -374,6 +375,7 @@
this.formWithErrors = ''; this.formWithErrors = '';
delete this.editForms[this.openedMetadatumId]; delete this.editForms[this.openedMetadatumId];
this.openedMetadatumId = ''; this.openedMetadatumId = '';
this.refreshMetadata();
this.$router.push({ query: {}}); this.$router.push({ query: {}});
}, },
onEditionCanceled() { onEditionCanceled() {
@ -404,6 +406,7 @@
.then((metadata) => { .then((metadata) => {
this.isLoadingMetadata = false; this.isLoadingMetadata = false;
this.childrenMetadata = metadata; this.childrenMetadata = metadata;
// Checks URL as router watcher would not wait for list to load // Checks URL as router watcher would not wait for list to load
if (this.$route.query.edit != undefined) { if (this.$route.query.edit != undefined) {
let existingMetadataIndex = this.childrenMetadata.findIndex((metadatum) => metadatum.id == this.$route.query.edit); let existingMetadataIndex = this.childrenMetadata.findIndex((metadatum) => metadatum.id == this.$route.query.edit);

View File

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

View File

@ -10,9 +10,8 @@ export const eventBusItemMetadata = new Vue({
errors() { errors() {
this.$emit('hasErrorsOnForm', this.errors.length > 0); 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); this.$emit('updateErrorMessageOf#' + error.metadatum_id, error);
}
} }
}, },
created() { created() {

View File

@ -76,12 +76,27 @@ export const setSingleMetadatum = (state, itemMetadatum) => {
if (parentIndex >= 0) { if (parentIndex >= 0) {
let currentParent = state.itemMetadata[parentIndex]; let currentParent = state.itemMetadata[parentIndex];
currentParent.value[itemMetadatum.metadatum.id] = { let updatedParent = {
parent_meta_id: itemMetadatum.parent_meta_id ? itemMetadatum.parent_meta_id : 0, parent_meta_id: itemMetadatum.parent_meta_id ? itemMetadatum.parent_meta_id : 0,
value: itemMetadatum.value ? itemMetadatum.value : [], value: itemMetadatum.value ? itemMetadatum.value : [],
value_as_html: itemMetadatum.value_as_html ? itemMetadatum.value_as_html : '', value_as_html: itemMetadatum.value_as_html ? itemMetadatum.value_as_html : '',
value_as_string: itemMetadatum.value_as_string ? itemMetadatum.value_as_string : '' 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); Vue.set(state.itemMetadata, parentIndex, currentParent);
} }
} }

View File

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