From 8ecced57b5dda5e5b9341b14adf847ae3acaf870 Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Tue, 29 Oct 2024 13:36:39 -0600 Subject: [PATCH 1/3] Add `scope :search` to ResearchOutput model Search by `research_outputs.title` (case-insensitive) --- app/models/research_output.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/models/research_output.rb b/app/models/research_output.rb index 243b925185..c401b1af23 100644 --- a/app/models/research_output.rb +++ b/app/models/research_output.rb @@ -70,6 +70,15 @@ class ResearchOutput < ApplicationRecord # Ensure presence of the :output_type_description if the user selected 'other' validates_presence_of :output_type_description, if: -> { other? }, message: PRESENCE_MESSAGE + # ========== + # = Scopes = + # ========== + + scope :search, lambda { |term| + search_pattern = "%#{term}%" + where('lower(title) LIKE lower(?)', search_pattern) + } + # ==================== # = Instance methods = # ==================== From 301231c6ed27d783122e007c1f14e3af89e18458 Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Tue, 29 Oct 2024 16:29:37 -0600 Subject: [PATCH 2/3] Create `paginable/research_outputs_controller.rb` --- .../paginable/research_outputs_controller.rb | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 app/controllers/paginable/research_outputs_controller.rb diff --git a/app/controllers/paginable/research_outputs_controller.rb b/app/controllers/paginable/research_outputs_controller.rb new file mode 100644 index 0000000000..9eb5d7f338 --- /dev/null +++ b/app/controllers/paginable/research_outputs_controller.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Paginable + # Controller for paginating/sorting/searching the research_outputs table + class ResearchOutputsController < ApplicationController + include Paginable + + after_action :verify_authorized + + # GET /paginable/plans/:plan_id/research_outputs + def index + @plan = Plan.find_by(id: params[:plan_id]) + # Same assignment as app/controllers/research_outputs_controller.rb + research_outputs = ResearchOutput.includes(:repositories).where(plan_id: @plan.id) + # Same authorize handling as app/controllers/research_outputs_controller.rb + # `|| ResearchOutput.new(plan_id: @plan.id)` prevents Pundit::NotDefinedError when a direct + # GET /paginable/plans/:id/research_outputs request is made on a plan with 0 research_outputs + authorize(research_outputs.first || ResearchOutput.new(plan_id: @plan.id)) + paginable_renderise( + partial: 'index', + scope: research_outputs, + query_params: { sort_field: 'research_outputs.title' }, + format: :json + ) + end + end +end From bb9c7f4dff042a8a618624f8cfce58662bc712ec Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Mon, 10 Feb 2025 14:45:47 -0700 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ace50817c5..d5e4bfd557 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fixed a bug in the deep copy of plans where the old identifier was being copied into the new plan. We now copy the generated id of the new plan to the identifier field. - Fixed bar chart click function in the Usage dashboard (GitHub issue #3443) - Fixed broken link for the V1 API documentation. +- Fix Paginating, Sorting, and Searching Issues Within "Research Outputs" Tab [#3477](https://github.com/DMPRoadmap/roadmap/pull/3477) **Note this upgrade is mainly a migration from Bootstrap 3 to Bootstrap 5.**