Skip to content

Commit

Permalink
✨ Zip les fichers excel
Browse files Browse the repository at this point in the history
  • Loading branch information
Guitguitou committed Nov 14, 2024
1 parent 512a1e4 commit 1b64d6e
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 36 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ gem 'recipient_interceptor'
gem 'redcarpet'
gem 'redis'
gem 'rollbar'
gem 'rubyzip'
gem 'sidekiq', '< 8'
gem 'sidekiq-scheduler'
gem 'spreadsheet'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ GEM
ruby-progressbar (1.13.0)
ruby-rc4 (0.1.5)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
rufus-scheduler (3.9.2)
fugit (~> 1.1, >= 1.11.1)
sass-rails (6.0.0)
Expand Down Expand Up @@ -714,6 +715,7 @@ DEPENDENCIES
rubocop-packaging
rubocop-rails
rubocop-rspec
rubyzip
sass-rails (>= 6)
shoulda-matchers
sidekiq (< 8)
Expand Down
34 changes: 23 additions & 11 deletions app/admin/questionnaires.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'zip'

ActiveAdmin.register Questionnaire do
menu parent: 'Parcours', if: proc { can? :manage, Compte }

Expand All @@ -11,9 +13,9 @@
member_action :export_questions, method: :get

action_item :export_questions, only: :show do
link_to 'Exporter les questions en XLS',
export_questions_admin_questionnaire_path(resource),
format: :xls
link_to export_questions_admin_questionnaire_path(resource), format: :xls do
image_tag('icones/icone_export_xls.png', alt: 'Exporter') + 'Exporter les questions en XLS' # rubocop:disable Style/StringConcatenation
end
end

form do |f|
Expand Down Expand Up @@ -55,15 +57,25 @@ def find_resource

def export_questions
questionnaire = find_resource
questions_par_type = questionnaire.questions_par_type
compressed_filestream = generate_zip_file(questionnaire.questions_par_type)

questions_par_type.each do |type, questions|
export = ImportExport::Questions::ImportExportDonnees.new(questions: questions,
type: type).exporte_donnees
send_data export[:xls],
content_type: export[:content_type],
filename: export[:filename]
end
send_data compressed_filestream.read,
filename: "questionnaire_#{questionnaire.id}_export.zip",
type: 'application/zip'
end

private

def generate_zip_file(questions_par_type)
Zip::OutputStream.write_buffer do |zip|
questions_par_type.each do |type, questions|
export =
ImportExport::Questions::ImportExportDonnees.new(questions: questions,
type: type).exporte_donnees
zip.put_next_entry("#{type}_questions_export.xls")
zip.write export[:xls]
end
end.tap(&:rewind)
end
end
end
10 changes: 6 additions & 4 deletions app/admin/questions_clic_dans_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
end

action_item :importer_question, only: :index do
link_to 'Importer question clic dans image',
admin_import_xls_path(type: 'QuestionClicDansImage')
link_to admin_import_xls_path(type: 'QuestionClicDansImage') do
image_tag('icones/icone_import_xls.png') + 'Importer questions clic dans image' # rubocop:disable Style/StringConcatenation
end
end

action_item :exporter_question, only: :show do
link_to 'Exporter le contenu de la question',
admin_question_export_xls_path(question_id: params[:id])
link_to admin_question_export_xls_path(question_id: params[:id]) do
image_tag('icones/icone_export_xls.png', alt: 'Exporter') + 'Exporter les questions en XLS' # rubocop:disable Style/StringConcatenation
end
end

show do
Expand Down
10 changes: 6 additions & 4 deletions app/admin/questions_glisser_deposer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
form partial: 'form'

action_item :importer_question, only: :index do
link_to 'Importer question glisser déposer',
admin_import_xls_path(type: 'QuestionGlisserDeposer')
link_to admin_import_xls_path(type: 'QuestionGlisserDeposer') do
image_tag('icones/icone_import_xls.png') + 'Importer questions glisser déposer' # rubocop:disable Style/StringConcatenation
end
end

action_item :exporter_question, only: :show do
link_to 'Exporter le contenu de la question',
admin_question_export_xls_path(question_id: params[:id])
link_to admin_question_export_xls_path(question_id: params[:id]) do
image_tag('icones/icone_export_xls.png', alt: 'Exporter') + 'Exporter les questions en XLS' # rubocop:disable Style/StringConcatenation
end
end

index do
Expand Down
10 changes: 6 additions & 4 deletions app/admin/questions_qcm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
form partial: 'form'

action_item :importer_question, only: :index do
link_to 'Importer question qcm',
admin_import_xls_path(type: 'QuestionQcm')
link_to admin_import_xls_path(type: 'QuestionQcm') do
image_tag('icones/icone_import_xls.png' + "Importer questions QCM" # rubocop:disable Style/StringConcatenation
end
end

action_item :exporter_question, only: :show do
link_to 'Exporter le contenu de la question',
admin_question_export_xls_path(question_id: params[:id])
link_to admin_question_export_xls_path(question_id: params[:id]) do
image_tag('icones/icone_export_xls.png', alt: 'Exporter') + 'Exporter les questions en XLS' # rubocop:disable Style/StringConcatenation
end
end

index do
Expand Down
10 changes: 6 additions & 4 deletions app/admin/questions_saisie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
filter :nom_technique

action_item :importer_question, only: :index do
link_to 'Importer question saisie',
admin_import_xls_path(type: 'QuestionSaisie')
link_to admin_import_xls_path(type: 'QuestionSaisie') do
image_tag('icones/icone_import_xls.png') + 'Importer questions saisies' # rubocop:disable Style/StringConcatenation
end
end

action_item :exporter_question, only: :show do
link_to 'Exporter le contenu de la question',
admin_question_export_xls_path(question_id: params[:id])
link_to admin_question_export_xls_path(question_id: params[:id]) do
image_tag('icones/icone_export_xls.png', alt: 'Exporter') + 'Exporter les questions en XLS' # rubocop:disable Style/StringConcatenation
end
end

form partial: 'form'
Expand Down
10 changes: 6 additions & 4 deletions app/admin/questions_sous_consigne.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
filter :nom_technique

action_item :importer_question, only: :index do
link_to 'Importer question sous consigne',
admin_import_xls_path(type: 'QuestionSousConsigne')
link_to admin_import_xls_path(type: 'QuestionSousConsigne') do
image_tag('icones/icone_import_xls.png') + 'Importer questions sous consigne' # rubocop:disable Style/StringConcatenation
end
end

action_item :exporter_question, only: :show do
link_to 'Exporter le contenu de la question',
admin_question_export_xls_path(question_id: params[:id])
link_to admin_question_export_xls_path(question_id: params[:id]) do
image_tag('icones/icone_export_xls.png', alt: 'Exporter') + 'Exporter les questions en XLS' # rubocop:disable Style/StringConcatenation
end
end

form do |f|
Expand Down
Binary file added app/assets/images/icones/icone_export_xls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icones/icone_import_xls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion spec/features/admin/question_clic_dans_image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

it "redirige vers le formulaire d'importation de question" do
within('.action-items-sidebar') do
click_on 'Importer question clic dans image'
click_on 'Importer questions clic dans image'
end
expect(page).to have_content 'Importer une ou plusieurs questions'
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/admin/question_glisser_deposer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

it "redirige vers le formulaire d'importation de question" do
within('.action-items-sidebar') do
click_on 'Importer question glisser déposer'
click_on 'Importer questions glisser déposer'
end
expect(page).to have_content 'Importer une ou plusieurs questions'
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/admin/question_qcm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

it "redirige vers le formulaire d'importation de question" do
within('.action-items-sidebar') do
click_on 'Importer question qcm'
click_on 'Importer questions QCM'
end
expect(page).to have_content 'Importer une ou plusieurs questions'
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/admin/question_saisie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

it "redirige vers le formulaire d'importation de question" do
within('.action-items-sidebar') do
click_on 'Importer question saisie'
click_on 'Importer questions saisie'
end
expect(page).to have_content 'Importer une ou plusieurs questions'
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/admin/question_sous_consigne_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

it "redirige vers le formulaire d'importation de question" do
within('.action-items-sidebar') do
click_on 'Importer question sous consigne'
click_on 'Importer questions sous consigne'
end
expect(page).to have_content 'Importer une ou plusieurs questions'
end
Expand Down

0 comments on commit 1b64d6e

Please sign in to comment.