From 5361e4e1e9c678709b72f1c643bc4bb2d9d76a8f Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 22 Nov 2017 17:27:02 +0100 Subject: [PATCH] [Fix #871] Add the date at the end of exported files --- .../new_gestionnaire/procedures_controller.rb | 11 +++++++++++ app/views/new_gestionnaire/procedures/show.html.haml | 6 +++--- config/routes.rb | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/controllers/new_gestionnaire/procedures_controller.rb b/app/controllers/new_gestionnaire/procedures_controller.rb index c13d70fc1..0b4894365 100644 --- a/app/controllers/new_gestionnaire/procedures_controller.rb +++ b/app/controllers/new_gestionnaire/procedures_controller.rb @@ -173,6 +173,17 @@ module NewGestionnaire redirect_back(fallback_location: procedure_url(procedure)) end + def download_dossiers + export = procedure.generate_export + filename = "dossiers_#{procedure.procedure_path.path}_#{Time.now.strftime('%Y-%m-%d_%H-%M')}" + + respond_to do |format| + format.csv { send_data(SpreadsheetArchitect.to_csv(data: export[:data], headers: export[:headers]), filename: "#{filename}.csv") } + format.xlsx { send_data(SpreadsheetArchitect.to_xlsx(data: export[:data], headers: export[:headers]), filename: "#{filename}.xlsx") } + format.ods { send_data(SpreadsheetArchitect.to_ods(data: export[:data], headers: export[:headers]), filename: "#{filename}.ods") } + end + end + private def statut diff --git a/app/views/new_gestionnaire/procedures/show.html.haml b/app/views/new_gestionnaire/procedures/show.html.haml index 7ab45f49c..be4f194fd 100644 --- a/app/views/new_gestionnaire/procedures/show.html.haml +++ b/app/views/new_gestionnaire/procedures/show.html.haml @@ -46,11 +46,11 @@ .dropdown-content.fade-in-down %ul.dropdown-items %li - = link_to "Au format .csv", backoffice_download_dossiers_tps_path(format: :csv, procedure_id: @procedure.id), target: "_blank" + = link_to "Au format .csv", download_dossiers_procedure_path(format: :csv, procedure_id: @procedure.id), target: "_blank" %li - = link_to "Au format .xlsx", backoffice_download_dossiers_tps_path(format: :xlsx, procedure_id: @procedure.id), target: "_blank" + = link_to "Au format .xlsx", download_dossiers_procedure_path(format: :xlsx, procedure_id: @procedure.id), target: "_blank" %li - = link_to "Au format .ods", backoffice_download_dossiers_tps_path(format: :ods, procedure_id: @procedure.id), target: "_blank" + = link_to "Au format .ods", download_dossiers_procedure_path(format: :ods, procedure_id: @procedure.id), target: "_blank" .container - if @dossiers.present? || @current_filters.count > 0 diff --git a/config/routes.rb b/config/routes.rb index 65ec0c82e..9930412c5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -240,6 +240,7 @@ Rails.application.routes.draw do get 'update_sort/:table/:column' => 'procedures#update_sort', as: 'update_sort' post 'add_filter' get 'remove_filter/:statut/:table/:column' => 'procedures#remove_filter', as: 'remove_filter' + get 'download_dossiers' resources :dossiers, only: [:show], param: :dossier_id do member do