alter the name Range filter type to Custom Interval, create the autocomplete filter type
This commit is contained in:
parent
fdd6203df2
commit
b638a55409
|
@ -0,0 +1,114 @@
|
|||
<template>
|
||||
<div class="block">
|
||||
<b-autocomplete
|
||||
rounded
|
||||
icon="magnify"
|
||||
:id="id"
|
||||
v-model="selected"
|
||||
:data="options"
|
||||
@input="search"
|
||||
:loading="loading"
|
||||
field="label"
|
||||
@select="option => setResults(option) ">
|
||||
</b-autocomplete>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import axios from '../../../js/axios/axios'
|
||||
|
||||
export default {
|
||||
created(){
|
||||
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id;
|
||||
this.type = ( this.filter_type ) ? this.filter_type : this.filter.field.field_type;
|
||||
},
|
||||
data(){
|
||||
return {
|
||||
results:'',
|
||||
selected:'',
|
||||
options: [],
|
||||
isLoading: false,
|
||||
type: '',
|
||||
collection: '',
|
||||
selected: '',
|
||||
}
|
||||
},
|
||||
props: {
|
||||
filter: {
|
||||
type: Object // concentrate all attributes field id and type
|
||||
},
|
||||
field_id: [Number], // not required, but overrides the filter field id if is set
|
||||
collection_id: [Number], // not required, but overrides the filter field id if is set
|
||||
filter_type: [String], // not required, but overrides the filter field type if is set
|
||||
id: ''
|
||||
},
|
||||
methods: {
|
||||
setResults(option){
|
||||
if(!option)
|
||||
return;
|
||||
this.results = option.value;
|
||||
this.onSelect()
|
||||
},
|
||||
onSelect(){
|
||||
let filter = null;
|
||||
if ( this.type ) {
|
||||
filter = 'term';
|
||||
} else {
|
||||
filter = 'selectbox';
|
||||
}
|
||||
|
||||
this.$emit('input', {
|
||||
filter: filter,
|
||||
field_id: ( this.field_id ) ? this.field_id : this.filter.field,
|
||||
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
|
||||
value: this.results
|
||||
});
|
||||
},
|
||||
search( query ){
|
||||
let promise = null;
|
||||
this.options = [];
|
||||
|
||||
if ( this.type === 'Tainacan\Field_types\Relationship' ) {
|
||||
|
||||
let collectionTarget = ( this.filter && this.filter.field.field_type_options.collection_id ) ?
|
||||
this.filter.field.field_type_options.collection_id : this.collection_id;
|
||||
promise = this.getValuesRelationship( collectionTarget, query );
|
||||
|
||||
} else if ( this.type === 'Tainacan\Field_types\Category' ) {
|
||||
|
||||
let collectionTarget = ( this.filter && this.filter.field.field_type_options.taxonomy ) ?
|
||||
this.filter.field.field_type_options.taxonomy : this.taxonomy;
|
||||
promise = this.getValuesCategory( collectionTarget, query );
|
||||
|
||||
} else {
|
||||
promise = this.getValuesPlainText( this.filter.field.id, query );
|
||||
}
|
||||
|
||||
promise.then( data => {
|
||||
this.isLoading = false;
|
||||
})
|
||||
.catch( error => {
|
||||
console.log('error select', error );
|
||||
this.isLoading = false;
|
||||
});
|
||||
},
|
||||
getValuesPlainText( field_id ){
|
||||
// TODO: get values from items
|
||||
},
|
||||
getValuesCategory( taxonomy ){
|
||||
// TODO: get taxonomy terms
|
||||
},
|
||||
getValuesRelationship( collectionTarget, search ){
|
||||
return axios.get( '/collection/' + collectionTarget + '/items?s=' + search )
|
||||
.then( res => {
|
||||
for (let item of res.data) {
|
||||
this.options.push({ label: item.title, value: item.id })
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
namespace Tainacan\Filter_Types;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Class TainacanFieldType
|
||||
*/
|
||||
class Autocomplete extends Filter_Type {
|
||||
|
||||
function __construct(){
|
||||
parent::set_supported_types(['string','Tainacan\Field_Types\Relationship']);
|
||||
$this->component = 'tainacan-filter-autocomplete';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filter
|
||||
* @return string
|
||||
*/
|
||||
|
||||
public function render( $filter ){
|
||||
return '<tainacan-filter-autocomplete name="'.$filter->get_name().'"
|
||||
collection_id="'.$filter->get_collection_id().'"
|
||||
field_id="'.$filter->get_field()->get_id().'"></tainacan-filter-autocomplete>';
|
||||
}
|
||||
}
|
|
@ -7,11 +7,11 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
|||
/**
|
||||
* Class TainacanFieldType
|
||||
*/
|
||||
class Range extends Filter_Type {
|
||||
class Custom_Interval extends Filter_Type {
|
||||
|
||||
function __construct(){
|
||||
parent::set_supported_types(['float','date']);
|
||||
$this->component = 'tainacan-filter-range';
|
||||
$this->component = 'tainacan-filter-custom-interval';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,10 +20,10 @@ class Range extends Filter_Type {
|
|||
*/
|
||||
public function render( $filter ){
|
||||
$type = ( $filter->get_field()->get_field_type() === 'Tainacan\Field_Types\Date' ) ? 'date' : 'numeric';
|
||||
return '<tainacan-filter-range
|
||||
return '<tainacan-filter-custom-interval
|
||||
name="'.$filter->get_name().'"
|
||||
typeRange="'.$type.'"
|
||||
collection_id="'.$filter->get_collection_id().'"
|
||||
field_id="'.$filter->get_field()->get_id().'"></tainacan-filter-range>';
|
||||
field_id="'.$filter->get_field()->get_id().'"></tainacan-filter-custom-interval>';
|
||||
}
|
||||
}
|
|
@ -1,20 +1,18 @@
|
|||
<template>
|
||||
<div class="block">
|
||||
<b-field>
|
||||
<b-select
|
||||
:id = "id"
|
||||
:laoding = "isLoading"
|
||||
v-model = "selected"
|
||||
@input = "onSelect()"
|
||||
expanded>
|
||||
<option
|
||||
v-for="option,index in options"
|
||||
:key="index"
|
||||
:label="option.label"
|
||||
:value="option.value"
|
||||
border>{{ option.label }}</option>
|
||||
</b-select>
|
||||
</b-field>
|
||||
<b-select
|
||||
:id = "id"
|
||||
:laoding = "isLoading"
|
||||
v-model = "selected"
|
||||
@input = "onSelect()"
|
||||
expanded>
|
||||
<option
|
||||
v-for="option,index in options"
|
||||
:key="index"
|
||||
:label="option.label"
|
||||
:value="option.value"
|
||||
border>{{ option.label }}</option>
|
||||
</b-select>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -24,6 +22,7 @@
|
|||
export default {
|
||||
created(){
|
||||
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id;
|
||||
this.type = ( this.filter_type ) ? this.filter_type : this.filter.field.field_type;
|
||||
this.loadOptions();
|
||||
},
|
||||
data(){
|
||||
|
|
|
@ -94,7 +94,7 @@ global $Tainacan_Filters;
|
|||
$Tainacan_Filters = new \Tainacan\Repositories\Filters();
|
||||
|
||||
//register filter type
|
||||
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Range');
|
||||
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Custom_Interval');
|
||||
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Selectbox');
|
||||
|
||||
global $Tainacan_Taxonomies;
|
||||
|
|
|
@ -186,7 +186,7 @@ class DevInterface {
|
|||
<?php Helpers\HtmlHelpers::collections_dropdown( $value ); ?>
|
||||
<?php elseif ($prop == 'collections_ids'): ?>
|
||||
<?php Helpers\HtmlHelpers::collections_checkbox_list( $value ); ?>
|
||||
<?php elseif ($prop == 'field'): ?>
|
||||
<?php elseif ( $prop == 'field' && $entity->get_collection_id() ): ?>
|
||||
<?php Helpers\HtmlHelpers::metadata_dropdown(
|
||||
$entity->get_collection_id(),
|
||||
( isset( $value ) ) ? $value : '',
|
||||
|
|
|
@ -20,7 +20,7 @@ import Numeric from '../classes/field-types/numeric/Numeric.vue';
|
|||
import Date from '../classes/field-types/date/Date.vue';
|
||||
import Relationship from '../classes/field-types/relationship/Relationship.vue';
|
||||
|
||||
import FilterRange from '../classes/filter-types/range/Range.vue';
|
||||
import FilterCustomInterval from '../classes/filter-types/custom-interval/CustomInterval.vue';
|
||||
import FilterSelectbox from '../classes/filter-types/selectbox/Selectbox.vue';
|
||||
|
||||
Vue.customElement('tainacan-text', Text);
|
||||
|
@ -51,8 +51,8 @@ eventBus.listener();
|
|||
|
||||
/* Filters */
|
||||
|
||||
Vue.customElement('tainacan-filter-range', FilterRange);
|
||||
eventFilterBus.registerComponent( 'tainacan-filter-range' );
|
||||
Vue.customElement('tainacan-filter-custom-interval', FilterCustomInterval);
|
||||
eventFilterBus.registerComponent( 'tainacan-filter-custom-interval' );
|
||||
|
||||
Vue.customElement('tainacan-filter-selectbox', FilterSelectbox);
|
||||
eventFilterBus.registerComponent( 'tainacan-filter-selectbox' );
|
||||
|
|
|
@ -32,10 +32,10 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
|
|||
|
||||
$request_body = json_encode(
|
||||
array(
|
||||
'filter_type' => 'range',
|
||||
'filter_type' => 'custom_interval',
|
||||
'filter' => [
|
||||
'name' => 'Filter name',
|
||||
'description' => 'This is RANGE!',
|
||||
'description' => 'This is CUSTOM INTERVAL!',
|
||||
]
|
||||
)
|
||||
);
|
||||
|
@ -48,7 +48,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
|
|||
|
||||
$data = $response->get_data();
|
||||
$this->assertTrue(is_array($data) && array_key_exists('filter_type', $data), sprintf('cannot create a range, response: %s', print_r($data, true)));
|
||||
$this->assertEquals('Tainacan\Filter_Types\Range', $data['filter_type']);
|
||||
$this->assertEquals('Tainacan\Filter_Types\Custom_Interval', $data['filter_type']);
|
||||
$this->assertEquals('Filter name', $data['name']);
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
|
|||
)
|
||||
);
|
||||
|
||||
$filter_type = $this->tainacan_filter_factory->create_filter('range');
|
||||
$filter_type = $this->tainacan_filter_factory->create_filter('custom_interval');
|
||||
|
||||
$filter = $this->tainacan_entity_factory->create_entity(
|
||||
'filter',
|
||||
|
@ -141,7 +141,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
|
|||
)
|
||||
);
|
||||
|
||||
$filter_type = $this->tainacan_filter_factory->create_filter('range');
|
||||
$filter_type = $this->tainacan_filter_factory->create_filter('custom_interval');
|
||||
|
||||
$filter = $this->tainacan_entity_factory->create_entity(
|
||||
'filter',
|
||||
|
@ -201,7 +201,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
|
|||
)
|
||||
);
|
||||
|
||||
$filter_type = $this->tainacan_filter_factory->create_filter('range');
|
||||
$filter_type = $this->tainacan_filter_factory->create_filter('custom_interval');
|
||||
|
||||
$filter = $this->tainacan_entity_factory->create_entity(
|
||||
'filter',
|
||||
|
|
|
@ -79,7 +79,7 @@ class Filters extends TAINACAN_UnitTestCase {
|
|||
true
|
||||
);
|
||||
|
||||
$filter_range_type = $this->tainacan_filter_factory->create_filter('range');
|
||||
$filter_range_type = $this->tainacan_filter_factory->create_filter('custom_interval');
|
||||
|
||||
//nao devera permitir um filtro Range para o tipo string
|
||||
$this->assertTrue( $filter->set_filter_type( $filter_range_type ) === null );
|
||||
|
|
Loading…
Reference in New Issue