Adds first version of component for compound metadata #17
This commit is contained in:
parent
963d48fd9f
commit
6d14dfa8b1
|
@ -0,0 +1,72 @@
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<a
|
||||||
|
class="collapse-all"
|
||||||
|
@click="toggleCollapseAllChildren()">
|
||||||
|
{{ collapseAllChildren ? $i18n.get('label_collapse_all') : $i18n.get('label_expand_all') }}
|
||||||
|
<span class="icon">
|
||||||
|
<i
|
||||||
|
:class="{ 'tainacan-icon-arrowdown' : collapseAllChildren, 'tainacan-icon-arrowright' : !collapseAllChildren }"
|
||||||
|
class="tainacan-icon tainacan-icon-1-25em"/>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<component
|
||||||
|
:is="'tainacan-form-item'"
|
||||||
|
v-for="(child, index) in children"
|
||||||
|
:key="index"
|
||||||
|
:metadatum="child"
|
||||||
|
:parent-meta-id="metadatum.metadatum.id"
|
||||||
|
:is-collapsed="childrenMetadataCollapses[index]"
|
||||||
|
@changeCollapse="onChangeCollapse($event, index)"/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
metadatum: Object,
|
||||||
|
value: [String, Number, Array],
|
||||||
|
disabled: false
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
uniqueId: new Date().getTime(),
|
||||||
|
valueChild: [],
|
||||||
|
children: [],
|
||||||
|
collapseAllChildren: false,
|
||||||
|
childrenMetadataCollapses: [],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.createChildInputs();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
toggleCollapseAllChildren() {
|
||||||
|
this.collapseAllChildren = !this.collapseAllChildren;
|
||||||
|
|
||||||
|
for (let i = 0; i < this.childreMetadataCollapses.length; i++)
|
||||||
|
this.childrenMetadataCollapses[i] = this.collapseAllChildren;
|
||||||
|
|
||||||
|
},
|
||||||
|
onChangeCollapse(event, index) {
|
||||||
|
this.childrenMetadataCollapses.splice(index, 1, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import '../../../admin/scss/_variables.scss';
|
||||||
|
</style>
|
|
@ -16,19 +16,18 @@ class Compound extends Metadata_Type {
|
||||||
// call metadatum type constructor
|
// call metadatum type constructor
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->set_name( __('Compound', 'tainacan') );
|
$this->set_name( __('Compound', 'tainacan') );
|
||||||
$this->set_description( __('A compount metadata', 'tainacan') );
|
$this->set_description( __('A compound metadata can have different types with groups of values.', 'tainacan') );
|
||||||
$this->set_primitive_type('compound');
|
$this->set_primitive_type('compound');
|
||||||
$this->set_component('tainacan-compound');
|
$this->set_component('tainacan-compound');
|
||||||
$this->set_form_component('tainacan-form-compound');
|
$this->set_form_component('tainacan-form-compound');
|
||||||
add_action( 'tainacan-insert-tainacan-metadatum', array( &$this, 'save_children' ), 10, 1 );
|
|
||||||
|
|
||||||
$this->set_preview_template('
|
$this->set_preview_template('
|
||||||
<div>
|
<div>
|
||||||
<div class="control is-clearfix">
|
<div class="control is-clearfix">
|
||||||
Compound
|
Compound
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
');
|
');
|
||||||
|
add_action( 'tainacan-insert-tainacan-metadatum', array( &$this, 'save_children' ), 10, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,7 +106,7 @@ class Compound extends Metadata_Type {
|
||||||
/**
|
/**
|
||||||
* Overrides and bring back all data for the children
|
* Overrides and bring back all data for the children
|
||||||
* that were not set yet.
|
* that were not set yet.
|
||||||
* @return array Field type options
|
* @return array Metadata type options
|
||||||
*/
|
*/
|
||||||
public function get_options() {
|
public function get_options() {
|
||||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
||||||
|
|
|
@ -108,7 +108,8 @@
|
||||||
name: 'TainacanFormItem',
|
name: 'TainacanFormItem',
|
||||||
props: {
|
props: {
|
||||||
metadatum: Object,
|
metadatum: Object,
|
||||||
isCollapsed: true
|
isCollapsed: true,
|
||||||
|
parentMetaId: false
|
||||||
},
|
},
|
||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
|
@ -182,12 +183,13 @@
|
||||||
eventBusItemMetadata.$emit('input', {
|
eventBusItemMetadata.$emit('input', {
|
||||||
itemId: this.metadatum.item.id,
|
itemId: this.metadatum.item.id,
|
||||||
metadatumId: this.metadatum.metadatum.id,
|
metadatumId: this.metadatum.metadatum.id,
|
||||||
values: this.inputs ? this.inputs : ''
|
values: this.inputs ? this.inputs : '',
|
||||||
|
parentMetaId: this.parentMetaId
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
createInputs() {
|
createInputs() {
|
||||||
if (this.metadatum.value instanceof Array)
|
if (this.metadatum.value instanceof Array)
|
||||||
this.inputs = this.metadatum.value.slice(0);
|
this.inputs = this.metadatum.value.slice(0); // This way we garantee this.inputs is a copy of the contents of this.metadatum.value, instead of a reference to it
|
||||||
else
|
else
|
||||||
this.metadatum.value == null || this.metadatum.value == undefined ? this.inputs = [] : this.inputs.push(this.metadatum.value);
|
this.metadatum.value == null || this.metadatum.value == undefined ? this.inputs = [] : this.inputs.push(this.metadatum.value);
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,10 +4,8 @@ import store from './store/store'
|
||||||
export const eventBusItemMetadata = new Vue({
|
export const eventBusItemMetadata = new Vue({
|
||||||
store,
|
store,
|
||||||
data: {
|
data: {
|
||||||
errors : []
|
errors : [],
|
||||||
},
|
compoundsMap: []
|
||||||
created() {
|
|
||||||
this.$on('input', this.updateValue);
|
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
errors() {
|
errors() {
|
||||||
|
@ -18,8 +16,14 @@ export const eventBusItemMetadata = new Vue({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
created() {
|
||||||
|
this.$on('input', this.updateValue);
|
||||||
|
},
|
||||||
|
beforeUpdate() {
|
||||||
|
this.$off('input', this.updateValue);
|
||||||
|
},
|
||||||
methods : {
|
methods : {
|
||||||
updateValue({ itemId, metadatumId, values}){
|
updateValue({ itemId, metadatumId, values, parentMetaId }){
|
||||||
|
|
||||||
this.$emit('isUpdatingValue', true);
|
this.$emit('isUpdatingValue', true);
|
||||||
|
|
||||||
|
@ -33,7 +37,8 @@ export const eventBusItemMetadata = new Vue({
|
||||||
this.$store.dispatch('item/updateMetadata', {
|
this.$store.dispatch('item/updateMetadata', {
|
||||||
item_id: itemId,
|
item_id: itemId,
|
||||||
metadatum_id: metadatumId,
|
metadatum_id: metadatumId,
|
||||||
values: Array.isArray(values[0]) ? values[0] : values
|
values: Array.isArray(values[0]) ? values[0] : values,
|
||||||
|
parent_meta_id: parentMetaId ? parentMetaId : null
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.$emit('isUpdatingValue', false);
|
this.$emit('isUpdatingValue', false);
|
||||||
|
@ -66,9 +71,5 @@ export const eventBusItemMetadata = new Vue({
|
||||||
clearAllErrors() {
|
clearAllErrors() {
|
||||||
this.errors = [];
|
this.errors = [];
|
||||||
}
|
}
|
||||||
},
|
|
||||||
beforeUpdate() {
|
|
||||||
this.$off('input', this.updateValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,11 +17,14 @@ export const sendMetadatum = ( { commit }, { item_id, metadatum_id, values }) =>
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateMetadata = ({ commit }, { item_id, metadatum_id, values }) => {
|
export const updateMetadata = ({ commit }, { item_id, metadatum_id, values, parent_meta_id }) => {
|
||||||
|
let body = { values: 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) => {
|
return new Promise((resolve, reject) => {
|
||||||
axios.tainacan.patch(`/item/${item_id}/metadata/${metadatum_id}`, {
|
axios.tainacan.patch(`/item/${item_id}/metadata/${metadatum_id}`, body)
|
||||||
values: values,
|
|
||||||
})
|
|
||||||
.then( res => {
|
.then( res => {
|
||||||
let metadatum = res.data;
|
let metadatum = res.data;
|
||||||
commit('setSingleMetadatum', metadatum);
|
commit('setSingleMetadatum', metadatum);
|
||||||
|
|
Loading…
Reference in New Issue