mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-29 03:35:25 +08:00
Add advanced filters for date/datetime/time range [SCI-6462] (#3806)
Co-authored-by: Anton <anton@scinote.net>
This commit is contained in:
parent
4546227eb3
commit
c8784d1f66
8 changed files with 274 additions and 0 deletions
|
@ -25,8 +25,11 @@
|
|||
import RepositoryNumberValue from 'vue/repository_filter/filters/repositoryNumberValue.vue'
|
||||
import RepositoryMyModuleValue from 'vue/repository_filter/filters/repositoryMyModuleValue.vue'
|
||||
import RepositoryDateValue from 'vue/repository_filter/filters/repositoryDateValue.vue'
|
||||
import RepositoryDateRangeValue from 'vue/repository_filter/filters/repositoryDateRangeValue.vue'
|
||||
import RepositoryDateTimeValue from 'vue/repository_filter/filters/repositoryDateTimeValue.vue'
|
||||
import RepositoryDateTimeRangeValue from 'vue/repository_filter/filters/repositoryDateTimeRangeValue.vue'
|
||||
import RepositoryTimeValue from 'vue/repository_filter/filters/repositoryTimeValue.vue'
|
||||
import RepositoryTimeRangeValue from 'vue/repository_filter/filters/repositoryTimeRangeValue.vue'
|
||||
import RepositoryListValue from 'vue/repository_filter/filters/repositoryListValue.vue'
|
||||
import RepositoryStatusValue from 'vue/repository_filter/filters/repositoryStatusValue.vue'
|
||||
import RepositoryChecklistValue from 'vue/repository_filter/filters/repositoryChecklistValue.vue'
|
||||
|
@ -47,8 +50,11 @@
|
|||
RepositoryNumberValue,
|
||||
RepositoryMyModuleValue,
|
||||
RepositoryDateValue,
|
||||
RepositoryDateRangeValue,
|
||||
RepositoryTimeValue,
|
||||
RepositoryTimeRangeValue,
|
||||
RepositoryDateTimeValue,
|
||||
RepositoryDateTimeRangeValue,
|
||||
RepositoryListValue,
|
||||
RepositoryStatusValue,
|
||||
RepositoryChecklistValue,
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
<template>
|
||||
<div class="filter-attributes">
|
||||
<div class="operator-selector">
|
||||
<DropdownSelector
|
||||
:disableSearch="true"
|
||||
:options="operators"
|
||||
:selectorId="`OperatorSelector${filter.id}`"
|
||||
:selectedValue="operator"
|
||||
@dropdown:changed="updateOperator" />
|
||||
</div>
|
||||
<div class="filter-datepicker-input">
|
||||
<DateTimePicker @change="updateDate" :selectorId="`DatePicker${filter.id}`" :onlyDate="true" />
|
||||
</div>
|
||||
<div class="filter-datepicker-to-input">
|
||||
<DateTimePicker @change="updateDateTo" :selectorId="`DatePickerTo${filter.id}`" :onlyDate="true" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import FilterMixin from 'vue/repository_filter/mixins/filter.js'
|
||||
import DateTimeFilterMixin from 'vue/repository_filter/mixins/filters/date_time_filter.js'
|
||||
import DropdownSelector from 'vue/shared/dropdown_selector.vue'
|
||||
import DateTimePicker from 'vue/shared/date_picker.vue'
|
||||
|
||||
export default {
|
||||
name: 'RepositoryDateRangeValue',
|
||||
mixins: [FilterMixin, DateTimeFilterMixin],
|
||||
data() {
|
||||
return {
|
||||
timeType: 'date',
|
||||
operators: [
|
||||
{ value: 'equal_to', label: this.i18n.t('repositories.show.repository_filter.filters.operators.equal_to') },
|
||||
{ value: 'unequal_to', label: this.i18n.t('repositories.show.repository_filter.filters.operators.unequal_to') },
|
||||
{ value: 'greater_than', label: this.i18n.t('repositories.show.repository_filter.filters.operators.greater_than') },
|
||||
{ value: 'greater_than_or_equal', label: this.i18n.t('repositories.show.repository_filter.filters.operators.greater_than_or_equal_to') },
|
||||
{ value: 'less_than', label: this.i18n.t('repositories.show.repository_filter.filters.operators.less_than') },
|
||||
{ value: 'less_than_or_equal', label: this.i18n.t('repositories.show.repository_filter.filters.operators.less_than_or_equal_to') },
|
||||
{ value: 'between', label: this.i18n.t('repositories.show.repository_filter.filters.operators.between') }
|
||||
],
|
||||
operator: 'equal_to',
|
||||
date: null,
|
||||
dateTo: null,
|
||||
value: null
|
||||
}
|
||||
},
|
||||
components: {
|
||||
DropdownSelector,
|
||||
DateTimePicker
|
||||
},
|
||||
watch: {
|
||||
value() {
|
||||
this.parameters = this.value;
|
||||
this.updateFilter();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
formattedDate(date) {
|
||||
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,65 @@
|
|||
<template>
|
||||
<div class="filter-attributes">
|
||||
<div class="operator-selector">
|
||||
<DropdownSelector
|
||||
:disableSearch="true"
|
||||
:options="operators"
|
||||
:selectorId="`OperatorSelector${filter.id}`"
|
||||
:selectedValue="operator"
|
||||
@dropdown:changed="updateOperator" />
|
||||
</div>
|
||||
<div class="datetime-filter-attributes">
|
||||
<div class="filter-datepicker-input">
|
||||
<DateTimePicker @change="updateDate" :selectorId="`DatePicker${filter.id}`" />
|
||||
</div>
|
||||
<div class="filter-datepicker-to-input">
|
||||
<DateTimePicker @change="updateDateTo" :selectorId="`DatePickerTo${filter.id}`" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import FilterMixin from 'vue/repository_filter/mixins/filter.js'
|
||||
import DateTimeFilterMixin from 'vue/repository_filter/mixins/filters/date_time_filter.js'
|
||||
import DropdownSelector from 'vue/shared/dropdown_selector.vue'
|
||||
import DateTimePicker from 'vue/shared/date_time_picker.vue'
|
||||
|
||||
export default {
|
||||
name: 'RepositoryDateRangeValue',
|
||||
mixins: [FilterMixin, DateTimeFilterMixin],
|
||||
data() {
|
||||
return {
|
||||
timeType: 'datetime',
|
||||
operators: [
|
||||
{ value: 'equal_to', label: this.i18n.t('repositories.show.repository_filter.filters.operators.equal_to') },
|
||||
{ value: 'unequal_to', label: this.i18n.t('repositories.show.repository_filter.filters.operators.unequal_to') },
|
||||
{ value: 'greater_than', label: this.i18n.t('repositories.show.repository_filter.filters.operators.greater_than') },
|
||||
{ value: 'greater_than_or_equal', label: this.i18n.t('repositories.show.repository_filter.filters.operators.greater_than_or_equal_to') },
|
||||
{ value: 'less_than', label: this.i18n.t('repositories.show.repository_filter.filters.operators.less_than') },
|
||||
{ value: 'less_than_or_equal', label: this.i18n.t('repositories.show.repository_filter.filters.operators.less_than_or_equal_to') },
|
||||
{ value: 'between', label: this.i18n.t('repositories.show.repository_filter.filters.operators.between') }
|
||||
],
|
||||
operator: 'equal_to',
|
||||
date: null,
|
||||
dateTo: null,
|
||||
value: null
|
||||
}
|
||||
},
|
||||
components: {
|
||||
DropdownSelector,
|
||||
DateTimePicker
|
||||
},
|
||||
watch: {
|
||||
value() {
|
||||
this.parameters = this.value;
|
||||
this.updateFilter();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
formattedDate(date) {
|
||||
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}`
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,63 @@
|
|||
<template>
|
||||
<div class="filter-attributes">
|
||||
<div class="operator-selector">
|
||||
<DropdownSelector
|
||||
:disableSearch="true"
|
||||
:options="operators"
|
||||
:selectorId="`OperatorSelector${filter.id}`"
|
||||
:selectedValue="operator"
|
||||
@dropdown:changed="updateOperator" />
|
||||
</div>
|
||||
<div class="filter-datepicker-input">
|
||||
<DateTimePicker @change="updateDate" :selectorId="`TimePicker${filter.id}`" :timeOnly="true" />
|
||||
</div>
|
||||
<div class="filter-datepicker-to-input">
|
||||
<DateTimePicker @change="updateDateTo" :selectorId="`TimePickerTo${filter.id}`" :timeOnly="true" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import FilterMixin from 'vue/repository_filter/mixins/filter.js'
|
||||
import DateTimeFilterMixin from 'vue/repository_filter/mixins/filters/date_time_filter.js'
|
||||
import DropdownSelector from 'vue/shared/dropdown_selector.vue'
|
||||
import DateTimePicker from 'vue/shared/date_time_picker.vue'
|
||||
|
||||
export default {
|
||||
name: 'RepositoryTimeRangeValue',
|
||||
mixins: [FilterMixin, DateTimeFilterMixin],
|
||||
data() {
|
||||
return {
|
||||
timeType: 'time',
|
||||
operators: [
|
||||
{ value: 'equal_to', label: this.i18n.t('repositories.show.repository_filter.filters.operators.equal_to')},
|
||||
{ value: 'unequal_to', label: this.i18n.t('repositories.show.repository_filter.filters.operators.unequal_to') },
|
||||
{ value: 'greater_than', label: this.i18n.t('repositories.show.repository_filter.filters.operators.greater_than') },
|
||||
{ value: 'greater_than_or_equal_to', label: this.i18n.t('repositories.show.repository_filter.filters.operators.greater_than_or_equal_to') },
|
||||
{ value: 'less_than', label: this.i18n.t('repositories.show.repository_filter.filters.operators.less_than') },
|
||||
{ value: 'less_than_or_equal_to', label: this.i18n.t('repositories.show.repository_filter.filters.operators.less_than_or_equal_to') },
|
||||
{ value: 'between', label: this.i18n.t('repositories.show.repository_filter.filters.operators.between') }
|
||||
],
|
||||
operator: 'equal_to',
|
||||
date: null,
|
||||
dateTo: null,
|
||||
value: null
|
||||
}
|
||||
},
|
||||
components: {
|
||||
DropdownSelector,
|
||||
DateTimePicker
|
||||
},
|
||||
watch: {
|
||||
value() {
|
||||
this.parameters = this.value;
|
||||
this.updateFilter();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
formattedDate(date) {
|
||||
return `${date.getHours()}:${date.getMinutes()}`
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -12,6 +12,29 @@ class RepositoryDateRangeValue < RepositoryDateTimeRangeValueBase
|
|||
super(:full_date)
|
||||
end
|
||||
|
||||
def self.add_filter_condition(repository_rows, filter_element)
|
||||
parameters = filter_element.parameters
|
||||
case filter_element.operator
|
||||
when 'equal_to'
|
||||
repository_rows.where(repository_date_time_range_values: { start_time: parameters['start_date'], end_time: parameters['end_date'] })
|
||||
when 'unequal_to'
|
||||
repository_rows.where.not(repository_date_time_range_values: { start_time: parameters['start_date'], end_time: parameters['end_date'] })
|
||||
when 'greater_than'
|
||||
repository_rows.where('repository_date_time_range_values.start_time > ?', parameters['end_date'])
|
||||
when 'greater_than_or_equal_to'
|
||||
repository_rows.where('repository_date_time_range_values.start_time >= ?', parameters['end_date'])
|
||||
when 'less_than'
|
||||
repository_rows.where('repository_date_time_range_values.end_time < ?', parameters['start_date'])
|
||||
when 'less_than_or_equal_to'
|
||||
repository_rows.where('repository_date_time_range_values.end_time <= ?', parameters['start_date'])
|
||||
when 'between'
|
||||
repository_rows.where('repository_date_time_range_values.start_time > ? AND repository_date_time_range_values.end_time < ?',
|
||||
parameters['start_date'], parameters['end_date'])
|
||||
else
|
||||
raise ArgumentError, 'Wrong operator for RepositoryDateRangeValue!'
|
||||
end
|
||||
end
|
||||
|
||||
def self.new_with_payload(payload, attributes)
|
||||
data = payload.is_a?(String) ? JSON.parse(payload).symbolize_keys : payload
|
||||
|
||||
|
|
|
@ -12,6 +12,29 @@ class RepositoryDateTimeRangeValue < RepositoryDateTimeRangeValueBase
|
|||
super(:full_with_comma)
|
||||
end
|
||||
|
||||
def self.add_filter_condition(repository_rows, filter_element)
|
||||
parameters = filter_element.parameters
|
||||
case filter_element.operator
|
||||
when 'equal_to'
|
||||
repository_rows.where(repository_date_time_range_values: { start_time: parameters['start_datetime'], end_time: parameters['end_datetime'] })
|
||||
when 'unequal_to'
|
||||
repository_rows.where.not(repository_date_time_range_values: { start_time: parameters['start_datetime'], end_time: parameters['end_datetime'] })
|
||||
when 'greater_than'
|
||||
repository_rows.where('repository_date_time_range_values.start_time > ?', parameters['end_datetime'])
|
||||
when 'greater_than_or_equal_to'
|
||||
repository_rows.where('repository_date_time_range_values.start_time >= ?', parameters['end_datetime'])
|
||||
when 'less_than'
|
||||
repository_rows.where('repository_date_time_range_values.end_time < ?', parameters['start_datetime'])
|
||||
when 'less_than_or_equal_to'
|
||||
repository_rows.where('repository_date_time_range_values.end_time <= ?', parameters['start_datetime'])
|
||||
when 'between'
|
||||
repository_rows.where('repository_date_time_range_values.start_time > ? AND repository_date_time_range_values.end_time < ?',
|
||||
parameters['start_datetime'], parameters['end_datetime'])
|
||||
else
|
||||
raise ArgumentError, 'Wrong operator for RepositoryDateTimeRangeValue!'
|
||||
end
|
||||
end
|
||||
|
||||
def self.new_with_payload(payload, attributes)
|
||||
data = payload.is_a?(String) ? JSON.parse(payload).symbolize_keys : payload
|
||||
|
||||
|
|
|
@ -13,6 +13,31 @@ class RepositoryTimeRangeValue < RepositoryDateTimeRangeValueBase
|
|||
super(:time)
|
||||
end
|
||||
|
||||
def self.add_filter_condition(repository_rows, filter_element)
|
||||
parameters = filter_element.parameters
|
||||
case filter_element.operator
|
||||
when 'equal_to'
|
||||
repository_rows.where('repository_date_time_range_values.start_time::time = ? AND repository_date_time_range_values.end_time::time = ?',
|
||||
parameters['start_time'], parameters['end_time'])
|
||||
when 'unequal_to'
|
||||
repository_rows.where.not('repository_date_time_range_values.start_time::time = ? AND repository_date_time_range_values.end_time::time = ?',
|
||||
parameters['start_time'], parameters['end_time'])
|
||||
when 'greater_than'
|
||||
repository_rows.where('repository_date_time_range_values.start_time::time > ?', parameters['end_datetime'])
|
||||
when 'greater_than_or_equal_to'
|
||||
repository_rows.where('repository_date_time_range_values.start_time::time >= ?', parameters['end_datetime'])
|
||||
when 'less_than'
|
||||
repository_rows.where('repository_date_time_range_values.end_time::time < ?', parameters['start_datetime'])
|
||||
when 'less_than_or_equal_to'
|
||||
repository_rows.where('repository_date_time_range_values.end_time::time <= ?', parameters['start_datetime'])
|
||||
when 'between'
|
||||
repository_rows.where('repository_date_time_range_values.start_time::time > ? AND repository_date_time_range_values.end_time::time < ?',
|
||||
parameters['start_datetime'], parameters['end_datetime'])
|
||||
else
|
||||
raise ArgumentError, 'Wrong operator for RepositoryTimeRangeValue!'
|
||||
end
|
||||
end
|
||||
|
||||
def self.new_with_payload(payload, attributes)
|
||||
data = payload.is_a?(String) ? JSON.parse(payload).symbolize_keys : payload
|
||||
|
||||
|
|
|
@ -109,10 +109,16 @@ class Extends
|
|||
includes: { repository_asset_values: { asset: { file_attachment: :blob } } }
|
||||
}, RepositoryDateTimeValue: {
|
||||
field: 'repository_date_time_values.data', includes: :repository_date_time_values
|
||||
}, RepositoryDateTimeRangeValue: {
|
||||
field: 'repository_date_time_range_values.data', includes: :repository_date_time_range_values
|
||||
}, RepositoryDateValue: {
|
||||
field: 'repository_date_time_values.data', includes: :repository_date_values
|
||||
}, RepositoryDateRangeValue: {
|
||||
field: 'repository_date_time_range_values.data', includes: :repository_date_range_values
|
||||
}, RepositoryTimeValue: {
|
||||
field: 'repository_date_time_values.data', includes: :repository_time_values
|
||||
}, RepositoryTimeRangeValue: {
|
||||
field: 'repository_date_time_range_values.data', includes: :repository_time_range_values
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue