Removes Taxonomy Selectbox filter type and replace metadata input types selectbox by radio (#121)
This commit is contained in:
parent
ddf6f7de3f
commit
d497d43c42
|
@ -30,7 +30,6 @@ import FilterTaginput from '../../classes/filter-types/taginput/Taginput.vue';
|
|||
|
||||
import FilterTaxonomyCheckbox from '../../classes/filter-types/taxonomy/Checkbox.vue';
|
||||
import FilterTaxonomyTaginput from '../../classes/filter-types/taxonomy/Taginput.vue';
|
||||
import FilterTaxonomySelectbox from '../../classes/filter-types/taxonomy/Selectbox.vue';
|
||||
|
||||
import TainacanFormItem from '../../classes/metadata-types/tainacan-form-item.vue';
|
||||
import TainacanFiltersList from '../../classes/filter-types/tainacan-filter-item.vue';
|
||||
|
@ -82,7 +81,6 @@ Vue.component('tainacan-filter-checkbox', FilterCheckbox);
|
|||
Vue.component('tainacan-filter-taginput', FilterTaginput);
|
||||
Vue.component('tainacan-filter-taxonomy-checkbox', FilterTaxonomyCheckbox);
|
||||
Vue.component('tainacan-filter-taxonomy-taginput', FilterTaxonomyTaginput);
|
||||
Vue.component('tainacan-filter-taxonomy-selectbox', FilterTaxonomySelectbox);
|
||||
|
||||
/* Others */
|
||||
Vue.component('help-button', HelpButton);
|
||||
|
|
|
@ -26,7 +26,6 @@ import FilterTaginput from '../../classes/filter-types/taginput/Taginput.vue';
|
|||
|
||||
import FilterTaxonomyCheckbox from '../../classes/filter-types/taxonomy/Checkbox.vue';
|
||||
import FilterTaxonomyTaginput from '../../classes/filter-types/taxonomy/Taginput.vue';
|
||||
import FilterTaxonomySelectbox from '../../classes/filter-types/taxonomy/Selectbox.vue';
|
||||
|
||||
import TaincanFormItem from '../../classes/metadata-types/tainacan-form-item.vue';
|
||||
import TaincanFiltersList from '../../classes/filter-types/tainacan-filter-item.vue';
|
||||
|
@ -78,7 +77,6 @@ Vue.component('tainacan-filter-checkbox', FilterCheckbox);
|
|||
Vue.component('tainacan-filter-taginput', FilterTaginput);
|
||||
Vue.component('tainacan-filter-taxonomy-checkbox', FilterTaxonomyCheckbox);
|
||||
Vue.component('tainacan-filter-taxonomy-taginput', FilterTaxonomyTaginput);
|
||||
Vue.component('tainacan-filter-taxonomy-selectbox', FilterTaxonomySelectbox);
|
||||
|
||||
/* Others */
|
||||
Vue.component('help-button', HelpButton);
|
||||
|
|
|
@ -1,145 +0,0 @@
|
|||
<template>
|
||||
<div class="block">
|
||||
<b-select
|
||||
:id="id"
|
||||
:loading="isLoading"
|
||||
:value="selected"
|
||||
@input="onSelect($event)"
|
||||
size="is-small"
|
||||
expanded
|
||||
:placeholder="$i18n.get('label_selectbox_init')">
|
||||
<option value="">{{ $i18n.get('label_selectbox_init') }}...</option>
|
||||
<option
|
||||
v-for=" (option, index) in options"
|
||||
:key="index"
|
||||
:label="option.label"
|
||||
:value="option.value">{{ option.label }}</option>
|
||||
</b-select>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import qs from 'qs';
|
||||
import { tainacan as axios } from "../../../js/axios/axios";
|
||||
|
||||
export default {
|
||||
created() {
|
||||
this.collection = this.collection_id
|
||||
? this.collection_id
|
||||
: this.filter.collection_id;
|
||||
this.metadatum = this.metadatum_id
|
||||
? this.metadatum_id
|
||||
: this.filter.metadatum.metadatum_id;
|
||||
this.type = this.filter_type
|
||||
? this.filter_type
|
||||
: this.filter.metadatum.metadata_type;
|
||||
this.loadOptions();
|
||||
|
||||
this.$eventBusSearch.$on("removeFromFilterTag", filterTag => {
|
||||
if (filterTag.filterId == this.filter.id) {
|
||||
this.onSelect();
|
||||
}
|
||||
});
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
isLoading: false,
|
||||
options: [],
|
||||
collection: "",
|
||||
metadatum: "",
|
||||
selected: "",
|
||||
taxonomy: ""
|
||||
};
|
||||
},
|
||||
props: {
|
||||
filter: {
|
||||
type: Object // concentrate all attributes metadatum id and type
|
||||
},
|
||||
metadatum_id: [Number], // not required, but overrides the filter metadatum id if is set
|
||||
collection_id: [Number], // not required, but overrides the filter metadatum id if is set
|
||||
filter_type: [String], // not required, but overrides the filter metadatum type if is set
|
||||
id: "",
|
||||
query: {
|
||||
type: Object // concentrate all attributes metadatum id and type
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
loadOptions() {
|
||||
this.isLoading = true;
|
||||
let query_items = { 'current_query': this.query };
|
||||
|
||||
axios.get('/collection/'+ this.collection +'/facets/' + this.metadatum + `?hideempty=0&order=asc&` + qs.stringify(query_items))
|
||||
.then( res => {
|
||||
|
||||
for (let item of res.data) {
|
||||
this.taxonomy = item.taxonomy;
|
||||
this.taxonomy_id = item.taxonomy_id;
|
||||
this.options.push(item);
|
||||
}
|
||||
|
||||
this.isLoading = false;
|
||||
this.selectedValues();
|
||||
})
|
||||
.catch(error => {
|
||||
this.$console.log(error);
|
||||
this.isLoading = false;
|
||||
});
|
||||
},
|
||||
getOptions(parent, level = 0) {
|
||||
// retrieve only ids
|
||||
let result = [];
|
||||
if (this.options) {
|
||||
for (let term of this.options) {
|
||||
if (term.parent == parent) {
|
||||
term["level"] = level;
|
||||
result.push(term);
|
||||
const levelTerm = level + 1;
|
||||
const children = this.getOptions(term.value, levelTerm);
|
||||
result = result.concat(children);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
},
|
||||
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];
|
||||
this.selected = metadata.terms;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
onSelect(value) {
|
||||
this.selected = value;
|
||||
this.$emit("input", {
|
||||
filter: "selectbox",
|
||||
compare: "IN",
|
||||
taxonomy: this.taxonomy,
|
||||
metadatum_id: this.metadatum,
|
||||
collection_id: this.collection,
|
||||
terms: this.selected
|
||||
});
|
||||
|
||||
let valueIndex = this.options.findIndex(
|
||||
option => option.value == this.selected
|
||||
);
|
||||
if (valueIndex >= 0) {
|
||||
this.$eventBusSearch.$emit("sendValuesToTags", {
|
||||
filterId: this.filter.id,
|
||||
value: this.options[valueIndex].label
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -22,6 +22,6 @@ class TaxonomyCheckbox extends Filter_Type {
|
|||
return '<tainacan-filter-taxonomy-checkbox name="'.$filter->get_name().'"
|
||||
filter_type="'.$filter->get_metadatum()->get_metadata_type().'"
|
||||
collection_id="'.$filter->get_collection_id().'"
|
||||
metadatum_id="'.$filter->get_metadatum()->get_id().'"></tainacan-filter-checkbox>';
|
||||
metadatum_id="'.$filter->get_metadatum()->get_id().'"></tainacan-filter-taxonomy-checkbox>';
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
namespace Tainacan\Filter_Types;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanMetadatumType
|
||||
*/
|
||||
class TaxonomySelectbox extends Filter_Type {
|
||||
|
||||
function __construct(){
|
||||
$this->set_supported_types(['term']);
|
||||
$this->set_component('tainacan-filter-taxonomy-selectbox');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filter
|
||||
* @return string
|
||||
*/
|
||||
|
||||
public function render( $filter ){
|
||||
return '<tainacan-filter-taxonomy-selectbox name="'.$filter->get_name().'"
|
||||
filter_type="'.$filter->get_metadatum()->get_metadata_type().'"
|
||||
collection_id="'.$filter->get_collection_id().'"
|
||||
metadatum_id="'.$filter->get_metadatum()->get_id().'"></tainacan-filter-selectbox>';
|
||||
}
|
||||
}
|
|
@ -22,6 +22,6 @@ class TaxonomyTaginput extends Filter_Type {
|
|||
return '<tainacan-filter-taxonomy-taginput name="'.$filter->get_name().'"
|
||||
filter_type="'.$filter->get_metadatum()->get_metadata_type().'"
|
||||
collection_id="'.$filter->get_collection_id().'"
|
||||
metadatum_id="'.$filter->get_metadatum()->get_id().'"></tainacan-filter-taginput>';
|
||||
metadatum_id="'.$filter->get_metadatum()->get_id().'"></tainacan-filter-taxonomy-taginput>';
|
||||
}
|
||||
}
|
|
@ -107,7 +107,6 @@
|
|||
}
|
||||
|
||||
this.single_types['tainacan-taxonomy-radio'] = 'Radio';
|
||||
this.single_types['tainacan-taxonomy-selectbox'] = 'Selectbox';
|
||||
this.multiple_types['tainacan-taxonomy-tag-input'] = 'Tag Input';
|
||||
this.multiple_types['tainacan-taxonomy-checkbox'] = 'Checkbox';
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
import TainacanTaxonomyRadio from './TaxonomyRadio.vue'
|
||||
import TainacanTaxonomyCheckbox from './TaxonomyCheckbox.vue'
|
||||
import TainacanTaxonomyTagInput from './TaxonomyTaginput.vue'
|
||||
import TainacanTaxonomySelectbox from './TaxonomySelectbox.vue'
|
||||
import AddNewTerm from './AddNewTerm.vue'
|
||||
import HierarchicalCheckboxModal from '../../../admin/components/other/checkbox-filter-modal.vue'
|
||||
|
||||
|
@ -63,7 +62,6 @@
|
|||
TainacanTaxonomyRadio,
|
||||
TainacanTaxonomyCheckbox,
|
||||
TainacanTaxonomyTagInput,
|
||||
TainacanTaxonomySelectbox,
|
||||
AddNewTerm
|
||||
},
|
||||
data(){
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
<template>
|
||||
<div>
|
||||
<div class="block">
|
||||
<b-select
|
||||
:disabled="disabled"
|
||||
:id="id"
|
||||
v-model="selected"
|
||||
@input="emitChange()"
|
||||
:placeholder="$i18n.get('label_select_taxonomy')"
|
||||
expanded>
|
||||
<option
|
||||
v-for="(option, index) in options"
|
||||
:key="index"
|
||||
:value="option.id"
|
||||
v-html="setSpaces( option.level ) + option.name"/>
|
||||
</b-select>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
export default {
|
||||
created(){
|
||||
if( this.value )
|
||||
this.selected = this.value;
|
||||
},
|
||||
data(){
|
||||
return {
|
||||
selected: ''
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
value( val ){
|
||||
this.selected = val;
|
||||
}
|
||||
},
|
||||
props: {
|
||||
id: String,
|
||||
options: {
|
||||
type: Array
|
||||
},
|
||||
value: [ Number, String, Array ],
|
||||
disabled: false,
|
||||
},
|
||||
methods: {
|
||||
emitChange() {
|
||||
this.$emit('input', this.selected);
|
||||
this.$emit('blur');
|
||||
},
|
||||
setSpaces( level ){
|
||||
let result = '';
|
||||
let space = ' '
|
||||
|
||||
for(let i = 0;i < level; i++)
|
||||
result += space;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -73,7 +73,7 @@ function tainacan_autoload($class_name){
|
|||
}
|
||||
|
||||
if( in_array('Metadata_Types', $class_path) || in_array('Filter_Types', $class_path) ){
|
||||
$exceptions = ['taxonomytaginput','taxonomycheckbox','taxonomyselectbox'];
|
||||
$exceptions = ['taxonomytaginput','taxonomycheckbox'];
|
||||
if( in_array( strtolower( $class_name ), $exceptions) ){
|
||||
$dir.= 'taxonomy/';
|
||||
}else{
|
||||
|
@ -115,7 +115,6 @@ $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Taginput');
|
|||
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Checkbox');
|
||||
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\TaxonomyTaginput');
|
||||
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\TaxonomyCheckbox');
|
||||
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\TaxonomySelectbox');
|
||||
|
||||
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
|
||||
|
||||
|
|
|
@ -239,7 +239,16 @@ class Migrations {
|
|||
['meta_value' => 'Tainacan\Filter_Types\TaxonomySelectbox'],
|
||||
['meta_value' => 'Tainacan\Filter_Types\CategorySelectbox'],
|
||||
'%s', '%s');
|
||||
|
||||
|
||||
$wpdb->update($wpdb->postmeta,
|
||||
['meta_value' => 'Tainacan\Filter_Types\TaxonomyTaginput'],
|
||||
['meta_value' => 'Tainacan\Filter_Types\TaxonomySelectbox'],
|
||||
'%s', '%s');
|
||||
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"UPDATE $wpdb->postmeta SET meta_value = REPLACE(meta_value, 'tainacan-taxonomy-selectbox', 'tainacan-taxonomy-radio')"
|
||||
));
|
||||
}
|
||||
|
||||
static function update_core_metadata() {
|
||||
|
|
Loading…
Reference in New Issue