From e953666762604e2bf86fa4a175442dcb46493a61 Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Thu, 13 May 2021 21:41:26 +0200 Subject: [PATCH] Add search field to reports page [SCI-5551] --- app/assets/javascripts/reports/reports_datatable.js | 4 ++++ app/assets/stylesheets/report_index.scss | 7 +++++++ app/datatables/report_datatable.rb | 5 +++++ app/views/reports/_index_toolbar.html.erb | 4 ++++ config/locales/en.yml | 1 + 5 files changed, 21 insertions(+) diff --git a/app/assets/javascripts/reports/reports_datatable.js b/app/assets/javascripts/reports/reports_datatable.js index 27d85550c..c1fe821fd 100644 --- a/app/assets/javascripts/reports/reports_datatable.js +++ b/app/assets/javascripts/reports/reports_datatable.js @@ -360,6 +360,10 @@ }); } + $('.reports-index').on('change', '.report-search', function() { + REPORTS_TABLE.search($(this).val()).draw(); + }); + $('#show_report_preview').click(); initDatatable(); diff --git a/app/assets/stylesheets/report_index.scss b/app/assets/stylesheets/report_index.scss index 8d7da8f8d..354085a04 100644 --- a/app/assets/stylesheets/report_index.scss +++ b/app/assets/stylesheets/report_index.scss @@ -18,6 +18,13 @@ } } } + + .search-report-container { + display: inline-block; + float: right; + margin-right: 2em; + width: 200px; + } } .reports-datatable { diff --git a/app/datatables/report_datatable.rb b/app/datatables/report_datatable.rb index 944e7b754..4e4e11e11 100644 --- a/app/datatables/report_datatable.rb +++ b/app/datatables/report_datatable.rb @@ -103,5 +103,10 @@ class ReportDatatable < CustomDatatable Report.from(res, :reports) end + def filter_records(records) + records.where('project_name ILIKE :q OR reports.name ILIKE :q OR reports.description ILIKE :q', + { q: "%#{dt_params.dig(:search, :value)}%" }) + end + # ==== Insert 'presenter'-like methods below if necessary end diff --git a/app/views/reports/_index_toolbar.html.erb b/app/views/reports/_index_toolbar.html.erb index a255a71c4..a47bbc8c8 100644 --- a/app/views/reports/_index_toolbar.html.erb +++ b/app/views/reports/_index_toolbar.html.erb @@ -46,4 +46,8 @@ <% end %> +
+ "> + +
<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index d0c3372d2..28da2ba69 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -495,6 +495,7 @@ en: report_button: "Report" update_pdf: "Update PDF" save_pdf_to_inventory: "Save PDF to Inventory" + search_reports: "Find Reports" request_docx: "Generate DOCX" update_docx: "Update DOCX" edit: "Edit"