Merge pull request #923 from sgmap/fix_html_tag_in_excel_export
Improve excel export
This commit is contained in:
commit
c9a2b2617d
4 changed files with 76 additions and 13 deletions
|
@ -70,6 +70,23 @@ class Champ < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def for_export
|
||||
if value.present?
|
||||
case type_champ
|
||||
when 'textarea'
|
||||
ActionView::Base.full_sanitizer.sanitize(value)
|
||||
when 'yes_no'
|
||||
value == 'yes' ? 'oui' : 'non'
|
||||
when 'multiple_drop_down_list'
|
||||
drop_down_list.selected_options_without_decorator(self).join(', ')
|
||||
else
|
||||
value
|
||||
end
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def format_date_to_iso
|
||||
|
|
|
@ -228,11 +228,11 @@ class Dossier < ActiveRecord::Base
|
|||
value = serialize_value_for_export(value)
|
||||
hash.store(key, value)
|
||||
end
|
||||
return hash
|
||||
hash
|
||||
end
|
||||
|
||||
def full_data_strings_array
|
||||
data_with_champs.map do |value|
|
||||
to_sorted_values.map do |value|
|
||||
serialize_value_for_export(value)
|
||||
end
|
||||
end
|
||||
|
@ -245,16 +245,16 @@ class Dossier < ActiveRecord::Base
|
|||
etablissement_attr = EtablissementSerializer.new(Etablissement.new).attributes.map { |k, v| ["etablissement.#{k}".parameterize.underscore.to_sym, v] }.to_h
|
||||
entreprise_attr = EntrepriseSerializer.new(Entreprise.new).attributes.map { |k, v| ["entreprise.#{k}".parameterize.underscore.to_sym, v] }.to_h
|
||||
end
|
||||
return convert_specific_hash_values_to_string(etablissement_attr.merge(entreprise_attr))
|
||||
convert_specific_hash_values_to_string(etablissement_attr.merge(entreprise_attr))
|
||||
end
|
||||
|
||||
def data_with_champs
|
||||
def to_sorted_values
|
||||
serialized_dossier = DossierTableExportSerializer.new(self)
|
||||
data = serialized_dossier.attributes.values
|
||||
data += self.ordered_champs.map(&:value)
|
||||
data += self.ordered_champs_private.map(&:value)
|
||||
data += self.export_entreprise_data.values
|
||||
return data
|
||||
values = serialized_dossier.attributes.values
|
||||
values += self.ordered_champs.map(&:for_export)
|
||||
values += self.ordered_champs_private.map(&:for_export)
|
||||
values += self.export_entreprise_data.values
|
||||
values
|
||||
end
|
||||
|
||||
def export_headers
|
||||
|
@ -263,7 +263,7 @@ class Dossier < ActiveRecord::Base
|
|||
headers += self.procedure.types_de_champ.order(:order_place).map { |types_de_champ| types_de_champ.libelle.parameterize.underscore.to_sym }
|
||||
headers += self.procedure.types_de_champ_private.order(:order_place).map { |types_de_champ| types_de_champ.libelle.parameterize.underscore.to_sym }
|
||||
headers += self.export_entreprise_data.keys
|
||||
return headers
|
||||
headers
|
||||
end
|
||||
|
||||
def followers_gestionnaires
|
||||
|
|
|
@ -63,4 +63,50 @@ describe Champ do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'for_export' do
|
||||
let(:type_de_champ) { create(:type_de_champ_public, type_champ: type_champ) }
|
||||
let(:champ) { Champ.new(type_de_champ: type_de_champ, value: value) }
|
||||
|
||||
before { champ.save }
|
||||
|
||||
context 'when type_de_champ is text' do
|
||||
let(:type_champ) { 'text' }
|
||||
let(:value) { '123' }
|
||||
|
||||
it { expect(champ.for_export).to eq('123') }
|
||||
end
|
||||
|
||||
context 'when type_de_champ is textarea' do
|
||||
let(:type_champ) { 'textarea' }
|
||||
let(:value) { '<b>gras<b>' }
|
||||
|
||||
it { expect(champ.for_export).to eq('gras') }
|
||||
end
|
||||
|
||||
context 'when type_de_champ is yes_no' do
|
||||
let(:type_champ) { 'yes_no' }
|
||||
|
||||
context 'if yes' do
|
||||
let(:value) { 'yes' }
|
||||
|
||||
it { expect(champ.for_export).to eq('oui') }
|
||||
end
|
||||
|
||||
context 'if no' do
|
||||
let(:value) { 'no' }
|
||||
|
||||
it { expect(champ.for_export).to eq('non') }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when type_de_champ is multiple_drop_down_list' do
|
||||
let(:type_champ) { 'multiple_drop_down_list' }
|
||||
let(:value) { '["Crétinier", "Mousserie"]' }
|
||||
|
||||
before { type_de_champ.drop_down_list = create(:drop_down_list) }
|
||||
|
||||
it { expect(champ.for_export).to eq('Crétinier, Mousserie') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -412,8 +412,8 @@ describe Dossier do
|
|||
}
|
||||
end
|
||||
|
||||
describe '#data_with_champs' do
|
||||
subject { dossier.data_with_champs }
|
||||
describe '#to_sorted_values' do
|
||||
subject { dossier.to_sorted_values }
|
||||
|
||||
it { expect(subject[0]).to be_a_kind_of(Integer) }
|
||||
it { expect(subject[1]).to be_a_kind_of(Time) }
|
||||
|
@ -441,7 +441,7 @@ describe Dossier do
|
|||
context 'dossier for individual' do
|
||||
let(:dossier_with_individual) { create(:dossier, :for_individual, user: user, procedure: procedure) }
|
||||
|
||||
subject { dossier_with_individual.data_with_champs }
|
||||
subject { dossier_with_individual.to_sorted_values }
|
||||
|
||||
it { expect(subject[12]).to eq(dossier_with_individual.individual.gender) }
|
||||
it { expect(subject[13]).to eq(dossier_with_individual.individual.prenom) }
|
||||
|
|
Loading…
Reference in a new issue