proposition de simplification

This commit is contained in:
simon lehericey 2021-05-17 15:42:21 +02:00 committed by kara Diaby
parent e043645a88
commit 02e2128fb7
2 changed files with 53 additions and 88 deletions

View file

@ -9,27 +9,13 @@ class RechercheController < ApplicationController
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
@instructeur_dossiers_ids = current_instructeur&.dossiers&.ids || []
matching_dossiers_ids = DossierSearchService.matching_dossiers(@instructeur_dossiers_ids, @search_terms, true)
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?
@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))
end
end
@paginated_ids = Kaminari
.paginate_array(matching_dossiers_ids.uniq)

View file

@ -1,13 +1,13 @@
- content_for(:title, "Recherche : #{@search_terms}")
- pagination = paginate @paginated_ids
- procedure_libelle_index = 0
- user_email_index = 1
.container
.page-title
Résultat de la recherche :
= t('pluralize.dossier_trouve', count: @dossiers_count)
= pagination
- if @projected_dossiers.present?
%table.table.dossiers-table.hoverable
%thead
@ -20,84 +20,63 @@
%th.action-col.follow-col
%tbody
- @projected_dossiers.each do |p|
- procedure_id = p.columns.last
- if current_expert.present?
- avis_id = @dossier_avis_ids_h[p.dossier_id]
- if (current_expert.present? && current_instructeur.blank?) || (current_instructeur.present? && current_expert.blank?)
- path = current_instructeur.present? ? instructeur_dossier_path(procedure_id, p.dossier_id) : expert_avis_path(procedure_id, avis_id)
- procedure_libelle, user_email, procedure_id = p.columns
- instructeur_dossier = @instructeur_dossiers_ids.include?(p.dossier_id)
- expert_dossier = @dossier_avis_ids_h[p.dossier_id].present?
- instructeur_and_expert_dossier = instructeur_dossier && expert_dossier
- path = instructeur_dossier ? instructeur_dossier_path(procedure_id, p.dossier_id) : expert_avis_path(procedure_id, @dossier_avis_ids_h[p.dossier_id])
%tr
%td.folder-col
= link_to(path, class: 'cell-link') do
- if instructeur_and_expert_dossier
%td.folder-col.cell-link
%span.icon.folder
%td.number-col
= link_to(path, class: 'cell-link') do
= p.dossier_id
- p.columns.values_at(procedure_libelle_index, user_email_index).each do |column|
.cell-link= p.dossier_id
%td
%a.cell-link{ href: path }= column
%td.status-col
= link_to(path, class: 'cell-link') do
= status_badge(p.state)
- if current_instructeur.present?
%td.action-col.follow-col= render partial: "instructeurs/procedures/dossier_actions",
locals: { procedure_id: procedure_id,
dossier_id: p.dossier_id,
state: p.state,
archived: p.archived,
button_class: false,
dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id) }
.cell-link= procedure_libelle
%td
.cell-link= user_email
%td
.cell-link= status_badge(p.state)
- else
%tr
%td.folder-col
%a.cell-link{ href: path }
%span.icon.folder
%td.number-col
.cell-link
= p.dossier_id
- p.columns.values_at(procedure_libelle_index, user_email_index).each do |column|
%td.number-col
%a.cell-link{ href: path }= p.dossier_id
%td
.cell-link
= column
%a.cell-link{ href: path }= procedure_libelle
%td
%a.cell-link{ href: path }= user_email
%td.status-col
.cell-link
= status_badge(p.state)
%a.cell-link{ href: path }= status_badge(p.state)
- if instructeur_dossier && expert_dossier
%td.action-col.follow-col
.dropdown
.button.dropdown-button
Actions
.dropdown-content.fade-in-down
%ul.dropdown-items.pl-0
- if current_instructeur.present?
%ul.dropdown-items
%li
= link_to(instructeur_dossier_path(procedure_id, p.dossier_id)) do
%span.icon.in-progress>
.dropdown-description
%h4
= render partial: "instructeurs/procedures/dossier_actions",
locals: { procedure_id: procedure_id,
dossier_id: p.dossier_id,
state: p.state,
archived: p.archived,
button_class: false,
dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id) }
Voir le dossier
%li
= link_to(expert_avis_path(procedure_id, @dossier_avis_ids_h[p.dossier_id])) do
%span.icon.in-progress>
.dropdown-description
Donner mon avis
- else
%td
%li
= link_to instructeur_dossier_path(procedure_id, p.dossier_id) do
%span.icon.in-progress
.dropdown-description
%h4 Instruire le dossier
- if avis_id.present?
%li
= link_to(expert_avis_path(procedure_id, avis_id)) do
%span.icon.in-progress
.dropdown-description
%h4 Donner mon avis
= pagination