Merge pull request #10975 from tchak/refactor-export-repetition
refactor(export): do not use dossier.champs in export
This commit is contained in:
commit
857f68c912
4 changed files with 13 additions and 22 deletions
|
@ -31,12 +31,6 @@ class Champs::RepetitionChamp < Champ
|
||||||
# The user cannot enter any information here so it doesn’t make much sense to search
|
# The user cannot enter any information here so it doesn’t make much sense to search
|
||||||
end
|
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
|
class Row < Hashie::Dash
|
||||||
property :index
|
property :index
|
||||||
property :row_id
|
property :row_id
|
||||||
|
|
|
@ -107,6 +107,12 @@ module DossierChampsConcern
|
||||||
assign_attributes(champs_attributes:)
|
assign_attributes(champs_attributes:)
|
||||||
end
|
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)
|
def repetition_row_ids(type_de_champ)
|
||||||
return [] if !type_de_champ.repetition?
|
return [] if !type_de_champ.repetition?
|
||||||
|
|
||||||
|
|
|
@ -1052,13 +1052,6 @@ class Dossier < ApplicationRecord
|
||||||
}
|
}
|
||||||
end
|
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)
|
def log_api_entreprise_job_exception(exception)
|
||||||
exceptions = self.api_entreprise_job_exceptions ||= []
|
exceptions = self.api_entreprise_job_exceptions ||= []
|
||||||
exceptions << exception.inspect
|
exceptions << exception.inspect
|
||||||
|
|
|
@ -47,7 +47,9 @@ class ProcedureExportService
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_geo_json
|
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)
|
create_blob(io, :json)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -92,9 +94,9 @@ class ProcedureExportService
|
||||||
end
|
end
|
||||||
|
|
||||||
def etablissements
|
def etablissements
|
||||||
@etablissements ||= dossiers.flat_map do |dossier|
|
@etablissements ||= dossiers
|
||||||
dossier.champs.filter { _1.is_a?(Champs::SiretChamp) }
|
.flat_map { _1.filled_champs.filter(&:siret?) }
|
||||||
end.filter_map(&:etablissement) + dossiers.filter_map(&:etablissement)
|
.filter_map(&:etablissement) + dossiers.filter_map(&:etablissement)
|
||||||
end
|
end
|
||||||
|
|
||||||
def avis
|
def avis
|
||||||
|
@ -102,16 +104,12 @@ class ProcedureExportService
|
||||||
end
|
end
|
||||||
|
|
||||||
def champs_repetables_options
|
def champs_repetables_options
|
||||||
champs_by_stable_id = dossiers
|
|
||||||
.flat_map { _1.champs.filter(&:repetition?) }
|
|
||||||
.group_by(&:stable_id)
|
|
||||||
|
|
||||||
procedure
|
procedure
|
||||||
.all_revisions_types_de_champ
|
.all_revisions_types_de_champ
|
||||||
.repetition
|
.repetition
|
||||||
.filter_map do |type_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
|
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?
|
if types_de_champ.present? && rows.present?
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue