Merge branch 'develop' of https://github.com/tainacan/tainacan into develop

This commit is contained in:
weryques 2018-02-28 12:53:05 -03:00
commit 5b2961a45a
8 changed files with 105 additions and 40 deletions

View File

@ -62,6 +62,7 @@
type: Object // concentrate all attributes field id and type type: Object // concentrate all attributes field id and type
}, },
field_id: [Number], // not required, but overrides the filter field id if is set field_id: [Number], // not required, but overrides the filter field id if is set
collection_id: [Number], // not required, but overrides the filter field id if is set
typeRange: [String], // not required, but overrides the filter field type if is set typeRange: [String], // not required, but overrides the filter field type if is set
id: '' id: ''
}, },
@ -82,23 +83,23 @@
} }
} }
}, },
// emit the operation for component listener // emit the operation for listeners
emit(){ emit(){
let values = null;
if( this.type === 'date' ){ if( this.type === 'date' ){
this.$emit('input', { values = [ this.date_init, this.date_end ]
filter: 'range',
type: 'date',
field_id: ( this.field_id ) ? this.field_id : this.filter.field,
values: [ this.date_init, this.date_end ]
});
} else { } else {
this.$emit('input', { values = [ this.value_init, this.value_end ]
filter: 'range',
type: 'numeric',
field_id: ( this.field_id ) ? this.field_id : this.filter.field,
values: [ this.value_init, this.value_end ]
});
} }
this.$emit('input', {
filter: 'range',
type: 'numeric',
compare: 'BETWEEN',
field_id: ( this.field_id ) ? this.field_id : this.filter.field,
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
value: values
});
}, },
// message for error // message for error
error_message(){ error_message(){

View File

@ -21,6 +21,7 @@ class Range extends Filter_Type {
public function render( $filter ){ public function render( $filter ){
return '<tainacan-filter-range return '<tainacan-filter-range
name="'.$filter->get_name().'" name="'.$filter->get_name().'"
collection_id="'.$filter->get_collection_id().'"
field_id="'.$filter->get_field()->get_id().'"></tainacan-filter-range>'; field_id="'.$filter->get_field()->get_id().'"></tainacan-filter-range>';
} }
} }

View File

@ -1,17 +1,27 @@
import Vue from 'vue'; import Vue from 'vue';
import store from './store/store'
export const eventFilterBus = new Vue({ export const eventFilterBus = new Vue({
store,
data: { data: {
componentsTag: [], componentsTag: [],
errors : [], errors : [],
query: {} query: {}
}, },
created(){ created(){
this.$on('input', data => this.search(data) ); this.$on('input', data => this.add_metaquery(data) );
}, },
methods: { methods: {
search( ){ add_metaquery( data ){
console.log( data ); if ( data.collection_id ){
this.$store.dispatch('filter/add_metaquery', data );
const promisse = this.$store.dispatch('filter/search_by_collection', data.collection_id );
promisse.then( response => {
}, error => {
});
}
}, },
/* Dev interfaces methods */ /* Dev interfaces methods */
@ -37,7 +47,7 @@ export const eventFilterBus = new Vue({
const components = this.getAllComponents(); const components = this.getAllComponents();
for (let eventElement of components){ for (let eventElement of components){
eventElement.addEventListener('input', (event) => { eventElement.addEventListener('input', (event) => {
console.log( event.detail, 'dev' ); this.add_metaquery( event.detail[0] );
}); });
} }
}, },

View File

@ -1,14 +1,32 @@
import axios from '../../../axios/axios'; import axios from '../../../axios/axios';
import qs from 'qs'; import qs from 'qs';
export const do_query = ({ commit, state }) => { export const search_by_collection = ({ commit, state, dispatch }, collectionId) => {
return new Promise((resolve, reject) =>{ commit('setPostQuery', 'meta_query', state.meta_query );
axios.get('/collections/' + state.collection + '/items?' + qs.stringify( state.query )) commit('setPostQuery', 'tax_query', state.tax_query );
.then(res => { return new Promise((resolve, reject) =>{
axios.get('/collection/' + collectionId + '/items?' + qs.stringify( state.query ))
}) .then(res => {
.catch(error => { resolve( res.data );
})
}) .catch(error => {
reject( error )
})
}); });
} };
export const set_postquery_attribute = ({ commit }, field, value ) => {
commit('setPostQuery', field, value );
};
export const add_metaquery = ( { commit }, filter ) => {
commit('addMetaQuery', filter );
};
export const remove_metaquery = ( { commit }, filter ) => {
commit('removeMetaQuery', filter );
};

View File

@ -1,7 +1,11 @@
export const getQuery = state => { export const getPostQuery = state => {
return state.query; return state.post_query;
} }
export const getCollection = state => { export const getMetaQuery = state => {
return state.collection; return state.meta_query;
} }
export const getTaxQuery = state => {
return state.tax_query;
}

View File

@ -3,8 +3,14 @@ import * as getters from './getters';
import * as mutations from './mutations'; import * as mutations from './mutations';
const state = { const state = {
query: {}, post_query: {
collection: null post_status: 'publish',
post_type: [],
meta_query: null,
tax_query: null
},
meta_query: [],
tax_query: []
}; };
export default { export default {

View File

@ -1,8 +1,31 @@
export const setQuery = ( state, query ) => { import Vue from 'vue';
state.query = query;
}
export const setCollection = ( state, collection ) => { export const setPostQuery = ( state, field, value ) => {
state.query = collection; Vue.set( state.post_query, field, value );
} };
export const addMetaQuery = ( state, filter ) => {
let index = state.meta_query.findIndex( item => item.key === filter.field_id);
if ( index >= 0){
Vue.set( state.meta_query, index, {
key: filter.field_id,
value: filter.value,
compare: filter.compare,
type: filter.type
} );
}else{
state.meta_query.push({
key: filter.field_id,
value: filter.value,
compare: filter.compare,
type: filter.type
});
}
};
export const removeMetaQuery = ( state, filter ) => {
let index = state.meta_query.findIndex( item => item.key === filter.field_id);
if (index >= 0) {
state.meta_query.splice(index, 1);
}
}

View File

@ -3,12 +3,14 @@ import Vuex from 'vuex';
import item from './modules/item/'; import item from './modules/item/';
import collection from './modules/collection/'; import collection from './modules/collection/';
import filter from './modules/filter/';
Vue.use(Vuex); Vue.use(Vuex);
export default new Vuex.Store({ export default new Vuex.Store({
modules: { modules: {
item, item,
collection collection,
filter
} }
}) })