From 8fe92b146539f037e51e96349ae0c61b7fb090ea Mon Sep 17 00:00:00 2001 From: JC Date: Mon, 7 Nov 2016 14:07:34 +0100 Subject: [PATCH 01/18] Hack rubyzip version from Gemfile.lock, then install spreadsheet_architect --- Gemfile | 1 + Gemfile.lock | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index b92fc4cbe..95f44b15d 100644 --- a/Gemfile +++ b/Gemfile @@ -86,6 +86,7 @@ gem "smart_listing" gem 'bootstrap-wysihtml5-rails', '~> 0.3.3.8' gem 'as_csv' +gem 'spreadsheet_architect' gem 'apipie-rails', '=0.3.1' gem "maruku" # for Markdown support in apipie diff --git a/Gemfile.lock b/Gemfile.lock index 706c620e8..c241db10b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,6 +62,10 @@ GEM autoprefixer-rails (5.2.1) execjs json + axlsx (2.0.1) + htmlentities (~> 4.3.1) + nokogiri (>= 1.4.1) + rubyzip (~> 1.0.0) bcrypt (3.1.11) bindata (2.1.0) binding_of_caller (0.7.2) @@ -294,6 +298,7 @@ GEM haml (~> 4.0.0) nokogiri (~> 1.6.0) ruby_parser (~> 3.5) + htmlentities (4.3.4) http-cookie (1.0.2) domain_name (~> 0.5) httpclient (2.6.0.1) @@ -437,6 +442,10 @@ GEM rgeo (0.3.20) rgeo-geojson (0.3.1) rgeo (~> 0.3) + rodf (0.3.7) + activesupport (>= 3.0, < 6.0) + builder (~> 3.0) + rubyzip (~> 1.0) rspec (3.2.0) rspec-core (~> 3.2.0) rspec-expectations (~> 3.2.0) @@ -473,7 +482,7 @@ GEM sexp_processor (~> 4.0) ruby_parser (3.7.0) sexp_processor (~> 4.1) - rubyzip (1.1.7) + rubyzip (1.0.0) safe_yaml (1.0.4) sass (3.4.22) sass-rails (5.0.6) @@ -510,6 +519,9 @@ GEM jquery-rails kaminari (~> 0.16.1) rails (>= 3.2) + spreadsheet_architect (1.4.6) + axlsx (>= 2.0) + rodf (>= 0.3.6) spring (1.3.6) spring-commands-rspec (1.0.4) spring (>= 0.9.1) @@ -641,6 +653,7 @@ DEPENDENCIES shoulda-matchers simplecov smart_listing + spreadsheet_architect spring spring-commands-rspec therubyracer @@ -654,4 +667,4 @@ DEPENDENCIES will_paginate-bootstrap BUNDLED WITH - 1.12.5 + 1.13.6 From fa767ad56f8964fe82bbe8211bac54d34b820fc2 Mon Sep 17 00:00:00 2001 From: JC Date: Mon, 7 Nov 2016 17:23:58 +0100 Subject: [PATCH 02/18] Config using default Serializers to generate both CSV and XLSX files from Dossier records, problem with ODS in gem -> github issue openned --- app/controllers/backoffice/dossiers_controller.rb | 9 ++++++--- app/models/dossier.rb | 14 +++++++++++--- app/models/entreprise.rb | 1 + app/models/etablissement.rb | 1 + app/views/backoffice/dossiers/index.html.haml | 3 ++- config/locales/dynamics/fr.yml | 5 +++-- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 9c4895798..33d2297c6 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -1,4 +1,5 @@ class Backoffice::DossiersController < Backoffice::DossiersListController + respond_to :html, :xlsx, :ods, :csv def index super @@ -20,9 +21,11 @@ class Backoffice::DossiersController < Backoffice::DossiersListController def download_dossiers_tps dossiers = current_gestionnaire.dossiers.where.not(state: :draft) - response.headers['Content-Type'] = 'text/csv' - - render csv: dossiers, status: 200 + respond_to do |format| + format.xlsx { render xlsx: dossiers } + format.ods { render ods: dossiers } + format.csv { render csv: dossiers } + end end def search diff --git a/app/models/dossier.rb b/app/models/dossier.rb index e7b9599d0..f0de965c3 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -1,4 +1,5 @@ class Dossier < ActiveRecord::Base + include SpreadsheetArchitect enum state: {draft: 'draft', initiated: 'initiated', @@ -297,14 +298,21 @@ class Dossier < ActiveRecord::Base dossier_attr = DossierSerializer.new(self).attributes unless entreprise.nil? - etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.map { |k, v| ["etablissement.#{k}", v] }.to_h - entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.map { |k, v| ["entreprise.#{k}", v] }.to_h - dossier_attr = dossier_attr.merge(etablissement_attr).merge(entreprise_attr) + etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.map { |k, v| ["etablissement.#{k}".parameterize.underscore.to_sym, v] }.to_h + entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.map { |k, v| ["entreprise.#{k}".parameterize.underscore.to_sym, v] }.to_h + else + 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 + dossier_attr = dossier_attr.merge(etablissement_attr).merge(entreprise_attr) dossier_attr end + def spreadsheet_columns + self.as_csv.to_a + end + def reset! etablissement.destroy entreprise.destroy diff --git a/app/models/entreprise.rb b/app/models/entreprise.rb index 5e24a31bb..8e14d7640 100644 --- a/app/models/entreprise.rb +++ b/app/models/entreprise.rb @@ -1,4 +1,5 @@ class Entreprise < ActiveRecord::Base + belongs_to :dossier has_one :etablissement, dependent: :destroy has_one :rna_information, dependent: :destroy diff --git a/app/models/etablissement.rb b/app/models/etablissement.rb index 44e840205..1e80b4bad 100644 --- a/app/models/etablissement.rb +++ b/app/models/etablissement.rb @@ -1,4 +1,5 @@ class Etablissement < ActiveRecord::Base + belongs_to :dossier belongs_to :entreprise diff --git a/app/views/backoffice/dossiers/index.html.haml b/app/views/backoffice/dossiers/index.html.haml index 2f1f62703..41fe588a4 100644 --- a/app/views/backoffice/dossiers/index.html.haml +++ b/app/views/backoffice/dossiers/index.html.haml @@ -2,7 +2,8 @@ #pref_list_menu = render partial: 'backoffice/dossiers/pref_list' - =link_to t('dynamics.backoffice.download_all_dossiers'), backoffice_download_dossiers_tps_path, {class: 'btn btn-success btn-sm', style: 'float: right; margin-right: 4%; margin-top: 7px'} + =link_to t('dynamics.backoffice.download_all_dossiers_csv'), backoffice_download_dossiers_tps_path(format: :csv), {class: 'btn btn-success btn-sm', style: 'float: right; margin-right: 4%; margin-top: 7px'} + =link_to t('dynamics.backoffice.download_all_dossiers_xlsx'), backoffice_download_dossiers_tps_path(format: :xlsx), {class: 'btn btn-success btn-sm', style: 'float: right; margin-right: 4%; margin-top: 7px'} %h1 =t('dynamics.backoffice.title') diff --git a/config/locales/dynamics/fr.yml b/config/locales/dynamics/fr.yml index 0d8e42293..824ede333 100644 --- a/config/locales/dynamics/fr.yml +++ b/config/locales/dynamics/fr.yml @@ -11,7 +11,8 @@ fr: pref_list: title: 'Gestion de colonnes affichées' description: 'Ce menu vous permet de choisir les différentes colonnes que vous souhaitez voir apparaître dans votre interface de suivi des dossiers.' - download_all_dossiers: 'Tous mes dossiers en CSV' + download_all_dossiers_csv: 'Tous mes dossiers en CSV' + download_all_dossiers_xlsx: 'Tous mes dossiers en XLSX' research: placeholder: 'Rechercher un dossier ...' filter_procedure: @@ -41,4 +42,4 @@ fr: title: Dossiers onglet_accompagnateurs: add: - title: 'Ajouter un accompagnateur' \ No newline at end of file + title: 'Ajouter un accompagnateur' From 59d33357555850ca0ebdb4043ebb4cbe28ab14b2 Mon Sep 17 00:00:00 2001 From: JC Date: Tue, 8 Nov 2016 10:26:51 +0100 Subject: [PATCH 03/18] The spreasheet_architect gem's author just made a fix, updating from v1.4.6 to v1.4.7 -> log life to ruby --- Gemfile.lock | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index c241db10b..346b3746d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -344,13 +344,12 @@ GEM method_source (0.8.2) mime-types (2.99.2) mini_portile2 (2.1.0) - minitest (5.9.0) + minitest (5.9.1) multi_json (1.11.2) multipart-post (2.0.0) netrc (0.10.3) - nokogiri (1.6.8) + nokogiri (1.6.8.1) mini_portile2 (~> 2.1.0) - pkg-config (~> 1.1.7) nyan-cat-formatter (0.11) rspec (>= 2.99, >= 2.14.2, < 4) open4 (1.3.4) @@ -374,7 +373,6 @@ GEM parser (2.2.2.2) ast (>= 1.1, < 3.0) pg (0.18.2) - pkg-config (1.1.7) poltergeist (1.6.0) capybara (~> 2.1) cliver (~> 0.3.1) @@ -519,7 +517,7 @@ GEM jquery-rails kaminari (~> 0.16.1) rails (>= 3.2) - spreadsheet_architect (1.4.6) + spreadsheet_architect (1.4.7) axlsx (>= 2.0) rodf (>= 0.3.6) spring (1.3.6) From 8dda0d3fb18ec284aedbc16e9e0df5553876b46d Mon Sep 17 00:00:00 2001 From: JC Date: Tue, 8 Nov 2016 11:48:36 +0100 Subject: [PATCH 04/18] Okay... Add some conversion method to catch .ods write of number and boolean values -> as strings, passing on initial test for as_csv method --- app/models/dossier.rb | 13 ++++- app/views/backoffice/dossiers/index.html.haml | 1 + config/locales/dynamics/fr.yml | 1 + spec/models/dossier_spec.rb | 52 +++++++++---------- 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index f0de965c3..fa388fe88 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -294,9 +294,18 @@ class Dossier < ActiveRecord::Base procedure.cerfa_flag? && cerfa.size != 0 end + def convert_specific_values_to_string(hash_to_convert) + hash = {} + hash_to_convert.each do |key, value| + value = value.to_s if !value.kind_of?(Time) && !value.nil? + hash.store(key, value) + end + return hash + end + def as_csv(options={}) dossier_attr = DossierSerializer.new(self).attributes - + dossier_attr = convert_specific_values_to_string(dossier_attr) unless entreprise.nil? etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.map { |k, v| ["etablissement.#{k}".parameterize.underscore.to_sym, v] }.to_h entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.map { |k, v| ["entreprise.#{k}".parameterize.underscore.to_sym, v] }.to_h @@ -304,7 +313,7 @@ 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 - dossier_attr = dossier_attr.merge(etablissement_attr).merge(entreprise_attr) + dossier_attr = dossier_attr.merge(convert_specific_values_to_string(etablissement_attr)).merge(convert_specific_values_to_string(entreprise_attr)) dossier_attr end diff --git a/app/views/backoffice/dossiers/index.html.haml b/app/views/backoffice/dossiers/index.html.haml index 41fe588a4..23ed11f42 100644 --- a/app/views/backoffice/dossiers/index.html.haml +++ b/app/views/backoffice/dossiers/index.html.haml @@ -4,6 +4,7 @@ =link_to t('dynamics.backoffice.download_all_dossiers_csv'), backoffice_download_dossiers_tps_path(format: :csv), {class: 'btn btn-success btn-sm', style: 'float: right; margin-right: 4%; margin-top: 7px'} =link_to t('dynamics.backoffice.download_all_dossiers_xlsx'), backoffice_download_dossiers_tps_path(format: :xlsx), {class: 'btn btn-success btn-sm', style: 'float: right; margin-right: 4%; margin-top: 7px'} + =link_to t('dynamics.backoffice.download_all_dossiers_ods'), backoffice_download_dossiers_tps_path(format: :ods), {class: 'btn btn-success btn-sm', style: 'float: right; margin-right: 4%; margin-top: 7px'} %h1 =t('dynamics.backoffice.title') diff --git a/config/locales/dynamics/fr.yml b/config/locales/dynamics/fr.yml index 824ede333..af50ff493 100644 --- a/config/locales/dynamics/fr.yml +++ b/config/locales/dynamics/fr.yml @@ -13,6 +13,7 @@ fr: description: 'Ce menu vous permet de choisir les différentes colonnes que vous souhaitez voir apparaître dans votre interface de suivi des dossiers.' download_all_dossiers_csv: 'Tous mes dossiers en CSV' download_all_dossiers_xlsx: 'Tous mes dossiers en XLSX' + download_all_dossiers_ods: 'Tous mes dossiers en ODS' research: placeholder: 'Rechercher un dossier ...' filter_procedure: diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 5fb127019..426026dca 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -664,37 +664,37 @@ describe Dossier do let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } subject { dossier.as_csv } - it { expect(subject[:archived]).to be_falsey } - it { expect(subject['etablissement.siret']).to eq('44011762001530') } - it { expect(subject['etablissement.siege_social']).to be_truthy } - it { expect(subject['etablissement.naf']).to eq('4950Z') } - it { expect(subject['etablissement.libelle_naf']).to eq('Transports par conduites') } - it { expect(subject['etablissement.adresse']).to eq("GRTGAZ IMMEUBLE BORA 6 RUE RAOUL NORDLING 92270 BOIS COLOMBES") } - it { expect(subject['etablissement.numero_voie']).to eq('6') } - it { expect(subject['etablissement.type_voie']).to eq('RUE') } - it { expect(subject['etablissement.nom_voie']).to eq('RAOUL NORDLING') } - it { expect(subject['etablissement.complement_adresse']).to eq('IMMEUBLE BORA') } - it { expect(subject['etablissement.code_postal']).to eq('92270') } - it { expect(subject['etablissement.localite']).to eq('BOIS COLOMBES') } - it { expect(subject['etablissement.code_insee_localite']).to eq('92009') } - it { expect(subject['entreprise.siren']).to eq('440117620') } - it { expect(subject['entreprise.capital_social']).to eq(537100000) } - it { expect(subject['entreprise.numero_tva_intracommunautaire']).to eq('FR27440117620') } - it { expect(subject['entreprise.forme_juridique']).to eq("SA à conseil d'administration (s.a.i.)") } - it { expect(subject['entreprise.forme_juridique_code']).to eq('5599') } - it { expect(subject['entreprise.nom_commercial']).to eq('GRTGAZ') } - it { expect(subject['entreprise.raison_sociale']).to eq('GRTGAZ') } - it { expect(subject['entreprise.siret_siege_social']).to eq('44011762001530') } - it { expect(subject['entreprise.code_effectif_entreprise']).to eq('51') } - it { expect(subject['entreprise.date_creation']).to eq('Thu, 28 Jan 2016 10:16:29 UTC +00:0') } - it { expect(subject['entreprise.nom']).to be_nil } - it { expect(subject['entreprise.prenom']).to be_nil } + it { expect(subject[:archived]).to eq('false') } + it { expect(subject[:etablissement_siret]).to eq('44011762001530') } + it { expect(subject[:etablissement_siege_social]).to eq('true') } + it { expect(subject[:etablissement_naf]).to eq('4950Z') } + it { expect(subject[:etablissement_libelle_naf]).to eq('Transports par conduites') } + it { expect(subject[:etablissement_adresse]).to eq('GRTGAZ IMMEUBLE BORA 6 RUE RAOUL NORDLING 92270 BOIS COLOMBES') } + it { expect(subject[:etablissement_numero_voie]).to eq('6') } + it { expect(subject[:etablissement_type_voie]).to eq('RUE') } + it { expect(subject[:etablissement_nom_voie]).to eq('RAOUL NORDLING') } + it { expect(subject[:etablissement_complement_adresse]).to eq('IMMEUBLE BORA') } + it { expect(subject[:etablissement_code_postal]).to eq('92270') } + it { expect(subject[:etablissement_localite]).to eq('BOIS COLOMBES') } + it { expect(subject[:etablissement_code_insee_localite]).to eq('92009') } + it { expect(subject[:entreprise_siren]).to eq('440117620') } + it { expect(subject[:entreprise_capital_social]).to eq('537100000') } + it { expect(subject[:entreprise_numero_tva_intracommunautaire]).to eq('FR27440117620') } + it { expect(subject[:entreprise_forme_juridique]).to eq("SA à conseil d'administration (s.a.i.)") } + it { expect(subject[:entreprise_forme_juridique_code]).to eq('5599') } + it { expect(subject[:entreprise_nom_commercial]).to eq('GRTGAZ') } + it { expect(subject[:entreprise_raison_sociale]).to eq('GRTGAZ') } + it { expect(subject[:entreprise_siret_siege_social]).to eq('44011762001530') } + it { expect(subject[:entreprise_code_effectif_entreprise]).to eq('51') } + it { expect(subject[:entreprise_date_creation]).to eq('Thu, 28 Jan 2016 10:16:29 UTC +00:0') } + it { expect(subject[:entreprise_nom]).to be_nil } + it { expect(subject[:entreprise_prenom]).to be_nil } context 'when dossier does not have enterprise' do let(:dossier) { create(:dossier, user: user, procedure: procedure) } subject { dossier.as_csv } - it { expect(subject[:archived]).to be_falsey } + it { expect(subject[:archived]).to eq('false') } end end From 7b8b5e28e11b778ce531eebbdac5cdb6c90e3e4e Mon Sep 17 00:00:00 2001 From: JC Date: Tue, 8 Nov 2016 14:40:42 +0100 Subject: [PATCH 05/18] Adding tests, reading csv values for Dossier.to_csv, instead... checking String returned by to_ods, to_xlsx, checking encode and fields values for them would be overkill --- spec/models/dossier_spec.rb | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 426026dca..9ee562670 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -698,6 +698,66 @@ describe Dossier do end end + describe '#Dossier.to_csv' do + let!(:procedure) { create(:procedure) } + let!(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } + + subject do + dossier_hash = {} + dossier_splitted = Dossier.to_csv.split("\n").map { |cell| cell.split(",") } + index = 0 + dossier_splitted[0].each do |column| + dossier_hash.store(column.to_sym, dossier_splitted[1][index]) + index = index + 1 + end + dossier_hash + end + + it { expect(subject[:archived]).to eq('false') } + it { expect(subject[:etablissement_siret]).to eq('44011762001530') } + it { expect(subject[:etablissement_siege_social]).to eq('true') } + it { expect(subject[:etablissement_naf]).to eq('4950Z') } + it { expect(subject[:etablissement_libelle_naf]).to eq('Transports par conduites') } + it { expect(subject[:etablissement_adresse]).to eq('GRTGAZ IMMEUBLE BORA 6 RUE RAOUL NORDLING 92270 BOIS COLOMBES') } + it { expect(subject[:etablissement_numero_voie]).to eq('6') } + it { expect(subject[:etablissement_type_voie]).to eq('RUE') } + it { expect(subject[:etablissement_nom_voie]).to eq('RAOUL NORDLING') } + it { expect(subject[:etablissement_complement_adresse]).to eq('IMMEUBLE BORA') } + it { expect(subject[:etablissement_code_postal]).to eq('92270') } + it { expect(subject[:etablissement_localite]).to eq('BOIS COLOMBES') } + it { expect(subject[:etablissement_code_insee_localite]).to eq('92009') } + it { expect(subject[:entreprise_siren]).to eq('440117620') } + it { expect(subject[:entreprise_capital_social]).to eq('537100000') } + it { expect(subject[:entreprise_numero_tva_intracommunautaire]).to eq('FR27440117620') } + it { expect(subject[:entreprise_forme_juridique]).to eq("SA à conseil d'administration (s.a.i.)") } + it { expect(subject[:entreprise_forme_juridique_code]).to eq('5599') } + it { expect(subject[:entreprise_nom_commercial]).to eq('GRTGAZ') } + it { expect(subject[:entreprise_raison_sociale]).to eq('GRTGAZ') } + it { expect(subject[:entreprise_siret_siege_social]).to eq('44011762001530') } + it { expect(subject[:entreprise_code_effectif_entreprise]).to eq('51') } + it { expect(subject[:entreprise_date_creation]).to eq('2016-01-28 10:16:29 UTC') } + it { expect(subject[:entreprise_nom]).to be_nil } + it { expect(subject[:entreprise_prenom]).to be_nil } + end + + describe '#Dossier.to_xlsx' do + let!(:procedure) { create(:procedure) } + let!(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } + + subject { Dossier.to_ods } + + it { expect(subject).is_a?(String) } + end + + describe '#Dossier.to_ods' do + let!(:procedure) { create(:procedure) } + let!(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } + + subject { Dossier.to_ods } + + it { expect(subject).is_a?(String) } + end + describe '#reset!' do let!(:dossier) { create :dossier, :with_entreprise, autorisation_donnees: true } let!(:rna_information) { create :rna_information, entreprise: dossier.entreprise } From 23ee1cb21cf68ed96ebd95621059dc6b4d976242 Mon Sep 17 00:00:00 2001 From: JC Date: Tue, 8 Nov 2016 15:28:39 +0100 Subject: [PATCH 06/18] Adding style for download link as dropdown menu, changing locales --- app/assets/stylesheets/application.scss | 2 +- app/views/backoffice/dossiers/index.html.haml | 19 ++++++++++++++++--- config/locales/dynamics/fr.yml | 7 ++++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index cb7b0123c..1e7eba0fc 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -290,4 +290,4 @@ div.pagination { margin-right: 0px !important; } -} \ No newline at end of file +} diff --git a/app/views/backoffice/dossiers/index.html.haml b/app/views/backoffice/dossiers/index.html.haml index 23ed11f42..67257a9c2 100644 --- a/app/views/backoffice/dossiers/index.html.haml +++ b/app/views/backoffice/dossiers/index.html.haml @@ -2,12 +2,25 @@ #pref_list_menu = render partial: 'backoffice/dossiers/pref_list' - =link_to t('dynamics.backoffice.download_all_dossiers_csv'), backoffice_download_dossiers_tps_path(format: :csv), {class: 'btn btn-success btn-sm', style: 'float: right; margin-right: 4%; margin-top: 7px'} - =link_to t('dynamics.backoffice.download_all_dossiers_xlsx'), backoffice_download_dossiers_tps_path(format: :xlsx), {class: 'btn btn-success btn-sm', style: 'float: right; margin-right: 4%; margin-top: 7px'} - =link_to t('dynamics.backoffice.download_all_dossiers_ods'), backoffice_download_dossiers_tps_path(format: :ods), {class: 'btn btn-success btn-sm', style: 'float: right; margin-right: 4%; margin-top: 7px'} %h1 =t('dynamics.backoffice.title') + %div.dropdown.pull-right#download_menu + %button.btn.btn-default.dropdown-toggle#dropdownDownloadMenu{ type: :button, 'data-toggle' => 'dropdown', 'aria-haspopup' => true, 'aria-expanded' => false} + %i.fa.fa-download + = t('dynamics.backoffice.download_all_dossiers') + %span.caret + %ul.dropdown-menu.dropdown-menu-right + %li + = link_to backoffice_download_dossiers_tps_path(format: :csv), { class: 'btn btn-sm' } do + = t('dynamics.backoffice.format_csv') + %li + = link_to backoffice_download_dossiers_tps_path(format: :xlsx), { class: 'btn btn-sm' } do + = t('dynamics.backoffice.format_xlsx') + %li + = link_to backoffice_download_dossiers_tps_path(format: :ods), { class: 'btn btn-sm' } do + = t('dynamics.backoffice.format_ods') + = render partial: 'backoffice/dossiers/onglets' = smart_listing_render :dossiers diff --git a/config/locales/dynamics/fr.yml b/config/locales/dynamics/fr.yml index af50ff493..816f75588 100644 --- a/config/locales/dynamics/fr.yml +++ b/config/locales/dynamics/fr.yml @@ -11,9 +11,10 @@ fr: pref_list: title: 'Gestion de colonnes affichées' description: 'Ce menu vous permet de choisir les différentes colonnes que vous souhaitez voir apparaître dans votre interface de suivi des dossiers.' - download_all_dossiers_csv: 'Tous mes dossiers en CSV' - download_all_dossiers_xlsx: 'Tous mes dossiers en XLSX' - download_all_dossiers_ods: 'Tous mes dossiers en ODS' + download_all_dossiers: 'Télécharger mes dossiers' + format_csv: 'Au format CSV' + format_xlsx: 'Au format XLSX' + format_ods: 'Au format ODS' research: placeholder: 'Rechercher un dossier ...' filter_procedure: From 973570332f8917573eb325792e3a162f895f1b5e Mon Sep 17 00:00:00 2001 From: JC Date: Wed, 9 Nov 2016 09:19:57 +0100 Subject: [PATCH 07/18] Implemented custom method to catch procedure_id while rendering data on each request format --- .../backoffice/dossiers_controller.rb | 13 ++++++++----- app/models/dossier.rb | 19 +++++++++++++++++-- app/views/backoffice/dossiers/index.html.haml | 6 +++--- spec/models/dossier_spec.rb | 6 +++--- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 33d2297c6..3dc04f42f 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -20,11 +20,14 @@ class Backoffice::DossiersController < Backoffice::DossiersListController def download_dossiers_tps dossiers = current_gestionnaire.dossiers.where.not(state: :draft) - - respond_to do |format| - format.xlsx { render xlsx: dossiers } - format.ods { render ods: dossiers } - format.csv { render csv: dossiers } + if procedure = Procedure.find_by(id: params[:procedure_id]) + respond_with Dossier.export_columns_and_procedure(dossiers, request.format, procedure) + else + respond_to do |format| + format.xlsx { render xlsx: dossiers } + format.ods { render ods: dossiers } + format.csv { render csv: dossiers } + end end end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index fa388fe88..21b6629e4 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -303,7 +303,7 @@ class Dossier < ActiveRecord::Base return hash end - def as_csv(options={}) + def export_default_columns dossier_attr = DossierSerializer.new(self).attributes dossier_attr = convert_specific_values_to_string(dossier_attr) unless entreprise.nil? @@ -319,7 +319,22 @@ class Dossier < ActiveRecord::Base end def spreadsheet_columns - self.as_csv.to_a + self.export_default_columns.to_a + end + + def self.export_columns_and_procedure(dossiers, format, procedure) + data = [] + headers = dossiers.first.export_default_columns.keys + dossiers.each do |dossier| + data << dossier.export_default_columns.values + end + if ["csv"].include?(format) + return SpreadsheetArchitect.to_csv(data: data, headers: headers) + elsif ["xlsx"].include?(format) + return SpreadsheetArchitect.to_xlsx(data: data, headers: headers) + elsif ["ods"].include?(format) + return SpreadsheetArchitect.to_ods(data: data, headers: headers) + end end def reset! diff --git a/app/views/backoffice/dossiers/index.html.haml b/app/views/backoffice/dossiers/index.html.haml index 67257a9c2..8629c2a79 100644 --- a/app/views/backoffice/dossiers/index.html.haml +++ b/app/views/backoffice/dossiers/index.html.haml @@ -12,13 +12,13 @@ %span.caret %ul.dropdown-menu.dropdown-menu-right %li - = link_to backoffice_download_dossiers_tps_path(format: :csv), { class: 'btn btn-sm' } do + = link_to backoffice_download_dossiers_tps_path(format: :csv, procedure_id: params[:id]), { class: 'btn btn-sm' } do = t('dynamics.backoffice.format_csv') %li - = link_to backoffice_download_dossiers_tps_path(format: :xlsx), { class: 'btn btn-sm' } do + = link_to backoffice_download_dossiers_tps_path(format: :xlsx, procedure_id: params[:id]), { class: 'btn btn-sm' } do = t('dynamics.backoffice.format_xlsx') %li - = link_to backoffice_download_dossiers_tps_path(format: :ods), { class: 'btn btn-sm' } do + = link_to backoffice_download_dossiers_tps_path(format: :ods, procedure_id: params[:id]), { class: 'btn btn-sm' } do = t('dynamics.backoffice.format_ods') = render partial: 'backoffice/dossiers/onglets' diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 9ee562670..7630c20e3 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -659,10 +659,10 @@ describe Dossier do end end - describe '#as_csv?' do + describe '#export_default_columns?' do let(:procedure) { create(:procedure) } let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } - subject { dossier.as_csv } + subject { dossier.export_default_columns } it { expect(subject[:archived]).to eq('false') } it { expect(subject[:etablissement_siret]).to eq('44011762001530') } @@ -692,7 +692,7 @@ describe Dossier do context 'when dossier does not have enterprise' do let(:dossier) { create(:dossier, user: user, procedure: procedure) } - subject { dossier.as_csv } + subject { dossier.export_default_columns } it { expect(subject[:archived]).to eq('false') } end From 2056605135d4d6af587288f866f674d1595abc99 Mon Sep 17 00:00:00 2001 From: JC Date: Wed, 9 Nov 2016 10:49:37 +0100 Subject: [PATCH 08/18] Working with procedure types_de_champ ordered by id ASC -> building bunch of 'extra' data to default data values... when value is set (obvious) --- app/models/dossier.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 21b6629e4..10708a082 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -325,8 +325,22 @@ class Dossier < ActiveRecord::Base def self.export_columns_and_procedure(dossiers, format, procedure) data = [] headers = dossiers.first.export_default_columns.keys + procedure_types = procedure.types_de_champ.order("id ASC") + procedure_types.map(&:libelle).each do |libelle| + headers << libelle.parameterize.underscore.to_sym + end dossiers.each do |dossier| - data << dossier.export_default_columns.values + dossier_data = dossier.export_default_columns.values + champs_with_value = dossier.champs.where.not(value: ["", nil]) + dossier_procedure_data = [] + procedure_types.map(&:id).each do |type_id| + if champs_with_value.map(&:type_de_champ_id).include?(type_id) + dossier_procedure_data << champs_with_value.find_by(type_de_champ_id: type_id).value + else + dossier_procedure_data << nil + end + end + data << (dossier_data << dossier_procedure_data).flatten end if ["csv"].include?(format) return SpreadsheetArchitect.to_csv(data: data, headers: headers) From c01e3987f6b8cc4575b231a4a6b345b57acec3d0 Mon Sep 17 00:00:00 2001 From: JC Date: Wed, 9 Nov 2016 15:36:18 +0100 Subject: [PATCH 09/18] Using serializer to get procedure.dossier from controller --- .../backoffice/dossiers_controller.rb | 5 ++- app/models/dossier.rb | 39 +++++++++---------- .../dossier_procedure_serializer.rb | 10 +++++ app/serializers/dossier_serializer.rb | 5 +-- 4 files changed, 33 insertions(+), 26 deletions(-) create mode 100644 app/serializers/dossier_procedure_serializer.rb diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 3dc04f42f..b5fd6caa2 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -19,10 +19,11 @@ class Backoffice::DossiersController < Backoffice::DossiersListController end def download_dossiers_tps - dossiers = current_gestionnaire.dossiers.where.not(state: :draft) if procedure = Procedure.find_by(id: params[:procedure_id]) - respond_with Dossier.export_columns_and_procedure(dossiers, request.format, procedure) + dossiers = procedure.dossiers.where.not(state: :draft) + respond_with Dossier.export_columns_and_procedure(dossiers, request.format) else + dossiers = current_gestionnaire.dossiers.where.not(state: :draft) respond_to do |format| format.xlsx { render xlsx: dossiers } format.ods { render ods: dossiers } diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 10708a082..2ea6d4307 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -303,9 +303,7 @@ class Dossier < ActiveRecord::Base return hash end - def export_default_columns - dossier_attr = DossierSerializer.new(self).attributes - dossier_attr = convert_specific_values_to_string(dossier_attr) + def export_entreprise_data unless entreprise.nil? etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.map { |k, v| ["etablissement.#{k}".parameterize.underscore.to_sym, v] }.to_h entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.map { |k, v| ["entreprise.#{k}".parameterize.underscore.to_sym, v] }.to_h @@ -313,34 +311,33 @@ 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 - dossier_attr = dossier_attr.merge(convert_specific_values_to_string(etablissement_attr)).merge(convert_specific_values_to_string(entreprise_attr)) + return convert_specific_values_to_string(etablissement_attr).merge(convert_specific_values_to_string(entreprise_attr)) + end - dossier_attr + def export_default_columns + dossier_attr = DossierSerializer.new(self).attributes + dossier_attr = convert_specific_values_to_string(dossier_attr) + dossier_attr = dossier_attr.merge(self.export_entreprise_data) + return dossier_attr end def spreadsheet_columns self.export_default_columns.to_a end - def self.export_columns_and_procedure(dossiers, format, procedure) + def self.export_columns_and_procedure(dossiers, format) data = [] - headers = dossiers.first.export_default_columns.keys - procedure_types = procedure.types_de_champ.order("id ASC") - procedure_types.map(&:libelle).each do |libelle| - headers << libelle.parameterize.underscore.to_sym - end + headers = [] dossiers.each do |dossier| - dossier_data = dossier.export_default_columns.values - champs_with_value = dossier.champs.where.not(value: ["", nil]) - dossier_procedure_data = [] - procedure_types.map(&:id).each do |type_id| - if champs_with_value.map(&:type_de_champ_id).include?(type_id) - dossier_procedure_data << champs_with_value.find_by(type_de_champ_id: type_id).value - else - dossier_procedure_data << nil - end + serialized_dossier = DossierProcedureSerializer.new(dossier).as_json[:dossier_procedure] + champs = {} + serialized_dossier[:champs].each do |champ_hash| + champs[champ_hash[:type_de_champ]["libelle"].parameterize.underscore.to_sym] = champ_hash[:value] end - data << (dossier_data << dossier_procedure_data).flatten + dossier_data = serialized_dossier.except(:champs).merge(champs) + dossier_data = dossier.convert_specific_values_to_string(dossier_data) + headers = (dossier_data.keys << dossier.export_entreprise_data.keys).flatten + data << (dossier_data.values << dossier.export_entreprise_data.values).flatten end if ["csv"].include?(format) return SpreadsheetArchitect.to_csv(data: data, headers: headers) diff --git a/app/serializers/dossier_procedure_serializer.rb b/app/serializers/dossier_procedure_serializer.rb new file mode 100644 index 000000000..493764948 --- /dev/null +++ b/app/serializers/dossier_procedure_serializer.rb @@ -0,0 +1,10 @@ +class DossierProcedureSerializer < ActiveModel::Serializer + attributes :id, + :created_at, + :updated_at, + :archived, + :mandataire_social, + :state + + has_many :champs +end diff --git a/app/serializers/dossier_serializer.rb b/app/serializers/dossier_serializer.rb index 5060598ab..eb074761b 100644 --- a/app/serializers/dossier_serializer.rb +++ b/app/serializers/dossier_serializer.rb @@ -4,8 +4,7 @@ class DossierSerializer < ActiveModel::Serializer :updated_at, :archived, :mandataire_social, - :state, - :total_commentaire + :state has_one :entreprise has_one :etablissement @@ -15,4 +14,4 @@ class DossierSerializer < ActiveModel::Serializer has_many :champs_private has_many :pieces_justificatives has_many :types_de_piece_justificative -end \ No newline at end of file +end From a89a40df34964221d89ac21a3aa3a5ae5b35e885 Mon Sep 17 00:00:00 2001 From: JC Date: Wed, 9 Nov 2016 17:20:55 +0100 Subject: [PATCH 10/18] Prevent call for headers writting (export with procedures), get filtered dossiers by using the 'yoloServiceRegexCraftedByHandMetaForAllProject' -> extra :), adding tests for generic methods, still need to test export_columns_and_procedure --- .../backoffice/dossiers_controller.rb | 4 +- app/models/dossier.rb | 4 +- spec/models/dossier_spec.rb | 58 ++++++++++++++++++- 3 files changed, 61 insertions(+), 5 deletions(-) diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index b5fd6caa2..ea5d52b05 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -20,10 +20,10 @@ class Backoffice::DossiersController < Backoffice::DossiersListController def download_dossiers_tps if procedure = Procedure.find_by(id: params[:procedure_id]) - dossiers = procedure.dossiers.where.not(state: :draft) + dossiers = DossiersListGestionnaireService.new(current_gestionnaire, nil, procedure).filter_dossiers respond_with Dossier.export_columns_and_procedure(dossiers, request.format) else - dossiers = current_gestionnaire.dossiers.where.not(state: :draft) + dossiers = DossiersListGestionnaireService.new(current_gestionnaire, nil, nil).filter_dossiers respond_to do |format| format.xlsx { render xlsx: dossiers } format.ods { render ods: dossiers } diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 2ea6d4307..9996fb005 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -327,7 +327,7 @@ class Dossier < ActiveRecord::Base def self.export_columns_and_procedure(dossiers, format) data = [] - headers = [] + headers = nil dossiers.each do |dossier| serialized_dossier = DossierProcedureSerializer.new(dossier).as_json[:dossier_procedure] champs = {} @@ -336,7 +336,7 @@ class Dossier < ActiveRecord::Base end dossier_data = serialized_dossier.except(:champs).merge(champs) dossier_data = dossier.convert_specific_values_to_string(dossier_data) - headers = (dossier_data.keys << dossier.export_entreprise_data.keys).flatten + headers ||= (dossier_data.keys << dossier.export_entreprise_data.keys).flatten data << (dossier_data.values << dossier.export_entreprise_data.values).flatten end if ["csv"].include?(format) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 7630c20e3..ac0a27b03 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -659,7 +659,63 @@ describe Dossier do end end - describe '#export_default_columns?' do + describe '#convert_specific_values_to_string(hash_to_convert)' do + let(:procedure) { create(:procedure) } + let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } + let(:dossier_serialized_attributes) { DossierSerializer.new(dossier).attributes } + + subject { dossier.convert_specific_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) } + it { expect(dossier_serialized_attributes[:updated_at]).to be_a(Time) } + it { expect(dossier_serialized_attributes[:archived]).to be_in([true, false]) } + it { expect(dossier_serialized_attributes[:mandataire_social]).to be_in([true, false]) } + it { expect(dossier_serialized_attributes[:state]).to be_a(String) } + + it { expect(subject[:id]).to be_a(String) } + it { expect(subject[:created_at]).to be_a(Time) } + it { expect(subject[:updated_at]).to be_a(Time) } + it { expect(subject[:archived]).to be_a(String) } + it { expect(subject[:mandataire_social]).to be_a(String) } + it { expect(subject[:state]).to be_a(String) } + end + + describe '#export_entreprise_data' do + let(:procedure) { create(:procedure) } + let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } + + subject { dossier.export_entreprise_data } + + it { expect(subject[:etablissement_siret]).to eq('44011762001530') } + it { expect(subject[:etablissement_siege_social]).to eq('true') } + it { expect(subject[:etablissement_naf]).to eq('4950Z') } + it { expect(subject[:etablissement_libelle_naf]).to eq('Transports par conduites') } + it { expect(subject[:etablissement_adresse]).to eq('GRTGAZ IMMEUBLE BORA 6 RUE RAOUL NORDLING 92270 BOIS COLOMBES') } + it { expect(subject[:etablissement_numero_voie]).to eq('6') } + it { expect(subject[:etablissement_type_voie]).to eq('RUE') } + it { expect(subject[:etablissement_nom_voie]).to eq('RAOUL NORDLING') } + it { expect(subject[:etablissement_complement_adresse]).to eq('IMMEUBLE BORA') } + it { expect(subject[:etablissement_code_postal]).to eq('92270') } + it { expect(subject[:etablissement_localite]).to eq('BOIS COLOMBES') } + it { expect(subject[:etablissement_code_insee_localite]).to eq('92009') } + it { expect(subject[:entreprise_siren]).to eq('440117620') } + it { expect(subject[:entreprise_capital_social]).to eq('537100000') } + it { expect(subject[:entreprise_numero_tva_intracommunautaire]).to eq('FR27440117620') } + it { expect(subject[:entreprise_forme_juridique]).to eq("SA à conseil d'administration (s.a.i.)") } + it { expect(subject[:entreprise_forme_juridique_code]).to eq('5599') } + it { expect(subject[:entreprise_nom_commercial]).to eq('GRTGAZ') } + it { expect(subject[:entreprise_raison_sociale]).to eq('GRTGAZ') } + it { expect(subject[:entreprise_siret_siege_social]).to eq('44011762001530') } + it { expect(subject[:entreprise_code_effectif_entreprise]).to eq('51') } + it { expect(subject[:entreprise_date_creation]).to eq('Thu, 28 Jan 2016 10:16:29 UTC +00:0') } + it { expect(subject[:entreprise_nom]).to be_nil } + it { expect(subject[:entreprise_prenom]).to be_nil } + + it { expect(subject.count).to eq(EntrepriseSerializer.new(Entreprise.new).as_json[:entreprise].count + EtablissementSerializer.new(Etablissement.new).as_json[:etablissement].count) } + end + + describe '#export_default_columns' do let(:procedure) { create(:procedure) } let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } subject { dossier.export_default_columns } From e49e0b02ef17d1b905a6839d13a64ce233b5395c Mon Sep 17 00:00:00 2001 From: JC Date: Mon, 14 Nov 2016 10:41:56 +0100 Subject: [PATCH 11/18] Split methods for export, need to write 2 tests for headers and raw data (export_headers, data_with_champs) --- .../backoffice/dossiers_controller.rb | 2 +- app/models/dossier.rb | 37 +++++++++++++------ spec/models/dossier_spec.rb | 12 ++++++ 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index ea5d52b05..9d14262fd 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -21,7 +21,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController def download_dossiers_tps if procedure = Procedure.find_by(id: params[:procedure_id]) dossiers = DossiersListGestionnaireService.new(current_gestionnaire, nil, procedure).filter_dossiers - respond_with Dossier.export_columns_and_procedure(dossiers, request.format) + respond_with Dossier.export_full_generation(dossiers, request.format) else dossiers = DossiersListGestionnaireService.new(current_gestionnaire, nil, nil).filter_dossiers respond_to do |format| diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 9996fb005..da355bf9c 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -325,19 +325,34 @@ class Dossier < ActiveRecord::Base self.export_default_columns.to_a end - def self.export_columns_and_procedure(dossiers, format) + def export_headers + serialized_dossier = DossierProcedureSerializer.new(self).as_json[:dossier_procedure] + champs = {} + serialized_dossier[:champs].each do |champ_hash| + champs[champ_hash[:type_de_champ]["libelle"].parameterize.underscore.to_sym] = champ_hash[:value] + end + dossier_data = serialized_dossier.except(:champs).merge(champs) + dossier_data = self.convert_specific_values_to_string(dossier_data) + return (dossier_data.keys << self.export_entreprise_data.keys).flatten + end + + def data_with_champs + serialized_dossier = DossierProcedureSerializer.new(self).as_json[:dossier_procedure] + champs = {} + serialized_dossier[:champs].each do |champ_hash| + champs[champ_hash[:type_de_champ]["libelle"].parameterize.underscore.to_sym] = champ_hash[:value] + end + dossier_data = serialized_dossier.except(:champs).merge(champs) + dossier_data = self.convert_specific_values_to_string(dossier_data) + return (dossier_data.values << self.export_entreprise_data.values).flatten + end + + def self.export_full_generation(dossiers, format) data = [] - headers = nil + headers = [] dossiers.each do |dossier| - serialized_dossier = DossierProcedureSerializer.new(dossier).as_json[:dossier_procedure] - champs = {} - serialized_dossier[:champs].each do |champ_hash| - champs[champ_hash[:type_de_champ]["libelle"].parameterize.underscore.to_sym] = champ_hash[:value] - end - dossier_data = serialized_dossier.except(:champs).merge(champs) - dossier_data = dossier.convert_specific_values_to_string(dossier_data) - headers ||= (dossier_data.keys << dossier.export_entreprise_data.keys).flatten - data << (dossier_data.values << dossier.export_entreprise_data.values).flatten + headers = dossier.export_headers if headers.empty? + data << dossier.data_with_champs end if ["csv"].include?(format) return SpreadsheetArchitect.to_csv(data: data, headers: headers) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index ac0a27b03..3267c74cf 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -754,6 +754,18 @@ describe Dossier do end end + describe '#export_headers' do + let(:procedure) { create(:procedure) } + let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } + + subject { dossier.export_headers } + it do + end + end + + describe '#data_with_champs' do + end + describe '#Dossier.to_csv' do let!(:procedure) { create(:procedure) } let!(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } From 5c3049d6bde6b8650a4b38799753bfd1784ce601 Mon Sep 17 00:00:00 2001 From: JC Date: Mon, 14 Nov 2016 14:39:59 +0100 Subject: [PATCH 12/18] Manualy sort type_de_champ by order_place --- app/models/dossier.rb | 30 +++++++++---------- app/models/type_de_champ.rb | 2 +- .../dossier_procedure_serializer.rb | 5 ++++ .../dossiers_list_gestionnaire_service.rb | 2 +- spec/models/dossier_spec.rb | 9 ------ 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index da355bf9c..f397c2bcb 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -297,8 +297,13 @@ class Dossier < ActiveRecord::Base def convert_specific_values_to_string(hash_to_convert) hash = {} hash_to_convert.each do |key, value| - value = value.to_s if !value.kind_of?(Time) && !value.nil? - hash.store(key, value) + if value.nil? + value = "" + hash.store(key, value) + else + value = value.to_s if !value.kind_of?(Time) + hash.store(key, value) + end end return hash end @@ -325,34 +330,27 @@ class Dossier < ActiveRecord::Base self.export_default_columns.to_a end - def export_headers - serialized_dossier = DossierProcedureSerializer.new(self).as_json[:dossier_procedure] - champs = {} - serialized_dossier[:champs].each do |champ_hash| - champs[champ_hash[:type_de_champ]["libelle"].parameterize.underscore.to_sym] = champ_hash[:value] - end - dossier_data = serialized_dossier.except(:champs).merge(champs) - dossier_data = self.convert_specific_values_to_string(dossier_data) - return (dossier_data.keys << self.export_entreprise_data.keys).flatten - end - def data_with_champs + data = [] serialized_dossier = DossierProcedureSerializer.new(self).as_json[:dossier_procedure] champs = {} serialized_dossier[:champs].each do |champ_hash| champs[champ_hash[:type_de_champ]["libelle"].parameterize.underscore.to_sym] = champ_hash[:value] end + binding.pry dossier_data = serialized_dossier.except(:champs).merge(champs) dossier_data = self.convert_specific_values_to_string(dossier_data) - return (dossier_data.values << self.export_entreprise_data.values).flatten + return dossier_data.merge(self.export_entreprise_data) end def self.export_full_generation(dossiers, format) data = [] headers = [] dossiers.each do |dossier| - headers = dossier.export_headers if headers.empty? - data << dossier.data_with_champs + if dossier.id == 948 || dossier.id == 955 + data << dossier.data_with_champs.values + headers = dossier.data_with_champs.keys if headers.empty? + end end if ["csv"].include?(format) return SpreadsheetArchitect.to_csv(data: data, headers: headers) diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 553efdf4e..9d1b2e693 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -43,4 +43,4 @@ class TypeDeChamp < ActiveRecord::Base self.mandatory = false if self.type_champ == 'header_section' true end -end \ No newline at end of file +end diff --git a/app/serializers/dossier_procedure_serializer.rb b/app/serializers/dossier_procedure_serializer.rb index 493764948..ade47dc23 100644 --- a/app/serializers/dossier_procedure_serializer.rb +++ b/app/serializers/dossier_procedure_serializer.rb @@ -7,4 +7,9 @@ class DossierProcedureSerializer < ActiveModel::Serializer :state has_many :champs + + + def champs + object.champs.order("type_de_champ_id") + end end diff --git a/app/services/dossiers_list_gestionnaire_service.rb b/app/services/dossiers_list_gestionnaire_service.rb index bc7923d08..0d84f33d3 100644 --- a/app/services/dossiers_list_gestionnaire_service.rb +++ b/app/services/dossiers_list_gestionnaire_service.rb @@ -183,4 +183,4 @@ class DossiersListGestionnaireService def current_preference_smart_listing_page @current_devise_profil.preference_smart_listing_page end -end \ No newline at end of file +end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 3267c74cf..bb040d9a3 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -754,15 +754,6 @@ describe Dossier do end end - describe '#export_headers' do - let(:procedure) { create(:procedure) } - let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } - - subject { dossier.export_headers } - it do - end - end - describe '#data_with_champs' do end From 5aa9c756697800276273fd60563b72fbed63ed61 Mon Sep 17 00:00:00 2001 From: JC Date: Mon, 14 Nov 2016 16:37:58 +0100 Subject: [PATCH 13/18] Ordering champs through export method, not through serializer --- app/models/dossier.rb | 30 +++++++++---------- .../dossier_procedure_serializer.rb | 7 ----- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index f397c2bcb..8b81d8dca 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -331,26 +331,26 @@ class Dossier < ActiveRecord::Base end def data_with_champs - data = [] - serialized_dossier = DossierProcedureSerializer.new(self).as_json[:dossier_procedure] - champs = {} - serialized_dossier[:champs].each do |champ_hash| - champs[champ_hash[:type_de_champ]["libelle"].parameterize.underscore.to_sym] = champ_hash[:value] - end - binding.pry - dossier_data = serialized_dossier.except(:champs).merge(champs) - dossier_data = self.convert_specific_values_to_string(dossier_data) - return dossier_data.merge(self.export_entreprise_data) + serialized_dossier = DossierProcedureSerializer.new(self) + data = serialized_dossier.attributes.values + data += self.champs.order('type_de_champ_id ASC').map(&:value) + data += self.export_entreprise_data.values + return data + end + + def export_headers + serialized_dossier = DossierProcedureSerializer.new(self) + headers = serialized_dossier.attributes.keys + headers += self.procedure.types_de_champ.order('id ASC').map { |types_de_champ| types_de_champ.libelle.parameterize.underscore.to_sym } + headers += self.export_entreprise_data.keys + return headers end def self.export_full_generation(dossiers, format) data = [] - headers = [] + headers = dossiers.first.export_headers dossiers.each do |dossier| - if dossier.id == 948 || dossier.id == 955 - data << dossier.data_with_champs.values - headers = dossier.data_with_champs.keys if headers.empty? - end + data << dossier.data_with_champs end if ["csv"].include?(format) return SpreadsheetArchitect.to_csv(data: data, headers: headers) diff --git a/app/serializers/dossier_procedure_serializer.rb b/app/serializers/dossier_procedure_serializer.rb index ade47dc23..278c6d4ce 100644 --- a/app/serializers/dossier_procedure_serializer.rb +++ b/app/serializers/dossier_procedure_serializer.rb @@ -5,11 +5,4 @@ class DossierProcedureSerializer < ActiveModel::Serializer :archived, :mandataire_social, :state - - has_many :champs - - - def champs - object.champs.order("type_de_champ_id") - end end From 2f96895bb8cb97eab07bc08173324104ebd59ef1 Mon Sep 17 00:00:00 2001 From: JC Date: Mon, 14 Nov 2016 17:25:17 +0100 Subject: [PATCH 14/18] Continue tests for data_with_champs method, and add a convert_specific_values_to_string for array --- app/models/dossier.rb | 9 ++------- spec/models/dossier_spec.rb | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 8b81d8dca..86fb24fc1 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -297,13 +297,8 @@ class Dossier < ActiveRecord::Base def convert_specific_values_to_string(hash_to_convert) hash = {} hash_to_convert.each do |key, value| - if value.nil? - value = "" - hash.store(key, value) - else - value = value.to_s if !value.kind_of?(Time) - hash.store(key, value) - end + value = value.to_s if !value.kind_of?(Time) && !value.nil? + hash.store(key, value) end return hash end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index bb040d9a3..8c53b2dba 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -754,7 +754,21 @@ describe Dossier do end end + describe '#export_headers' do + let(:procedure) { create(:procedure, :with_type_de_champ) } + let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } + subject { dossier.export_headers } + + it { expect(subject).to include(:description) } + it { expect(subject.count).to eq(DossierProcedureSerializer.new(dossier).attributes.count + dossier.procedure.types_de_champ.count + dossier.export_entreprise_data.count) } + end + describe '#data_with_champs' do + let(:procedure) { create(:procedure, :with_type_de_champ) } + let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } + subject { dossier.data_with_champs } + + it { expect(subject.count).to eq(DossierProcedureSerializer.new(dossier).attributes.count + dossier.procedure.types_de_champ.count + dossier.export_entreprise_data.count) } end describe '#Dossier.to_csv' do @@ -803,7 +817,7 @@ describe Dossier do let!(:procedure) { create(:procedure) } let!(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } - subject { Dossier.to_ods } + subject { Dossier.to_xlsx } it { expect(subject).is_a?(String) } end From a549f95da1106da7e28ee314b74fe4f53625d425 Mon Sep 17 00:00:00 2001 From: JC Date: Mon, 14 Nov 2016 17:43:34 +0100 Subject: [PATCH 15/18] Continue test for data_with_champs --- app/models/dossier.rb | 17 +++++++++++++---- spec/models/dossier_spec.rb | 18 ++++++++++++++++-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 86fb24fc1..700c7da20 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -294,7 +294,7 @@ class Dossier < ActiveRecord::Base procedure.cerfa_flag? && cerfa.size != 0 end - def convert_specific_values_to_string(hash_to_convert) + def convert_specific_hash_values_to_string(hash_to_convert) hash = {} hash_to_convert.each do |key, value| value = value.to_s if !value.kind_of?(Time) && !value.nil? @@ -303,6 +303,15 @@ class Dossier < ActiveRecord::Base return hash end + def convert_specific_array_values_to_string(array_to_convert) + array = [] + array_to_convert.each do |value| + value = value.to_s if !value.kind_of?(Time) && !value.nil? + array << value + end + return array + end + def export_entreprise_data unless entreprise.nil? etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.map { |k, v| ["etablissement.#{k}".parameterize.underscore.to_sym, v] }.to_h @@ -311,12 +320,12 @@ 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_values_to_string(etablissement_attr).merge(convert_specific_values_to_string(entreprise_attr)) + return convert_specific_hash_values_to_string(etablissement_attr.merge(entreprise_attr)) end def export_default_columns dossier_attr = DossierSerializer.new(self).attributes - dossier_attr = convert_specific_values_to_string(dossier_attr) + dossier_attr = convert_specific_hash_values_to_string(dossier_attr) dossier_attr = dossier_attr.merge(self.export_entreprise_data) return dossier_attr end @@ -345,7 +354,7 @@ class Dossier < ActiveRecord::Base data = [] headers = dossiers.first.export_headers dossiers.each do |dossier| - data << dossier.data_with_champs + data << dossier.convert_specific_array_values_to_string(data_with_champs) end if ["csv"].include?(format) return SpreadsheetArchitect.to_csv(data: data, headers: headers) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 8c53b2dba..0bd7f73a8 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -659,12 +659,12 @@ describe Dossier do end end - describe '#convert_specific_values_to_string(hash_to_convert)' do + describe '#convert_specific_hash_values_to_string(hash_to_convert)' do let(:procedure) { create(:procedure) } let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } let(:dossier_serialized_attributes) { DossierSerializer.new(dossier).attributes } - subject { dossier.convert_specific_values_to_string(dossier_serialized_attributes) } + subject { dossier.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) } @@ -681,6 +681,14 @@ describe Dossier do it { expect(subject[:state]).to be_a(String) } end + describe '#convert_specific_array_values_to_string(array_to_convert)' do + let(:procedure) { create(:procedure) } + let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } + let(:dossier_data_with_champs) { dossier.data_with_champs } + + subject { dossier.convert_specific_hash_values_to_string(dossier_data_with_champs) } + end + describe '#export_entreprise_data' do let(:procedure) { create(:procedure) } let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } @@ -768,6 +776,12 @@ describe Dossier do let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } subject { dossier.data_with_champs } + it do + binding.pry + end + it { expect(subject[0]).to be_a_kind_of(Integer)} + it { expect(subject[1]).to be_a_kind_of(Time)} + it { expect(subject[2]).to be_a_kind_of(Time)} it { expect(subject.count).to eq(DossierProcedureSerializer.new(dossier).attributes.count + dossier.procedure.types_de_champ.count + dossier.export_entreprise_data.count) } end From f1b177e0bb48d0558cc5e6658327d97f9972ce05 Mon Sep 17 00:00:00 2001 From: JC Date: Tue, 15 Nov 2016 10:19:47 +0100 Subject: [PATCH 16/18] Testing only primary dossier attributes for data_with_champs methods --- spec/models/dossier_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 0bd7f73a8..1cc26e1b4 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -776,12 +776,12 @@ describe Dossier do let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } subject { dossier.data_with_champs } - it do - binding.pry - end - it { expect(subject[0]).to be_a_kind_of(Integer)} - it { expect(subject[1]).to be_a_kind_of(Time)} - it { expect(subject[2]).to be_a_kind_of(Time)} + it { expect(subject[0]).to be_a_kind_of(Integer) } + it { expect(subject[1]).to be_a_kind_of(Time) } + it { expect(subject[2]).to be_a_kind_of(Time) } + it { expect(subject[3]).to be_in([true, false]) } + it { expect(subject[4]).to be_in([true, false]) } + it { expect(subject[5]).to eq("draft") } it { expect(subject.count).to eq(DossierProcedureSerializer.new(dossier).attributes.count + dossier.procedure.types_de_champ.count + dossier.export_entreprise_data.count) } end From 23b928f1601389006bb7a7c1e58b6aea584b1a7e Mon Sep 17 00:00:00 2001 From: JC Date: Tue, 15 Nov 2016 17:06:40 +0100 Subject: [PATCH 17/18] Adding limit (200) for dossier exportation --- Gemfile | 5 ++++- app/controllers/backoffice/dossiers_controller.rb | 4 ++-- app/views/backoffice/dossiers/index.html.haml | 9 ++++++--- config/locales/dynamics/fr.yml | 1 + 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 84905ae0c..98ccff836 100644 --- a/Gemfile +++ b/Gemfile @@ -112,6 +112,10 @@ group :test do gem 'vcr' end +group :development do + gem 'web-console', '~> 2.0' +end + group :development, :test do # gem 'terminal-notifier' # gem 'terminal-notifier-guard' @@ -121,7 +125,6 @@ group :development, :test do gem 'pry-byebug' # Access an IRB console on exception pages or by using <%= console %> in views - gem 'web-console', '~> 2.0' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 3b2a84dba..ce39dbed1 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -20,10 +20,10 @@ class Backoffice::DossiersController < Backoffice::DossiersListController def download_dossiers_tps if procedure = Procedure.find_by(id: params[:procedure_id]) - dossiers = DossiersListGestionnaireService.new(current_gestionnaire, nil, procedure).filter_dossiers + dossiers = dossiers_list_facade(param_liste).dossiers_to_display respond_with Dossier.export_full_generation(dossiers, request.format) else - dossiers = DossiersListGestionnaireService.new(current_gestionnaire, nil, nil).filter_dossiers + dossiers = dossiers_list_facade(param_liste).dossiers_to_display respond_to do |format| format.xlsx { render xlsx: dossiers } format.ods { render ods: dossiers } diff --git a/app/views/backoffice/dossiers/index.html.haml b/app/views/backoffice/dossiers/index.html.haml index 8629c2a79..b747a2d4f 100644 --- a/app/views/backoffice/dossiers/index.html.haml +++ b/app/views/backoffice/dossiers/index.html.haml @@ -6,9 +6,12 @@ =t('dynamics.backoffice.title') %div.dropdown.pull-right#download_menu - %button.btn.btn-default.dropdown-toggle#dropdownDownloadMenu{ type: :button, 'data-toggle' => 'dropdown', 'aria-haspopup' => true, 'aria-expanded' => false} - %i.fa.fa-download - = t('dynamics.backoffice.download_all_dossiers') + %button.btn.btn-success.dropdown-toggle#dropdownDownloadMenu{ type: :button, 'data-toggle' => 'dropdown', 'aria-haspopup' => true, 'aria-expanded' => false, class: ('disabled' if (@dossiers.count > 200)) } + - if (@dossiers.count > 200) + = t('dynamics.backoffice.limit_excess_download_all_dossiers') + - else + %i.fa.fa-download + = t('dynamics.backoffice.download_all_dossiers') %span.caret %ul.dropdown-menu.dropdown-menu-right %li diff --git a/config/locales/dynamics/fr.yml b/config/locales/dynamics/fr.yml index 7b8e4a9ca..c85b36fab 100644 --- a/config/locales/dynamics/fr.yml +++ b/config/locales/dynamics/fr.yml @@ -13,6 +13,7 @@ fr: title: 'Gestion de colonnes affichées' description: 'Ce menu vous permet de choisir les différentes colonnes que vous souhaitez voir apparaître dans votre interface de suivi des dossiers.' download_all_dossiers: 'Télécharger mes dossiers' + limit_excess_download_all_dossiers: 'Limite de dossiers fixée à 200 pour le téléchargement' format_csv: 'Au format CSV' format_xlsx: 'Au format XLSX' format_ods: 'Au format ODS' From 305410f7a38cb6bbc290c0a2e8c3959a3af2a317 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 15 Nov 2016 17:20:36 +0100 Subject: [PATCH 18/18] Fix Gemfile.lock and tests --- Gemfile.lock | 369 +++++++++--------- .../api/v1/dossiers_controller_spec.rb | 3 +- 2 files changed, 190 insertions(+), 182 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3789d86e8..319e88f59 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,15 +1,15 @@ GIT remote: https://github.com/mina-deploy/mina.git - revision: 5f407b28be1cf05cdfaab0558285aa031c445491 + revision: a66b55a72833b19ac0ffb240afb37c86c0227582 specs: - mina (1.0.3) + mina (0.3.7) open4 (~> 1.3.4) rake GEM remote: https://rubygems.org/ specs: - CFPropertyList (2.3.3) + CFPropertyList (2.3.2) actionmailer (4.2.7.1) actionpack (= 4.2.7.1) actionview (= 4.2.7.1) @@ -29,11 +29,8 @@ GEM erubis (~> 2.7.0) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) - active_model_serializers (0.10.2) - actionpack (>= 4.1, < 6) - activemodel (>= 4.1, < 6) - jsonapi (~> 0.1.1.beta2) - railties (>= 4.1, < 6) + active_model_serializers (0.8.3) + activemodel (>= 3.0) activejob (4.2.7.1) activesupport (= 4.2.7.1) globalid (>= 0.3.0) @@ -50,8 +47,7 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.5.0) - public_suffix (~> 2.0, >= 2.0.2) + addressable (2.3.8) apipie-rails (0.3.1) json arel (6.0.3) @@ -59,61 +55,74 @@ GEM actionpack (>= 3.0) activemodel (>= 3.0) responders - ast (2.3.0) - attr_required (1.0.1) - autoprefixer-rails (6.5.3) + ast (2.0.0) + astrolabe (1.3.0) + parser (>= 2.2.0.pre.3, < 3.0) + attr_required (1.0.0) + autoprefixer-rails (5.2.1) execjs + json axlsx (2.0.1) htmlentities (~> 4.3.1) nokogiri (>= 1.4.1) rubyzip (~> 1.0.0) bcrypt (3.1.11) - bindata (2.3.4) + bindata (2.1.0) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) - bootstrap-datepicker-rails (1.6.4.1) + bootstrap-datepicker-rails (1.4.0) railties (>= 3.0) - bootstrap-sass (3.3.7) - autoprefixer-rails (>= 5.2.1) - sass (>= 3.3.4) + bootstrap-sass (3.3.5) + autoprefixer-rails (>= 5.0.0.1) + sass (>= 3.2.19) bootstrap-wysihtml5-rails (0.3.3.8) railties (>= 3.0) - brakeman (3.4.1) - browser (2.3.0) + brakeman (3.1.1) + erubis (~> 2.6) + fastercsv (~> 1.5) + haml (>= 3.0, < 5.0) + highline (~> 1.6) + multi_json (~> 1.2) + ruby2ruby (>= 2.1.1, < 2.3.0) + ruby_parser (~> 3.7.0) + sass (~> 3.0) + slim (>= 1.3.6, < 4.0) + terminal-table (~> 1.4) + browser (2.2.0) builder (3.2.2) - byebug (9.0.6) - capybara (2.10.1) - addressable + byebug (5.0.0) + columnize (= 0.9.0) + capybara (2.4.4) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - carrierwave (0.11.2) + carrierwave (0.10.0) activemodel (>= 3.2.0) activesupport (>= 3.2.0) json (>= 1.7) mime-types (>= 1.16) - mimemagic (>= 0.3.0) - chartkick (2.1.1) - childprocess (0.5.9) + chartkick (1.3.2) + childprocess (0.5.5) ffi (~> 1.0, >= 1.0.11) - clamav-client (3.1.0) + clamav-client (3.0.0) cliver (0.3.2) - coderay (1.1.1) - coffee-rails (4.1.1) + coderay (1.1.0) + coffee-rails (4.1.0) coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.1.x) + railties (>= 4.0.0, < 5.0) coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.10.0) + coffee-script-source (1.9.1.1) + columnize (0.9.0) concurrent-ruby (1.0.2) - crack (0.4.3) + crack (0.4.2) safe_yaml (~> 1.0.0) - database_cleaner (1.5.3) + database_cleaner (1.4.1) debug_inspector (0.0.2) - deep_cloneable (2.2.2) + deep_cloneable (2.2.1) activerecord (>= 3.1.0, < 5.2.0) devise (3.5.10) bcrypt (~> 3.0) @@ -124,7 +133,7 @@ GEM warden (~> 1.2.3) diff-lcs (1.2.5) docile (1.1.5) - domain_name (0.5.20161021) + domain_name (0.5.24) unf (>= 0.0.5, < 1.0.0) draper (2.1.0) actionpack (>= 3.0) @@ -132,13 +141,14 @@ GEM activesupport (>= 3.0) request_store (~> 1.0) erubis (2.7.0) - excon (0.54.0) + excon (0.49.0) execjs (2.7.0) - factory_girl (4.7.0) + factory_girl (4.5.0) activesupport (>= 3.0.0) - faraday (0.9.2) + faraday (0.9.1) multipart-post (>= 1.2, < 3) - ffi (1.9.14) + fastercsv (1.5.5) + ffi (1.9.6) fission (0.5.0) CFPropertyList (~> 2.2) fog (1.38.0) @@ -178,12 +188,12 @@ GEM fog-atmos (0.1.0) fog-core fog-xml - fog-aws (0.12.0) - fog-core (~> 1.38) + fog-aws (0.9.2) + fog-core (~> 1.27) fog-json (~> 1.0) fog-xml (~> 0.1) ipaddress (~> 0.8) - fog-brightbox (0.11.0) + fog-brightbox (0.10.1) fog-core (~> 1.22) fog-json inflecto (~> 0.0.2) @@ -192,7 +202,7 @@ GEM fog-json (~> 1.0) fog-xml (~> 0.1) ipaddress (~> 0.8) - fog-core (1.43.0) + fog-core (1.38.0) builder excon (~> 0.49) formatador (~> 0.2) @@ -210,20 +220,22 @@ GEM fog-json (1.0.2) fog-core (~> 1.0) multi_json (~> 1.10) - fog-local (0.3.1) + fog-local (0.3.0) fog-core (~> 1.27) - fog-openstack (0.1.17) - fog-core (>= 1.40) + fog-openstack (0.1.5) + fog-core (>= 1.38) fog-json (>= 1.0) + fog-xml (>= 0.1) ipaddress (>= 0.8) fog-powerdns (0.1.1) fog-core (~> 1.27) fog-json (~> 1.0) fog-xml (~> 0.1) - fog-profitbricks (3.0.0) - fog-core (~> 1.42) - fog-json (~> 1.0) - fog-rackspace (0.1.2) + fog-profitbricks (0.0.5) + fog-core + fog-xml + nokogiri + fog-rackspace (0.1.1) fog-core (>= 1.35) fog-json (>= 1.0) fog-xml (>= 0.1) @@ -242,7 +254,7 @@ GEM fog-serverlove (0.1.2) fog-core fog-json - fog-softlayer (1.1.4) + fog-softlayer (1.1.1) fog-core fog-json fog-storm_on_demand (0.1.1) @@ -257,21 +269,21 @@ GEM fog-voxel (0.1.0) fog-core fog-xml - fog-vsphere (1.5.1) + fog-vsphere (0.6.4) fog-core - rbvmomi (~> 1.9) + rbvmomi (~> 1.8) fog-xenserver (0.2.3) fog-core fog-xml fog-xml (0.1.2) fog-core nokogiri (~> 1.5, >= 1.5.11) - font-awesome-rails (4.7.0.0) - railties (>= 3.2, < 5.1) + font-awesome-rails (4.4.0.0) + railties (>= 3.2, < 5.0) formatador (0.2.5) globalid (0.3.7) activesupport (>= 4.1.0) - haml (4.0.7) + haml (4.0.6) tilt haml-rails (0.9.0) actionpack (>= 4.0.1) @@ -279,113 +291,105 @@ GEM haml (>= 4.0.6, < 5.0) html2haml (>= 1.0.1) railties (>= 4.0.1) - hashdiff (0.3.0) - hashie (3.4.6) + hashie (3.4.1) + highline (1.7.8) html2haml (2.0.0) erubis (~> 2.7.0) haml (~> 4.0.0) nokogiri (~> 1.6.0) ruby_parser (~> 3.5) htmlentities (4.3.4) - http-cookie (1.0.3) + http-cookie (1.0.2) domain_name (~> 0.5) - httpclient (2.8.2.4) + httpclient (2.6.0.1) i18n (0.7.0) inflecto (0.0.2) ipaddress (0.8.3) - jbuilder (2.6.0) - activesupport (>= 3.0.0, < 5.1) + jbuilder (2.3.1) + activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) - jquery-rails (4.2.1) - rails-dom-testing (>= 1, < 3) + jquery-rails (4.0.4) + rails-dom-testing (~> 1.0) railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (1.8.3) - json-jwt (1.6.5) + json-jwt (1.5.1) activesupport bindata multi_json (>= 1.3) securecompare url_safe_base64 - jsonapi (0.1.1.beta6) - jsonapi-parser (= 0.1.1.beta3) - jsonapi-renderer (= 0.1.1.beta1) - jsonapi-parser (0.1.1.beta3) - jsonapi-renderer (0.1.1.beta1) - kaminari (0.17.0) + kaminari (0.16.3) actionpack (>= 3.0.0) activesupport (>= 3.0.0) - kgio (2.10.0) + kgio (2.9.3) leaflet-draw-rails (0.1.0) leaflet-markercluster-rails (0.7.0) railties (>= 3.1) - leaflet-rails (0.7.7) - libv8 (3.16.14.15) + leaflet-rails (0.7.4) + libv8 (3.16.14.7) logstash-event (1.2.02) - logstasher (1.0.1) - activerecord (>= 4.0) - activesupport (>= 4.0) + logstasher (0.6.5) logstash-event (~> 1.2.0) request_store loofah (2.0.3) nokogiri (>= 1.5.9) mail (2.6.4) mime-types (>= 1.16, < 4) - mailjet (1.4.10) + mailjet (1.1.0) activesupport (>= 3.1.0) rack (>= 1.4.0) rest-client maruku (0.7.2) method_source (0.8.2) - mime-types (3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - mimemagic (0.3.2) + mime-types (2.99.2) mini_portile2 (2.1.0) - minitest (5.9.1) - multi_json (1.12.1) + minitest (5.9.0) + multi_json (1.11.2) multipart-post (2.0.0) - netrc (0.11.0) - nokogiri (1.6.8.1) + netrc (0.10.3) + nokogiri (1.6.8) mini_portile2 (~> 2.1.0) + pkg-config (~> 1.1.7) nyan-cat-formatter (0.11) rspec (>= 2.99, >= 2.14.2, < 4) open4 (1.3.4) - openid_connect (0.12.0) + openid_connect (0.9.2) activemodel attr_required (>= 1.0.0) json (>= 1.4.3) json-jwt (>= 1.5.0) - rack-oauth2 (>= 1.3.1) + rack-oauth2 (>= 1.2.1) swd (>= 1.0.0) tzinfo validate_email validate_url webfinger (>= 1.0.1) - openstack (3.3.3) + openstack (2.0.2) json orm_adapter (0.5.0) parallel (1.9.0) parallel_tests (1.9.0) parallel - parser (2.3.1.4) - ast (~> 2.2) - pg (0.19.0) - poltergeist (1.11.0) + parser (2.2.2.2) + ast (>= 1.1, < 3.0) + pg (0.18.2) + pkg-config (1.1.7) + poltergeist (1.6.0) capybara (~> 2.1) cliver (~> 0.3.1) + multi_json (~> 1.0) websocket-driver (>= 0.2.0) - powerpack (0.1.1) - pry (0.10.4) + powerpack (0.1.0) + pry (0.10.1) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) - pry-byebug (3.4.0) - byebug (~> 9.0) + pry-byebug (3.2.0) + byebug (~> 5.0) pry (~> 0.10) - public_suffix (2.0.4) - rack (1.6.5) - rack-oauth2 (1.4.0) + rack (1.6.4) + rack-oauth2 (1.2.1) activesupport (>= 2.3) attr_required (>= 0.0.5) httpclient (>= 2.4) @@ -393,7 +397,7 @@ GEM rack (>= 1.1) rack-test (0.6.3) rack (>= 1.0) - railroady (1.5.2) + railroady (1.3.0) rails (4.2.7.1) actionmailer (= 4.2.7.1) actionpack (= 4.2.7.1) @@ -418,63 +422,65 @@ GEM activesupport (= 4.2.7.1) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rainbow (2.1.0) - raindrops (0.17.0) - rake (11.3.0) - rbvmomi (1.9.4) - builder (~> 3.2) - json (>= 1.8) - nokogiri (~> 1.5) - trollop (~> 2.1) - rdoc (4.3.0) + rainbow (2.0.0) + raindrops (0.13.0) + rake (11.2.2) + rbvmomi (1.8.2) + builder + nokogiri (>= 1.4.1) + trollop + rdoc (4.2.0) + json (~> 1.4) ref (2.0.0) - request_store (1.3.1) + request_store (1.1.0) responders (2.3.0) railties (>= 4.2.0, < 5.1) - rest-client (2.0.0) + rest-client (1.8.0) http-cookie (>= 1.0.2, < 2.0) - mime-types (>= 1.16, < 4.0) - netrc (~> 0.8) - rgeo (0.5.3) - rgeo-geojson (0.4.3) - rgeo (~> 0.5) + mime-types (>= 1.16, < 3.0) + netrc (~> 0.7) + rgeo (0.3.20) + rgeo-geojson (0.3.1) + rgeo (~> 0.3) rodf (0.3.7) activesupport (>= 3.0, < 6.0) builder (~> 3.0) rubyzip (~> 1.0) - rspec (3.5.0) - rspec-core (~> 3.5.0) - rspec-expectations (~> 3.5.0) - rspec-mocks (~> 3.5.0) - rspec-core (3.5.4) - rspec-support (~> 3.5.0) - rspec-expectations (3.5.0) + rspec (3.2.0) + rspec-core (~> 3.2.0) + rspec-expectations (~> 3.2.0) + rspec-mocks (~> 3.2.0) + rspec-core (3.2.3) + rspec-support (~> 3.2.0) + rspec-expectations (3.2.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.5.0) - rspec-mocks (3.5.0) + rspec-support (~> 3.2.0) + rspec-mocks (3.2.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.5.0) - rspec-rails (3.5.2) - actionpack (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 3.5.0) - rspec-expectations (~> 3.5.0) - rspec-mocks (~> 3.5.0) - rspec-support (~> 3.5.0) - rspec-support (3.5.0) - rubocop (0.45.0) - parser (>= 2.3.1.1, < 3.0) + rspec-support (~> 3.2.0) + rspec-rails (3.2.1) + actionpack (>= 3.0, < 4.3) + activesupport (>= 3.0, < 4.3) + railties (>= 3.0, < 4.3) + rspec-core (~> 3.2.0) + rspec-expectations (~> 3.2.0) + rspec-mocks (~> 3.2.0) + rspec-support (~> 3.2.0) + rspec-support (3.2.2) + rubocop (0.30.1) + astrolabe (~> 1.3) + parser (>= 2.2.2.1, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) - ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) - rubocop-checkstyle_formatter (0.3.0) - rubocop (>= 0.30.1) - rubocop-rspec (1.8.0) - rubocop (>= 0.42.0) - ruby-progressbar (1.8.1) - ruby_parser (3.8.3) + ruby-progressbar (~> 1.4) + rubocop-checkstyle_formatter (0.2.0) + rubocop (>= 0.20.1) + rubocop-rspec (1.3.0) + ruby-progressbar (1.7.5) + ruby2ruby (2.1.4) + ruby_parser (~> 3.1) + sexp_processor (~> 4.0) + ruby_parser (3.7.0) sexp_processor (~> 4.1) rubyzip (1.0.0) safe_yaml (1.0.4) @@ -488,71 +494,75 @@ GEM scenic (1.3.0) activerecord (>= 4.0.0) railties (>= 4.0.0) - sdoc (0.4.2) + sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) securecompare (1.0.0) - selenium-webdriver (3.0.1) + selenium-webdriver (2.44.0) childprocess (~> 0.5) + multi_json (~> 1.0) rubyzip (~> 1.0) websocket (~> 1.0) - sentry-raven (2.1.2) - faraday (>= 0.7.6, < 0.10.x) - sexp_processor (4.7.0) - shoulda-matchers (3.1.1) - activesupport (>= 4.0.0) - simplecov (0.12.0) + sentry-raven (0.13.1) + faraday (>= 0.7.6) + sexp_processor (4.6.0) + shoulda-matchers (2.8.0) + activesupport (>= 3.0.0) + simplecov (0.9.1) docile (~> 1.1.0) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.0) + multi_json (~> 1.0) + simplecov-html (~> 0.8.0) + simplecov-html (0.8.0) + slim (3.0.6) + temple (~> 0.7.3) + tilt (>= 1.3.3, < 2.1) slop (3.6.0) - smart_listing (1.2.0) + smart_listing (1.1.2) coffee-rails jquery-rails - kaminari (~> 0.17) + kaminari (~> 0.16.1) rails (>= 3.2) spreadsheet_architect (1.4.7) axlsx (>= 2.0) rodf (>= 0.3.6) - spring (2.0.0) - activesupport (>= 4.2) + spring (1.3.6) spring-commands-rspec (1.0.4) spring (>= 0.9.1) sprockets (3.7.0) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.0) + sprockets-rails (3.1.1) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - swd (1.0.1) + swd (1.0.0) activesupport (>= 3) attr_required (>= 0.0.5) httpclient (>= 2.4) i18n json (>= 1.4.3) + temple (0.7.6) + terminal-table (1.5.2) therubyracer (0.12.2) libv8 (~> 3.16.14.0) ref thor (0.19.1) thread_safe (0.3.5) tilt (2.0.5) - timecop (0.8.1) + timecop (0.7.3) trollop (2.1.2) - turbolinks (5.0.1) - turbolinks-source (~> 5) - turbolinks-source (5.0.0) + turbolinks (2.5.3) + coffee-rails tzinfo (1.2.2) thread_safe (~> 0.1) - uglifier (3.0.3) + uglifier (3.0.2) execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext - unf_ext (0.0.7.2) - unicode-display_width (1.1.1) - unicorn (5.2.0) + unf_ext (0.0.7.1) + unicorn (4.9.0) kgio (~> 2.6) + rack raindrops (~> 0.7) url_safe_base64 (0.2.2) validate_email (0.1.6) @@ -561,27 +571,26 @@ GEM validate_url (1.0.2) activemodel (>= 3.0.0) addressable - vcr (3.0.3) + vcr (3.0.1) warden (1.2.6) rack (>= 1.0) - web-console (2.3.0) + web-console (2.2.1) activemodel (>= 4.0) binding_of_caller (>= 0.7.2) railties (>= 4.0) sprockets-rails (>= 2.0, < 4.0) - webfinger (1.0.2) + webfinger (1.0.1) activesupport httpclient (>= 2.4) multi_json - webmock (2.1.0) + webmock (1.21.0) addressable (>= 2.3.6) crack (>= 0.3.2) - hashdiff - websocket (1.2.3) - websocket-driver (0.6.4) + websocket (1.2.1) + websocket-driver (0.5.3) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) - will_paginate (3.1.5) + will_paginate (3.0.7) will_paginate-bootstrap (1.0.1) will_paginate (>= 3.0.3) xml-simple (1.1.5) diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb index 5295b7d49..0c00308bb 100644 --- a/spec/controllers/api/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/v1/dossiers_controller_spec.rb @@ -115,7 +115,7 @@ describe API::V1::DossiersController do let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } } let(:dossier_id) { dossier.id } let(:body) { JSON.parse(retour.body, symbolize_names: true) } - let(:field_list) { [:id, :created_at, :updated_at, :archived, :mandataire_social, :total_commentaire, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state] } + let(:field_list) { [:id, :created_at, :updated_at, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state] } subject { body[:dossier] } it 'return REST code 200', :show_in_doc do @@ -127,7 +127,6 @@ describe API::V1::DossiersController do it { expect(subject[:updated_at]).to eq('2008-09-01T08:05:00.000Z') } it { expect(subject[:archived]).to eq(dossier.archived) } it { expect(subject[:mandataire_social]).to eq(dossier.mandataire_social) } - it { expect(subject[:total_commentaire]).to eq(dossier.total_commentaire) } it { expect(subject.keys).to match_array(field_list) }