parent
2a61ed5b1c
commit
f22b39b7c5
3 changed files with 21 additions and 9 deletions
|
@ -33,6 +33,12 @@ class Champs::RepetitionChamp < Champ
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# We have to truncate the label here as spreadsheets have a (30 char) limit on length.
|
||||||
|
def libelle_for_export
|
||||||
|
str = "(#{type_de_champ.stable_id}) #{libelle}"
|
||||||
|
ActiveStorage::Filename.new(str).sanitized.truncate(30)
|
||||||
|
end
|
||||||
|
|
||||||
class Row < Hashie::Dash
|
class Row < Hashie::Dash
|
||||||
property :index
|
property :index
|
||||||
property :dossier_id
|
property :dossier_id
|
||||||
|
|
|
@ -53,7 +53,7 @@ class ProcedureExportV2Service
|
||||||
[dossier.champs, dossier.champs_private]
|
[dossier.champs, dossier.champs_private]
|
||||||
.flatten
|
.flatten
|
||||||
.filter { |champ| champ.is_a?(Champs::RepetitionChamp) }
|
.filter { |champ| champ.is_a?(Champs::RepetitionChamp) }
|
||||||
end.group_by(&:libelle)
|
end.group_by(&:libelle_for_export)
|
||||||
end
|
end
|
||||||
|
|
||||||
def champs_repetables_options
|
def champs_repetables_options
|
||||||
|
@ -70,10 +70,6 @@ class ProcedureExportV2Service
|
||||||
row_style: { background_color: nil, color: "000000", font_size: 12 }
|
row_style: { background_color: nil, color: "000000", font_size: 12 }
|
||||||
}
|
}
|
||||||
|
|
||||||
def sanitize_sheet_name(name)
|
|
||||||
ActiveStorage::Filename.new(name.to_s).sanitized.truncate(30)
|
|
||||||
end
|
|
||||||
|
|
||||||
def options_for(table, format)
|
def options_for(table, format)
|
||||||
case table
|
case table
|
||||||
when :dossiers
|
when :dossiers
|
||||||
|
@ -83,8 +79,7 @@ class ProcedureExportV2Service
|
||||||
when :avis
|
when :avis
|
||||||
{ instances: avis.to_a, sheet_name: 'Avis' }.merge(DEFAULT_STYLES)
|
{ instances: avis.to_a, sheet_name: 'Avis' }.merge(DEFAULT_STYLES)
|
||||||
when Array
|
when Array
|
||||||
# We have to truncate the label here as spreadsheets have a (30 char) limit on length.
|
{ instances: table.last, sheet_name: table.first }.merge(DEFAULT_STYLES)
|
||||||
{ instances: table.last, sheet_name: sanitize_sheet_name(table.first) }.merge(DEFAULT_STYLES)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -311,7 +311,7 @@ describe ProcedureExportV2Service do
|
||||||
let(:champ_repetition) { dossiers.first.champs.find { |champ| champ.type_champ == 'repetition' } }
|
let(:champ_repetition) { dossiers.first.champs.find { |champ| champ.type_champ == 'repetition' } }
|
||||||
|
|
||||||
it 'should have sheets' do
|
it 'should have sheets' do
|
||||||
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', champ_repetition.libelle])
|
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', champ_repetition.libelle_for_export])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should have headers' do
|
it 'should have headers' do
|
||||||
|
@ -333,7 +333,18 @@ describe ProcedureExportV2Service do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should have valid sheet name' do
|
it 'should have valid sheet name' do
|
||||||
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', "A - B - C"])
|
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', "(#{champ_repetition.type_de_champ.stable_id}) A - B - C"])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with non unique labels' do
|
||||||
|
let(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :for_individual, procedure: procedure) }
|
||||||
|
let(:champ_repetition) { dossier.champs.find { |champ| champ.type_champ == 'repetition' } }
|
||||||
|
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, procedure: procedure, libelle: champ_repetition.libelle) }
|
||||||
|
let!(:another_champ_repetition) { create(:champ_repetition, type_de_champ: type_de_champ_repetition, dossier: dossier) }
|
||||||
|
|
||||||
|
it 'should have sheets' do
|
||||||
|
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', champ_repetition.libelle_for_export, another_champ_repetition.libelle_for_export])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue