refactor(dossier): make new methods arguments named

This commit is contained in:
Paul Chavard 2024-02-08 18:28:15 +01:00
parent 436caa2305
commit 9b26dedab4
8 changed files with 18 additions and 18 deletions

View file

@ -157,7 +157,7 @@ module Types
.for(object, private: false)
.load(ApplicationRecord.id_from_typed_id(id))
else
object.champs_for_revision(:public, true).filter(&:visible?)
object.champs_for_revision(scope: :public, root: true).filter(&:visible?)
end
end
@ -167,7 +167,7 @@ module Types
.for(object, private: true)
.load(ApplicationRecord.id_from_typed_id(id))
else
object.champs_for_revision(:private, true).filter(&:visible?)
object.champs_for_revision(scope: :private, root: true).filter(&:visible?)
end
end

View file

@ -79,7 +79,7 @@ class AttestationTemplate < ApplicationRecord
end
def unspecified_champs_for_dossier(dossier)
champs_by_stable_id = dossier.champs_for_revision(nil, true).index_by { "tdc#{_1.stable_id}" }
champs_by_stable_id = dossier.champs_for_revision(root: true).index_by { "tdc#{_1.stable_id}" }
used_tags.filter_map do |used_tag|
corresponding_champ = champs_by_stable_id[used_tag]

View file

@ -4,7 +4,7 @@ class Champs::RepetitionChamp < Champ
def rows
dossier
.champs_for_revision(type_de_champ)
.champs_for_revision(scope: type_de_champ)
.group_by(&:row_id).values
end

View file

@ -42,10 +42,10 @@ module DossierCloneConcern
end
def make_diff(editing_fork)
origin_champs_index = champs_for_revision(:public).index_by(&:stable_id_with_row)
forked_champs_index = editing_fork.champs_for_revision(:public).index_by(&:stable_id_with_row)
origin_champs_index = champs_for_revision(scope: :public).index_by(&:stable_id_with_row)
forked_champs_index = editing_fork.champs_for_revision(scope: :public).index_by(&:stable_id_with_row)
updated_champs_index = editing_fork
.champs_for_revision(:public)
.champs_for_revision(scope: :public)
.filter { _1.updated_at > editing_fork.created_at }
.index_by(&:stable_id_with_row)
@ -142,7 +142,7 @@ module DossierCloneConcern
end
def apply_diff(diff)
champs_index = (champs_for_revision(:public) + diff[:added]).index_by(&:stable_id_with_row)
champs_index = (champs_for_revision(scope: :public) + diff[:added]).index_by(&:stable_id_with_row)
diff[:added].each do |champ|
if champ.child?

View file

@ -6,11 +6,11 @@ module DossierSectionsConcern
@sections = Hash.new do |hash, parent|
case parent
when :public
hash[parent] = champs_for_revision(:public, true).filter(&:header_section?)
hash[parent] = champs_for_revision(scope: :public, root: true).filter(&:header_section?)
when :private
hash[parent] = champs_for_revision(:private, true).filter(&:header_section?)
hash[parent] = champs_for_revision(scope: :private, root: true).filter(&:header_section?)
else
hash[parent] = champs_for_revision(parent.type_de_champ).filter(&:header_section?)
hash[parent] = champs_for_revision(scope: parent.type_de_champ).filter(&:header_section?)
end
end
@sections[champ.parent || (champ.public? ? :public : :private)]
@ -23,7 +23,7 @@ module DossierSectionsConcern
end
def index_for_section_header(champ)
champs = champ.private? ? champs_for_revision(:private, true) : champs_for_revision(:public, true)
champs = champ.private? ? champs_for_revision(scope: :private, root: true) : champs_for_revision(scope: :public, root: true)
index = 1
champs.each do |c|
if c.repetition?

View file

@ -610,7 +610,7 @@ class Dossier < ApplicationRecord
def any_etablissement_as_degraded_mode?
return true if etablissement&.as_degraded_mode?
return true if champs_for_revision(:public).any? { _1.etablissement&.as_degraded_mode? }
return true if champs_for_revision(scope: :public).any? { _1.etablissement&.as_degraded_mode? }
false
end
@ -1165,7 +1165,7 @@ class Dossier < ApplicationRecord
end
def check_mandatory_and_visible_champs
champs_for_revision(:public)
champs_for_revision(scope: :public)
.filter { _1.child? ? _1.parent.visible? : true }
.filter(&:visible?)
.filter(&:mandatory_blank?)
@ -1396,13 +1396,13 @@ class Dossier < ApplicationRecord
champs_for_revision.index_by(&:stable_id_with_row)
end
def champs_for_revision(scope = nil, root = false)
def champs_for_revision(scope: nil, root: false)
champs_index = champs.group_by(&:stable_id)
if scope.is_a?(TypeDeChamp)
revision.children_of(scope)
else
revision.types_de_champ_for(scope, root)
revision.types_de_champ_for(scope:, root:)
end.flat_map { champs_index[_1.stable_id] || [] }
end

View file

@ -155,7 +155,7 @@ class ProcedureRevision < ApplicationRecord
dossier
end
def types_de_champ_for(scope = nil, root = false)
def types_de_champ_for(scope: nil, root: false)
# We return an unordered collection
return types_de_champ if !root && scope.nil?
return types_de_champ.filter { scope == :public ? _1.public? : _1.private? } if !root

View file

@ -47,7 +47,7 @@ class ChampSerializer < ActiveModel::Serializer
def rows
object.dossier
.champs_for_revision(object.type_de_champ)
.champs_for_revision(scope: object.type_de_champ)
.group_by(&:row_id)
.values
.map.with_index(1) { |champs, index| Row.new(index:, champs:) }