Adds first and second comparator options to intersection metadata. #887.
This commit is contained in:
parent
685b61b0b1
commit
a9df08c15f
|
@ -420,7 +420,7 @@ export default {
|
||||||
-webkit-column-gap: 0;
|
-webkit-column-gap: 0;
|
||||||
-webkit-column-rule: none;
|
-webkit-column-rule: none;
|
||||||
column-count: 2;
|
column-count: 2;
|
||||||
column-gap: 4em;
|
column-gap: 3em;
|
||||||
column-rule: none;
|
column-rule: none;
|
||||||
padding-bottom: 0.5em;
|
padding-bottom: 0.5em;
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,46 @@
|
||||||
</option>
|
</option>
|
||||||
</b-select>
|
</b-select>
|
||||||
</b-field>
|
</b-field>
|
||||||
|
<div style="column-count: 2;">
|
||||||
|
<b-field :addons="false">
|
||||||
|
<label
|
||||||
|
style="line-height: normal;"
|
||||||
|
class="label is-inline">
|
||||||
|
{{ $i18n.getHelperTitle('tainacan-filter-dates-intersection', 'first_comparator') }}<span> * </span>
|
||||||
|
<help-button
|
||||||
|
:title="$i18n.getHelperTitle('tainacan-filter-dates-intersection', 'first_comparator')"
|
||||||
|
:message="$i18n.getHelperMessage('tainacan-filter-dates-intersection', 'first_comparator')" />
|
||||||
|
</label>
|
||||||
|
<b-select
|
||||||
|
v-model="firstComparator"
|
||||||
|
@update:model-value="emitValues()">
|
||||||
|
<option
|
||||||
|
v-for="(comparatorObject, comparatorKey) in comparatorsObject"
|
||||||
|
:key="comparatorKey"
|
||||||
|
:value="comparatorKey"
|
||||||
|
v-html="comparatorObject.symbol + ' ' + comparatorObject.label" />
|
||||||
|
</b-select>
|
||||||
|
</b-field>
|
||||||
|
<b-field :addons="false">
|
||||||
|
<label
|
||||||
|
style="line-height: normal;"
|
||||||
|
class="label is-inline">
|
||||||
|
{{ $i18n.getHelperTitle('tainacan-filter-dates-intersection', 'second_comparator') }}<span> * </span>
|
||||||
|
<help-button
|
||||||
|
:title="$i18n.getHelperTitle('tainacan-filter-dates-intersection', 'second_comparator')"
|
||||||
|
:message="$i18n.getHelperMessage('tainacan-filter-dates-intersection', 'second_comparator')" />
|
||||||
|
</label>
|
||||||
|
<b-select
|
||||||
|
v-model="secondComparator"
|
||||||
|
@update:model-value="emitValues()">
|
||||||
|
<option
|
||||||
|
v-for="(comparatorObject, comparatorKey) in comparatorsObject"
|
||||||
|
:key="comparatorKey"
|
||||||
|
:value="comparatorKey"
|
||||||
|
v-html="comparatorObject.symbol + ' ' + comparatorObject.label" />
|
||||||
|
</b-select>
|
||||||
|
</b-field>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -50,7 +90,11 @@
|
||||||
loading: true,
|
loading: true,
|
||||||
metadataType: '',
|
metadataType: '',
|
||||||
metadataMessage: '',
|
metadataMessage: '',
|
||||||
secondDateMetadatumId: [Number, String]
|
secondDateMetadatumId: [Number, String],
|
||||||
|
secondDateMetadatumName: String,
|
||||||
|
firstComparator: String,
|
||||||
|
secondComparator: String,
|
||||||
|
comparatorsObject: {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
@ -63,13 +107,46 @@
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.secondDateMetadatumId = this.modelValue && this.modelValue.secondary_filter_metadatum_id ? this.modelValue.secondary_filter_metadatum_id : '';
|
this.secondDateMetadatumId = this.modelValue && this.modelValue.secondary_filter_metadatum_id ? this.modelValue.secondary_filter_metadatum_id : '';
|
||||||
|
this.secondDateMetadatumName = this.modelValue && this.modelValue.secondary_filter_metadatum_name ? this.modelValue.secondary_filter_metadatum_name : '';
|
||||||
|
this.firstComparator = this.modelValue && this.modelValue.first_comparator ? this.modelValue.first_comparator : '>=';
|
||||||
|
this.secondComparator = this.modelValue && this.modelValue.second_comparator ? this.modelValue.second_comparator : '<=';
|
||||||
|
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.fetchMetadata();
|
this.fetchMetadata();
|
||||||
console.log(this.filter)
|
|
||||||
|
this.comparatorsObject = {
|
||||||
|
'=': {
|
||||||
|
symbol: '=',
|
||||||
|
label: this.$i18n.get('is_equal_to')
|
||||||
|
},
|
||||||
|
'!=': {
|
||||||
|
symbol: '≠',
|
||||||
|
label: this.$i18n.get('is_not_equal_to')
|
||||||
|
},
|
||||||
|
'>': {
|
||||||
|
symbol: '>',
|
||||||
|
label: this.$i18n.get('after')
|
||||||
|
},
|
||||||
|
'>=': {
|
||||||
|
symbol: '≥',
|
||||||
|
label: this.$i18n.get('after_or_on_day')
|
||||||
|
},
|
||||||
|
'<': {
|
||||||
|
symbol: '<',
|
||||||
|
label: this.$i18n.get('before')
|
||||||
|
},
|
||||||
|
'<=': {
|
||||||
|
symbol: '≤',
|
||||||
|
label: this.$i18n.get('before_or_on_day')
|
||||||
|
}
|
||||||
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async fetchMetadata() {
|
async fetchMetadata() {
|
||||||
let endpoint = this.filter.collectionId && this.filter.collectionId !== 'default' ? ( '/collections/' + this.filter.collectionId + '/metadata' ) : '/metadata';
|
|
||||||
|
let endpoint = this.filter.collection_id && this.filter.collection_id !== 'default' ? ( '/collection/' + this.filter.collection_id + '/metadata' ) : '/metadata';
|
||||||
|
endpoint += '?metaquery[0][key]=metadata_type&metaquery[0][value]=Tainacan\\Metadata_Types\\Date&nopaging=1&exclude=' + this.filter.metadatum_id;
|
||||||
|
|
||||||
return await tainacanApi.get(endpoint)
|
return await tainacanApi.get(endpoint)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
@ -82,8 +159,17 @@
|
||||||
},
|
},
|
||||||
onUpdateSecondDateMetadatumId() {
|
onUpdateSecondDateMetadatumId() {
|
||||||
const selectedMetadatum = this.metadata.find( aMetadatum => aMetadatum.id == this.secondDateMetadatumId );
|
const selectedMetadatum = this.metadata.find( aMetadatum => aMetadatum.id == this.secondDateMetadatumId );
|
||||||
const selectedMetadatumName = selectedMetadatum ? selectedMetadatum.name : '';
|
this.selectedMetadatumName = selectedMetadatum ? selectedMetadatum.name : '';
|
||||||
this.$emit('update:model-value', { secondary_filter_metadatum_id: this.secondDateMetadatumId, secondary_filter_metadatum_name: selectedMetadatumName});
|
this.selectedMetadatumId = selectedMetadatum ? selectedMetadatum.id : '';
|
||||||
|
this.emitValues();
|
||||||
|
},
|
||||||
|
emitValues() {
|
||||||
|
this.$emit('update:model-value', {
|
||||||
|
first_comparator: this.firstComparator,
|
||||||
|
second_comparator: this.secondComparator,
|
||||||
|
secondary_filter_metadatum_id: this.secondDateMetadatumId,
|
||||||
|
secondary_filter_metadatum_name: this.secondDateMetadatumName
|
||||||
|
});
|
||||||
},
|
},
|
||||||
setErrorsAttributes( type, message ) {
|
setErrorsAttributes( type, message ) {
|
||||||
this.metadataType = type;
|
this.metadataType = type;
|
||||||
|
|
|
@ -159,7 +159,7 @@
|
||||||
this.$emit('input', {
|
this.$emit('input', {
|
||||||
filter: 'intersection',
|
filter: 'intersection',
|
||||||
type: 'DATE',
|
type: 'DATE',
|
||||||
compare: '>=',
|
compare: this.filterTypeOptions.first_comparator,
|
||||||
metadatum_id: this.metadatumId,
|
metadatum_id: this.metadatumId,
|
||||||
collection_id: this.collectionId,
|
collection_id: this.collectionId,
|
||||||
value: values
|
value: values
|
||||||
|
@ -167,7 +167,7 @@
|
||||||
this.$emit('input', {
|
this.$emit('input', {
|
||||||
filter: 'intersection',
|
filter: 'intersection',
|
||||||
type: 'DATE',
|
type: 'DATE',
|
||||||
compare: '<=',
|
compare: this.filterTypeOptions.second_comparator,
|
||||||
metadatum_id: this.filterTypeOptions.secondary_filter_metadatum_id,
|
metadatum_id: this.filterTypeOptions.secondary_filter_metadatum_id,
|
||||||
collection_id: this.collectionId,
|
collection_id: this.collectionId,
|
||||||
value: values
|
value: values
|
||||||
|
|
|
@ -17,6 +17,8 @@ class Dates_Intersection extends Filter_Type {
|
||||||
$this->set_default_options([
|
$this->set_default_options([
|
||||||
'secondary_filter_metadatum_id' => '',
|
'secondary_filter_metadatum_id' => '',
|
||||||
'secondary_filter_metadatum_name' => '',
|
'secondary_filter_metadatum_name' => '',
|
||||||
|
'first_comparator' => '>=',
|
||||||
|
'second_comparator' => '<='
|
||||||
]);
|
]);
|
||||||
$this->set_use_max_options(false);
|
$this->set_use_max_options(false);
|
||||||
$this->set_preview_template('
|
$this->set_preview_template('
|
||||||
|
@ -59,6 +61,14 @@ class Dates_Intersection extends Filter_Type {
|
||||||
'secondary_filter_metadatum_name' => [
|
'secondary_filter_metadatum_name' => [
|
||||||
'title' => __( 'Second date metadatum', 'tainacan' ),
|
'title' => __( 'Second date metadatum', 'tainacan' ),
|
||||||
'description' => __( 'Label of the other metadatum to which this filter will compare values to find if there is an intersection of dates.', 'tainacan' ),
|
'description' => __( 'Label of the other metadatum to which this filter will compare values to find if there is an intersection of dates.', 'tainacan' ),
|
||||||
|
],
|
||||||
|
'first_comparator' => [
|
||||||
|
'title' => __( 'First comparator', 'tainacan' ),
|
||||||
|
'description' => __( 'Comparator to be used for checking the first metadata value.', 'tainacan' ),
|
||||||
|
],
|
||||||
|
'second_comparator' => [
|
||||||
|
'title' => __( 'Second comparator', 'tainacan' ),
|
||||||
|
'description' => __( 'Comparator to be used for checking the second metadata value.', 'tainacan' ),
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -68,18 +78,28 @@ class Dates_Intersection extends Filter_Type {
|
||||||
* @return array|bool true if is validate or array if has error
|
* @return array|bool true if is validate or array if has error
|
||||||
*/
|
*/
|
||||||
public function validate_options(\Tainacan\Entities\Filter $filter) {
|
public function validate_options(\Tainacan\Entities\Filter $filter) {
|
||||||
|
|
||||||
if ( !in_array($filter->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
|
if ( !in_array($filter->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ( empty($this->get_option('secondary_filter_metadatum_id')) ) {
|
$errors = [];
|
||||||
return [
|
|
||||||
|
if ( empty($this->get_option('secondary_filter_metadatum_id')) )
|
||||||
|
$errors[] = [
|
||||||
'secondary_filter_metadatum_id' => __('The secondary date metadatum is required.','tainacan')
|
'secondary_filter_metadatum_id' => __('The secondary date metadatum is required.','tainacan')
|
||||||
];
|
];
|
||||||
}
|
|
||||||
|
|
||||||
// Validate if the second date metadatum is a date metadatum
|
if ( empty($this->get_option('first_comparator')) )
|
||||||
|
$errors[] = [
|
||||||
|
'first_comparator' => __('The first comparator is required.','tainacan')
|
||||||
|
];
|
||||||
|
|
||||||
|
if ( empty($this->get_option('second_comparator')) )
|
||||||
|
$errors[] = [
|
||||||
|
'second_comparator' => __('The second comparator is required.','tainacan')
|
||||||
|
];
|
||||||
|
|
||||||
return true;
|
return count($errors) > 0 ? $errors : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue