Continues compound child inputs #17.

This commit is contained in:
mateuswetah 2020-03-13 17:08:06 -03:00
parent 3a793a70db
commit df4ffec561
2 changed files with 27 additions and 5 deletions

View File

@ -21,6 +21,7 @@
</template>
<script>
import { mapActions } from 'vuex';
export default {
props: {
metadatum: Object,
@ -29,7 +30,7 @@
},
data() {
return {
children: [],
childrenMetadatum: [],
collapseAllChildren: false,
childrenMetadataCollapses: [],
}
@ -38,15 +39,21 @@
this.createChildInputs();
},
methods: {
...mapActions('item', [
'fetchChildrenMetadata'
]),
createChildInputs() {
if (this.metadatum.metadatum &&
this.metadatum.metadatum.metadata_type_options &&
this.metadatum.metadatum.metadata_type_options.children_objects.length > 0
) {
for (let metadatum of this.metadatum.metadatum.metadata_type_options.children_objects) {
this.children.push(metadatum);
this.childrenMetadataCollapses.push(true);
}
this.fetchChildrenMetadata({
itemId: this.metadatum.item.id,
parentId: this.metadatum.metadatum.id
}).then(childrenMetadata => {
this.children = childrenMetadata;
this.childrenMetadataCollapses = new Array(childrenMetadata.length).fill(true);
})
}
},
toggleCollapseAllChildren() {

View File

@ -52,6 +52,21 @@ export const fetchMetadata = ({ commit }, item_id) => {
});
};
export const fetchChildrenMetadata = ({ commit }, { itemId, parentId }) => {
return new Promise((resolve, reject) => {
// axios.tainacan.get('/item/' + itemId + '/metadata?parent_meta_id=' + parentId)
axios.tainacan.get('/item/' + itemId + '/metadata?parent=any')
.then(res => {
const childMetadata = res.data.filter(metadatum => metadatum.parent_meta_id == parentId);
console.log(childMetadata)
resolve( childMetadata );
})
.catch(error => {
reject( error );
});
});
};
export const cleanMetadata = ({ commit }) => {
commit('cleanMetadata');
};