refactor(dossier): extract sections logic in a concern

This commit is contained in:
Colin Darie 2023-02-21 11:42:30 +01:00
parent 8156e1cc01
commit ae93d3927e
4 changed files with 106 additions and 99 deletions

View file

@ -48,8 +48,9 @@
class Dossier < ApplicationRecord
self.ignored_columns = [:en_construction_conservation_extension]
include DossierFilteringConcern
include DossierRebaseConcern
include DossierPrefillableConcern
include DossierRebaseConcern
include DossierSectionsConcern
enum state: {
brouillon: 'brouillon',
@ -1237,20 +1238,6 @@ class Dossier < ApplicationRecord
termine_expired_to_delete.find_each(&:purge_discarded)
end
def sections_for(champ)
@sections = Hash.new do |hash, parent|
case parent
when :public
hash[parent] = champs_public.filter(&:header_section?)
when :private
hash[parent] = champs_private.filter(&:header_section?)
else
hash[parent] = parent.champs.filter(&:header_section?)
end
end
@sections[champ.parent || (champ.public? ? :public : :private)]
end
def clone
dossier_attributes = [:autorisation_donnees, :user_id, :revision_id, :groupe_instructeur_id]
relationships = [:individual, :etablissement]
@ -1291,22 +1278,6 @@ class Dossier < ApplicationRecord
false
end
def auto_numbering_section_headers_for?(champ)
sections_for(champ)&.none?(&:libelle_with_section_index?)
end
def index_for_section_header(champ)
champs = champ.private? ? champs_private : champs_public
index = 1
champs.each do |c|
return index if c.stable_id == champ.stable_id
next unless c.visible?
index += 1 if c.type_de_champ.header_section?
end
end
private
def create_missing_traitemets