refactor: include corrections
This commit is contained in:
parent
c415b066b9
commit
bb198000fe
6 changed files with 20 additions and 85 deletions
|
@ -1,12 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Instructeurs::SVASVRDecisionBadgeComponent < ApplicationComponent
|
||||
attr_reader :object
|
||||
attr_reader :dossier
|
||||
attr_reader :procedure
|
||||
attr_reader :with_label
|
||||
|
||||
def initialize(projection_or_dossier:, procedure:, with_label: false)
|
||||
@object = projection_or_dossier
|
||||
def initialize(dossier:, procedure:, with_label: false)
|
||||
@dossier = dossier
|
||||
@procedure = procedure
|
||||
@decision = procedure.sva_svr_configuration.decision.to_sym
|
||||
@with_label = with_label
|
||||
|
@ -15,11 +15,11 @@ class Instructeurs::SVASVRDecisionBadgeComponent < ApplicationComponent
|
|||
def render?
|
||||
return false unless procedure.sva_svr_enabled?
|
||||
|
||||
[:en_construction, :en_instruction].include? object.state.to_sym
|
||||
[:en_construction, :en_instruction].include? dossier.state.to_sym
|
||||
end
|
||||
|
||||
def without_date?
|
||||
object.sva_svr_decision_on.nil?
|
||||
dossier.sva_svr_decision_on.nil?
|
||||
end
|
||||
|
||||
def classes
|
||||
|
@ -31,17 +31,17 @@ class Instructeurs::SVASVRDecisionBadgeComponent < ApplicationComponent
|
|||
end
|
||||
|
||||
def soon?
|
||||
return false if object.sva_svr_decision_on.nil?
|
||||
return false if dossier.sva_svr_decision_on.nil?
|
||||
|
||||
object.sva_svr_decision_on < 7.days.from_now.to_date
|
||||
dossier.sva_svr_decision_on < 7.days.from_now.to_date
|
||||
end
|
||||
|
||||
def pending_correction?
|
||||
object.pending_correction?
|
||||
dossier.pending_correction?
|
||||
end
|
||||
|
||||
def days_count
|
||||
(object.sva_svr_decision_on - Date.current).to_i
|
||||
(dossier.sva_svr_decision_on - Date.current).to_i
|
||||
end
|
||||
|
||||
def sva?
|
||||
|
@ -66,7 +66,7 @@ class Instructeurs::SVASVRDecisionBadgeComponent < ApplicationComponent
|
|||
elsif pending_correction?
|
||||
t(".dossier_terminated_x_days_after_correction", count: days_count)
|
||||
else
|
||||
t(".dossier_terminated_on", date: helpers.l(object.sva_svr_decision_on))
|
||||
t(".dossier_terminated_on", date: helpers.l(dossier.sva_svr_decision_on))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -75,14 +75,10 @@ class Instructeurs::SVASVRDecisionBadgeComponent < ApplicationComponent
|
|||
end
|
||||
|
||||
def previously_termine?
|
||||
return if !object.respond_to?(:previously_termine?)
|
||||
|
||||
object.previously_termine?
|
||||
dossier.previously_termine?
|
||||
end
|
||||
|
||||
def depose_before_configuration?
|
||||
return if !object.respond_to?(:sva_svr_decision_triggered_at)
|
||||
|
||||
object.sva_svr_decision_on.nil? && object.sva_svr_decision_triggered_at.nil?
|
||||
dossier.sva_svr_decision_on.nil? && dossier.sva_svr_decision_triggered_at.nil?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,19 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DossierProjectionService
|
||||
class DossierProjection < Struct.new(:dossier, :corrections, :columns) do
|
||||
def pending_correction?
|
||||
return false if corrections.blank?
|
||||
|
||||
corrections.any? { _1[:resolved_at].nil? }
|
||||
end
|
||||
|
||||
def resolved_corrections?
|
||||
return false if corrections.blank?
|
||||
|
||||
corrections.all? { _1[:resolved_at].present? }
|
||||
end
|
||||
end
|
||||
class DossierProjection < Struct.new(:dossier, :columns)
|
||||
end
|
||||
|
||||
def self.for_tiers_translation(array)
|
||||
|
@ -51,9 +39,7 @@ class DossierProjectionService
|
|||
end
|
||||
champ_value = champ_value_formatter(dossiers_ids, fields)
|
||||
|
||||
dossier_corrections = { TABLE => 'dossier_corrections', COLUMN => 'resolved_at' }
|
||||
|
||||
([dossier_corrections] + fields)
|
||||
fields
|
||||
.each { |f| f[:id_value_h] = {} }
|
||||
.group_by { |f| f[TABLE] } # one query per table
|
||||
.each do |table, fields|
|
||||
|
@ -163,12 +149,11 @@ class DossierProjectionService
|
|||
end
|
||||
end
|
||||
|
||||
dossiers = Dossier.find(dossiers_ids)
|
||||
dossiers = Dossier.includes(:corrections, :pending_corrections).find(dossiers_ids)
|
||||
|
||||
dossiers_ids.map do |dossier_id|
|
||||
DossierProjection.new(
|
||||
dossiers.find { _1.id == dossier_id },
|
||||
dossier_corrections[:id_value_h][dossier_id],
|
||||
fields.map { |f| f[:id_value_h][dossier_id] }
|
||||
)
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
= pending_correction_badge(:for_instructeur)
|
||||
- elsif dossier.en_construction? && dossier.last_correction_resolved?
|
||||
= correction_resolved_badge
|
||||
= render Instructeurs::SVASVRDecisionBadgeComponent.new(projection_or_dossier: dossier, procedure: dossier.procedure, with_label: true)
|
||||
= render Instructeurs::SVASVRDecisionBadgeComponent.new(dossier:, procedure: dossier.procedure, with_label: true)
|
||||
|
||||
|
||||
.header-actions.fr-ml-auto
|
||||
|
|
|
@ -152,16 +152,16 @@
|
|||
|
||||
%td
|
||||
- status = [status_badge(dossier.state)]
|
||||
- if p.pending_correction?
|
||||
- if dossier.pending_correction?
|
||||
- status << pending_correction_badge(:for_instructeur, html_class: "fr-mt-1v")
|
||||
- elsif dossier.state.to_sym == :en_construction && p.resolved_corrections?
|
||||
- elsif dossier.last_correction_resolved?
|
||||
- status << correction_resolved_badge(html_class: "fr-mt-1v")
|
||||
= 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 dossier.hidden_by_administration_at.blank?, render(Instructeurs::SVASVRDecisionBadgeComponent.new(projection_or_dossier: dossier, procedure: @procedure)), path
|
||||
= link_to_if dossier.hidden_by_administration_at.blank?, render(Instructeurs::SVASVRDecisionBadgeComponent.new(dossier:, procedure: @procedure)), path
|
||||
|
||||
%td.follow-col
|
||||
%ul.fr-btns-group.fr-btns-group--sm.fr-btns-group--inline.fr-btns-group--icon-right
|
||||
|
|
|
@ -10,7 +10,7 @@ RSpec.describe Instructeurs::SVASVRDecisionBadgeComponent, type: :component do
|
|||
|
||||
context 'with dossier object' do
|
||||
subject do
|
||||
render_inline(described_class.new(projection_or_dossier: dossier, procedure:, with_label:))
|
||||
render_inline(described_class.new(dossier:, procedure:, with_label:))
|
||||
end
|
||||
|
||||
let(:title) { subject.at_css("span")["title"] }
|
||||
|
@ -54,22 +54,4 @@ RSpec.describe Instructeurs::SVASVRDecisionBadgeComponent, type: :component do
|
|||
it { expect(subject).to have_text("4 j. après correction") }
|
||||
end
|
||||
end
|
||||
|
||||
context 'with projection object' do
|
||||
subject do
|
||||
render_inline(described_class.new(projection_or_dossier: projection, procedure:, with_label:))
|
||||
end
|
||||
|
||||
context 'dossier en instruction' do
|
||||
let(:projection) { DossierProjectionService::DossierProjection.new(dossier_id: 12, state: :en_instruction, sva_svr_decision_on: Date.new(2023, 9, 5)) }
|
||||
|
||||
it { expect(subject).to have_text("dans 4 jours") }
|
||||
end
|
||||
|
||||
context 'dossier without sva decision date' do
|
||||
let(:projection) { DossierProjectionService::DossierProjection.new(dossier_id: 12, state: :en_instruction) }
|
||||
|
||||
it { expect(subject).to have_text("Instruction manuelle") }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -249,34 +249,6 @@ describe DossierProjectionService do
|
|||
|
||||
it { is_expected.to eq('38') }
|
||||
end
|
||||
|
||||
context 'for dossier corrections table' do
|
||||
let(:table) { 'dossier_corrections' }
|
||||
let(:column) { 'resolved_at' }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:columns) { [Column.new(procedure_id: procedure.id, table:, column:)] } # should somehow be present in column concern
|
||||
let(:dossier) { create(:dossier, :en_construction, procedure:) }
|
||||
subject { described_class.project(dossiers_ids, columns)[0] }
|
||||
|
||||
context "when dossier has pending correction" do
|
||||
before { create(:dossier_correction, dossier:) }
|
||||
|
||||
it { expect(subject.pending_correction?).to be(true) }
|
||||
it { expect(subject.resolved_corrections?).to eq(false) }
|
||||
end
|
||||
|
||||
context "when dossier has a resolved correction" do
|
||||
before { create(:dossier_correction, :resolved, dossier:) }
|
||||
|
||||
it { expect(subject.pending_correction?).to eq(false) }
|
||||
it { expect(subject.resolved_corrections?).to eq(true) }
|
||||
end
|
||||
|
||||
context "when dossier has no correction at all" do
|
||||
it { expect(subject.pending_correction?).to eq(false) }
|
||||
it { expect(subject.resolved_corrections?).to eq(false) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue