From db2d785dbc417ac352fc200508d93913afe322b2 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Mon, 12 Mar 2018 15:45:59 -0300 Subject: [PATCH] Disables hover on opened form in drandrop fields and filters. Creates actions for filter CRUD in axios (needs api update). Initiates FiltersList comonent. --- src/admin/components/lists/fields-list.vue | 8 +- src/admin/components/lists/filters-list.vue | 303 +++++++++++++++++++- src/admin/tainacan-admin-i18n.php | 5 +- src/js/store/modules/fields/actions.js | 2 +- src/js/store/modules/filter/actions.js | 141 ++++++++- src/js/store/modules/filter/getters.js | 9 + src/js/store/modules/filter/index.js | 4 +- src/js/store/modules/filter/mutations.js | 29 +- 8 files changed, 486 insertions(+), 15 deletions(-) diff --git a/src/admin/components/lists/fields-list.vue b/src/admin/components/lists/fields-list.vue index 0c8262eca..08d273758 100644 --- a/src/admin/components/lists/fields-list.vue +++ b/src/admin/components/lists/fields-list.vue @@ -12,7 +12,7 @@ :options="{group: { name:'fields', pull: false, put: true }, 'handle': '.handle', chosenClass: 'sortable-chosen', filter: '.not-sortable-item'}">
@@ -43,7 +43,7 @@
- +
@@ -260,7 +260,9 @@ export default { height: 1em; width: 1em; } - &.not-sortable-item { + &.not-sortable-item, &.not-sortable-item:hover { + box-shadow: none !important; + top: 0px !important; color: gray; cursor: default; } diff --git a/src/admin/components/lists/filters-list.vue b/src/admin/components/lists/filters-list.vue index 471fc72dc..497696df8 100644 --- a/src/admin/components/lists/filters-list.vue +++ b/src/admin/components/lists/filters-list.vue @@ -1,21 +1,314 @@ - - diff --git a/src/admin/tainacan-admin-i18n.php b/src/admin/tainacan-admin-i18n.php index 59a80b6c3..56c23dbcf 100644 --- a/src/admin/tainacan-admin-i18n.php +++ b/src/admin/tainacan-admin-i18n.php @@ -76,7 +76,10 @@ return [ 'label_items_per_page' => __('Items per Page:', 'tainacan'), 'label_active_fields' => __('Active Fields', 'tainacan'), 'label_available_fields' => __('Available Fields', 'tainacan'), - 'label_available_fields_types' => __('Available Fields Types', 'tainacan'), + 'label_available_fields_types' => __('Available Field Types', 'tainacan'), + 'label_active_filters' => __('Active Filters', 'tainacan'), + 'label_available_filters' => __('Available Filters', 'tainacan'), + 'label_available_filter_types' => __('Available Filter Types', 'tainacan'), 'label_per_page' => __('per Page', 'tainacan'), 'label_table_fields' => __('Fields on table', 'tainacan'), 'label_required' => __('Required', 'tainacan'), diff --git a/src/js/store/modules/fields/actions.js b/src/js/store/modules/fields/actions.js index d9f796b5b..f6a42fc85 100644 --- a/src/js/store/modules/fields/actions.js +++ b/src/js/store/modules/fields/actions.js @@ -59,7 +59,7 @@ export const sendField = ( { commit }, { collectionId, name, fieldType, status, status: status }) .then( res => { - commit('setField', { collection_id: collectionId, name: name, field_type: fieldType, status: status }); + commit('setSingleField', { collection_id: collectionId, name: name, field_type: fieldType, status: status }); resolve( res.data ); }) .catch(error => { diff --git a/src/js/store/modules/filter/actions.js b/src/js/store/modules/filter/actions.js index b77c19476..39438ea38 100644 --- a/src/js/store/modules/filter/actions.js +++ b/src/js/store/modules/filter/actions.js @@ -1,6 +1,7 @@ import axios from '../../../axios/axios'; 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 )) @@ -14,9 +15,8 @@ export const search_by_collection = ({ state, dispatch, rootGetters }, collecti }); }; - -export const set_postquery_attribute = ({ commit }, field, value ) => { - commit('setPostQuery', { attr: field, value: value } ); +export const set_postquery_attribute = ({ commit }, filter, value ) => { + commit('setPostQuery', { attr: filter, value: value } ); }; export const add_metaquery = ( { commit }, filter ) => { @@ -27,5 +27,140 @@ export const remove_metaquery = ( { commit }, filter ) => { commit('removeMetaQuery', filter ); }; +// FILTERS -------------------------------------------------------- +export const fetchFilters = ({ commit }, {collectionId, isRepositoryLevel}) => { + return new Promise((resolve, reject) => { + let endpoint = ''; + if (!isRepositoryLevel) + endpoint = '/collection/' + collectionId + '/filters/'; + else + endpoint = '/filters/'; + + axios.tainacan.get(endpoint + '?context=edit') + .then((res) => { + let filters= res.data; + commit('setFilters', filters); + resolve (filters); + }) + .catch((error) => { + console.log(error); + reject(error); + }); + }); +} +export const fetchFilter = ({ commit }, {collectionId, filterId, isRepositoryLevel}) => { + return new Promise((resolve, reject) => { + + let endpoint = ''; + if (!isRepositoryLevel) + endpoint = '/collection/' + collectionId + '/filters/' + filterId; + else + endpoint = '/filters/' + filterId; + + axios.tainacan.get(endpoint + '?context=edit') + .then((res) => { + let filter = res.data; + commit('setSingleFilter', filter); + resolve (filter); + }) + .catch((error) => { + console.log(error); + reject(error); + }); + }); +} + +export const sendFilter = ( { commit }, { collectionId, fieldId, name, filterType, status, isRepositoryLevel }) => { + return new Promise(( resolve, reject ) => { + let endpoint = ''; + if (!isRepositoryLevel) + endpoint = '/collection/' + collectionId + '/field/' + fieldId +'/filters/'; + else + endpoint = '/filters/'; + axios.tainacan.post(endpoint + '?context=edit', { + name: name, + filter_type: filterType, + status: status + }) + .then( res => { + commit('setSingleFilter', { collection_id: collectionId, name: name, filter_type: filterType, status: status }); + resolve( res.data ); + }) + .catch(error => { + reject( error.response ); + }); + }); +}; + +export const updateFilter = ( { commit }, { collectionId, fieldId, filterId, isRepositoryLevel, options }) => { + return new Promise(( resolve, reject ) => { + let endpoint = ''; + + if (!isRepositoryLevel) + endpoint = '/collection/' + collectionId + '/field/' + fieldId +'/filters/'; + else + endpoint = '/filters/' + filterId; + + axios.tainacan.put(endpoint, options) + .then( res => { + commit('setSingleFilter', res.data); + resolve( res.data ); + }) + .catch(error => { + console.log(error); + reject({ error_message: error['response']['data'].error_message, errors: error['response']['data'].errors }); + }); + }); +}; + + +export const deleteFilter = ({ commit }, { collectionId, fieldId, filterId, isRepositoryLevel }) => { + let endpoint = ''; + if (!isRepositoryLevel) + endpoint = '/collection/' + collectionId + '/field/' + fieldId +'/filters/'; + else + endpoint = '/filters/' + filterId; + + return new Promise((resolve, reject) => { + axios.tainacan.delete(endpoint) + .then( res => { + commit('deleteFilter', { filterId } ); + resolve( res.data ); + }).catch((error) => { + console.log(error); + reject( error ); + }); + + }); +}; + +export const updateCollectionFiltersOrder = ({ commit }, { collectionId, filtersOrder }) => { + return new Promise((resolve, reject) => { + axios.tainacan.patch('/collections/' + collectionId, { + filters_order: filtersOrder + }).then( res => { + commit('setCollection', res.data); + resolve( res.data ); + }).catch( error => { + reject( error.response ); + }); + + }); +} + +export const fetchFilterTypes = ({ commit} ) => { + return new Promise((resolve, reject) => { + axios.tainacan.get('/filter-types') + .then((res) => { + let filterTypes = res.data; + commit('setFilterTypes', filterTypes); + resolve (filterTypes); + }) + .catch((error) => { + console.log(error); + reject(error); + }); + }); +} diff --git a/src/js/store/modules/filter/getters.js b/src/js/store/modules/filter/getters.js index 7b02215b3..bef8849a0 100644 --- a/src/js/store/modules/filter/getters.js +++ b/src/js/store/modules/filter/getters.js @@ -8,4 +8,13 @@ export const getMetaQuery = state => { export const getTaxQuery = state => { return state.taxquery; +} + +export const getFilters = state => { + + return state.filters; +} + +export const getFilterTypes = state => { + return state.flterTypes; } \ No newline at end of file diff --git a/src/js/store/modules/filter/index.js b/src/js/store/modules/filter/index.js index cd31313b2..9863a909b 100644 --- a/src/js/store/modules/filter/index.js +++ b/src/js/store/modules/filter/index.js @@ -8,7 +8,9 @@ const state = { post_type: [], metaquery: [], taxquery: [] - } + }, + filters: [], + filterTypes: [] }; export default { diff --git a/src/js/store/modules/filter/mutations.js b/src/js/store/modules/filter/mutations.js index 5cbb6a4cb..62a6d22a4 100644 --- a/src/js/store/modules/filter/mutations.js +++ b/src/js/store/modules/filter/mutations.js @@ -1,9 +1,10 @@ import Vue from 'vue'; +// METAQUERIES ---------------------------------------------------------------------------- export const setPostQuery = ( state, { attr, value }) => { Vue.set( state.postquery, attr , value ); }; - + export const addMetaQuery = ( state, filter ) => { let index = state.postquery.metaquery.findIndex( item => item.key === filter.field_id); if ( index >= 0){ @@ -29,3 +30,29 @@ export const removeMetaQuery = ( state, filter ) => { state.metaquery.splice(index, 1); } } + +// FILTERS ------------------------------------------------------------------------ +export const deleteFilter = ( state, filter ) => { + let index = state.filters.findIndex(deletedFilter => deletedFilter.id === filter.id); + if (index >= 0) { + state.filters.splice(index, 1); + } +} + +export const setSingleFilter = (state, filter) => { + let index = state.filters.findIndex(newFilter => newFilter.id === filter.id); + + if ( index >= 0){ + Vue.set( state.filters, index, filter ); + } else { + state.filters.push( filter ); + } +} + +export const setFilters = (state, filters) => { + state.filters = filters; +} + +export const setFilterTypes = (state, filterTypes) => { + state.filterTypes = filterTypes; +} \ No newline at end of file