Closed terrywbrady closed 1 year ago
Use cases
Repositories
scope :by_template, lambda { |template_id| joins(:templates).where('templates.id = :template_id', template_id: template_id) }
ResearchOutputsController
def repository_search @plan = Plan.find_by(id: params[:plan_id]) @research_output = ResearchOutput.new(plan: @plan) authorize @research_output @search_results = Repository.by_template(@plan.template.id) @search_results = if @search_results.any? @search_results.by_type(repo_search_params[:type_filter]) else Repository.by_type(repo_search_params[:type_filter]) end @search_results = @search_results.by_subject(repo_search_params[:subject_filter]) @search_results = @search_results.search(repo_search_params[:search_term]) @search_results = @search_results.order(:name).page(params[:page]) end
scope :preferred_by_template, lambda { |template_id| where(%{ exists ( select 1 from template_repositories tr where tr.template_id=:template_id and tr.repository_id=repositories.id ) }, template_id: template_id) } scope :custom_by_template, lambda { |template_id| where(%{custom_repository_owner_template_id=:template}, template_id: template_id) } scope :preferred_or_custom_by_template, lambda { |template_id| where(%{ custom_repository_owner_template_id=:template_id OR exists ( select 1 from template_repositories tr where tr.template_id=:template_id and tr.repository_id=repositories.id ) }, template_id: template_id) } scope :standard_or_custom_by_template, lambda { |template_id| where(%{custom_repository_owner_template_id=:template_id OR custom_repository_owner_template_id is null}, template_id: template_id) }
def repository_search @plan = Plan.find_by(id: params[:plan_id]) template = @plan.template @research_output = ResearchOutput.new(plan: @plan) authorize @research_output @search_results = template.template_repositories.any? ? Repository.preferred_or_custom_by_template(template.id) : Repository.standard_or_custom_by_template(template.id) @search_results = @search_results.by_type(repo_search_params[:type_filter]) @search_results = @search_results.by_subject(repo_search_params[:subject_filter]) @search_results = @search_results.search(repo_search_params[:search_term]) @search_results = @search_results.order(:name).page(params[:page]) end
Question (from slack): When a template has custom repositories...
Table change
Preferences screen
Research Outputs Screen
Use cases
Current Logic in stage
Repositories
ResearchOutputsController
New logic needed
Repositories
ResearchOutputsController