Merge pull request #56 from sgmap/download_all_dossiers
Download dossiers button exports all dossiers except draft
This commit is contained in:
commit
11a471b6a6
5 changed files with 58 additions and 34 deletions
|
@ -39,16 +39,13 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
|
|||
end
|
||||
|
||||
def download_dossiers_tps
|
||||
if procedure = Procedure.find_by(id: params[:procedure_id])
|
||||
dossiers = dossiers_list_facade(param_liste).dossiers_to_display
|
||||
respond_with Dossier.export_full_generation(dossiers, request.format) unless dossiers.empty?
|
||||
else
|
||||
dossiers = dossiers_list_facade(param_liste).dossiers_to_display
|
||||
procedure = Procedure.find_by(id: params[:procedure_id])
|
||||
export = Dossier.export_full_generation(procedure.dossiers.downloadable)
|
||||
|
||||
respond_to do |format|
|
||||
format.xlsx { render xlsx: dossiers }
|
||||
format.ods { render ods: dossiers }
|
||||
format.csv { render csv: dossiers }
|
||||
end
|
||||
format.csv { send_data(SpreadsheetArchitect.to_csv(data: export[:data], headers: export[:headers]), filename: 'dossiers.csv') }
|
||||
format.xlsx { send_data(SpreadsheetArchitect.to_xlsx(data: export[:data], headers: export[:headers]), filename: 'dossiers.xlsx') }
|
||||
format.ods { send_data(SpreadsheetArchitect.to_ods(data: export[:data], headers: export[:headers]), filename: 'dossiers.ods') }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -201,6 +201,8 @@ class Dossier < ActiveRecord::Base
|
|||
|
||||
scope :archived, -> { where(archived: true) }
|
||||
|
||||
scope :downloadable, -> { all_state }
|
||||
|
||||
def cerfa_available?
|
||||
procedure.cerfa_flag? && cerfa.size != 0
|
||||
end
|
||||
|
@ -261,21 +263,21 @@ class Dossier < ActiveRecord::Base
|
|||
return headers
|
||||
end
|
||||
|
||||
def self.export_full_generation(dossiers, format)
|
||||
if dossiers && !dossiers.empty?
|
||||
def self.export_full_generation(dossiers)
|
||||
data = []
|
||||
headers = []
|
||||
|
||||
if dossiers && dossiers.any?
|
||||
headers = dossiers.first.export_headers
|
||||
dossiers.each do |dossier|
|
||||
data << dossier.convert_specific_array_values_to_string(dossier.data_with_champs)
|
||||
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
|
||||
|
||||
return {
|
||||
data: data,
|
||||
headers: headers
|
||||
}
|
||||
end
|
||||
|
||||
def followers_gestionnaires_emails
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
%div.dropdown.pull-right#download-menu
|
||||
- if @facade_data_view.dossiers_to_display.count > 400
|
||||
%button.btn.btn-error.dropdown-toggle#dropdownDownloadMenu{ type: :button, 'data-toggle' => 'dropdown', 'aria-haspopup' => true, 'aria-expanded' => false, class: 'disabled'}
|
||||
%span{'data-toggle' => :tooltip, "data-placement" => :left, title: 'Pour réduire le nombre de dossiers et ne pas dépasser la limite autorisée de 400, merci de bien vouloir appliquer des filtres.'}
|
||||
= t('dynamics.backoffice.limit_excess_download_all_dossiers')
|
||||
- else
|
||||
%a.dropdown-toggle#dropdownDownloadMenu.button_navbar{ type: :button, 'data-toggle' => 'dropdown', 'aria-haspopup' => true, 'aria-expanded' => false }
|
||||
.dropdown.pull-right#download-menu
|
||||
%a.dropdown-toggle.button_navbar{ type: :button, 'data-toggle' => 'dropdown', 'aria-haspopup' => true, 'aria-expanded' => false }
|
||||
%i.fa.fa-download
|
||||
= t('dynamics.backoffice.download_all_dossiers')
|
||||
Télécharger tous les dossiers
|
||||
%span.caret
|
||||
%ul.dropdown-menu.dropdown-menu-right
|
||||
%li
|
||||
|
|
|
@ -12,8 +12,6 @@ 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: 'Télécharger mes dossiers'
|
||||
limit_excess_download_all_dossiers: 'Limite de dossiers fixée à 400 pour le téléchargement'
|
||||
format_csv: 'Au format CSV'
|
||||
format_xlsx: 'Au format XLSX'
|
||||
format_ods: 'Au format ODS'
|
||||
|
|
|
@ -611,7 +611,6 @@ describe Dossier do
|
|||
end
|
||||
|
||||
describe '#data_with_champs' do
|
||||
|
||||
subject { dossier.data_with_champs }
|
||||
|
||||
it { expect(subject[0]).to be_a_kind_of(Integer) }
|
||||
|
@ -626,6 +625,27 @@ describe Dossier do
|
|||
it { expect(subject[9]).to eq(dossier.followers_gestionnaires_emails) }
|
||||
it { expect(subject.count).to eq(DossierProcedureSerializer.new(dossier).attributes.count + dossier.procedure.types_de_champ.count + dossier.export_entreprise_data.count) }
|
||||
end
|
||||
|
||||
describe '.export_full_generation' do
|
||||
|
||||
context 'when there are no dossiers' do
|
||||
subject { Dossier.export_full_generation(Dossier.none) }
|
||||
|
||||
it { expect(subject[:data]).to eq([]) }
|
||||
it { expect(subject[:headers]).to eq([]) }
|
||||
end
|
||||
|
||||
context 'when there are some dossiers' do
|
||||
let!(:dossier){ create(:dossier) }
|
||||
let!(:dossier2){ create(:dossier) }
|
||||
|
||||
subject { Dossier.export_full_generation(Dossier.all) }
|
||||
|
||||
it { expect(subject[:data].size).to eq(2) }
|
||||
it { expect(subject[:headers]).to eq(dossier.export_headers) }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe '#Dossier.to_csv' do
|
||||
|
@ -670,7 +690,6 @@ describe Dossier do
|
|||
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) }
|
||||
|
@ -966,4 +985,17 @@ describe Dossier do
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
describe '.downloadable' do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: :draft) }
|
||||
let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure, state: :initiated) }
|
||||
let!(:dossier3) { create(:dossier, :with_entreprise, procedure: procedure, state: :received) }
|
||||
|
||||
subject { procedure.dossiers.downloadable }
|
||||
|
||||
it { is_expected.not_to include(dossier)}
|
||||
it { is_expected.to include(dossier2)}
|
||||
it { is_expected.to include(dossier3)}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue