Splits filter type mixin into two.
This commit is contained in:
parent
c15bae9156
commit
920777d651
|
@ -278,11 +278,11 @@
|
|||
<script>
|
||||
import qs from 'qs';
|
||||
import { tainacan as axios, isCancel } from '../../../js/axios/axios';
|
||||
import { filterTypeMixin } from '../../../classes/filter-types/filter-types-mixin';
|
||||
import { dynamicFilterTypeMixin } from '../../../classes/filter-types/filter-types-mixin';
|
||||
|
||||
export default {
|
||||
name: 'CheckboxFilterModal',
|
||||
mixins: [ filterTypeMixin ],
|
||||
mixins: [ dynamicFilterTypeMixin ],
|
||||
props: {
|
||||
isFilter: {
|
||||
type: Boolean,
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
|
||||
<script>
|
||||
import { tainacan as axios, isCancel } from '../../../js/axios/axios'
|
||||
import { filterTypeMixin } from '../filter-types-mixin';
|
||||
import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin';
|
||||
// import qs from 'qs';
|
||||
|
||||
export default {
|
||||
|
@ -77,7 +77,7 @@
|
|||
label: ''
|
||||
}
|
||||
},
|
||||
mixins: [filterTypeMixin],
|
||||
mixins: [filterTypeMixin, dynamicFilterTypeMixin],
|
||||
methods: {
|
||||
setResults(option){
|
||||
if(!option)
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
|
||||
<script>
|
||||
import { tainacan as axios, isCancel } from '../../../js/axios/axios';
|
||||
import { filterTypeMixin } from '../filter-types-mixin';
|
||||
import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin';
|
||||
import CheckboxRadioModal from '../../../admin/components/other/checkbox-radio-modal.vue';
|
||||
|
||||
export default {
|
||||
|
@ -79,7 +79,7 @@
|
|||
metadatum_object: {}
|
||||
}
|
||||
},
|
||||
mixins: [filterTypeMixin],
|
||||
mixins: [filterTypeMixin, dynamicFilterTypeMixin],
|
||||
watch: {
|
||||
selected: function(){
|
||||
//this.selected = val;
|
||||
|
@ -115,7 +115,8 @@
|
|||
.catch( (error) => {
|
||||
if (isCancel(error)) {
|
||||
this.$console.log('Request canceled: ' + error.message);
|
||||
}else
|
||||
this.selectedValues();
|
||||
} else
|
||||
this.$console.error( error );
|
||||
});
|
||||
}
|
||||
|
@ -132,11 +133,10 @@
|
|||
});
|
||||
|
||||
let onlyLabels = [];
|
||||
|
||||
if(!isNaN(this.selected[0])){
|
||||
for (let aSelected of this.selected) {
|
||||
let valueIndex = this.options.findIndex(option => option.value == aSelected);
|
||||
|
||||
|
||||
if (valueIndex >= 0) {
|
||||
onlyLabels.push(this.options[valueIndex].label);
|
||||
}
|
||||
|
@ -153,7 +153,6 @@
|
|||
if ( index >= 0){
|
||||
let query = this.query.metaquery.slice();
|
||||
this.selected = query[ index ].value;
|
||||
|
||||
} else {
|
||||
this.selected = [];
|
||||
return false;
|
||||
|
@ -187,30 +186,18 @@
|
|||
cleanSearchFromTags(filterTag) {
|
||||
|
||||
if (filterTag.filterId == this.filter.id) {
|
||||
|
||||
let selectedIndex = this.selected.findIndex(option => option == filterTag.singleValue);
|
||||
let optionIndex = this.options.findIndex(option => option.label == filterTag.singleValue);
|
||||
|
||||
let alternativeIndex;
|
||||
|
||||
if (optionIndex >= 0) {
|
||||
if (optionIndex >= 0)
|
||||
alternativeIndex = this.selected.findIndex(option => this.options[optionIndex].value == option);
|
||||
}
|
||||
|
||||
if (selectedIndex >= 0 || alternativeIndex >= 0) {
|
||||
|
||||
selectedIndex >= 0 ? this.selected.splice(selectedIndex, 1) : this.selected.splice(alternativeIndex, 1);
|
||||
|
||||
this.$emit('input', {
|
||||
filter: 'checkbox',
|
||||
compare: 'IN',
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
value: this.selected
|
||||
});
|
||||
|
||||
this.$emit( 'sendValuesToTags', this.selected);
|
||||
|
||||
this.selectedValues();
|
||||
this.onSelect();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -147,7 +147,6 @@
|
|||
data(){
|
||||
return {
|
||||
value: null,
|
||||
clear: false,
|
||||
filterTypeOptions: [],
|
||||
metadatum_object: {},
|
||||
comparator: '=', // =, !=, >, >=, <, <=
|
||||
|
@ -204,8 +203,6 @@
|
|||
},
|
||||
clearSearch(){
|
||||
|
||||
this.clear = true;
|
||||
|
||||
this.$emit('input', {
|
||||
filter: 'date',
|
||||
type: 'DATE',
|
||||
|
|
|
@ -5,18 +5,14 @@ import { mapGetters } from 'vuex';
|
|||
export const filterTypeMixin = {
|
||||
data () {
|
||||
return {
|
||||
thumbPlaceholderPath: tainacan_plugin.base_url + '/admin/images/placeholder_square.png',
|
||||
getOptionsValuesCancel: undefined,
|
||||
isUsingElasticSearch: tainacan_plugin.wp_elasticpress == "1" ? true : false,
|
||||
isLoadingOptions: false,
|
||||
collectionId: '',
|
||||
metadatumId: ''
|
||||
metadatumId: '',
|
||||
isRepositoryLevel: Boolean
|
||||
}
|
||||
},
|
||||
props: {
|
||||
filter: Object,
|
||||
query: Object,
|
||||
isRepositoryLevel: Boolean
|
||||
query: Object
|
||||
},
|
||||
created() {
|
||||
this.collectionId = this.filter.collection_id ? this.filter.collection_id : this.collectionId;
|
||||
|
@ -24,11 +20,30 @@ export const filterTypeMixin = {
|
|||
},
|
||||
mounted() {
|
||||
this.$eventBusSearch.$on('removeFromFilterTag', this.cleanSearchFromTags);
|
||||
},
|
||||
computed: {
|
||||
facetsFromItemSearch() {
|
||||
return this.getFacets();
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.$eventBusSearch.$off('removeFromFilterTag', this.cleanSearchFromTags);
|
||||
},
|
||||
};
|
||||
|
||||
export const dynamicFilterTypeMixin = {
|
||||
data () {
|
||||
return {
|
||||
thumbPlaceholderPath: tainacan_plugin.base_url + '/admin/images/placeholder_square.png',
|
||||
getOptionsValuesCancel: undefined,
|
||||
isUsingElasticSearch: tainacan_plugin.wp_elasticpress == "1" ? true : false,
|
||||
isLoadingOptions: false
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
// We listen to event, but reload event if hasFiltered is negative, as
|
||||
// an empty query also demands filters reloading.
|
||||
if (this.options != undefined)
|
||||
this.$eventBusSearch.$on('hasFiltered', this.reloadOptionsDueToFiltering);
|
||||
this.$eventBusSearch.$on('hasFiltered', this.reloadOptionsDueToFiltering);
|
||||
},
|
||||
computed: {
|
||||
facetsFromItemSearch() {
|
||||
|
@ -305,7 +320,7 @@ export const filterTypeMixin = {
|
|||
this.noMorePage = 1;
|
||||
|
||||
|
||||
if(this.options.length < this.maxNumOptionsCheckboxList)
|
||||
if (this.options.length < this.maxNumOptionsCheckboxList)
|
||||
this.noMorePage = 1;
|
||||
|
||||
if (this.filter.max_options && this.options.length >= this.filter.max_options) {
|
||||
|
@ -327,8 +342,7 @@ export const filterTypeMixin = {
|
|||
// Cancels previous Request
|
||||
if (this.getOptionsValuesCancel != undefined)
|
||||
this.getOptionsValuesCancel.cancel('Facet search Canceled.');
|
||||
|
||||
this.$eventBusSearch.$off('removeFromFilterTag', this.cleanSearchFromTags);
|
||||
|
||||
this.$eventBusSearch.$off('hasFiltered', this.reloadOptionsDueToFiltering);
|
||||
},
|
||||
};
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
<script>
|
||||
import { tainacan as axios, isCancel } from '../../../js/axios/axios';
|
||||
import { filterTypeMixin } from '../filter-types-mixin';
|
||||
import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin';
|
||||
|
||||
export default {
|
||||
created(){
|
||||
|
@ -65,7 +65,7 @@
|
|||
type: ''
|
||||
}
|
||||
},
|
||||
mixins: [filterTypeMixin],
|
||||
mixins: [filterTypeMixin, dynamicFilterTypeMixin],
|
||||
watch: {
|
||||
selected(value) {
|
||||
if (value)
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
|
||||
<script>
|
||||
import { tainacan as axios, isCancel } from '../../../js/axios/axios';
|
||||
import { filterTypeMixin } from '../filter-types-mixin';
|
||||
import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin';
|
||||
import qs from 'qs';
|
||||
|
||||
export default {
|
||||
|
@ -79,7 +79,7 @@
|
|||
metadatum_object: {}
|
||||
}
|
||||
},
|
||||
mixins: [filterTypeMixin],
|
||||
mixins: [filterTypeMixin, dynamicFilterTypeMixin],
|
||||
watch: {
|
||||
selected( value ){
|
||||
this.selected = value;
|
||||
|
|
|
@ -31,8 +31,7 @@
|
|||
</span>
|
||||
<span class="collapse-label">{{ filter.name }}</span>
|
||||
</button>
|
||||
<div
|
||||
:id="'filter-input-id-' + filter.id">
|
||||
<div :id="'filter-input-id-' + filter.id">
|
||||
<component
|
||||
:is="filter.filter_type_object.component"
|
||||
:filter="filter"
|
||||
|
@ -54,16 +53,9 @@
|
|||
isRepositoryLevel: Boolean,
|
||||
open: true,
|
||||
},
|
||||
data(){
|
||||
return {
|
||||
inputs: [],
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onInput(inputEvent){
|
||||
this.$eventBusSearch.$emit(
|
||||
'input', ( inputEvent.metadatum_id ) ? inputEvent : inputEvent.detail[0]
|
||||
);
|
||||
this.$eventBusSearch.$emit('input', inputEvent);
|
||||
},
|
||||
onSendValuesToTags(values) {
|
||||
this.$eventBusSearch.$emit('sendValuesToTags', {
|
||||
|
|
|
@ -50,10 +50,10 @@
|
|||
import { tainacan as axios, CancelToken, isCancel } from '../../../js/axios/axios';
|
||||
import { mapGetters } from 'vuex';
|
||||
import CheckboxRadioModal from '../../../admin/components/other/checkbox-radio-modal.vue';
|
||||
import { filterTypeMixin } from '../filter-types-mixin';
|
||||
import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin';
|
||||
|
||||
export default {
|
||||
mixins: [ filterTypeMixin ],
|
||||
mixins: [ filterTypeMixin, dynamicFilterTypeMixin ],
|
||||
created(){
|
||||
this.type = this.filter.metadatum.metadata_type;
|
||||
|
||||
|
@ -284,18 +284,7 @@
|
|||
|
||||
this.selected.splice(selectedIndex, 1);
|
||||
|
||||
this.$emit('input', {
|
||||
filter: 'checkbox',
|
||||
compare: 'IN',
|
||||
taxonomy: this.taxonomy,
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
terms: this.selected
|
||||
});
|
||||
|
||||
this.$emit( 'sendValuesToTags', this.selected);
|
||||
|
||||
this.selectedValues();
|
||||
this.onSelect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,10 +38,10 @@
|
|||
<script>
|
||||
import qs from 'qs';
|
||||
import { tainacan as axios } from '../../../js/axios/axios';
|
||||
import { filterTypeMixin } from '../filter-types-mixin';
|
||||
import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin';
|
||||
|
||||
export default {
|
||||
mixins: [ filterTypeMixin ],
|
||||
mixins: [ filterTypeMixin, dynamicFilterTypeMixin ],
|
||||
created(){
|
||||
this.type = this.filter.metadatum.metadata_type;
|
||||
|
||||
|
|
|
@ -87,8 +87,6 @@ export const removeFetchOnlyMeta = ( state, metadatum ) => {
|
|||
fetch_meta.splice(index, 1);
|
||||
|
||||
state.postquery.fetch_only_meta = fetch_meta.toString();
|
||||
|
||||
console.info(state.postquery.fetch_only_meta);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -149,24 +147,20 @@ export const setOrderByName = ( state, orderByName ) => {
|
|||
|
||||
export const addFilterTag = ( state, filterTag ) => {
|
||||
state.filter_tags = ( ! state.filter_tags) ? [] : state.filter_tags;
|
||||
|
||||
let index = state.filter_tags.findIndex( tag => tag.filterId == filterTag.filterId);
|
||||
|
||||
if ( index >= 0 ) {
|
||||
if (index >= 0)
|
||||
Vue.set(state.filter_tags, index, filterTag);
|
||||
} else {
|
||||
else
|
||||
state.filter_tags.push(filterTag);
|
||||
}
|
||||
};
|
||||
|
||||
export const removeFilterTag = ( state, filterTag ) => {
|
||||
state.filter_tags = ( ! state.filter_tags ) ? [] : state.filter_tags;
|
||||
|
||||
let index = state.filter_tags.findIndex( tag => tag.filterId == filterTag.filterId);
|
||||
|
||||
if (index >= 0) {
|
||||
if (index >= 0)
|
||||
state.filter_tags.splice(index, 1);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export const cleanFilterTags = ( state ) => {
|
||||
|
|
Loading…
Reference in New Issue