Improve ProcedureExportService

This commit is contained in:
gregoirenovel 2018-12-28 17:54:53 +01:00
parent b4781f7440
commit 083dfb4eaa

View file

@ -120,11 +120,9 @@ class ProcedureExportService
def etablissements_table_data def etablissements_table_data
@etablissements = @dossiers.flat_map do |dossier| @etablissements = @dossiers.flat_map do |dossier|
dossier.champs.select do |champ| [dossier.champs, dossier.champs_private]
champ.is_a?(Champs::SiretChamp) .flatten
end + dossier.champs_private.select do |champ| .select { |champ| champ.is_a?(Champs::SiretChamp) }
champ.is_a?(Champs::SiretChamp)
end
end.map(&:etablissement).compact end.map(&:etablissement).compact
if @etablissements.any? if @etablissements.any?
@ -139,22 +137,13 @@ class ProcedureExportService
end end
def dossiers_headers def dossiers_headers
headers = ATTRIBUTES.map do |key| headers = ATTRIBUTES.map(&:to_s) +
label_for_export(key.to_s) @procedure.types_de_champ.reject(&:exclude_from_export?).map(&:libelle) +
end @procedure.types_de_champ_private.reject(&:exclude_from_export?).map(&:libelle) +
headers += @procedure.types_de_champ.reject(&:exclude_from_export?).map do |champ| ETABLISSEMENT_ATTRIBUTES.map { |key| "etablissement.#{key}" } +
label_for_export(champ.libelle) ENTREPRISE_ATTRIBUTES.map { |key| "entreprise.#{key}" }
end
headers += @procedure.types_de_champ_private.reject(&:exclude_from_export?).map do |champ| headers.map { |header| label_for_export(header) }
label_for_export(champ.libelle)
end
headers += ETABLISSEMENT_ATTRIBUTES.map do |key|
label_for_export("etablissement.#{key}")
end
headers += ENTREPRISE_ATTRIBUTES.map do |key|
label_for_export("entreprise.#{key}")
end
headers
end end
def dossiers_data def dossiers_data
@ -183,33 +172,28 @@ class ProcedureExportService
dossier.read_attribute(key) dossier.read_attribute(key)
end end
end end
values = normalize_values(values)
values += dossier.champs.reject(&:exclude_from_export?).map(&:for_export) normalize_values(values) +
values += dossier.champs_private.reject(&:exclude_from_export?).map(&:for_export) dossier.champs.reject(&:exclude_from_export?).map(&:for_export) +
values += etablissement_data(dossier.etablissement) dossier.champs_private.reject(&:exclude_from_export?).map(&:for_export) +
values etablissement_data(dossier.etablissement)
end end
end end
def etablissements_headers def etablissements_headers
headers = [:dossier_id, :libelle] headers = ["dossier_id", "libelle"] +
headers += ETABLISSEMENT_ATTRIBUTES.map do |key| ETABLISSEMENT_ATTRIBUTES.map { |key| "etablissement.#{key}" } +
label_for_export("etablissement.#{key}") ENTREPRISE_ATTRIBUTES.map { |key| "entreprise.#{key}" }
end
headers += ENTREPRISE_ATTRIBUTES.map do |key| headers.map { |header| label_for_export(header) }
label_for_export("entreprise.#{key}")
end
headers
end end
def etablissements_data def etablissements_data
@etablissements.map do |etablissement| @etablissements.map do |etablissement|
data = [ [
etablissement.champ.dossier_id, etablissement.champ.dossier_id,
label_for_export(etablissement.champ.libelle).to_s label_for_export(etablissement.champ.libelle).to_s
] ] + etablissement_data(etablissement)
data + etablissement_data(etablissement)
end end
end end