Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.**
Expand Down
27 changes: 27 additions & 0 deletions app/controllers/paginable/research_outputs_controller.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions app/models/research_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
# ====================
Expand Down
Loading