structure filter
This commit is contained in:
parent
80b0387ec2
commit
2c433586a2
|
@ -16,6 +16,12 @@ import FormRelationship from '../../classes/field-types/relationship/FormRelatio
|
|||
import FormCategory from '../../classes/field-types/category/FormCategory.vue';
|
||||
import FormSelectbox from '../../classes/field-types/selectbox/FormSelectbox.vue';
|
||||
|
||||
import FilterCustomInterval from '../../classes/filter-types/custom-interval/CustomInterval.vue';
|
||||
import FilterSelectbox from '../../classes/filter-types/selectbox/Selectbox.vue';
|
||||
import FilterAutocomplete from '../../classes/filter-types/autocomplete/Autocomplete.vue';
|
||||
import FilterCheckbox from '../../classes/filter-types/checkbox/Checkbox.vue';
|
||||
import FilterTaginput from '../../classes/filter-types/taginput/Taginput.vue';
|
||||
|
||||
import TaincanFormItem from '../../classes/field-types/tainacan-form-item.vue';
|
||||
import TaincanFiltersList from '../../classes/filter-types/tainacan-filters-list.vue';
|
||||
|
||||
|
@ -54,6 +60,14 @@ Vue.component('tainacan-form-item', TaincanFormItem);
|
|||
Vue.component('tainacan-filters-list', TaincanFiltersList);
|
||||
Vue.component('draggable', draggable);
|
||||
|
||||
/* Filters */
|
||||
|
||||
Vue.component('tainacan-filter-custom-interval', FilterCustomInterval);
|
||||
Vue.component('tainacan-filter-selectbox', FilterSelectbox);
|
||||
Vue.component('tainacan-filter-autocomplete', FilterAutocomplete);
|
||||
Vue.component('tainacan-filter-checkbox', FilterCheckbox);
|
||||
Vue.component('tainacan-filter-taginput', FilterTaginput);
|
||||
|
||||
new Vue({
|
||||
el: '#tainacan-admin-app',
|
||||
store,
|
||||
|
|
|
@ -14,13 +14,25 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { tainacan as axios } from '../../../js/axios/axios'
|
||||
import { tainacan as axios } from '../../../js/axios/axios';
|
||||
import qs from 'qs';
|
||||
|
||||
export default {
|
||||
created(){
|
||||
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id;
|
||||
this.field = ( this.field_id ) ? this.field_id : this.filter.collection_id;
|
||||
this.type = ( this.filter_type ) ? this.filter_type : this.filter.field.field_type;
|
||||
this.field = ( this.field_id ) ? this.field_id : this.filter.field;
|
||||
const vm = this;
|
||||
axios.get('/collection/' + this.collection + '/fields/' + this.field )
|
||||
.then( res => {
|
||||
let result = res.data;
|
||||
if( result && result.field_type ){
|
||||
vm.field_object = result;
|
||||
vm.type = result.field_type;
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
data(){
|
||||
return {
|
||||
|
@ -32,6 +44,7 @@
|
|||
collection: '',
|
||||
field: '',
|
||||
selected: '',
|
||||
field_object: {}
|
||||
}
|
||||
},
|
||||
props: {
|
||||
|
@ -54,8 +67,9 @@
|
|||
}
|
||||
this.$emit('input', {
|
||||
filter: 'taginput',
|
||||
field_id: ( this.field_id ) ? this.field_id : this.filter.field,
|
||||
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
|
||||
compare: 'IN',
|
||||
field_id: this.field,
|
||||
collection_id: this.collection,
|
||||
value: values
|
||||
});
|
||||
}
|
||||
|
@ -64,10 +78,9 @@
|
|||
search( query ){
|
||||
let promise = null;
|
||||
this.options = [];
|
||||
if ( this.type === 'Tainacan\Field_types\Relationship' ) {
|
||||
|
||||
let collectionTarget = ( this.filter && this.filter.field.field_type_options.collection_id ) ?
|
||||
this.filter.field.field_type_options.collection_id : this.collection_id;
|
||||
if ( this.type === 'Tainacan\\Field_Types\\Relationship' ) {
|
||||
let collectionTarget = ( this.field_object && this.field_object.field_type_options.collection_id ) ?
|
||||
this.field_object.field_type_options.collection_id : this.collection_id;
|
||||
promise = this.getValuesRelationship( collectionTarget, query );
|
||||
|
||||
} else {
|
||||
|
@ -82,7 +95,7 @@
|
|||
});
|
||||
},
|
||||
getValuesPlainText( field_id ){
|
||||
return axios.get( '/collection/' + this.collection_id + '/fields/' + field_id + '?fetch=all_field_values')
|
||||
return axios.get( '/collection/' + this.collection + '/fields/' + field_id + '?fetch=all_field_values')
|
||||
.then( res => {
|
||||
for (let metadata of res.data) {
|
||||
let index = this.options.findIndex(itemMetadata => itemMetadata.value === metadata.mvalue);
|
||||
|
@ -97,23 +110,12 @@
|
|||
});
|
||||
},
|
||||
getValuesRelationship( collectionTarget, search ){
|
||||
return axios.get( '/collection/' + collectionTarget + '/items?s=' + search )
|
||||
return axios.get( '/collection/' + collectionTarget + '/items?search=' + search )
|
||||
.then( res => {
|
||||
if( res.data.length > 0 ){
|
||||
this.getItemsName( collectionTarget, res.data);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
getItemsName( collectionId, ids){
|
||||
let query = qs.stringify({ postin: ( Array.isArray( ids ) ) ? ids : [ ids ] });
|
||||
|
||||
return axios.get('/collection/'+collectionId+'/items?' + query)
|
||||
.then( res => {
|
||||
for (let item of res.data) {
|
||||
this.options.push({ label: item.title, value: item.id, img: '' });
|
||||
for (let item of res.data) {
|
||||
this.options.push({ label: item.title, value: item.id, img: '' });
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<component
|
||||
:id="filter.filter_type_object.component + '-' + filter.slug"
|
||||
:is="filter.filter_type_object.component"
|
||||
:filter="filter"
|
||||
:filter="getFilter"
|
||||
@input="listen( $event )"></component>
|
||||
</div>
|
||||
</b-field>
|
||||
|
@ -42,12 +42,15 @@
|
|||
this.filterTypeMessage = '';
|
||||
}
|
||||
return msg;
|
||||
},
|
||||
getFilter(){
|
||||
return this.filter;
|
||||
}
|
||||
|
||||
},
|
||||
methods: {
|
||||
listen( event ){
|
||||
eventFilterBus.$emit( 'input', event.detail[0] );
|
||||
eventFilterBus.$emit( 'input', ( event.detail ) ? event.detail[0] : event );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,6 @@ export const eventFilterBus = new Vue({
|
|||
},
|
||||
methods: {
|
||||
add_metaquery( data ){
|
||||
|
||||
console.log( data , data.collection_id );
|
||||
if ( data && data.collection_id ){
|
||||
this.$store.dispatch('filter/add_metaquery', data );
|
||||
const promisse = this.$store.dispatch('filter/search_by_collection', data.collection_id );
|
||||
|
|
|
@ -3,7 +3,6 @@ import qs from 'qs';
|
|||
|
||||
// METAQUERIES ----------------------------------------------------
|
||||
export const search_by_collection = ({ state, dispatch, rootGetters }, collectionId) => {
|
||||
|
||||
return new Promise((resolve, reject) =>{
|
||||
axios.tainacan.get('/collection/' + collectionId + '/items?' + qs.stringify( state.postquery ))
|
||||
.then(res => {
|
||||
|
@ -21,7 +20,11 @@ export const set_postquery_attribute = ({ commit }, filter, value ) => {
|
|||
};
|
||||
|
||||
export const add_metaquery = ( { commit }, filter ) => {
|
||||
commit('addMetaQuery', filter );
|
||||
if( filter && filter.value.length === 0 ){
|
||||
commit('removeMetaQuery', filter );
|
||||
} else {
|
||||
commit('addMetaQuery', filter );
|
||||
}
|
||||
};
|
||||
|
||||
export const remove_metaquery = ( { commit }, filter ) => {
|
||||
|
|
|
@ -27,7 +27,7 @@ export const addMetaQuery = ( state, filter ) => {
|
|||
export const removeMetaQuery = ( state, filter ) => {
|
||||
let index = state.postquery.metaquery.findIndex( item => item.key === filter.field_id);
|
||||
if (index >= 0) {
|
||||
state.metaquery.splice(index, 1);
|
||||
state.postquery.metaquery.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue