diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index 5c7e2011e..fad6c0056 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -105,7 +105,7 @@ module Instructeurs .per(ITEMS_PER_PAGE) @projected_dossiers = DossierProjectionService.project(@filtered_sorted_paginated_ids, procedure_presentation.displayed_columns) - @disable_checkbox_all = @projected_dossiers.all? { _1.batch_operation_id.present? } + @disable_checkbox_all = @projected_dossiers.all? { _1.dossier.batch_operation_id.present? } @batch_operations = BatchOperation.joins(:groupe_instructeurs) .where(groupe_instructeurs: current_instructeur.groupe_instructeurs.where(procedure_id: @procedure.id)) diff --git a/app/services/dossier_projection_service.rb b/app/services/dossier_projection_service.rb index 65a531ed1..8720a0797 100644 --- a/app/services/dossier_projection_service.rb +++ b/app/services/dossier_projection_service.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class DossierProjectionService - class DossierProjection < Struct.new(:dossier_id, :state, :archived, :hidden_by_user_at, :hidden_by_administration_at, :hidden_by_reason, :for_tiers, :batch_operation_id, :sva_svr_decision_on, :corrections, :columns) do + class DossierProjection < Struct.new(:dossier, :corrections, :columns) do def pending_correction? return false if corrections.blank? @@ -51,17 +51,9 @@ class DossierProjectionService end champ_value = champ_value_formatter(dossiers_ids, fields) - state_field = { TABLE => 'self', COLUMN => 'state' } - archived_field = { TABLE => 'self', COLUMN => 'archived' } - batch_operation_field = { TABLE => 'self', COLUMN => 'batch_operation_id' } - hidden_by_user_at_field = { TABLE => 'self', COLUMN => 'hidden_by_user_at' } - hidden_by_administration_at_field = { TABLE => 'self', COLUMN => 'hidden_by_administration_at' } - hidden_by_reason_field = { TABLE => 'self', COLUMN => 'hidden_by_reason' } - for_tiers_field = { TABLE => 'self', COLUMN => 'for_tiers' } - sva_svr_decision_on_field = { TABLE => 'self', COLUMN => 'sva_svr_decision_on' } dossier_corrections = { TABLE => 'dossier_corrections', COLUMN => 'resolved_at' } - ([state_field, archived_field, sva_svr_decision_on_field, hidden_by_user_at_field, hidden_by_administration_at_field, hidden_by_reason_field, for_tiers_field, batch_operation_field, dossier_corrections] + fields) + ([dossier_corrections] + fields) .each { |f| f[:id_value_h] = {} } .group_by { |f| f[TABLE] } # one query per table .each do |table, fields| @@ -89,7 +81,7 @@ class DossierProjectionService .each do |id, *columns| fields.zip(columns).each do |field, value| # SVA must remain a date: in other column we compute remaining delay with it - field[:id_value_h][id] = if value.respond_to?(:strftime) && field != sva_svr_decision_on_field + field[:id_value_h][id] = if value.respond_to?(:strftime) I18n.l(value.to_date) else value @@ -171,17 +163,11 @@ class DossierProjectionService end end + dossiers = Dossier.find(dossiers_ids) + dossiers_ids.map do |dossier_id| DossierProjection.new( - dossier_id, - state_field[:id_value_h][dossier_id], - archived_field[:id_value_h][dossier_id], - hidden_by_user_at_field[:id_value_h][dossier_id], - hidden_by_administration_at_field[:id_value_h][dossier_id], - hidden_by_reason_field[:id_value_h][dossier_id], - for_tiers_field[:id_value_h][dossier_id], - batch_operation_field[:id_value_h][dossier_id], - sva_svr_decision_on_field[:id_value_h][dossier_id], + dossiers.find { _1.id == dossier_id }, dossier_corrections[:id_value_h][dossier_id], fields.map { |f| f[:id_value_h][dossier_id] } ) diff --git a/app/views/instructeurs/procedures/show.html.haml b/app/views/instructeurs/procedures/show.html.haml index bc3bc3f31..6cb301ba6 100644 --- a/app/views/instructeurs/procedures/show.html.haml +++ b/app/views/instructeurs/procedures/show.html.haml @@ -110,70 +110,71 @@ = render Dossiers::BatchSelectMoreComponent.new(dossiers_count: @dossiers_count, filtered_sorted_ids: @filtered_sorted_ids) - @projected_dossiers.each do |p| - - path = instructeur_dossier_path(@procedure, p.dossier_id) - %tr{ class: class_names("file-hidden-by-user" => p.hidden_by_user_at.present?), id: "table-dossiers-row-#{p.dossier_id}", "aria-selected" => "false", "data-row-key" => p.dossier_id } + - dossier = p.dossier + - path = instructeur_dossier_path(@procedure, dossier.id) + %tr{ class: class_names("file-hidden-by-user" => dossier.hidden_by_user_at.present?), id: "table-dossiers-row-#{dossier.id}", "aria-selected" => "false", "data-row-key" => dossier.id } - if batch_operation_component.render? %th.fr-cell--fixed{ scope: 'row' } .fr-checkbox-group.fr-checkbox-group--sm - - if p.batch_operation_id.present? - = check_box_tag "batch_operation[dossier_ids][]", p.dossier_id, true, disabled: true, - id: dom_id(BatchOperation.new, "checkbox_#{p.dossier_id}"), - aria: { label: t('views.instructeurs.dossiers.batch_operation.disabled', dossier_id: p.dossier_id) }, + - if dossier.batch_operation_id.present? + = check_box_tag "batch_operation[dossier_ids][]", dossier.id, true, disabled: true, + id: dom_id(BatchOperation.new, "checkbox_#{dossier.id}"), + aria: { label: t('views.instructeurs.dossiers.batch_operation.disabled', dossier_id: dossier.id) }, data: { "fr-row-select" => "true" } - else - = check_box_tag "batch_operation[dossier_ids][]", p.dossier_id, false, - data: { batch_operation_target: "input", action: "batch-operation#onCheckOne", operations: batch_operation_component.operations_for_dossier(p).join(','), "fr-row-select" => "true" }, - form: dom_id(BatchOperation.new), id: dom_id(BatchOperation.new, "checkbox_#{p.dossier_id}"), - aria: { label: t('views.instructeurs.dossiers.batch_operation.enabled', dossier_id: p.dossier_id) } - = label_tag dom_id(BatchOperation.new, "checkbox_#{p.dossier_id}"), "Sélectionner le dossier #{p.dossier_id}", class: 'fr-label' + = check_box_tag "batch_operation[dossier_ids][]", dossier.id, false, + data: { batch_operation_target: "input", action: "batch-operation#onCheckOne", operations: batch_operation_component.operations_for_dossier(dossier).join(','), "fr-row-select" => "true" }, + form: dom_id(BatchOperation.new), id: dom_id(BatchOperation.new, "checkbox_#{dossier.id}"), + aria: { label: t('views.instructeurs.dossiers.batch_operation.enabled', dossier_id: dossier.id) } + = label_tag dom_id(BatchOperation.new, "checkbox_#{dossier.id}"), "Sélectionner le dossier #{dossier.id}", class: 'fr-label' %td.fr-cell--numeric - - if p.hidden_by_administration_at.present? - %span= p.dossier_id + - if dossier.hidden_by_administration_at.present? + %span= dossier.id - else %a.fr-link.relative{ href: path } - = p.dossier_id - - if @not_archived_notifications_dossier_ids.include?(p.dossier_id) + = dossier.id + - if @not_archived_notifications_dossier_ids.include?(dossier.id) %span.notifications{ 'aria-label': 'notifications' } - p.columns.each do |column| %td.fr-cell--multiline - - if p.hidden_by_administration_at.present? + - if dossier.hidden_by_administration_at.present? %span = column.is_a?(Hash) ? tags_label(column[:value]) : column - - if p.hidden_by_user_at.present? - = "- #{t("views.instructeurs.dossiers.deleted_reason.#{p.hidden_by_reason}")}" + - if dossier.hidden_by_user_at.present? + = "- #{t("views.instructeurs.dossiers.deleted_reason.#{dossier.hidden_by_reason}")}" - else %a{ href: path } = column.is_a?(Hash) ? tags_label(column[:value]) : column - = "- #{t("views.instructeurs.dossiers.deleted_reason.#{p.hidden_by_reason}")}" if p.hidden_by_user_at.present? + = "- #{t("views.instructeurs.dossiers.deleted_reason.#{dossier.hidden_by_reason}")}" if dossier.hidden_by_user_at.present? %td - - status = [status_badge(p.state)] + - status = [status_badge(dossier.state)] - if p.pending_correction? - status << pending_correction_badge(:for_instructeur, html_class: "fr-mt-1v") - - elsif p.state.to_sym == :en_construction && p.resolved_corrections? + - elsif dossier.state.to_sym == :en_construction && p.resolved_corrections? - status << correction_resolved_badge(html_class: "fr-mt-1v") - = link_to_if(p.hidden_by_administration_at.blank?, safe_join(status), path, class: "flex column") + = link_to_if(dossier.hidden_by_administration_at.blank?, safe_join(status), path, class: "flex column") - if @procedure.sva_svr_enabled? %td %span - = link_to_if p.hidden_by_administration_at.blank?, render(Instructeurs::SVASVRDecisionBadgeComponent.new(projection_or_dossier: p, procedure: @procedure)), path + = link_to_if dossier.hidden_by_administration_at.blank?, render(Instructeurs::SVASVRDecisionBadgeComponent.new(projection_or_dossier: dossier, procedure: @procedure)), path %td.follow-col %ul.fr-btns-group.fr-btns-group--sm.fr-btns-group--inline.fr-btns-group--icon-right = render partial: 'instructeurs/procedures/dossier_actions', locals: { procedure_id: @procedure.id, - dossier_id: p.dossier_id, - state: p.state, - archived: p.archived, - dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id), + dossier_id: dossier.id, + state: dossier.state, + archived: dossier.archived, + dossier_is_followed: @followed_dossiers_id.include?(dossier.id), close_to_expiration: @statut == 'expirant', hidden_by_administration: @statut == 'supprimes', - hidden_by_expired: p.hidden_by_reason == 'expired', + hidden_by_expired: dossier.hidden_by_reason == 'expired', sva_svr: @procedure.sva_svr_enabled?, - has_blocking_pending_correction: @procedure.feature_enabled?(:blocking_pending_correction) && p.pending_correction?, + has_blocking_pending_correction: @procedure.feature_enabled?(:blocking_pending_correction) && dossier.pending_correction?, turbo: false, with_menu: false } diff --git a/spec/services/dossier_projection_service_spec.rb b/spec/services/dossier_projection_service_spec.rb index c9168eb39..e08743c0c 100644 --- a/spec/services/dossier_projection_service_spec.rb +++ b/spec/services/dossier_projection_service_spec.rb @@ -29,17 +29,17 @@ describe DossierProjectionService do it 'respects the dossiers_ids order, returns state, archived and nil for empty result' do expect(result.length).to eq(3) - expect(result[0].dossier_id).to eq(dossier_3.id) - expect(result[1].dossier_id).to eq(dossier_1.id) - expect(result[2].dossier_id).to eq(dossier_2.id) + expect(result[0].dossier.id).to eq(dossier_3.id) + expect(result[1].dossier.id).to eq(dossier_1.id) + expect(result[2].dossier.id).to eq(dossier_2.id) - expect(result[0].state).to eq('en_instruction') - expect(result[1].state).to eq('brouillon') - expect(result[2].state).to eq('en_construction') + expect(result[0].dossier.state).to eq('en_instruction') + expect(result[1].dossier.state).to eq('brouillon') + expect(result[2].dossier.state).to eq('en_construction') - expect(result[0].archived).to be false - expect(result[1].archived).to be false - expect(result[2].archived).to be true + expect(result[0].dossier.archived).to be false + expect(result[1].dossier.archived).to be false + expect(result[2].dossier.archived).to be true expect(result[0].columns[0]).to be nil expect(result[1].columns[0]).to eq('champ_1') @@ -66,7 +66,7 @@ describe DossierProjectionService do it 'returns champ value' do expect(result.length).to eq(1) - expect(result[0].dossier_id).to eq(dossier.id) + expect(result[0].dossier.id).to eq(dossier.id) expect(result[0].columns[0]).to eq('Châteldon (63290)') end end