add and modify controllers

This commit is contained in:
kara Diaby 2021-04-29 09:32:47 +02:00
parent b3caa2e5f4
commit 7d9cf63056
2 changed files with 53 additions and 12 deletions

View file

@ -1,12 +0,0 @@
module Instructeurs
class RechercheController < InstructeurController
def index
@search_terms = params[:q]
@dossiers = DossierSearchService.matching_dossiers_for_instructeur(@search_terms, current_instructeur)
@followed_dossiers_id = current_instructeur
.followed_dossiers
.where(groupe_instructeur_id: @dossiers.pluck(:groupe_instructeur_id))
.pluck(:id)
end
end
end

View file

@ -0,0 +1,53 @@
class RechercheController < ApplicationController
before_action :authenticate_logged_user!
ITEMS_PER_PAGE = 25
PROJECTIONS = [
{ "table" => 'procedure', "column" => 'libelle' },
{ "table" => 'user', "column" => 'email' },
{ "table" => 'procedure', "column" => 'procedure_id' }
]
def index
@search_terms = search_terms
matching_dossiers_ids = []
instructeur_dossiers_ids = []
expert_dossiers_ids = []
if instructeur_signed_in?
instructeur_dossiers_ids.concat(current_instructeur.dossiers.ids)
@followed_dossiers_id = current_instructeur.followed_dossiers.where(id: instructeur_dossiers_ids).ids
if instructeur_dossiers_ids.present?
matching_dossiers_ids.concat(DossierSearchService.matching_dossiers(instructeur_dossiers_ids, @search_terms, true))
end
end
if expert_signed_in?
@dossier_avis_ids_h = current_expert.avis.pluck(:dossier_id, :id).to_h
expert_dossiers_ids.concat(@dossier_avis_ids_h.keys)
if expert_dossiers_ids.present?
matching_dossiers_ids.concat(DossierSearchService.matching_dossiers(expert_dossiers_ids, @search_terms))
end
end
@paginated_ids = Kaminari
.paginate_array(matching_dossiers_ids.uniq)
.page(page)
.per(ITEMS_PER_PAGE)
@dossiers_count = matching_dossiers_ids.count
@projected_dossiers = DossierProjectionService.project(@paginated_ids, PROJECTIONS)
end
private
def page
params[:page].presence || 1
end
def search_terms
params[:q]
end
end