refactor(dossier): filled champs

This commit is contained in:
Paul Chavard 2024-10-07 11:45:05 +02:00
parent d22ae1f76f
commit 8c8bb870fc
No known key found for this signature in database
5 changed files with 66 additions and 7 deletions

View file

@ -39,6 +39,34 @@ module DossierChampsConcern
revision.types_de_champ_private.map { project_champ(_1, nil) }
end
def filled_champs_public
project_champs_public.flat_map do |champ|
if champ.repetition?
champ.rows.flatten.filter { _1.persisted? && _1.fillable? }
elsif champ.persisted? && champ.fillable?
champ
else
[]
end
end
end
def filled_champs_private
project_champs_private.flat_map do |champ|
if champ.repetition?
champ.rows.flatten.filter { _1.persisted? && _1.fillable? }
elsif champ.persisted? && champ.fillable?
champ
else
[]
end
end
end
def filled_champs
filled_champs_public + filled_champs_private
end
def project_rows_for(type_de_champ)
return [] if !type_de_champ.repetition?

View file

@ -517,7 +517,7 @@ class Dossier < ApplicationRecord
def can_passer_en_construction?
return true if !revision.ineligibilite_enabled || !revision.ineligibilite_rules
!revision.ineligibilite_rules.compute(champs_for_revision(scope: :public))
!revision.ineligibilite_rules.compute(filled_champs_public)
end
def can_passer_en_instruction?
@ -567,7 +567,7 @@ class Dossier < ApplicationRecord
def any_etablissement_as_degraded_mode?
return true if etablissement&.as_degraded_mode?
return true if champs_for_revision(scope: :public).any? { _1.etablissement&.as_degraded_mode? }
return true if filled_champs_public.any? { _1.etablissement&.as_degraded_mode? }
false
end
@ -1031,7 +1031,7 @@ class Dossier < ApplicationRecord
end
def linked_dossiers_for(instructeur_or_expert)
dossier_ids = champs_for_revision.filter(&:dossier_link?).filter_map(&:value)
dossier_ids = filled_champs.filter(&:dossier_link?).filter_map(&:value)
instructeur_or_expert.dossiers.where(id: dossier_ids)
end
@ -1040,7 +1040,7 @@ class Dossier < ApplicationRecord
end
def geo_data?
GeoArea.exists?(champ_id: champs_for_revision)
GeoArea.exists?(champ_id: filled_champs)
end
def to_feature_collection
@ -1195,7 +1195,7 @@ class Dossier < ApplicationRecord
end
def geo_areas
champs_for_revision.flat_map(&:geo_areas)
filled_champs.flat_map(&:geo_areas)
end
def bounding_box