From be4a8d494a00789d30da72c979a3aeeb192c69e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Wed, 14 Jun 2017 19:28:12 +0200 Subject: [PATCH 1/4] Search functionality added to custom columns of custom repositories. [SCI-1357] --- app/datatables/repository_datatable.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/app/datatables/repository_datatable.rb b/app/datatables/repository_datatable.rb index 175d9ec54..f2d7ecb4f 100644 --- a/app/datatables/repository_datatable.rb +++ b/app/datatables/repository_datatable.rb @@ -174,16 +174,33 @@ class RepositoryDatatable < AjaxDatatablesRails::Base def fetch_records records = get_raw_records 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? && !sorting_by_custom_column + records = sort_records(records) if params[:order].present? records = paginate_records(records) if !(params[:length].present? && params[:length] == '-1') && !sorting_by_custom_column + escape_special_chars records 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 def sort_records(records) if params[:order].present? && params[:order].length == 1 From e38947b1f8de50486eb2697e985292bc1c51dc86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Wed, 14 Jun 2017 19:28:53 +0200 Subject: [PATCH 2/4] Minor repository search refactoring. [SCI-1357] --- app/datatables/repository_datatable.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/datatables/repository_datatable.rb b/app/datatables/repository_datatable.rb index f2d7ecb4f..7ca2f07c0 100644 --- a/app/datatables/repository_datatable.rb +++ b/app/datatables/repository_datatable.rb @@ -191,12 +191,9 @@ class RepositoryDatatable < AjaxDatatablesRails::Base 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? + row_cells = [r.name, r.created_at.to_s, r.created_by.full_name] + row_cells.push(*r.repository_cells.collect { |c| c.value.data }) + row_cells.any? { |c| c.include?(search_val) } end records.where!(id: filtered_ids) end From 092e82c7224aa32ce2e786eb2ef6e4c856c5e08a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Wed, 14 Jun 2017 19:33:06 +0200 Subject: [PATCH 3/4] Date search fix for repositories. [SCI-1357] --- app/datatables/repository_datatable.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/datatables/repository_datatable.rb b/app/datatables/repository_datatable.rb index 7ca2f07c0..bf1f2f947 100644 --- a/app/datatables/repository_datatable.rb +++ b/app/datatables/repository_datatable.rb @@ -184,14 +184,15 @@ class RepositoryDatatable < AjaxDatatablesRails::Base records end - # Overriden to make it work for custom columns, because they are polymorphic + # 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| - row_cells = [r.name, r.created_at.to_s, r.created_by.full_name] + row_cells = [r.name, r.created_at.strftime(Constants::DATE_FORMAT), + r.created_by.full_name] row_cells.push(*r.repository_cells.collect { |c| c.value.data }) row_cells.any? { |c| c.include?(search_val) } end From bae1e298d76cff11e7079f6062fc202f97a6400c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Wed, 14 Jun 2017 19:49:08 +0200 Subject: [PATCH 4/4] Fixed repositories search to only search the current repository. [SCI-1357] --- app/datatables/repository_datatable.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/datatables/repository_datatable.rb b/app/datatables/repository_datatable.rb index bf1f2f947..9e9550c98 100644 --- a/app/datatables/repository_datatable.rb +++ b/app/datatables/repository_datatable.rb @@ -185,18 +185,20 @@ class RepositoryDatatable < AjaxDatatablesRails::Base 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? + # NOTE: Function assumes the provided records/rows are only from the current + # repository! + def simple_search(repo_rows) + return repo_rows unless params[:search].present? && + params[:search][:value].present? search_val = params[:search][:value] - filtered_ids = RepositoryRow.select do |r| + filtered_rows = repo_rows.select do |r| row_cells = [r.name, r.created_at.strftime(Constants::DATE_FORMAT), r.created_by.full_name] row_cells.push(*r.repository_cells.collect { |c| c.value.data }) row_cells.any? { |c| c.include?(search_val) } end - records.where!(id: filtered_ids) + repo_rows.where(id: filtered_rows) end # Override default sort method if needed