mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-04 02:45:53 +08:00
Merge pull request #691 from mz3944/mz-SCI-1357-v2
Repository management - filter on custom columns [SCI-1357]
This commit is contained in:
commit
e027a871e9
1 changed files with 32 additions and 12 deletions
|
@ -179,12 +179,10 @@ class RepositoryDatatable < AjaxDatatablesRails::Base
|
||||||
def fetch_records
|
def fetch_records
|
||||||
records = get_raw_records
|
records = get_raw_records
|
||||||
records = @assigned_rows if @my_module && params[:assigned] == 'assigned'
|
records = @assigned_rows if @my_module && params[:assigned] == 'assigned'
|
||||||
records = filter_records(records) if params[:search].present? &&
|
records = filter_records(records) if params[:search].present?
|
||||||
!sorting_by_custom_column
|
|
||||||
records = sort_records(records) if params[:order].present?
|
records = sort_records(records) if params[:order].present?
|
||||||
records = paginate_records(records) if !(params[:length].present? &&
|
records = paginate_records(records) unless params[:length].present? &&
|
||||||
params[:length] == '-1') &&
|
params[:length] == '-1'
|
||||||
!sorting_by_custom_column
|
|
||||||
escape_special_chars
|
escape_special_chars
|
||||||
records
|
records
|
||||||
end
|
end
|
||||||
|
@ -192,17 +190,39 @@ class RepositoryDatatable < AjaxDatatablesRails::Base
|
||||||
# Overriden to make it work for custom columns, because they are polymorphic
|
# Overriden to make it work for custom columns, because they are polymorphic
|
||||||
# NOTE: Function assumes the provided records/rows are only from the current
|
# NOTE: Function assumes the provided records/rows are only from the current
|
||||||
# repository!
|
# repository!
|
||||||
def simple_search(repo_rows)
|
def filter_records(repo_rows)
|
||||||
return repo_rows unless params[:search].present? &&
|
return repo_rows unless params[:search].present? &&
|
||||||
params[:search][:value].present?
|
params[:search][:value].present?
|
||||||
search_val = params[:search][:value]
|
search_val = params[:search][:value]
|
||||||
|
|
||||||
filtered_rows = repo_rows.select do |r|
|
filtered_rows = repo_rows.find_by_sql(
|
||||||
row_cells = [r.name, r.created_at.strftime(Constants::DATE_FORMAT),
|
"SELECT DISTINCT repository_rows.*
|
||||||
r.created_by.full_name]
|
FROM repository_rows
|
||||||
row_cells.push(*r.repository_cells.collect { |c| c.value.data })
|
INNER JOIN (
|
||||||
row_cells.any? { |c| c.include?(search_val) }
|
SELECT users.*
|
||||||
end
|
FROM users
|
||||||
|
) AS users
|
||||||
|
ON users.id = repository_rows.created_by_id
|
||||||
|
LEFT OUTER JOIN (
|
||||||
|
SELECT repository_cells.repository_row_id,
|
||||||
|
repository_text_values.data AS text_value,
|
||||||
|
to_char(repository_date_values.data, 'DD.MM.YYYY HH24:MI')
|
||||||
|
AS date_value
|
||||||
|
FROM repository_cells
|
||||||
|
INNER JOIN repository_text_values
|
||||||
|
ON repository_text_values.id = repository_cells.value_id
|
||||||
|
FULL OUTER JOIN repository_date_values
|
||||||
|
ON repository_date_values.id = repository_cells.value_id
|
||||||
|
) AS values
|
||||||
|
ON values.repository_row_id = repository_rows.id
|
||||||
|
WHERE repository_rows.repository_id = #{@repository.id}
|
||||||
|
AND (repository_rows.name ILIKE '%#{search_val}%'
|
||||||
|
OR to_char(repository_rows.created_at, 'DD.MM.YYYY HH24:MI')
|
||||||
|
ILIKE '%#{search_val}%'
|
||||||
|
OR users.full_name ILIKE '%#{search_val}%'
|
||||||
|
OR text_value ILIKE '%#{search_val}%'
|
||||||
|
OR date_value ILIKE '%#{search_val}%')"
|
||||||
|
)
|
||||||
repo_rows.where(id: filtered_rows)
|
repo_rows.where(id: filtered_rows)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue