mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-29 23:46:32 +08:00
Search functionality added to custom columns of custom repositories. [SCI-1357]
This commit is contained in:
parent
074a47aae1
commit
be4a8d494a
1 changed files with 19 additions and 2 deletions
|
|
@ -174,16 +174,33 @@ 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 = sort_records(records) if params[:order].present?
|
|
||||||
escape_special_chars
|
|
||||||
records = filter_records(records) if params[:search].present? &&
|
records = filter_records(records) if params[:search].present? &&
|
||||||
!sorting_by_custom_column
|
!sorting_by_custom_column
|
||||||
|
records = sort_records(records) if params[:order].present?
|
||||||
records = paginate_records(records) if !(params[:length].present? &&
|
records = paginate_records(records) if !(params[:length].present? &&
|
||||||
params[:length] == '-1') &&
|
params[:length] == '-1') &&
|
||||||
!sorting_by_custom_column
|
!sorting_by_custom_column
|
||||||
|
escape_special_chars
|
||||||
records
|
records
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Overriden to make it work for custom columns, because they are polymorphic
|
||||||
|
def simple_search(records)
|
||||||
|
return records unless params[:search].present? &&
|
||||||
|
params[:search][:value].present?
|
||||||
|
search_val = params[:search][:value]
|
||||||
|
|
||||||
|
filtered_ids = RepositoryRow.select do |r|
|
||||||
|
[r.name, r.created_at.to_s, r.created_by.full_name].any? do |s|
|
||||||
|
s.include?(search_val)
|
||||||
|
end ||
|
||||||
|
r.repository_cells.map do |c|
|
||||||
|
c.value.data.include?(search_val)
|
||||||
|
end.any?
|
||||||
|
end
|
||||||
|
records.where!(id: filtered_ids)
|
||||||
|
end
|
||||||
|
|
||||||
# Override default sort method if needed
|
# Override default sort method if needed
|
||||||
def sort_records(records)
|
def sort_records(records)
|
||||||
if params[:order].present? && params[:order].length == 1
|
if params[:order].present? && params[:order].length == 1
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue