mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-18 21:42:07 +08:00
Merge pull request #7612 from rekonder/aj_SCI_10751
Add advanced repository filter for updated on and updated by [SCI-10751]
This commit is contained in:
commit
38751cedd0
2 changed files with 112 additions and 1 deletions
|
@ -64,6 +64,26 @@ const DEFAULT_FILTERS = [
|
|||
},
|
||||
data: { operator: 'any_of' },
|
||||
isBlank: true
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
column: {
|
||||
data_type: 'RepositoryDateTimeValue',
|
||||
id: 'updated_on',
|
||||
name: I18n.t('repositories.table.updated_on')
|
||||
},
|
||||
data: { operator: 'equal_to' },
|
||||
isBlank: true
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
column: {
|
||||
data_type: 'RepositoryUserValue',
|
||||
id: 'updated_by',
|
||||
name: I18n.t('repositories.table.updated_by')
|
||||
},
|
||||
data: { operator: 'any_of' },
|
||||
isBlank: true
|
||||
}
|
||||
];
|
||||
|
||||
|
@ -76,6 +96,8 @@ window.initRepositoryFilter = () => {
|
|||
{ id: 'relationships', name: I18n.t('repositories.table.relationships'), data_type: 'RepositoryRelationshipValue' },
|
||||
{ id: 'added_on', name: I18n.t('repositories.table.added_on'), data_type: 'RepositoryDateTimeValue' },
|
||||
{ id: 'added_by', name: I18n.t('repositories.table.added_by'), data_type: 'RepositoryUserValue' },
|
||||
{ id: 'updated_on', name: I18n.t('repositories.table.updated_on'), data_type: 'RepositoryDateTimeValue' },
|
||||
{ id: 'updated_by', name: I18n.t('repositories.table.updated_by'), data_type: 'RepositoryUserValue' },
|
||||
{ id: 'archived_by', name: I18n.t('repositories.table.archived_by'), data_type: 'RepositoryUserValue' },
|
||||
{ id: 'archived_on', name: I18n.t('repositories.table.archived_on'), data_type: 'RepositoryDateTimeValue' }
|
||||
];
|
||||
|
|
|
@ -10,7 +10,8 @@ class RepositoryDatatableService
|
|||
include MyModulesHelper
|
||||
attr_reader :repository_rows, :all_count, :mappings
|
||||
|
||||
PREDEFINED_COLUMNS = %w(row_id row_name added_on added_by archived_on archived_by assigned relationships).freeze
|
||||
PREDEFINED_COLUMNS = %w(row_id row_name added_on added_by archived_on archived_by
|
||||
assigned relationships updated_on updated_by).freeze
|
||||
|
||||
def initialize(repository, params, user, my_module = nil)
|
||||
@repository = repository
|
||||
|
@ -160,6 +161,10 @@ class RepositoryDatatableService
|
|||
build_added_on_filter_condition(repository_rows, filter_element_params)
|
||||
when 'added_by'
|
||||
build_added_by_filter_condition(repository_rows, filter_element_params)
|
||||
when 'updated_on'
|
||||
build_updated_on_filter_condition(repository_rows, filter_element_params)
|
||||
when 'updated_by'
|
||||
build_updated_by_filter_condition(repository_rows, filter_element_params)
|
||||
when 'archived_by'
|
||||
build_archived_by_filter_condition(repository_rows, filter_element_params)
|
||||
when 'archived_on'
|
||||
|
@ -356,6 +361,77 @@ class RepositoryDatatableService
|
|||
end
|
||||
end
|
||||
|
||||
def build_updated_on_filter_condition(repository_rows, filter_element_params)
|
||||
case filter_element_params[:operator]
|
||||
when 'today'
|
||||
repository_rows.where(
|
||||
"date_trunc('minute', \"repository_rows\".\"updated_at\") >= ? AND " \
|
||||
"date_trunc('minute', \"repository_rows\".\"updated_at\") < ?",
|
||||
Time.zone.now.beginning_of_day,
|
||||
Time.zone.now.end_of_day
|
||||
)
|
||||
when 'yesterday'
|
||||
repository_rows.where(
|
||||
"date_trunc('minute', \"repository_rows\".\"updated_at\") >= ? AND "\
|
||||
"date_trunc('minute', \"repository_rows\".\"updated_at\") < ?",
|
||||
Time.zone.now.beginning_of_day - 1.day, Time.zone.now.beginning_of_day
|
||||
)
|
||||
when 'last_week'
|
||||
repository_rows.where(
|
||||
"date_trunc('minute', \"repository_rows\".\"updated_at\") >= ? AND "\
|
||||
"date_trunc('minute', \"repository_rows\".\"updated_at\") < ?",
|
||||
Time.zone.now.beginning_of_week - 1.week, Time.zone.now.beginning_of_week
|
||||
)
|
||||
when 'this_month'
|
||||
repository_rows.where(
|
||||
"date_trunc('minute', \"repository_rows\".\"updated_at\") >= ? AND "\
|
||||
"date_trunc('minute', \"repository_rows\".\"updated_at\") <= ?",
|
||||
Time.zone.now.beginning_of_month,
|
||||
Time.zone.now.end_of_month
|
||||
)
|
||||
when 'last_year'
|
||||
repository_rows.where(
|
||||
"date_trunc('minute', \"repository_rows\".\"updated_at\") >= ? AND "\
|
||||
"date_trunc('minute', \"repository_rows\".\"updated_at\") < ?",
|
||||
Time.zone.now.beginning_of_year - 1.year, Time.zone.now.beginning_of_year
|
||||
)
|
||||
when 'this_year'
|
||||
repository_rows.where(
|
||||
"date_trunc('minute', \"repository_rows\".\"updated_at\") >= ? AND "\
|
||||
"date_trunc('minute', \"repository_rows\".\"updated_at\") <= ?",
|
||||
Time.zone.now.beginning_of_year,
|
||||
Time.zone.now.end_of_year
|
||||
)
|
||||
when 'equal_to'
|
||||
repository_rows.where("date_trunc('minute', \"repository_rows\".\"updated_at\") = ?",
|
||||
Time.zone.parse(filter_element_params.dig(:parameters, :datetime)))
|
||||
when 'unequal_to'
|
||||
repository_rows.where.not("date_trunc('minute', \"repository_rows\".\"updated_at\") = ?",
|
||||
Time.zone.parse(filter_element_params.dig(:parameters, :datetime)))
|
||||
when 'greater_than'
|
||||
repository_rows.where("date_trunc('minute', \"repository_rows\".\"updated_at\") > ?",
|
||||
Time.zone.parse(filter_element_params.dig(:parameters, :datetime)))
|
||||
when 'greater_than_or_equal_to'
|
||||
repository_rows.where("date_trunc('minute', \"repository_rows\".\"updated_at\") >= ?",
|
||||
Time.zone.parse(filter_element_params.dig(:parameters, :datetime)))
|
||||
when 'less_than'
|
||||
repository_rows.where("date_trunc('minute', \"repository_rows\".\"updated_at\") < ?",
|
||||
Time.zone.parse(filter_element_params.dig(:parameters, :datetime)))
|
||||
when 'less_than_or_equal_to'
|
||||
repository_rows.where("date_trunc('minute', \"repository_rows\".\"updated_at\") <= ?",
|
||||
Time.zone.parse(filter_element_params.dig(:parameters, :datetime)))
|
||||
when 'between'
|
||||
repository_rows.where(
|
||||
"date_trunc('minute', \"repository_rows\".\"updated_at\") > ? AND "\
|
||||
"date_trunc('minute', \"repository_rows\".\"updated_at\") < ?",
|
||||
Time.zone.parse(filter_element_params.dig(:parameters, :start_datetime)),
|
||||
Time.zone.parse(filter_element_params.dig(:parameters, :end_datetime))
|
||||
)
|
||||
else
|
||||
raise ArgumentError, 'Wrong operator for RepositoryRow Updated on!'
|
||||
end
|
||||
end
|
||||
|
||||
def build_added_by_filter_condition(repository_rows, filter_element_params)
|
||||
case filter_element_params[:operator]
|
||||
when 'any_of'
|
||||
|
@ -384,6 +460,19 @@ class RepositoryDatatableService
|
|||
end
|
||||
end
|
||||
|
||||
def build_updated_by_filter_condition(repository_rows, filter_element_params)
|
||||
case filter_element_params[:operator]
|
||||
when 'any_of'
|
||||
repository_rows.joins(:last_modified_by)
|
||||
.where(last_modified_by: { id: filter_element_params.dig(:parameters, :user_ids) })
|
||||
when 'none_of'
|
||||
repository_rows.joins(:last_modified_by)
|
||||
.where.not(last_modified_by: { id: filter_element_params.dig(:parameters, :user_ids) })
|
||||
else
|
||||
raise ArgumentError, 'Wrong operator for RepositoryRow Updated By!'
|
||||
end
|
||||
end
|
||||
|
||||
def build_assigned_filter_condition(repository_rows, filter_element_params)
|
||||
return repository_rows if filter_element_params.dig(:parameters, :my_module_ids).blank?
|
||||
|
||||
|
|
Loading…
Reference in a new issue