From 45042d0200b519a3637d16571000f87821508688 Mon Sep 17 00:00:00 2001 From: JC Date: Tue, 3 Jan 2017 15:50:44 +0100 Subject: [PATCH] Catching case for empty dossiers, cannot download them while locked on procedure, third fix making good condition about empty dossiers --- .../backoffice/dossiers_controller.rb | 2 +- app/models/dossier.rb | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 89a3a63cc..3227eac29 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -41,7 +41,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController 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) if dossiers.empty? + respond_with Dossier.export_full_generation(dossiers, request.format) unless dossiers.empty? else dossiers = dossiers_list_facade(param_liste).dossiers_to_display respond_to do |format| diff --git a/app/models/dossier.rb b/app/models/dossier.rb index e3f719e38..ee3288d98 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -293,17 +293,19 @@ class Dossier < ActiveRecord::Base end def self.export_full_generation(dossiers, format) - data = [] - 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) + if dossiers && !dossiers.empty? + data = [] + 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 end