diff --git a/app/models/champs/repetition_champ.rb b/app/models/champs/repetition_champ.rb index cfa6ff5ab..4bb65c484 100644 --- a/app/models/champs/repetition_champ.rb +++ b/app/models/champs/repetition_champ.rb @@ -31,12 +31,6 @@ class Champs::RepetitionChamp < Champ # The user cannot enter any information here so it doesn’t make much sense to search end - def rows_for_export - row_ids.map.with_index(1) do |row_id, index| - Champs::RepetitionChamp::Row.new(index:, row_id:, dossier:) - end - end - class Row < Hashie::Dash property :index property :row_id diff --git a/app/models/concerns/dossier_champs_concern.rb b/app/models/concerns/dossier_champs_concern.rb index 17ce89a25..82fa8e5fc 100644 --- a/app/models/concerns/dossier_champs_concern.rb +++ b/app/models/concerns/dossier_champs_concern.rb @@ -107,6 +107,12 @@ module DossierChampsConcern assign_attributes(champs_attributes:) end + def repetition_rows_for_export(type_de_champ) + repetition_row_ids(type_de_champ).map.with_index(1) do |row_id, index| + Champs::RepetitionChamp::Row.new(index:, row_id:, dossier: self) + end + end + def repetition_row_ids(type_de_champ) return [] if !type_de_champ.repetition? diff --git a/app/models/dossier.rb b/app/models/dossier.rb index fc80584f4..90ca00d4f 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -1052,13 +1052,6 @@ class Dossier < ApplicationRecord } end - def self.to_feature_collection - { - type: 'FeatureCollection', - features: GeoArea.joins(:champ).where(champ: { dossier: ids }).map(&:to_feature) - } - end - def log_api_entreprise_job_exception(exception) exceptions = self.api_entreprise_job_exceptions ||= [] exceptions << exception.inspect diff --git a/app/services/procedure_export_service.rb b/app/services/procedure_export_service.rb index 001ee7ef7..9482cc045 100644 --- a/app/services/procedure_export_service.rb +++ b/app/services/procedure_export_service.rb @@ -47,7 +47,9 @@ class ProcedureExportService end def to_geo_json - io = StringIO.new(dossiers.to_feature_collection.to_json) + champs_carte = dossiers.flat_map { _1.filled_champs.filter(&:carte?) } + features = GeoArea.where(champ_id: champs_carte).map(&:to_feature) + io = StringIO.new({ type: 'FeatureCollection', features: }.to_json) create_blob(io, :json) end @@ -92,9 +94,9 @@ class ProcedureExportService end def etablissements - @etablissements ||= dossiers.flat_map do |dossier| - dossier.champs.filter { _1.is_a?(Champs::SiretChamp) } - end.filter_map(&:etablissement) + dossiers.filter_map(&:etablissement) + @etablissements ||= dossiers + .flat_map { _1.filled_champs.filter(&:siret?) } + .filter_map(&:etablissement) + dossiers.filter_map(&:etablissement) end def avis @@ -102,16 +104,12 @@ class ProcedureExportService end def champs_repetables_options - champs_by_stable_id = dossiers - .flat_map { _1.champs.filter(&:repetition?) } - .group_by(&:stable_id) - procedure .all_revisions_types_de_champ .repetition .filter_map do |type_de_champ_repetition| types_de_champ = procedure.all_revisions_types_de_champ(parent: type_de_champ_repetition).to_a - rows = champs_by_stable_id.fetch(type_de_champ_repetition.stable_id, []).flat_map(&:rows_for_export) + rows = dossiers.flat_map { _1.repetition_rows_for_export(type_de_champ_repetition) } if types_de_champ.present? && rows.present? {