Merge branch 'develop' of https://github.com/tainacan/tainacan into develop
This commit is contained in:
commit
cfde8abf06
1
build.sh
1
build.sh
|
@ -72,6 +72,7 @@ rsync -axz --exclude='vendor/bin/phpc*' --exclude='vendor/squizlabs' --exclude='
|
|||
--exclude='vendor/respect/validation/docs' --exclude='vendor/respect/validation/tests' \
|
||||
--exclude='pdf-viewer/pdfjs-dist/web/compressed.tracemonkey-pldi-09.pdf' \
|
||||
--exclude='vendor/tecnickcom/tcpdf/fonts' \
|
||||
--exclude='vendor/smalot/pdfparser/src/Smalot/PdfParser/Tests/' \
|
||||
src/* $wp_plugin_dir/
|
||||
|
||||
rm -rf $wp_plugin_dir/scss
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
:key="index"
|
||||
attached
|
||||
closable
|
||||
@close="removeMetaQuery(filterTag.filterId, filterTag.value, filterTag.singleValue)">
|
||||
{{ filterTag.singleValue != undefined ? filterTag.singleValue : filterTag.value }}
|
||||
@close="removeMetaQuery(filterTag)">
|
||||
{{ filterTag.singleLabel != undefined ? filterTag.singleLabel : filterTag.label }}
|
||||
</b-tag>
|
||||
<button
|
||||
@click="clearAllFilters()"
|
||||
|
@ -19,7 +19,7 @@
|
|||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { mapGetters, mapActions } from 'vuex';
|
||||
import { mapGetters } from 'vuex';
|
||||
|
||||
export default {
|
||||
name: 'FiltersTagsList',
|
||||
|
@ -31,9 +31,9 @@
|
|||
let tags = this.getFilterTags();
|
||||
let flattenTags = [];
|
||||
for (let tag of tags) {
|
||||
if (Array.isArray(tag.value)) {
|
||||
for (let valueTag of tag.value)
|
||||
flattenTags.push({filterId: tag.filterId, value: tag, singleValue: valueTag});
|
||||
if (Array.isArray(tag.label)) {
|
||||
for (let i = 0; i < tag.label.length; i++)
|
||||
flattenTags.push({filterId: tag.filterId, label: tag.label, singleLabel: tag.label[i], value: tag.value[i], taxonomy: tag.taxonomy, metadatumId: tag.metadatumId});
|
||||
} else {
|
||||
flattenTags.push(tag);
|
||||
}
|
||||
|
@ -43,22 +43,22 @@
|
|||
},
|
||||
methods: {
|
||||
...mapGetters('search',[
|
||||
'getPostQuery',
|
||||
'getFilterTags'
|
||||
]),
|
||||
...mapActions('metadata',[
|
||||
'fetchMetadatum'
|
||||
]),
|
||||
removeMetaQuery(filterId, value, singleValue) {
|
||||
if (singleValue != undefined)
|
||||
this.$eventBusSearch.removeMetaFromFilterTag({ filterId: filterId, singleValue: singleValue });
|
||||
else
|
||||
this.$eventBusSearch.removeMetaFromFilterTag({ filterId: filterId, value: value });
|
||||
removeMetaQuery({ filterId, value, singleLabel, label, taxonomy, metadatumId }) {
|
||||
this.$eventBusSearch.removeMetaFromFilterTag({
|
||||
filterId: filterId,
|
||||
singleLabel: singleLabel,
|
||||
label: label,
|
||||
value: value,
|
||||
taxonomy: taxonomy,
|
||||
metadatumId: metadatumId
|
||||
});
|
||||
},
|
||||
clearAllFilters() {
|
||||
// this.$eventBusSearch.clearAllFilters();
|
||||
for (let tag of this.filterTags) {
|
||||
this.removeMetaQuery(tag.filterId, tag.value, tag.singleValue);
|
||||
this.removeMetaQuery(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -610,11 +610,11 @@ return apply_filters( 'tainacan-admin-i18n', [
|
|||
'info_updated_at' => __( 'Updated at', 'tainacan' ),
|
||||
'info_editing_metadata_values' => __( 'Editing metadata values...', 'tainacan' ),
|
||||
'info_updating_metadata_values' => __( 'Updating metadata values...', 'tainacan' ),
|
||||
'info_type_to_add_items' => __( 'Add items...', 'tainacan' ),
|
||||
'info_type_to_add_items' => __( 'Add items to filter...', 'tainacan' ),
|
||||
'info_type_to_search_items' => __( 'Search items...', 'tainacan' ),
|
||||
'info_type_to_add_terms' => __( 'Add terms...', 'tainacan' ),
|
||||
'info_type_to_add_terms' => __( 'Add terms to filter...', 'tainacan' ),
|
||||
'info_type_to_search_metadata' => __( 'Search metadata...', 'tainacan' ),
|
||||
'info_type_to_add_metadata' => __( 'Add metadata...', 'tainacan' ),
|
||||
'info_type_to_add_metadata' => __( 'Add metadata to filter...', 'tainacan' ),
|
||||
'info_visibility_helper' => __( 'How the item will be available to visualization.', 'tainacan' ),
|
||||
'info_errors_in_form' => __( 'There are errors in the form', 'tainacan' ),
|
||||
'info_no_document_to_item' => __( 'No document was uploaded to this item.', 'tainacan' ),
|
||||
|
|
|
@ -93,10 +93,10 @@ class Item extends Entity {
|
|||
}
|
||||
|
||||
$attachments_query = [
|
||||
'post_type' => 'attachment',
|
||||
'post_per_page' => -1,
|
||||
'post_parent' => $item_id,
|
||||
'exclude' => $to_exclude,
|
||||
'post_type' => 'attachment',
|
||||
'posts_per_page' => -1,
|
||||
'post_parent' => $item_id,
|
||||
'exclude' => $to_exclude,
|
||||
];
|
||||
|
||||
$attachments = get_posts( $attachments_query );
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
:loading="isLoadingOptions"
|
||||
@input="search"
|
||||
field="label"
|
||||
@select="option => setResults(option) "
|
||||
@select="onSelect"
|
||||
:placeholder="(metadatumType === 'Tainacan\\Metadata_Types\\Relationship') ? $i18n.get('info_type_to_search_items') : $i18n.get('info_type_to_search_metadata')">
|
||||
<template slot-scope="props">
|
||||
<div class="media">
|
||||
|
@ -42,43 +42,45 @@
|
|||
<script>
|
||||
import { tainacan as axios, isCancel } from '../../../js/axios/axios'
|
||||
import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin';
|
||||
// import qs from 'qs';
|
||||
|
||||
export default {
|
||||
mixins: [filterTypeMixin, dynamicFilterTypeMixin],
|
||||
data(){
|
||||
return {
|
||||
results:'',
|
||||
selected:'',
|
||||
options: [],
|
||||
label: ''
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'query.metaquery'() {
|
||||
this.selectedValues();
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.selectedValues();
|
||||
},
|
||||
methods: {
|
||||
setResults(option){
|
||||
onSelect(option){
|
||||
|
||||
if(!option)
|
||||
return;
|
||||
this.results = option.value;
|
||||
this.selected = option.value;
|
||||
this.label = option.label;
|
||||
this.onSelect()
|
||||
},
|
||||
onSelect(){
|
||||
|
||||
this.$emit('input', {
|
||||
filter: 'autocomplete',
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
value: this.results
|
||||
value: this.selected
|
||||
});
|
||||
this.selectedValues();
|
||||
},
|
||||
search: _.debounce( function(query) {
|
||||
|
||||
if (query != '') {
|
||||
let promise = null;
|
||||
this.options = [];
|
||||
|
||||
// Cancels previous Request
|
||||
if (this.getOptionsValuesCancel != undefined)
|
||||
this.getOptionsValuesCancel.cancel('Facet search Canceled.');
|
||||
|
@ -99,7 +101,14 @@
|
|||
this.getOptionsValuesCancel = promise.source;
|
||||
|
||||
} else {
|
||||
this.cleanSearch();
|
||||
this.label = '';
|
||||
this.selected = '';
|
||||
this.$emit('input', {
|
||||
filter: 'autocomplete',
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
value: this.selected
|
||||
});
|
||||
}
|
||||
}, 500),
|
||||
selectedValues(){
|
||||
|
@ -113,45 +122,27 @@
|
|||
|
||||
if (this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship') {
|
||||
|
||||
axios.get('/items/' + metadata.value)
|
||||
axios.get('/items/' + metadata.value + '?fetch_only=title,thumbnail')
|
||||
.then( res => {
|
||||
|
||||
let item = res.data;
|
||||
this.results = item.title;
|
||||
this.label = item.title;
|
||||
this.selected = item.title;
|
||||
|
||||
this.$emit( 'sendValuesToTags', this.label);
|
||||
this.$emit( 'sendValuesToTags', { label: this.label, value: this.selected });
|
||||
})
|
||||
.catch(error => {
|
||||
this.$console.log(error);
|
||||
});
|
||||
} else {
|
||||
this.results = metadata.value;
|
||||
this.label = metadata.value;
|
||||
this.selected = metadata.value;
|
||||
|
||||
this.$emit( 'sendValuesToTags', metadata.value);
|
||||
this.$emit( 'sendValuesToTags', { label: this.label, value: this.selected });
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
cleanSearchFromTags(filterTag) {
|
||||
if (filterTag.filterId == this.filter.id)
|
||||
this.cleanSearch();
|
||||
},
|
||||
cleanSearch(){
|
||||
this.results = '';
|
||||
this.label = '';
|
||||
this.selected = '';
|
||||
this.$emit('input', {
|
||||
filter: 'autocomplete',
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
value: ''
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -52,8 +52,17 @@
|
|||
}
|
||||
},
|
||||
watch: {
|
||||
selected: function(){
|
||||
this.onSelect();
|
||||
selected(newVal, oldVal) {
|
||||
const isEqual = (newVal.length == oldVal.length) && newVal.every((element, index) => {
|
||||
return element === oldVal[index];
|
||||
});
|
||||
|
||||
if (!isEqual)
|
||||
this.onSelect();
|
||||
},
|
||||
'query.metaquery'() {
|
||||
if (!this.isUsingElasticSearch)
|
||||
this.loadOptions();
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
|
@ -72,7 +81,7 @@
|
|||
promise = this.getValuesRelationship( null, this.isRepositoryLevel, [], 0, this.filter.max_options, false, '1');
|
||||
else
|
||||
promise = this.getValuesPlainText( this.metadatumId, null, this.isRepositoryLevel, [], 0, this.filter.max_options, false, '1' );
|
||||
|
||||
|
||||
if (skipSelected != undefined && skipSelected == true) {
|
||||
promise.request
|
||||
.then(() => {
|
||||
|
@ -105,9 +114,22 @@
|
|||
collection_id: this.collectionId,
|
||||
value: this.selected
|
||||
});
|
||||
},
|
||||
selectedValues() {
|
||||
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
|
||||
return false;
|
||||
|
||||
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key == this.metadatumId );
|
||||
|
||||
if ( index >= 0){
|
||||
let query = this.query.metaquery.slice();
|
||||
this.selected = query[ index ].value;
|
||||
} else {
|
||||
this.selected = [];
|
||||
}
|
||||
|
||||
let onlyLabels = [];
|
||||
if(!isNaN(this.selected[0])){
|
||||
if (!isNaN(this.selected[0])){
|
||||
for (let aSelected of this.selected) {
|
||||
let valueIndex = this.options.findIndex(option => option.value == aSelected);
|
||||
|
||||
|
@ -117,20 +139,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
this.$emit( 'sendValuesToTags', onlyLabels.length ? onlyLabels : this.selected);
|
||||
},
|
||||
selectedValues() {
|
||||
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
|
||||
return false;
|
||||
|
||||
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key == this.metadatumId );
|
||||
if ( index >= 0){
|
||||
let query = this.query.metaquery.slice();
|
||||
this.selected = query[ index ].value;
|
||||
} else {
|
||||
this.selected = [];
|
||||
return false;
|
||||
}
|
||||
this.$emit( 'sendValuesToTags', { label: onlyLabels.length ? onlyLabels : this.selected, value: this.selected });
|
||||
},
|
||||
openCheckboxModal() {
|
||||
this.$buefy.modal.open({
|
||||
|
@ -156,26 +165,8 @@
|
|||
trapFocus: true
|
||||
});
|
||||
},
|
||||
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)
|
||||
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.onSelect();
|
||||
}
|
||||
}
|
||||
},
|
||||
updatesIsLoading(isLoading) {
|
||||
this.isLoadingOptions = isLoading;
|
||||
updatesIsLoading(isLoadingOptions) {
|
||||
this.isLoadingOptions = isLoadingOptions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<div>
|
||||
<!-- Date -->
|
||||
<div v-if="type === 'Tainacan\\Metadata_Types\\Date'">
|
||||
<div v-if="metadatumType === 'Tainacan\\Metadata_Types\\Date'">
|
||||
<b-datepicker
|
||||
:aria-labelledby="'filter-label-id-' + filter.id"
|
||||
:placeholder="$i18n.get('label_selectbox_init')"
|
||||
|
@ -47,18 +47,20 @@
|
|||
|
||||
<!-- Numeric -->
|
||||
<div v-else>
|
||||
<b-numberinput
|
||||
<b-input
|
||||
type="number"
|
||||
:aria-labelledby="'filter-label-id-' + filter.id"
|
||||
size="is-small"
|
||||
step="any"
|
||||
@input="validate_values()"
|
||||
@input="validate_values"
|
||||
v-model="value_init"/>
|
||||
<p class="is-size-7 has-text-centered is-marginless">{{ $i18n.get('label_until') }}</p>
|
||||
<b-numberinput
|
||||
<b-input
|
||||
type="number"
|
||||
:aria-labelledby="'filter-label-id-' + filter.id"
|
||||
size="is-small"
|
||||
step="any"
|
||||
@input="validate_values()"
|
||||
@input="validate_values"
|
||||
@focus="isTouched = true"
|
||||
v-model="value_end"/>
|
||||
</div>
|
||||
|
@ -66,7 +68,6 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { tainacan as axios } from '../../../js/axios/axios';
|
||||
import { wpAjax, dateInter } from "../../../admin/js/mixins";
|
||||
import { filterTypeMixin } from '../filter-types-mixin';
|
||||
import moment from 'moment';
|
||||
|
@ -82,14 +83,14 @@
|
|||
},
|
||||
data(){
|
||||
return {
|
||||
value_init: null,
|
||||
value_end: null,
|
||||
value_init: '',
|
||||
value_end: '',
|
||||
date_init: undefined,
|
||||
date_end: undefined,
|
||||
isTouched: false,
|
||||
isValid: false,
|
||||
clear: false,
|
||||
type: 'numeric'
|
||||
type: 'DECIMAL'
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
@ -99,39 +100,46 @@
|
|||
|
||||
if ( val && this.date_end === null)
|
||||
this.date_end = new Date();
|
||||
|
||||
this.isTouched = val;
|
||||
},
|
||||
'query.metaquery'() {
|
||||
this.selectedValues();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// only validate if the first value is higher than first
|
||||
validate_values: _.debounce( function (){
|
||||
if( this.metadatumType === 'date' ){
|
||||
if (this.date_init === undefined)
|
||||
|
||||
if( this.metadatumType === 'Tainacan\\Metadata_Types\\Date' ){
|
||||
if (this.date_init === undefined)
|
||||
this.date_init = new Date();
|
||||
|
||||
if (this.date_end === undefined)
|
||||
this.date_end = new Date();
|
||||
|
||||
if ( this.date_init > this.date_end ) {
|
||||
let result = this.date_init;
|
||||
result.setDate(result.getDate() + 1);
|
||||
this.date_end = result;
|
||||
|
||||
result.setDate(result.getDate() - 1);
|
||||
this.date_init = result;
|
||||
//this.error_message();
|
||||
this.error_message();
|
||||
return
|
||||
}
|
||||
|
||||
} else {
|
||||
if ( parseFloat( this.value_init ) > parseFloat( this.value_end )) {
|
||||
//this.value_end = parseFloat( this.value_init ) + 1;
|
||||
//this.error_message();
|
||||
if (this.value_init.constructor == Number)
|
||||
this.value_init = this.value_init.valueOf();
|
||||
|
||||
if (this.value_end.constructor == Number)
|
||||
this.value_end = this.value_end.valueOf();
|
||||
|
||||
this.value_init = parseFloat(this.value_init);
|
||||
this.value_end = parseFloat(this.value_end);
|
||||
|
||||
if (isNaN(this.value_init) || isNaN(this.value_end))
|
||||
return
|
||||
|
||||
if (this.value_init > this.value_end) {
|
||||
this.error_message();
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.emit();
|
||||
}, 1000),
|
||||
}, 800),
|
||||
// message for error
|
||||
error_message(){
|
||||
if ( !this.isTouched ) return false;
|
||||
|
@ -143,87 +151,56 @@
|
|||
type: 'is-danger'
|
||||
})
|
||||
},
|
||||
dateFormatter(dateObject) {
|
||||
dateFormatter(dateObject){
|
||||
return moment(dateObject, moment.ISO_8601).format(this.dateFormat);
|
||||
},
|
||||
dateParser(dateString) {
|
||||
dateParser(dateString){
|
||||
return moment(dateString, this.dateFormat).toDate();
|
||||
},
|
||||
selectedValues(){
|
||||
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
|
||||
return false;
|
||||
|
||||
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key == this.metadatumId );
|
||||
if ( index >= 0){
|
||||
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key == this.metadatumId);
|
||||
|
||||
if (index >= 0) {
|
||||
let metadata = this.query.metaquery[ index ];
|
||||
if( metadata.value && metadata.value.length > 0 && this.metadatumType === 'numeric'){
|
||||
this.value_init = metadata.value[0];
|
||||
this.value_end = metadata.value[1];
|
||||
|
||||
if( metadata.value && metadata.value.length > 0 && this.metadatumType === 'Tainacan\\Metadata_Types\\Numeric'){
|
||||
this.value_init = parseFloat(metadata.value[0]);
|
||||
this.value_end = parseFloat(metadata.value[1]);
|
||||
this.isValid = true;
|
||||
} else if( metadata.value && metadata.value.length > 0 ){
|
||||
this.date_init = new Date( metadata.value[0] );
|
||||
this.date_end = new Date( metadata.value[1] );
|
||||
|
||||
this.date_init = new Date(metadata.value[0]);
|
||||
this.date_end = new Date(metadata.value[1]);
|
||||
this.isValid = true;
|
||||
}
|
||||
|
||||
if (metadata.value[0] != undefined && metadata.value[1] != undefined)
|
||||
this.$emit( 'sendValuesToTags', this.parseDateToNavigatorLanguage(metadata.value[0]) + ' - ' + this.parseDateToNavigatorLanguage(metadata.value[1]));
|
||||
|
||||
this.$emit('sendValuesToTags', {
|
||||
label: (this.metadatumType === 'Tainacan\\Metadata_Types\\Numeric' ? (metadata.value[0] + ' - ' + metadata.value[1]) : this.parseDateToNavigatorLanguage(metadata.value[0]) + ' - ' + this.parseDateToNavigatorLanguage(metadata.value[1])),
|
||||
value: [metadata.value[0], metadata.value[1]]
|
||||
});
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
showSearch(){
|
||||
if( this.metadatumType === 'date' ){
|
||||
|
||||
if( this.date_init === null || this.date_end === null ){
|
||||
this.clear = true;
|
||||
return '';
|
||||
if (this.metadatumType === 'Tainacan\\Metadata_Types\\Numeric') {
|
||||
this.value_init = '';
|
||||
this.value_end = '';
|
||||
} else {
|
||||
this.date_init = null;
|
||||
this.date_end = null;
|
||||
}
|
||||
|
||||
return this.date_init.toLocaleString().split(' ')[0] + ' - ' + this.date_end.toLocaleString().split(' ')[0];
|
||||
}
|
||||
// else {
|
||||
// return this.value_init + ' - ' +this.value_end;
|
||||
// }
|
||||
},
|
||||
cleanSearchFromTags(filterTag) {
|
||||
if (filterTag.filterId == this.filter.id)
|
||||
this.clearSearch();
|
||||
},
|
||||
clearSearch(){
|
||||
|
||||
this.clear = true;
|
||||
|
||||
this.$emit('input', {
|
||||
filter: 'range',
|
||||
compare: 'BETWEEN',
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
value: ''
|
||||
});
|
||||
|
||||
if( this.metadatumType === 'date' ){
|
||||
this.date_init = null;
|
||||
this.date_end = null;
|
||||
this.isTouched = false;
|
||||
} else {
|
||||
this.value_end = null;
|
||||
this.value_init = null;
|
||||
this.isTouched = false;
|
||||
|
||||
}
|
||||
},
|
||||
// emit the operation for listeners
|
||||
emit() {
|
||||
let values = [];
|
||||
let type = '';
|
||||
|
||||
|
||||
if (this.metadatumType === 'Tainacan\\Metadata_Types\\Date') {
|
||||
|
||||
if (this.date_init === null && this.date_end === null) {
|
||||
values = [];
|
||||
type = 'DATE';
|
||||
this.type = 'DATE';
|
||||
this.isValid = false;
|
||||
this.clear = true;
|
||||
} else {
|
||||
|
@ -234,7 +211,7 @@
|
|||
('00' + (this.date_end.getUTCMonth() + 1)).slice(-2) + '-' +
|
||||
('00' + this.date_end.getUTCDate()).slice(-2);
|
||||
values = [ date_init, date_end ];
|
||||
type = 'DATE';
|
||||
this.type = 'DATE';
|
||||
this.isValid = true;
|
||||
this.clear = false;
|
||||
}
|
||||
|
@ -246,17 +223,17 @@
|
|||
values = [ this.value_init, this.value_end ];
|
||||
|
||||
if(this.value_init !== this.value_end && (this.value_init % 1 !== 0 && this.value_end % 1 == 0)) {
|
||||
type = 'DECIMAL';
|
||||
this.type = 'DECIMAL';
|
||||
} else if(this.value_init !== this.value_end &&
|
||||
this.value_init % 1 !== 0 &&
|
||||
this.value_end % 1 !== 0) {
|
||||
|
||||
type = '';
|
||||
this.type = '';
|
||||
} else if(this.value_init !== this.value_end &&
|
||||
!(this.value_init % 1 == 0 && this.value_end % 1 !== 0)){
|
||||
type = 'DECIMAL';
|
||||
this.type = 'DECIMAL';
|
||||
} else {
|
||||
type = '';
|
||||
this.type = '';
|
||||
}
|
||||
//this.isValid = true;
|
||||
//this.clear = false;
|
||||
|
@ -265,7 +242,7 @@
|
|||
|
||||
this.$emit('input', {
|
||||
filter: 'range',
|
||||
type: type,
|
||||
type: this.type,
|
||||
compare: 'BETWEEN',
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
|
@ -273,7 +250,10 @@
|
|||
});
|
||||
|
||||
if (values[0] != undefined && values[1] != undefined)
|
||||
this.$emit( 'sendValuesToTags', this.parseDateToNavigatorLanguage(values[0]) + ' - ' + this.parseDateToNavigatorLanguage(values[1]));
|
||||
this.$emit( 'sendValuesToTags', {
|
||||
label: (this.metadatumType === 'Tainacan\\Metadata_Types\\Numeric' ? (values[0] + ' - ' + values[1]) : this.parseDateToNavigatorLanguage(values[0]) + ' - ' + this.parseDateToNavigatorLanguage(values[1])),
|
||||
value: [ values[0], values[1] ]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,7 +110,6 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { tainacan as axios } from '../../../js/axios/axios';
|
||||
import { wpAjax, dateInter } from "../../../admin/js/mixins";
|
||||
import { filterTypeMixin } from '../filter-types-mixin';
|
||||
import moment from 'moment';
|
||||
|
@ -130,6 +129,11 @@
|
|||
comparator: '=', // =, !=, >, >=, <, <=
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'query.metaquery'() {
|
||||
this.selectedValues();
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
yearsOnlyValue() {
|
||||
return this.value && typeof this.value.getUTCFullYear === 'function' ? this.value.getUTCFullYear() : null
|
||||
|
@ -152,7 +156,7 @@
|
|||
return false;
|
||||
|
||||
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key == this.metadatumId );
|
||||
|
||||
|
||||
if ( index >= 0){
|
||||
let metadata = this.query.metaquery[ index ];
|
||||
|
||||
|
@ -167,30 +171,15 @@
|
|||
|
||||
this.value = new Date(textValue);
|
||||
|
||||
this.$emit('sendValuesToTags', this.comparator + ' ' + moment(this.value, moment.ISO_8601).format(this.dateFormat));
|
||||
this.$emit('sendValuesToTags', {
|
||||
label: this.comparator + ' ' + moment(this.value, moment.ISO_8601).format(this.dateFormat),
|
||||
value: textValue
|
||||
});
|
||||
}
|
||||
|
||||
} else {
|
||||
return false;
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
},
|
||||
cleanSearchFromTags(filterTag) {
|
||||
if (filterTag.filterId == this.filter.id)
|
||||
this.clearSearch();
|
||||
},
|
||||
clearSearch(){
|
||||
|
||||
this.$emit('input', {
|
||||
filter: 'date',
|
||||
type: 'DATE',
|
||||
compare: this.comparator,
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
value: ''
|
||||
});
|
||||
|
||||
this.value = null;
|
||||
},
|
||||
dateFormatter(dateObject) {
|
||||
return moment(dateObject, moment.ISO_8601).format(this.dateFormat);
|
||||
|
@ -227,7 +216,10 @@
|
|||
collection_id: this.collectionId,
|
||||
value: valueQuery
|
||||
});
|
||||
this.$emit('sendValuesToTags', this.comparator + ' ' + moment(this.value, moment.ISO_8601).format(this.dateFormat));
|
||||
this.$emit('sendValuesToTags', {
|
||||
label: this.comparator + ' ' + moment(this.value, moment.ISO_8601).format(this.dateFormat),
|
||||
value: valueQuery
|
||||
});
|
||||
|
||||
},
|
||||
onChangeComparator(newComparator) {
|
||||
|
|
|
@ -9,36 +9,21 @@ export const filterTypeMixin = {
|
|||
metadatumId: '',
|
||||
metadatumType: '',
|
||||
filterTypeOptions: [],
|
||||
isRepositoryLevel: Boolean
|
||||
}
|
||||
},
|
||||
props: {
|
||||
filter: Object,
|
||||
query: Object
|
||||
query: Object,
|
||||
isRepositoryLevel: Boolean,
|
||||
isUsingElasticSearch: Boolean,
|
||||
isLoadingItems: Boolean
|
||||
},
|
||||
created() {
|
||||
this.collectionId = this.filter.collection_id ? this.filter.collection_id : this.collectionId;
|
||||
this.metadatumId = this.filter.metadatum.metadatum_id ? this.filter.metadatum.metadatum_id : this.metadatumId;
|
||||
this.filterTypeOptions = this.filter.filter_type_options ? this.filter.filter_type_options : this.filterTypeOptions;
|
||||
this.metadatumType = this.filter.metadatum.metadata_type_object.className ? this.filter.metadatum.metadata_type_object.className : this.metadatumType;
|
||||
},
|
||||
mounted() {
|
||||
this.$eventBusSearch.$on('removeFromFilterTag', this.cleanFromTags );
|
||||
},
|
||||
computed: {
|
||||
facetsFromItemSearch() {
|
||||
return this.getFacets();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
cleanFromTags(filterTag) {
|
||||
if (typeof this.cleanSearchFromTags === 'function')
|
||||
this.cleanSearchFromTags(filterTag)
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.$eventBusSearch.$off('removeFromFilterTag', this.cleanFromTags);
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export const dynamicFilterTypeMixin = {
|
||||
|
@ -46,19 +31,7 @@ export const dynamicFilterTypeMixin = {
|
|||
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.
|
||||
this.$eventBusSearch.$on('hasFiltered', this.reloadOptionsDueToFiltering);
|
||||
|
||||
if (this.isUsingElasticSearch) {
|
||||
this.$eventBusSearch.$on('isLoadingItems', isLoading => {
|
||||
this.isLoadingOptions = isLoading;
|
||||
});
|
||||
isLoadingOptions: false,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
@ -66,6 +39,11 @@ export const dynamicFilterTypeMixin = {
|
|||
return this.getFacets();
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
isLoadingItems() {
|
||||
this.isLoadingOptions = this.isLoadingItems;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
...mapGetters('search', [
|
||||
'getFacets'
|
||||
|
@ -349,20 +327,10 @@ export const dynamicFilterTypeMixin = {
|
|||
}
|
||||
}
|
||||
},
|
||||
reloadOptionsDueToFiltering() {
|
||||
if (typeof this.loadOptions === "function")
|
||||
this.loadOptions(true);
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
// Cancels previous Request
|
||||
if (this.getOptionsValuesCancel != undefined)
|
||||
this.getOptionsValuesCancel.cancel('Facet search Canceled.');
|
||||
|
||||
this.$eventBusSearch.$off('hasFiltered', this.reloadOptionsDueToFiltering);
|
||||
|
||||
if (this.isUsingElasticSearch)
|
||||
this.$eventBusSearch.$off('isLoadingItems');
|
||||
|
||||
},
|
||||
};
|
|
@ -30,6 +30,9 @@
|
|||
withError: false
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.selectedValues();
|
||||
},
|
||||
methods: {
|
||||
// only validate if the first value is higher than first
|
||||
validate_values: _.debounce( function (){
|
||||
|
@ -51,24 +54,6 @@
|
|||
type: 'is-danger'
|
||||
})
|
||||
},
|
||||
|
||||
cleanSearchFromTags(filterTag) {
|
||||
if (filterTag.filterId == this.filter.id)
|
||||
this.clearSearch();
|
||||
},
|
||||
clearSearch(){
|
||||
|
||||
this.$emit('input', {
|
||||
filter: 'range',
|
||||
compare: 'BETWEEN',
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
value: ''
|
||||
});
|
||||
this.valueEnd = null;
|
||||
this.valueInit = null;
|
||||
|
||||
},
|
||||
// emit the operation for listeners
|
||||
emit() {
|
||||
let values = [ this.valueInit, this.valueEnd ];
|
||||
|
@ -84,7 +69,7 @@
|
|||
});
|
||||
|
||||
if (values[0] != undefined && values[1] != undefined)
|
||||
this.$emit('sendValuesToTags', values[0] + ' - ' + values[1]);
|
||||
this.$emit('sendValuesToTags', { label: values[0] + ' - ' + values[1], value: values });
|
||||
},
|
||||
selectedValues(){
|
||||
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
|
||||
|
@ -99,15 +84,12 @@
|
|||
}
|
||||
|
||||
if (metaquery.value[0] != undefined && metaquery.value[1] != undefined)
|
||||
this.$emit( 'sendValuesToTags', this.valueInit + ' - ' + this.valueEnd);
|
||||
this.$emit('sendValuesToTags', { label: this.valueInit + ' - ' + this.valueEnd, value: metaquery.values });
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.selectedValues();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -29,32 +29,28 @@
|
|||
selectedInterval: ''
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.selectedValues();
|
||||
},
|
||||
methods: {
|
||||
cleanSearchFromTags(filterTag) {
|
||||
if (filterTag.filterId == this.filter.id)
|
||||
this.clearSearch();
|
||||
},
|
||||
changeInterval() {
|
||||
if (this.selectedInterval !== '') {
|
||||
this.valueInit = this.filterTypeOptions.intervals[this.selectedInterval].from;
|
||||
this.valueEnd = this.filterTypeOptions.intervals[this.selectedInterval].to;
|
||||
this.emit();
|
||||
} else {
|
||||
this.clearSearch();
|
||||
this.$emit('input', {
|
||||
filter: 'range',
|
||||
compare: 'BETWEEN',
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
value: ''
|
||||
});
|
||||
this.valueEnd = null;
|
||||
this.valueInit = null;
|
||||
}
|
||||
|
||||
},
|
||||
clearSearch(){
|
||||
this.$emit('input', {
|
||||
filter: 'range',
|
||||
compare: 'BETWEEN',
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
value: ''
|
||||
});
|
||||
this.valueEnd = null;
|
||||
this.valueInit = null;
|
||||
},
|
||||
// emit the operation for listeners
|
||||
emit() {
|
||||
let values = [ this.valueInit, this.valueEnd ];
|
||||
|
@ -69,7 +65,7 @@
|
|||
|
||||
if (values[0] != undefined && values[1] != undefined) {
|
||||
let labelValue = this.filterTypeOptions.intervals[this.selectedInterval].label + (this.filterTypeOptions.showIntervalOnTag ? `(${values[0]}-${values[1]})` : '');
|
||||
this.$emit( 'sendValuesToTags', labelValue);
|
||||
this.$emit('sendValuesToTags', { label: labelValue, value: values });
|
||||
}
|
||||
},
|
||||
selectedValues(){
|
||||
|
@ -94,14 +90,11 @@
|
|||
);
|
||||
|
||||
let labelValue = this.filterTypeOptions.intervals[this.selectedInterval].label + (this.filterTypeOptions.showIntervalOnTag ? `(${this.valueInit}-${this.valueEnd})` : '');
|
||||
this.$emit( 'sendValuesToTags', labelValue);
|
||||
this.$emit('sendValuesToTags', { label: labelValue, value: [ this.valueInit, this.valueEnd ] });
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.selectedValues();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -70,8 +70,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { tainacan as axios } from '../../../js/axios/axios';
|
||||
import { wpAjax } from "../../../admin/js/mixins";
|
||||
import { wpAjax } from '../../../admin/js/mixins';
|
||||
import { filterTypeMixin } from '../filter-types-mixin';
|
||||
|
||||
export default {
|
||||
|
@ -119,30 +118,13 @@
|
|||
this.comparator = metadata.compare;
|
||||
|
||||
if (this.value != undefined)
|
||||
this.$emit('sendValuesToTags', this.comparator + ' ' + this.value);
|
||||
this.$emit('sendValuesToTags', { label: this.comparator + ' ' + this.value, value: this.value });
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
},
|
||||
cleanSearchFromTags(filterTag) {
|
||||
if (filterTag.filterId == this.filter.id)
|
||||
this.clearSearch();
|
||||
},
|
||||
clearSearch(){
|
||||
|
||||
this.$emit('input', {
|
||||
filter: 'numeric',
|
||||
compare: this.comparator,
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
value: '',
|
||||
type: 'NUMERIC'
|
||||
});
|
||||
|
||||
this.value = null;
|
||||
},
|
||||
// emit the operation for listeners
|
||||
emit() {
|
||||
|
||||
|
@ -158,7 +140,7 @@
|
|||
type: 'NUMERIC'
|
||||
});
|
||||
|
||||
this.$emit('sendValuesToTags', this.comparator + ' ' + this.value);
|
||||
this.$emit('sendValuesToTags', { label: this.comparator + ' ' + this.value, value: this.value });
|
||||
|
||||
},
|
||||
onChangeComparator(newComparator) {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { tainacan as axios, isCancel } from '../../../js/axios/axios';
|
||||
import { isCancel } from '../../../js/axios/axios';
|
||||
import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin';
|
||||
|
||||
export default {
|
||||
|
@ -38,7 +38,7 @@
|
|||
watch: {
|
||||
selected(value) {
|
||||
if (value)
|
||||
this.$emit('sendValuesToTags', value);
|
||||
this.$emit('sendValuesToTags', { label: value, value: value });
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
@ -80,17 +80,12 @@
|
|||
this.getOptionsValuesCancel = promise.source;
|
||||
},
|
||||
onSelect(value){
|
||||
//this.selected = value;
|
||||
this.$emit('input', {
|
||||
filter: 'selectbox',
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
value: ( value ) ? value : ''
|
||||
});
|
||||
},
|
||||
cleanSearchFromTags(filterTag) {
|
||||
if (filterTag.filterId == this.filter.id)
|
||||
this.onSelect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
@typing="search"
|
||||
:aria-close-label="$i18n.get('remove_value')"
|
||||
:aria-labelledby="'filter-label-id-' + filter.id"
|
||||
:placeholder="(metadatumType == 'Tainacan\\Metadata_Types\\Relationship') ? $i18n.get('info_type_to_search_items') : $i18n.get('info_type_to_add_metadata')">
|
||||
:placeholder="(metadatumType == 'Tainacan\\Metadata_Types\\Relationship') ? $i18n.get('info_type_to_add_items') : $i18n.get('info_type_to_add_metadata')">
|
||||
<template slot-scope="props">
|
||||
<div class="media">
|
||||
<div
|
||||
|
@ -48,56 +48,27 @@
|
|||
import qs from 'qs';
|
||||
|
||||
export default {
|
||||
created(){
|
||||
let endpoint = '/collection/' + this.collectionId + '/metadata/' + this.metadatumId;
|
||||
|
||||
if (this.isRepositoryLevel || this.collectionId == 'default')
|
||||
endpoint = '/metadata/'+ this.metadatumId + '?nopaging=1';
|
||||
|
||||
axios.get(endpoint)
|
||||
.then( res => {
|
||||
let result = res.data;
|
||||
if( result && result.metadata_type ){
|
||||
this.metadatum_object = result;
|
||||
this.selectedValues();
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
this.$console.log(error);
|
||||
});
|
||||
},
|
||||
mixins: [filterTypeMixin, dynamicFilterTypeMixin],
|
||||
data(){
|
||||
return {
|
||||
results:'',
|
||||
selected:[],
|
||||
options: [],
|
||||
metadatum_object: {}
|
||||
options: []
|
||||
}
|
||||
},
|
||||
mixins: [filterTypeMixin, dynamicFilterTypeMixin],
|
||||
watch: {
|
||||
selected( value ){
|
||||
this.selected = value;
|
||||
|
||||
let values = [];
|
||||
let labels = [];
|
||||
if( this.selected.length > 0 ){
|
||||
for(let val of this.selected){
|
||||
values.push( val.value );
|
||||
labels.push( val.label );
|
||||
}
|
||||
}
|
||||
this.$emit('input', {
|
||||
filter: 'taginput',
|
||||
compare: 'IN',
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
value: values
|
||||
selected(newVal, oldVal) {
|
||||
const isEqual = (newVal.length == oldVal.length) && newVal.every((element, index) => {
|
||||
return element === oldVal[index];
|
||||
});
|
||||
|
||||
this.$emit( 'sendValuesToTags', labels);
|
||||
if (!isEqual)
|
||||
this.onSelect();
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.selectedValues();
|
||||
},
|
||||
methods: {
|
||||
search: _.debounce( function(query) {
|
||||
let promise = null;
|
||||
|
@ -129,25 +100,26 @@
|
|||
|
||||
}, 500),
|
||||
selectedValues(){
|
||||
const instance = this;
|
||||
|
||||
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
|
||||
return false;
|
||||
|
||||
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key == this.metadatumId );
|
||||
if ( index >= 0){
|
||||
let metadata = this.query.metaquery[ index ];
|
||||
let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadata_type_options.collection_id ) ?
|
||||
this.metadatum_object.metadata_type_options.collection_id : this.collectionId;
|
||||
|
||||
|
||||
if ( this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship' ) {
|
||||
let query = qs.stringify({ postin: metadata.value });
|
||||
let query = qs.stringify({ postin: metadata.value, fetch_only: 'title,thumbnail', fetch_only_meta: '' });
|
||||
|
||||
axios.get('/collection/' + collectionTarget + '/items?' + query)
|
||||
axios.get('/items?' + query)
|
||||
.then( res => {
|
||||
if (res.data.items) {
|
||||
for (let item of res.data) {
|
||||
instance.selected.push({ label: item.title, value: item.id, img: item.thumbnail.thumbnail[0] });
|
||||
for (let item of res.data.items) {
|
||||
this.selected.push({
|
||||
label: item.title,
|
||||
value: item.id,
|
||||
img: item.thumbnail && item.thumbnail.thumbnail && item.thumbnail.thumbnail[0] ? item.thumbnail.thumbnail[0] : null
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -156,40 +128,31 @@
|
|||
});
|
||||
} else {
|
||||
for (let item of metadata.value) {
|
||||
instance.selected.push({ label: item, value: item, img: '' });
|
||||
this.selected.push({ label: item, value: item, img: null });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
cleanSearchFromTags(filterTag) {
|
||||
|
||||
if (filterTag.filterId == this.filter.id) {
|
||||
|
||||
let selectedIndex = this.selected.findIndex(option => option.label == filterTag.singleValue);
|
||||
if (selectedIndex >= 0) {
|
||||
|
||||
this.selected.splice(selectedIndex, 1);
|
||||
|
||||
let values = [];
|
||||
let labels = [];
|
||||
for(let val of this.selected){
|
||||
values.push( val.value );
|
||||
labels.push( val.label );
|
||||
}
|
||||
|
||||
this.$emit('input', {
|
||||
filter: 'taginput',
|
||||
compare: 'IN',
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
value: values
|
||||
});
|
||||
|
||||
this.$emit( 'sendValuesToTags', labels);
|
||||
onSelect() {
|
||||
let values = [];
|
||||
let labels = [];
|
||||
if( this.selected.length > 0 ){
|
||||
for(let val of this.selected){
|
||||
values.push( val.value );
|
||||
labels.push( val.label );
|
||||
}
|
||||
}
|
||||
this.$emit('input', {
|
||||
filter: 'taginput',
|
||||
compare: 'IN',
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
value: values
|
||||
});
|
||||
|
||||
this.$emit( 'sendValuesToTags', { label: labels, value: values });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
:filter="filter"
|
||||
:query="query"
|
||||
:is-repository-level="isRepositoryLevel"
|
||||
:is-loading-items.sync="isLoadingItems"
|
||||
@input="onInput"
|
||||
@sendValuesToTags="onSendValuesToTags"/>
|
||||
</div>
|
||||
|
@ -51,18 +52,47 @@
|
|||
filter: Object,
|
||||
query: Object,
|
||||
isRepositoryLevel: Boolean,
|
||||
open: true,
|
||||
open: true
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
isLoadingItems: Boolean,
|
||||
isUsingElasticSearch: tainacan_plugin.wp_elasticpress == "1" ? true : false,
|
||||
reloadDueFiltering: Boolean
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (this.isUsingElasticSearch) {
|
||||
this.$eventBusSearch.$on('isLoadingItems', isLoadingItems => {
|
||||
this.isLoadingOptions = isLoadingItems;
|
||||
});
|
||||
}
|
||||
// We listen to event, but reload event if hasFiltered is negative, as
|
||||
// an empty query also demands filters reloading.
|
||||
this.$eventBusSearch.$on('hasFiltered', this.reloadFilter);
|
||||
},
|
||||
methods: {
|
||||
onInput(inputEvent){
|
||||
this.$eventBusSearch.$emit('input', inputEvent);
|
||||
},
|
||||
onSendValuesToTags(values) {
|
||||
this.$eventBusSearch.$emit('sendValuesToTags', {
|
||||
onSendValuesToTags($event) {
|
||||
this.$eventBusSearch.$emit('sendValuesToTags', {
|
||||
filterId: this.filter.id,
|
||||
value: values
|
||||
label: $event.label,
|
||||
value: $event.value,
|
||||
taxonomy: $event.taxonomy,
|
||||
metadatumId: this.filter.metadatum_id
|
||||
});
|
||||
},
|
||||
reloadFilter() {
|
||||
this.reloadDueFiltering = !this.reloadDueFiltering;
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (this.isUsingElasticSearch)
|
||||
this.$eventBusSearch.$off('isLoadingItems');
|
||||
|
||||
this.$eventBusSearch.$off('hasFiltered', this.reloadFilter);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
<template>
|
||||
<div
|
||||
:style="{ 'height': isLoading ? (Number(filter.max_options)*28) + 'px' : 'auto' }"
|
||||
:class="{ 'skeleton': isLoading }"
|
||||
:style="{ 'height': isLoadingOptions ? (Number(filter.max_options)*28) + 'px' : 'auto' }"
|
||||
:class="{ 'skeleton': isLoadingOptions }"
|
||||
class="block">
|
||||
<!-- <span
|
||||
v-if="isLoading"
|
||||
v-if="isLoadingOptions"
|
||||
style="width: 100%"
|
||||
class="icon has-text-centered loading-icon">
|
||||
<div class="control has-icons-right is-loading is-clearfix" />
|
||||
</span> -->
|
||||
<div
|
||||
v-for="(option, index) in options.slice(0, filter.max_options)"
|
||||
v-if="!isLoading"
|
||||
v-if="!isLoadingOptions"
|
||||
:key="index"
|
||||
:value="index"
|
||||
class="control">
|
||||
|
@ -38,7 +38,7 @@
|
|||
</button>
|
||||
</div>
|
||||
<p
|
||||
v-if="!isLoading && options.length != undefined && options.length <= 0"
|
||||
v-if="!isLoadingOptions && options.length != undefined && options.length <= 0"
|
||||
class="no-options-placeholder">
|
||||
{{ $i18n.get('info_no_options_avialable_filtering') }}
|
||||
</p>
|
||||
|
@ -53,36 +53,36 @@
|
|||
import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin';
|
||||
|
||||
export default {
|
||||
mixins: [ filterTypeMixin, dynamicFilterTypeMixin ],
|
||||
created(){
|
||||
this.loadOptions();
|
||||
},
|
||||
mixins: [ filterTypeMixin, dynamicFilterTypeMixin ],
|
||||
data(){
|
||||
return {
|
||||
isLoading: true,
|
||||
isLoadingOptions: true,
|
||||
options: [],
|
||||
selected: [],
|
||||
taxonomy: '',
|
||||
taxonomy_id: Number,
|
||||
getOptionsValuesCancel: undefined,
|
||||
isUsingElasticSearch: tainacan_plugin.wp_elasticpress == "1" ? true : false
|
||||
taxonomy_id: Number
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
selected: function(){
|
||||
//this.selected = val;
|
||||
this.onSelect();
|
||||
selected(newVal, oldVal) {
|
||||
const isEqual = (newVal.length == oldVal.length) && newVal.every((element, index) => {
|
||||
return element === oldVal[index];
|
||||
});
|
||||
|
||||
if (!isEqual)
|
||||
this.onSelect();
|
||||
},
|
||||
facetsFromItemSearch() {
|
||||
if (this.isUsingElasticSearch)
|
||||
this.loadOptions();
|
||||
},
|
||||
'query.taxquery'() {
|
||||
this.loadOptions();
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
facetsFromItemSearch() {
|
||||
return this.getFacets();
|
||||
}
|
||||
},
|
||||
mounted(){
|
||||
this.loadOptions();
|
||||
},
|
||||
methods: {
|
||||
...mapGetters('search', [
|
||||
'getFacets'
|
||||
|
@ -96,7 +96,7 @@
|
|||
if (this.getOptionsValuesCancel != undefined)
|
||||
this.getOptionsValuesCancel.cancel('Facet search Canceled.');
|
||||
|
||||
this.isLoading = true;
|
||||
this.isLoadingOptions = true;
|
||||
let query_items = { 'current_query': this.query };
|
||||
|
||||
let route = '';
|
||||
|
@ -124,14 +124,14 @@
|
|||
promise.request
|
||||
.then((res) => {
|
||||
this.prepareOptionsForTaxonomy(res.data.values ? res.data.values : res.data, skipSelected);
|
||||
this.isLoading = false;
|
||||
this.isLoadingOptions = false;
|
||||
})
|
||||
.catch( error => {
|
||||
if (isCancel(error)) {
|
||||
this.$console.log('Request canceled: ' + error.message);
|
||||
} else {
|
||||
this.$console.log('Error on facets request: ', error);
|
||||
this.isLoading = false;
|
||||
this.isLoadingOptions = false;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -148,14 +148,13 @@
|
|||
this.prepareOptionsForTaxonomy(Object.values(this.facetsFromItemSearch[facet]), skipSelected);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
selectedValues(){
|
||||
|
||||
if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) )
|
||||
return false;
|
||||
|
||||
|
||||
let index = this.query.taxquery.findIndex(newMetadatum => newMetadatum.taxonomy == this.taxonomy );
|
||||
if ( index >= 0){
|
||||
let metadata = this.query.taxquery[ index ];
|
||||
|
@ -164,16 +163,7 @@
|
|||
this.selected = [];
|
||||
return false;
|
||||
}
|
||||
},
|
||||
onSelect(){
|
||||
this.$emit('input', {
|
||||
filter: 'checkbox',
|
||||
taxonomy: this.taxonomy,
|
||||
compare: 'IN',
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
terms: this.selected
|
||||
});
|
||||
|
||||
|
||||
let onlyLabels = [];
|
||||
|
||||
|
@ -231,7 +221,17 @@
|
|||
}
|
||||
}
|
||||
|
||||
this.$emit("sendValuesToTags", onlyLabels);
|
||||
this.$emit('sendValuesToTags', { label: onlyLabels, taxonomy: this.taxonomy, value: this.selected });
|
||||
},
|
||||
onSelect(){
|
||||
this.$emit('input', {
|
||||
filter: 'checkbox',
|
||||
taxonomy: this.taxonomy,
|
||||
compare: 'IN',
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
terms: this.selected
|
||||
});
|
||||
},
|
||||
openCheckboxModal(parent) {
|
||||
this.$buefy.modal.open({
|
||||
|
@ -253,27 +253,10 @@
|
|||
this.loadOptions();
|
||||
}
|
||||
},
|
||||
width: 'calc(100% - 8.333333333%)',
|
||||
width: 'calc(100% - 16.6666%)',
|
||||
trapFocus: true
|
||||
});
|
||||
},
|
||||
cleanSearchFromTags(filterTag) {
|
||||
if (filterTag.filterId == this.filter.id) {
|
||||
|
||||
let selectedOption = this.options.find(option => option.label == filterTag.singleValue);
|
||||
|
||||
if (selectedOption) {
|
||||
|
||||
let selectedIndex = this.selected.findIndex(option => option == selectedOption.value);
|
||||
if (selectedIndex >= 0) {
|
||||
|
||||
this.selected.splice(selectedIndex, 1);
|
||||
|
||||
this.onSelect();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
prepareOptionsForTaxonomy(items, skipSelected) {
|
||||
|
||||
if (items[0] != undefined) {
|
||||
|
@ -304,13 +287,12 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (skipSelected == undefined || skipSelected == false) {
|
||||
this.selectedValues();
|
||||
}
|
||||
},
|
||||
updatesIsLoading(isLoading) {
|
||||
this.isLoading = isLoading;
|
||||
updatesIsLoading(isLoadingOptions) {
|
||||
this.isLoadingOptions = isLoadingOptions;
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
v-model="selected"
|
||||
:data="options"
|
||||
autocomplete
|
||||
:loading="isLoading"
|
||||
:loading="isLoadingOptions"
|
||||
expanded
|
||||
:remove-on-keys="[]"
|
||||
field="label"
|
||||
|
@ -27,7 +27,7 @@
|
|||
</div>
|
||||
</template>
|
||||
<template
|
||||
v-if="!isLoading"
|
||||
v-if="!isLoadingOptions"
|
||||
slot="empty">
|
||||
{{ $i18n.get('info_no_options_found' ) }}
|
||||
</template>
|
||||
|
@ -60,38 +60,12 @@
|
|||
results:'',
|
||||
selected:[],
|
||||
options: [],
|
||||
isLoading: false,
|
||||
taxonomy: '',
|
||||
isUsingElasticSearch: tainacan_plugin.wp_elasticpress == "1" ? true : false
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
selected( value ){
|
||||
this.selected = value;
|
||||
|
||||
let values = [];
|
||||
let labels = [];
|
||||
if( this.selected.length > 0 ){
|
||||
for(let val of this.selected){
|
||||
values.push( val.value );
|
||||
labels.push( val.label );
|
||||
}
|
||||
}
|
||||
this.$emit('input', {
|
||||
filter: 'taginput',
|
||||
compare: 'IN',
|
||||
taxonomy: this.taxonomy,
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
terms: values
|
||||
});
|
||||
|
||||
this.$emit("sendValuesToTags", labels);
|
||||
taxonomy: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
search: _.debounce( function(query) {
|
||||
this.isLoading = true;
|
||||
this.isLoadingOptions = true;
|
||||
this.options = [];
|
||||
|
||||
let query_items = {
|
||||
|
@ -133,10 +107,10 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
this.isLoading = false;
|
||||
this.isLoadingOptions = false;
|
||||
})
|
||||
.catch(error => {
|
||||
this.isLoading = false;
|
||||
this.isLoadingOptions = false;
|
||||
this.$console.log(error);
|
||||
});
|
||||
}, 500),
|
||||
|
@ -157,6 +131,26 @@
|
|||
return false;
|
||||
}
|
||||
},
|
||||
onSelect() {
|
||||
let values = [];
|
||||
let labels = [];
|
||||
if( this.selected.length > 0 ){
|
||||
for(let val of this.selected){
|
||||
values.push( val.value );
|
||||
labels.push( val.label );
|
||||
}
|
||||
}
|
||||
this.$emit('input', {
|
||||
filter: 'taginput',
|
||||
compare: 'IN',
|
||||
taxonomy: this.taxonomy,
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
terms: values
|
||||
});
|
||||
|
||||
this.$emit('sendValuesToTags', { label: labels, taxonomy: this.taxonomy, value: values });
|
||||
},
|
||||
getTerm( taxonomy, id ){
|
||||
//getting a specific value from api, does not need be in fecat api
|
||||
return axios.get('/taxonomy/' + taxonomy + '/terms/' + id + '?order=asc' )
|
||||
|
@ -166,34 +160,6 @@
|
|||
.catch(error => {
|
||||
this.$console.log(error);
|
||||
});
|
||||
},
|
||||
cleanSearchFromTags(filterTag) {
|
||||
|
||||
if (filterTag.filterId == this.filter.id) {
|
||||
|
||||
let selectedIndex = this.selected.findIndex(option => option.label == filterTag.singleValue);
|
||||
if (selectedIndex >= 0) {
|
||||
|
||||
this.selected.splice(selectedIndex, 1);
|
||||
|
||||
let values = [];
|
||||
let labels = [];
|
||||
for(let val of this.selected){
|
||||
values.push( val.value );
|
||||
labels.push( val.label );
|
||||
}
|
||||
|
||||
this.$emit('input', {
|
||||
filter: 'taginput',
|
||||
compare: 'IN',
|
||||
taxonomy: this.taxonomy,
|
||||
metadatum_id: this.metadatumId,
|
||||
collection_id: this.collectionId,
|
||||
terms: values
|
||||
});
|
||||
this.$emit( 'sendValuesToTags', labels);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,14 +16,12 @@ export default {
|
|||
},
|
||||
created() {
|
||||
this.$on('input', data => {
|
||||
console.log("inputei")
|
||||
this.$store.dispatch('search/setPage', 1);
|
||||
|
||||
if (data.taxonomy)
|
||||
this.add_taxquery(data);
|
||||
this.addTaxquery(data);
|
||||
else
|
||||
this.add_metaquery(data);
|
||||
|
||||
this.updateURLQueries();
|
||||
this.addMetaquery(data);
|
||||
});
|
||||
|
||||
this.$on('sendValuesToTags', data => {
|
||||
|
@ -173,24 +171,40 @@ export default {
|
|||
this.$store.dispatch('search/set_advanced_query', data);
|
||||
this.updateURLQueries();
|
||||
},
|
||||
add_metaquery( data ){
|
||||
addMetaquery( data ){
|
||||
if ( data && data.collection_id ){
|
||||
this.$store.dispatch('search/add_metaquery', data );
|
||||
}
|
||||
},
|
||||
removeMetaQuery(query) {
|
||||
this.$store.dispatch('search/remove_metaquery', query );
|
||||
this.updateURLQueries();
|
||||
},
|
||||
removeMetaFromFilterTag(filterTag) {
|
||||
this.$emit('removeFromFilterTag', filterTag);
|
||||
if (filterTag.singleValue == undefined)
|
||||
this.$store.dispatch('search/removeFilterTag', filterTag);
|
||||
},
|
||||
add_taxquery( data ){
|
||||
addTaxquery( data ){
|
||||
if ( data && data.collection_id ){
|
||||
this.$store.dispatch('search/add_taxquery', data );
|
||||
}
|
||||
this.updateURLQueries();
|
||||
},
|
||||
removeMetaFromFilterTag(filterTag) {
|
||||
|
||||
if (filterTag.singleLabel != undefined || filterTag.label != undefined) {
|
||||
|
||||
if (filterTag.taxonomy)
|
||||
this.$store.dispatch('search/remove_taxquery', {
|
||||
filterId: filterTag.filterId,
|
||||
label: filterTag.singleLabel ? filterTag.singleLabel : filterTag.label,
|
||||
isMultiValue: filterTag.singleLabel ? false : true,
|
||||
taxonomy: filterTag.taxonomy,
|
||||
value: filterTag.value
|
||||
});
|
||||
else
|
||||
this.$store.dispatch('search/remove_metaquery', {
|
||||
filterId: filterTag.filterId,
|
||||
label: filterTag.singleLabel ? filterTag.singleLabel : filterTag.label,
|
||||
isMultiValue: filterTag.singleLabel ? false : true,
|
||||
metadatum_id: filterTag.metadatumId,
|
||||
value: filterTag.value
|
||||
});
|
||||
}
|
||||
this.updateURLQueries();
|
||||
},
|
||||
addFetchOnly( metadatum, ignorePrefs, metadatumIDs ){
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ export const set_advanced_query = ({commit}, advancedSearchQuery) => {
|
|||
};
|
||||
|
||||
// Meta Queries from filters
|
||||
export const add_metaquery = ( { commit }, filter ) => {
|
||||
export const add_metaquery = ( { commit }, filter ) => {
|
||||
if (filter && (filter.value == undefined || filter.value == null || filter.value.length === 0 || filter.value == '')) {
|
||||
commit('removeMetaQuery', filter );
|
||||
} else {
|
||||
|
@ -50,6 +50,10 @@ export const remove_metaquery = ( { commit }, filter ) => {
|
|||
commit('removeMetaQuery', filter );
|
||||
};
|
||||
|
||||
export const remove_taxquery = ( { commit }, filter ) => {
|
||||
commit('removeTaxQuery', filter );
|
||||
};
|
||||
|
||||
// Pagination queries
|
||||
export const setTotalItems = ({ commit }, total ) => {
|
||||
commit('setTotalItems', total);
|
||||
|
|
|
@ -22,7 +22,7 @@ export const addMetaQuery = ( state, filter ) => {
|
|||
state.postquery.metaquery = ( ! state.postquery.metaquery || state.postquery.metaquery.length == undefined ) ? [] : state.postquery.metaquery;
|
||||
|
||||
let index = state.postquery.metaquery.findIndex( item => item.key === filter.metadatum_id);
|
||||
|
||||
|
||||
if ( index >= 0 ){
|
||||
Vue.set( state.postquery.metaquery, index, {
|
||||
key: filter.metadatum_id,
|
||||
|
@ -94,17 +94,29 @@ export const removeMetaQuery = ( state, filter ) => {
|
|||
state.postquery.metaquery = ( ! state.postquery.metaquery ) ? [] : state.postquery.metaquery;
|
||||
|
||||
let index = state.postquery.metaquery.findIndex( item => item.key == filter.metadatum_id);
|
||||
|
||||
if (index >= 0) {
|
||||
state.postquery.metaquery.splice(index, 1);
|
||||
if (!filter.isMultiValue && Array.isArray(state.postquery.metaquery[index].value) && state.postquery.metaquery[index].value.length > 1) {
|
||||
let otherIndex = state.postquery.metaquery[index].value.findIndex(item => item == filter.value);
|
||||
if (otherIndex >= 0)
|
||||
state.postquery.metaquery[index].value.splice(otherIndex, 1)
|
||||
} else
|
||||
state.postquery.metaquery.splice(index, 1);
|
||||
}
|
||||
};
|
||||
|
||||
export const removeTaxQuery = ( state, filter ) => {
|
||||
let index = state.postquery.taxquery.findIndex( item => item.taxonomy == filter.taxonomy);
|
||||
state.postquery.taxquery = ( ! state.postquery.taxquery ) ? [] : state.postquery.taxquery;
|
||||
|
||||
let index = state.postquery.taxquery.findIndex( item => item.taxonomy == filter.taxonomy);
|
||||
|
||||
if (index >= 0) {
|
||||
state.postquery.taxquery.splice(index, 1);
|
||||
if (Array.isArray(state.postquery.taxquery[index].terms) && state.postquery.taxquery[index].terms.length > 1) {
|
||||
let otherIndex = state.postquery.taxquery[index].terms.findIndex(item => item == filter.value);
|
||||
|
||||
if (otherIndex >= 0)
|
||||
state.postquery.taxquery[index].terms.splice(otherIndex, 1)
|
||||
} else
|
||||
state.postquery.taxquery.splice(index, 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
|
|||
'description' => 'Is filtered',
|
||||
'collection_id' => $collection->get_id(),
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
|
||||
'status' => 'publish'
|
||||
),
|
||||
true,
|
||||
true
|
||||
|
@ -69,6 +70,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
|
|||
'description' => 'Is filtered',
|
||||
'collection_id' => $collection->get_id(),
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
|
||||
'status' => 'publish'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
@ -134,6 +136,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
|
|||
array(
|
||||
'name' => 'Metadatum filtered',
|
||||
'description' => 'Is filtered',
|
||||
'status' => 'publish',
|
||||
'collection_id' => $collection->get_id(),
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
|
||||
),
|
||||
|
@ -187,6 +190,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
|
|||
array(
|
||||
'name' => 'Metadatum filtered',
|
||||
'description' => 'Is filtered',
|
||||
'status' => 'publish',
|
||||
'collection_id' => $collection->get_id(),
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Numeric'
|
||||
),
|
||||
|
@ -199,7 +203,8 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
|
|||
'name' => 'Other filtered',
|
||||
'description' => 'Is filtered',
|
||||
'collection_id' => $collection->get_id(),
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Numeric'
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Numeric',
|
||||
'status' => 'publish'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
@ -276,7 +281,8 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
|
|||
'name' => 'Metadatum filtered',
|
||||
'description' => 'Is filtered',
|
||||
'collection_id' => $collection->get_id(),
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Text'
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
||||
'status' => 'publish'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
@ -287,7 +293,8 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
|
|||
'name' => 'Metadatum filtered',
|
||||
'description' => 'Is filtered',
|
||||
'collection_id' => 'default',
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Text'
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
||||
'status' => 'publish'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
|
|
@ -100,6 +100,7 @@ class CoreMetadatumTypes extends TAINACAN_UnitTestCase {
|
|||
'collection',
|
||||
array(
|
||||
'name' => 'test',
|
||||
'status' => 'publish'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue