Store management of children_objects on metadatum update. #17
This commit is contained in:
parent
67e2f8e4ac
commit
6b784b7bf5
|
@ -166,7 +166,7 @@
|
|||
</div>
|
||||
<child-metadata-list
|
||||
v-if="metadatum.metadata_type_object && metadatum.metadata_type_object.component == 'tainacan-compound'"
|
||||
:parent="metadatum.id"
|
||||
:parent.sync="metadatum"
|
||||
:is-repository-level="isRepositoryLevel" />
|
||||
</div>
|
||||
</draggable>
|
||||
|
|
|
@ -142,7 +142,6 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
console.log(currentValue)
|
||||
return _.groupBy(currentValue, 'parent_meta_id');
|
||||
}
|
||||
},
|
||||
|
|
|
@ -173,7 +173,7 @@
|
|||
},
|
||||
props: {
|
||||
isRepositoryLevel: Boolean,
|
||||
parent: String
|
||||
parent: Object
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
@ -185,7 +185,18 @@
|
|||
hightlightedMetadatum: '',
|
||||
editForms: {},
|
||||
metadataSearchCancel: undefined,
|
||||
childrenMetadata: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
childrenMetadata() {
|
||||
console.log(this.parent.metadata_type_options.children_objects)
|
||||
if (this.parent &&
|
||||
this.parent.metadata_type_options &&
|
||||
this.parent.metadata_type_options.children_objects.length > 0
|
||||
)
|
||||
return this.parent.metadata_type_options.children_objects;
|
||||
else
|
||||
return [];
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
@ -228,7 +239,11 @@
|
|||
}
|
||||
},
|
||||
mounted() {
|
||||
this.isLoadingMetadata = true;
|
||||
if (this.isRepositoryLevel)
|
||||
this.collectionId = 'default';
|
||||
else
|
||||
this.collectionId = this.$route.params.collectionId;
|
||||
|
||||
this.refreshMetadata();
|
||||
},
|
||||
beforeDestroy() {
|
||||
|
@ -264,7 +279,7 @@
|
|||
this.isUpdatingMetadataOrder = true;
|
||||
this.updateChildMetadataOrder({
|
||||
collectionId: this.collectionId,
|
||||
parentMetadatumId: this.parent,
|
||||
parentMetadatumId: this.parent.id,
|
||||
childMetadataOrder: metadataOrder
|
||||
})
|
||||
.then(() => {
|
||||
|
@ -283,7 +298,7 @@
|
|||
this.isUpdatingMetadataOrder = true;
|
||||
this.updateChildMetadataOrder({
|
||||
collectionId: this.collectionId,
|
||||
parentMetadatumId: this.parent,
|
||||
parentMetadatumId: this.parent.id,
|
||||
childMetadataOrder: metadataOrder
|
||||
})
|
||||
.then(() => {
|
||||
|
@ -300,13 +315,13 @@
|
|||
status: 'auto-draft',
|
||||
isRepositoryLevel: this.isRepositoryLevel,
|
||||
newIndex: newIndex,
|
||||
parent: this.parent
|
||||
parent: this.parent.id
|
||||
})
|
||||
.then((metadatum) => {
|
||||
if (!this.isRepositoryLevel)
|
||||
this.updateMetadataOrder();
|
||||
|
||||
this.childrenMetadata.splice(newIndex, 1, metadatum);
|
||||
//this.childrenMetadata.splice(newIndex, 1, metadatum);
|
||||
|
||||
this.toggleMetadatumEdition(metadatum.id)
|
||||
this.hightlightedMetadatum = '';
|
||||
|
@ -387,22 +402,19 @@
|
|||
this.$router.push({ query: {}});
|
||||
},
|
||||
refreshMetadata() {
|
||||
|
||||
/*
|
||||
this.isLoadingMetadata = true;
|
||||
|
||||
// Cancels previous Request
|
||||
if (this.metadataSearchCancel != undefined)
|
||||
this.metadataSearchCancel.cancel('Metadata search Canceled.');
|
||||
|
||||
if (this.isRepositoryLevel)
|
||||
this.collectionId = 'default';
|
||||
else
|
||||
this.collectionId = this.$route.params.collectionId;
|
||||
|
||||
this.fetchMetadata({
|
||||
collectionId: this.collectionId,
|
||||
isRepositoryLevel: this.isRepositoryLevel,
|
||||
isContextEdit: true,
|
||||
includeDisabled: true,
|
||||
parent: this.parent
|
||||
parent: this.parent.id
|
||||
}).then((resp) => {
|
||||
resp.request
|
||||
.then((metadata) => {
|
||||
|
@ -424,6 +436,7 @@
|
|||
this.metadataSearchCancel = resp.source;
|
||||
})
|
||||
.catch(() => this.isLoadingMetadata = false);
|
||||
*/
|
||||
},
|
||||
isAvailableChildMetadata(to, from, item) {
|
||||
return !['tainacan-compound', 'tainacan-taxonomy', 'tainacan-relationship'].includes(item.id);
|
||||
|
|
|
@ -63,7 +63,7 @@ export const cleanItemMetadata = (state) => {
|
|||
}
|
||||
|
||||
export const setSingleMetadatum = (state, itemMetadatum) => {
|
||||
|
||||
|
||||
if (itemMetadatum.metadatum.parent <= 0) {
|
||||
let index = state.itemMetadata.findIndex(anItemMetadatum => anItemMetadatum.metadatum.id == itemMetadatum.metadatum.id);
|
||||
if (index >= 0)
|
||||
|
|
|
@ -61,8 +61,8 @@ export const sendMetadatum = ({commit}, {collectionId, name, metadatumType, stat
|
|||
})
|
||||
.then(res => {
|
||||
let metadatum = res.data;
|
||||
if (metadatum.parent == undefined || metadatum.parent == null || metadatum.parent <= 0)
|
||||
commit('setSingleMetadatum', { metadatum: metadatum, index: newIndex });
|
||||
commit('setSingleMetadatum', { metadatum: metadatum, index: newIndex });
|
||||
|
||||
resolve(metadatum);
|
||||
})
|
||||
.catch(error => {
|
||||
|
@ -83,8 +83,8 @@ export const updateMetadatum = ({commit}, {collectionId, metadatumId, isReposito
|
|||
axios.tainacan.put(endpoint + '?context=edit', options)
|
||||
.then(res => {
|
||||
let metadatum = res.data;
|
||||
if (metadatum.parent == undefined || metadatum.parent == null || metadatum.parent <= 0)
|
||||
commit('setSingleMetadatum', { metadatum: metadatum, index: index });
|
||||
commit('setSingleMetadatum', { metadatum: metadatum, index: index });
|
||||
|
||||
resolve(metadatum);
|
||||
})
|
||||
.catch(error => {
|
||||
|
|
|
@ -8,12 +8,33 @@ export const deleteMetadatum = ( state, metadatum ) => {
|
|||
}
|
||||
|
||||
export const setSingleMetadatum = (state, {metadatum, index}) => {
|
||||
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)
|
||||
if (metadatum.parent && metadatum.parent >= 0) {
|
||||
const existingParentIndex = state.metadata.findIndex((aMetadatum) => aMetadatum.id == metadatum.parent);
|
||||
if (existingParentIndex >= 0) {
|
||||
let existingParent = JSON.parse(JSON.stringify(state.metadata[existingParentIndex]));
|
||||
let existingParentChildrenObject = existingParent.metadata_type_options.children_objects;
|
||||
|
||||
if (index != undefined && index != null)
|
||||
existingParentChildrenObject.splice(index, 0, metadatum);
|
||||
else {
|
||||
const existingIndex = existingParentChildrenObject.findIndex((aMetadatum) => aMetadatum.id == metadatum.id);
|
||||
if (existingIndex >= 0)
|
||||
existingParentChildrenObject.splice(existingIndex, 0, metadatum);
|
||||
else
|
||||
existingParentChildrenObject.push(metadatum);
|
||||
}
|
||||
|
||||
existingParent.metadata_type_options.children_objects = existingParentChildrenObject;
|
||||
Vue.set(state.metadata, existingParentIndex, existingParent)
|
||||
}
|
||||
} else {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue