Merge pull request #895 from tainacan/feature/894

Feature: Add placeholder option to most filters. #894.
This commit is contained in:
Mateus Machado Luna 2024-06-12 18:29:31 -03:00 committed by GitHub
commit 5950929dfc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 89 additions and 22 deletions

View File

@ -72,9 +72,16 @@ class Filter extends Entity {
/**
* @return mixed|null
*/
function get_description(){
function get_description() {
return $this->get_mapped_property('description');
}
/**
* @return mixed|null
*/
function get_placeholder() {
return $this->get_mapped_property('placeholder');
}
/**
* Return the filter order type
@ -220,6 +227,16 @@ class Filter extends Entity {
$this->set_mapped_property('description', $value);
}
/**
* Define the filter placeholder
*
* @param [string] $value
* @return void
*/
function set_placeholder($value) {
$this->set_mapped_property('placeholder', $value);
}
/**
* Define the filter metadatum passing an object
*

View File

@ -110,7 +110,14 @@ class Filters extends Repository {
'description' => __( 'The max number of options to be showed in filter sidebar.', 'tainacan' ),
'validation' => '',
'default' => 4
]
],
'placeholder' => [
'map' => 'meta',
'title' => __( 'Placeholder', 'tainacan' ),
'type' => 'string',
'description' => __( 'The filter input placeholder. This is a simple message that will appear inside textual input and may indicate to the user what kind of information is expected.', 'tainacan' ),
'default' => '',
],
] );
}

View File

@ -49,6 +49,24 @@
@focus="clearErrors('description')" />
</b-field>
<b-field
v-if="form.filter_type_object.use_input_placeholder"
:addons="false"
:type="formErrors['placeholder'] != undefined ? 'is-danger' : ''"
:message="formErrors['placeholder'] != undefined ? formErrors['placeholder'] : ''">
<label class="label is-inline">
{{ $i18n.getHelperTitle('filters', 'placeholder') }}
<help-button
:title="$i18n.getHelperTitle('filters', 'placeholder')"
:message="$i18n.getHelperMessage('filters', 'placeholder')"
:extra-classes="isRepositoryLevel ? 'tainacan-repository-tooltip' : ''" />
</label>
<b-input
v-model="form.placeholder"
name="placeholder"
@focus="clearErrors('placeholder')" />
</b-field>
<b-field
:addons="false"
:type="formErrors['status'] != undefined ? 'is-danger' : ''"

View File

@ -10,7 +10,7 @@
:loading="isLoadingOptions"
field="label"
clearable
:placeholder="(metadatumType === 'Tainacan\\Metadata_Types\\Relationship') ? $i18n.get('info_type_to_search_items') : $i18n.get('info_type_to_search_metadata')"
:placeholder="filter.placeholder ? filter.placeholder : ( (metadatumType === 'Tainacan\\Metadata_Types\\Relationship') ? $i18n.get('info_type_to_search_items') : $i18n.get('info_type_to_search_metadata') )"
check-infinite-scroll
@update:model-value="($event) => { resetPage(); search($event); }"
@select="onSelect"

View File

@ -12,6 +12,7 @@ class Checkbox extends Filter_Type {
$this->set_name( __('Checkbox List', 'tainacan') );
$this->set_supported_types(['string','long_string','item', 'control']);
$this->set_component('tainacan-filter-checkbox');
$this->set_use_input_placeholder(false);
$this->set_preview_template('
<div>
<div>

View File

@ -3,7 +3,7 @@
<b-datepicker
v-model="dateInit"
:aria-labelledby="'filter-label-id-' + filter.id"
:placeholder="$i18n.get('instruction_select_a_date')"
:placeholder="filter.placeholder ? filter.placeholder : $i18n.get('instruction_select_a_date')"
editable
:trap-focus="false"
:date-formatter="(date) => dateFormatter(date)"
@ -43,7 +43,7 @@
<b-datepicker
v-model="dateEnd"
:aria-labelledby="'filter-label-id-' + filter.id"
:placeholder="$i18n.get('label_selectbox_init')"
:placeholder="filter.placeholder ? filter.placeholder : $i18n.get('instruction_select_a_date')"
editable
:trap-focus="false"
:date-formatter="(date) => dateFormatter(date)"

View File

@ -34,7 +34,7 @@
v-model="value"
position="is-bottom-right"
:aria-labelledby="'filter-label-id-' + filter.id"
:placeholder="$i18n.get('instruction_select_a_date')"
:placeholder="filter.placeholder ? filter.placeholder : $i18n.get('instruction_select_a_date')"
editable
:trap-focus="false"
:date-formatter="(date) => dateFormatter(date)"

View File

@ -3,7 +3,7 @@
<b-datepicker
v-model="dateInit"
:aria-labelledby="'filter-label-id-' + filter.id"
:placeholder="$i18n.get('instruction_select_a_date')"
:placeholder="filter.placeholder ? filter.placeholder : $i18n.get('instruction_select_a_date')"
editable
:trap-focus="false"
:date-formatter="(date) => dateFormatter(date)"
@ -45,7 +45,7 @@
v-if="filterTypeOptions.accept_date_interval === 'yes'"
v-model="dateEnd"
:aria-labelledby="'filter-label-id-' + filter.id"
:placeholder="$i18n.get('instruction_select_a_date')"
:placeholder="filter.placeholder ? filter.placeholder : $i18n.get('instruction_select_a_date')"
editable
:trap-focus="false"
:date-formatter="(date) => dateFormatter(date)"

View File

@ -53,8 +53,17 @@ abstract class Filter_Type {
* @var string
*/
private $preview_template = '';
/**
* Defines if the filter type should use the max options
*/
protected $use_max_options = true;
/**
* Defines if the filter type should provide a placeholder for the input field
*/
protected $use_input_placeholder = true;
public function __construct(){
add_action('register_filter_types', array(&$this, 'register_filter_type'));
}
@ -126,15 +135,16 @@ abstract class Filter_Type {
public function _toArray(){
$attributes = [];
$attributes['className'] = get_class($this);
$attributes['name'] = $this->get_name();
$attributes['component'] = $this->get_component();
$attributes['script'] = $this->get_script();
$attributes['options'] = $this->get_options();
$attributes['supported_types'] = $this->get_supported_types();
$attributes['preview_template'] = $this->get_preview_template();
$attributes['use_max_options'] = $this->get_use_max_options();
$attributes['form_component'] = $this->get_form_component();
$attributes['className'] = get_class($this);
$attributes['name'] = $this->get_name();
$attributes['component'] = $this->get_component();
$attributes['script'] = $this->get_script();
$attributes['options'] = $this->get_options();
$attributes['supported_types'] = $this->get_supported_types();
$attributes['preview_template'] = $this->get_preview_template();
$attributes['use_max_options'] = $this->get_use_max_options();
$attributes['use_input_placeholder'] = $this->get_use_input_placeholder();
$attributes['form_component'] = $this->get_form_component();
return $attributes;
}
@ -208,6 +218,14 @@ abstract class Filter_Type {
return $this->use_max_options;
}
public function set_use_input_placeholder($use_input_placeholder) {
$this->use_input_placeholder = $use_input_placeholder;
}
public function get_use_input_placeholder() {
return $this->use_input_placeholder;
}
/**
* Gets one option from the options array.
*

View File

@ -5,6 +5,7 @@
:aria-labelledby="'filter-label-id-' + filter.id"
:aria-minus-label="$i18n.get('label_decrease')"
:aria-plus-label="$i18n.get('label_increase')"
:placeholder="filter.placeholder ? filter.placeholder : ''"
size="is-small"
:step="filterTypeOptions.step"
@update:model-value="($event) => { resetPage(); validadeValues($event) }"
@ -19,6 +20,7 @@
:aria-labelledby="'filter-label-id-' + filter.id"
:aria-minus-label="$i18n.get('label_decrease')"
:aria-plus-label="$i18n.get('label_increase')"
:placeholder="filter.placeholder ? filter.placeholder : ''"
size="is-small"
:step="filterTypeOptions.step"
@update:model-value="($event) => { resetPage(); validadeValues($event) }" />

View File

@ -3,7 +3,7 @@
<b-select
v-model="selectedInterval"
expanded
:placeholder="$i18n.get('instruction_select_a_interval')"
:placeholder="filter.placeholder ? filter.placeholder : $i18n.get('instruction_select_a_interval')"
@update:model-value="($event) => { resetPage; changeInterval($event) }">
<option value="">
{{ $i18n.get('label_selectbox_init') }}...

View File

@ -35,6 +35,7 @@
:aria-labelledby="'filter-label-id-' + filter.id"
:aria-minus-label="$i18n.get('label_decrease')"
:aria-plus-label="$i18n.get('label_increase')"
:placeholder="filter.placeholder ? filter.placeholder : ''"
size="is-small"
:step="Number(filterTypeOptions.step)"
@update:model-value="($event) => { resetPage($event); emit($event); }" />

View File

@ -5,6 +5,7 @@
:aria-labelledby="'filter-label-id-' + filter.id"
:aria-minus-label="$i18n.get('label_decrease')"
:aria-plus-label="$i18n.get('label_increase')"
:placeholder="filter.placeholder ? filter.placeholder : ''"
size="is-small"
:step="filterTypeOptions.step"
@update:model-value="($event) => { resetPage(); validadeValues($event) }"
@ -21,6 +22,7 @@
:aria-labelledby="'filter-label-id-' + filter.id"
:aria-minus-label="$i18n.get('label_decrease')"
:aria-plus-label="$i18n.get('label_increase')"
:placeholder="filter.placeholder ? filter.placeholder : ''"
size="is-small"
:step="filterTypeOptions.step"
@update:model-value="($event) => { resetPage(); validadeValues($event) }" />

View File

@ -6,7 +6,7 @@
v-if="!isLoadingOptions"
:model-value="selected"
:aria-labelledby="'filter-label-id-' + filter.id"
:placeholder="$i18n.get('label_selectbox_init')"
:placeholder="filter.placeholder ? filter.placeholder : $i18n.get('label_selectbox_init')"
expanded
@update:model-value="($event) => { resetPage(); onSelect($event) }">
<option value="">

View File

@ -13,7 +13,7 @@
attached
:aria-close-label="$i18n.get('remove_value')"
:aria-labelledby="'filter-label-id-' + filter.id"
:placeholder="getInputPlaceholder"
:placeholder="filter.placeholder ? filter.placeholder : getInputPlaceholder()"
check-infinite-scroll
@update:model-value="($event) => { resetPage(); onSelect($event) }"
@typing="search"

View File

@ -14,7 +14,7 @@
:aria-close-label="$i18n.get('remove_value')"
:aria-labelledby="'filter-label-id-' + filter.id"
:class="{'has-selected': selected != undefined && selected != []}"
:placeholder="$i18n.get('info_type_to_add_terms')"
:placeholder="filter.placeholder ? filter.placeholder : $i18n.get('info_type_to_add_terms')"
check-infinite-scroll
@typing="search"
@focus="($event) => { searchQuery = $event.target.value; performSearch(searchQuery) }"

View File

@ -12,6 +12,7 @@ class TaxonomyCheckbox extends Filter_Type {
$this->set_name( __('Taxonomy Checkbox List', 'tainacan') );
$this->set_supported_types(['term']);
$this->set_component('tainacan-filter-taxonomy-checkbox');
$this->set_use_input_placeholder(false);
$this->set_preview_template('
<div>
<div>

View File

@ -98,7 +98,7 @@ export const removeMetaQuery = ( state, filter ) => {
state.postquery.metaquery[index].value.splice(otherIndex, 1)
} else
state.postquery.metaquery.splice(index, 1);
console.log(filter)
// Handles removing metaqueries from secondary filter metadata
if ( filter.secondaryMetadatumId ) {
let secondaryIndex = state.postquery.metaquery.findIndex( item => item.key == filter.secondaryMetadatumId);