2021-04-29 09:32:47 +02:00
|
|
|
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
|
2021-05-17 15:42:21 +02:00
|
|
|
|
|
|
|
@instructeur_dossiers_ids = current_instructeur&.dossiers&.ids || []
|
|
|
|
matching_dossiers_ids = DossierSearchService.matching_dossiers(@instructeur_dossiers_ids, @search_terms, true)
|
|
|
|
|
|
|
|
@dossier_avis_ids_h = current_expert&.avis&.pluck(:dossier_id, :id).to_h || {}
|
|
|
|
expert_dossiers_ids = @dossier_avis_ids_h.keys
|
|
|
|
matching_dossiers_ids.concat(DossierSearchService.matching_dossiers(expert_dossiers_ids, @search_terms))
|
2021-04-29 09:32:47 +02:00
|
|
|
|
|
|
|
@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
|