Merge branch 'dev'

This commit is contained in:
gregoirenovel 2018-05-04 10:01:44 +02:00
commit a62a47f10d
4 changed files with 66 additions and 60 deletions

View file

@ -132,47 +132,21 @@ class Dossier < ApplicationRecord
procedure.cerfa_flag? && cerfa.size != 0
end
def convert_specific_hash_values_to_string(hash_to_convert)
hash_to_convert.transform_values do |value|
serialize_value_for_export(value)
end
end
def full_data_strings_array
to_sorted_values.map do |value|
serialize_value_for_export(value)
end
end
def export_entreprise_data
if entreprise.present?
etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.transform_keys { |k| "etablissement.#{k}".parameterize.underscore.to_sym }
entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.transform_keys { |k| "entreprise.#{k}".parameterize.underscore.to_sym }
else
etablissement_attr = EtablissementSerializer.new(Etablissement.new).attributes.transform_keys { |k| "etablissement.#{k}".parameterize.underscore.to_sym }
entreprise_attr = EntrepriseSerializer.new(Entreprise.new).attributes.transform_keys { |k| "entreprise.#{k}".parameterize.underscore.to_sym }
end
convert_specific_hash_values_to_string(etablissement_attr.merge(entreprise_attr))
end
def to_sorted_values
serialized_dossier = DossierTableExportSerializer.new(self)
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
serialized_dossier = DossierTableExportSerializer.new(self)
headers = serialized_dossier.attributes.keys
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
headers += procedure.types_de_champ.order(:order_place).map { |types_de_champ| types_de_champ.libelle.parameterize.underscore.to_sym }
headers += procedure.types_de_champ_private.order(:order_place).map { |types_de_champ| types_de_champ.libelle.parameterize.underscore.to_sym }
headers += export_etablissement_data.keys
headers
end
def export_values
sorted_values.map do |value|
serialize_value_for_export(value)
end
end
def followers_gestionnaires
follows.includes(:gestionnaire).map(&:gestionnaire)
end
@ -316,6 +290,32 @@ class Dossier < ApplicationRecord
value.nil? || value.kind_of?(Time) ? value : value.to_s
end
def convert_specific_hash_values_to_string(hash_to_convert)
hash_to_convert.transform_values do |value|
serialize_value_for_export(value)
end
end
def export_etablissement_data
if etablissement.present?
etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.transform_keys { |k| "etablissement.#{k}".parameterize.underscore.to_sym }
entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.transform_keys { |k| "entreprise.#{k}".parameterize.underscore.to_sym }
else
etablissement_attr = EtablissementSerializer.new(Etablissement.new).attributes.transform_keys { |k| "etablissement.#{k}".parameterize.underscore.to_sym }
entreprise_attr = EntrepriseSerializer.new(Entreprise.new).attributes.transform_keys { |k| "entreprise.#{k}".parameterize.underscore.to_sym }
end
convert_specific_hash_values_to_string(etablissement_attr.merge(entreprise_attr))
end
def sorted_values
serialized_dossier = DossierTableExportSerializer.new(self)
values = serialized_dossier.attributes.values
values += ordered_champs.map(&:for_export)
values += ordered_champs_private.map(&:for_export)
values += export_etablissement_data.values
values
end
def send_dossier_received
if saved_change_to_state? && en_instruction?
NotificationMailer.send_dossier_received(id).deliver_later

View file

@ -189,8 +189,8 @@ class Procedure < ApplicationRecord
def generate_export
exportable_dossiers = dossiers.downloadable_sorted
headers = exportable_dossiers.any? ? exportable_dossiers.first.export_headers : []
data = exportable_dossiers.any? ? exportable_dossiers.map { |d| d.full_data_strings_array } : [[]]
headers = exportable_dossiers&.first&.export_headers || []
data = exportable_dossiers.any? ? exportable_dossiers.map(&:export_values) : [[]]
{
headers: headers,

View file

@ -37,6 +37,26 @@
à l'ensemble des services de l'État plateforme
.landing-panel
.container
.role-panel-wrapper
.role-panel-30.role-usagers-image
%img.role-image{ :src => image_url("landing/roles/usagers.svg"), alt: "" }
.role-panel-70
%h1.role-panel-title Usagers
%p.role-panel-explanation Déposez des demandes en toute simplicité et retrouvez vos dossiers en ligne
= link_to "Se connecter",
new_user_session_path,
class: "role-panel-button-primary"
= link_to "Voir les démarches disponibles",
"https://demarches-simplifiees.gitbook.io/demarches-simplifiees/listes-des-demarches",
target: "_blank",
rel: "noopener noreferrer",
class: "role-panel-button-secondary"
.landing-panel.admins-panel
.container
.role-panel-wrapper.role-administrations-panel
.role-panel-30.role-administrations-image
@ -59,20 +79,6 @@
rel: "noopener noreferrer",
class: "role-panel-button-secondary"
.landing-panel.admins-panel
.container
.role-panel-wrapper
.role-panel-30.role-usagers-image
%img.role-image{ :src => image_url("landing/roles/usagers.svg"), alt: "" }
.role-panel-70
%h1.role-panel-title Usagers
%p.role-panel-explanation Déposez des demandes en toute simplicité et retrouvez vos dossiers en ligne
= link_to "Se connecter",
new_user_session_path,
class: "role-panel-button-primary"
.landing-panel
.container
%h2.landing-panel-title Ce que les utilisateurs pensent du service

View file

@ -158,7 +158,7 @@ describe Dossier do
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
let(:dossier_serialized_attributes) { DossierSerializer.new(dossier).attributes }
subject { dossier.convert_specific_hash_values_to_string(dossier_serialized_attributes) }
subject { dossier.send(:convert_specific_hash_values_to_string, dossier_serialized_attributes) }
it { expect(dossier_serialized_attributes[:id]).to be_an(Integer) }
it { expect(dossier_serialized_attributes[:created_at]).to be_a(Time) }
@ -173,11 +173,11 @@ describe Dossier do
it { expect(subject[:state]).to be_a(String) }
end
describe '#export_entreprise_data' do
describe '#export_etablissement_data' do
let(:procedure) { create(:procedure) }
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
subject { dossier.export_entreprise_data }
subject { dossier.send(:export_etablissement_data) }
it { expect(subject[:etablissement_siret]).to eq('44011762001530') }
it { expect(subject[:etablissement_siege_social]).to eq('true') }
@ -228,12 +228,12 @@ describe Dossier do
expect(subject.count).to eq(DossierTableExportSerializer.new(dossier).attributes.count +
dossier.procedure.types_de_champ.count +
dossier.procedure.types_de_champ_private.count +
dossier.export_entreprise_data.count)
dossier.send(:export_etablissement_data).count)
end
end
describe '#to_sorted_values' do
subject { dossier.to_sorted_values }
describe '#sorted_values' do
subject { dossier.send(:sorted_values) }
it { expect(subject[0]).to be_a_kind_of(Integer) }
it { expect(subject[1]).to be_a_kind_of(Time) }
@ -255,13 +255,13 @@ describe Dossier do
expect(subject.count).to eq(DossierTableExportSerializer.new(dossier).attributes.count +
dossier.procedure.types_de_champ.count +
dossier.procedure.types_de_champ_private.count +
dossier.export_entreprise_data.count)
dossier.send(:export_etablissement_data).count)
end
context 'dossier for individual' do
let(:dossier_with_individual) { create(:dossier, :for_individual, user: user, procedure: procedure) }
subject { dossier_with_individual.to_sorted_values }
subject { dossier_with_individual.send(:sorted_values) }
it { expect(subject[11]).to eq(dossier_with_individual.individual.gender) }
it { expect(subject[12]).to eq(dossier_with_individual.individual.prenom) }
@ -319,7 +319,7 @@ describe Dossier do
subject { dossier }
it { expect(dossier.full_data_strings_array).to eq(expected_string) }
it { expect(dossier.export_values).to eq(expected_string) }
end
end