feat(export): add zip format support
This commit is contained in:
parent
2832ea0286
commit
d14e132305
4 changed files with 27 additions and 6 deletions
|
@ -18,8 +18,9 @@ class Export < ApplicationRecord
|
||||||
enum format: {
|
enum format: {
|
||||||
csv: 'csv',
|
csv: 'csv',
|
||||||
ods: 'ods',
|
ods: 'ods',
|
||||||
xlsx: 'xlsx'
|
xlsx: 'xlsx',
|
||||||
}
|
zip: 'zip'
|
||||||
|
}, _prefix: true
|
||||||
|
|
||||||
enum time_span_type: {
|
enum time_span_type: {
|
||||||
everything: 'everything',
|
everything: 'everything',
|
||||||
|
@ -52,7 +53,7 @@ class Export < ApplicationRecord
|
||||||
{ format: format, time_span_type: time_span_type }
|
{ format: format, time_span_type: time_span_type }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
FORMATS = [:xlsx, :ods, :csv].map do |format|
|
FORMATS = [:xlsx, :ods, :csv, :zip].map do |format|
|
||||||
{ format: format }
|
{ format: format }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -98,6 +99,10 @@ class Export < ApplicationRecord
|
||||||
format == self.class.formats.fetch(:csv)
|
format == self.class.formats.fetch(:csv)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def zip?
|
||||||
|
format == self.class.formats.fetch(:zip)
|
||||||
|
end
|
||||||
|
|
||||||
def self.find_or_create_export(format, groupe_instructeurs, time_span_type: time_span_types.fetch(:everything), statut: statuts.fetch(:tous), procedure_presentation: nil)
|
def self.find_or_create_export(format, groupe_instructeurs, time_span_type: time_span_types.fetch(:everything), statut: statuts.fetch(:tous), procedure_presentation: nil)
|
||||||
create_with(groupe_instructeurs: groupe_instructeurs, procedure_presentation: procedure_presentation, procedure_presentation_snapshot: procedure_presentation&.snapshot)
|
create_with(groupe_instructeurs: groupe_instructeurs, procedure_presentation: procedure_presentation, procedure_presentation_snapshot: procedure_presentation&.snapshot)
|
||||||
.includes(:procedure_presentation)
|
.includes(:procedure_presentation)
|
||||||
|
@ -128,6 +133,10 @@ class Export < ApplicationRecord
|
||||||
csv: {
|
csv: {
|
||||||
time_span_type: not_filtered.filter(&:csv?).index_by(&:time_span_type),
|
time_span_type: not_filtered.filter(&:csv?).index_by(&:time_span_type),
|
||||||
statut: filtered.filter(&:csv?).index_by(&:statut)
|
statut: filtered.filter(&:csv?).index_by(&:statut)
|
||||||
|
},
|
||||||
|
zip: {
|
||||||
|
time_span_type: {},
|
||||||
|
statut: filtered.filter(&:zip?).index_by(&:statut)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -181,6 +190,8 @@ class Export < ApplicationRecord
|
||||||
service.to_xlsx
|
service.to_xlsx
|
||||||
when :ods
|
when :ods
|
||||||
service.to_ods
|
service.to_ods
|
||||||
|
when :zip
|
||||||
|
service.to_zip
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,13 @@ class ProcedureExportService
|
||||||
end.bytes)
|
end.bytes)
|
||||||
create_blob(io, :ods)
|
create_blob(io, :ods)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_zip
|
||||||
|
attachments = ActiveStorage::DownloadableFile.create_list_from_dossiers(dossiers, true)
|
||||||
|
|
||||||
|
DownloadableFileService.download_and_zip(procedure, attachments, base_filename) do |zip_filepath|
|
||||||
|
ArchiveUploader.new(procedure: procedure, filename: filename(:zip), filepath: zip_filepath).blob
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -62,6 +69,8 @@ class ProcedureExportService
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||||
when :ods
|
when :ods
|
||||||
'application/vnd.oasis.opendocument.spreadsheet'
|
'application/vnd.oasis.opendocument.spreadsheet'
|
||||||
|
when :zip
|
||||||
|
'application/zip'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ fr:
|
||||||
everything_csv_html: Demander un export au format .csv<br>(uniquement les dossiers, sans les champs répétables)
|
everything_csv_html: Demander un export au format .csv<br>(uniquement les dossiers, sans les champs répétables)
|
||||||
everything_xlsx_html: Demander un export au format .xlsx
|
everything_xlsx_html: Demander un export au format .xlsx
|
||||||
everything_ods_html: Demander un export au format .ods
|
everything_ods_html: Demander un export au format .ods
|
||||||
|
everything_zip_html: Demander un export au format .zip
|
||||||
everything_short: Demander un export au format %{export_format}
|
everything_short: Demander un export au format %{export_format}
|
||||||
everything_pending_html: Un export au format %{export_format} est en train d’être généré<br>(demandé il y a %{export_time})
|
everything_pending_html: Un export au format %{export_format} est en train d’être généré<br>(demandé il y a %{export_time})
|
||||||
everything_ready_html: Télécharger l’export au format %{export_format}<br>(généré il y a %{export_time})
|
everything_ready_html: Télécharger l’export au format %{export_format}<br>(généré il y a %{export_time})
|
||||||
|
|
|
@ -48,9 +48,9 @@ RSpec.describe Export, type: :model do
|
||||||
context 'when an export is made for one groupe instructeur' do
|
context 'when an export is made for one groupe instructeur' do
|
||||||
let!(:export) { create(:export, groupe_instructeurs: [gi_1, gi_2]) }
|
let!(:export) { create(:export, groupe_instructeurs: [gi_1, gi_2]) }
|
||||||
|
|
||||||
it { expect(Export.find_for_groupe_instructeurs([gi_1.id], nil)).to eq({ csv: { statut: {}, time_span_type: {} }, xlsx: { statut: {}, time_span_type: {} }, ods: { statut: {}, time_span_type: {} } }) }
|
it { expect(Export.find_for_groupe_instructeurs([gi_1.id], nil)).to eq({ csv: { statut: {}, time_span_type: {} }, xlsx: { statut: {}, time_span_type: {} }, ods: { statut: {}, time_span_type: {} }, zip: { statut: {}, time_span_type: {} } }) }
|
||||||
it { expect(Export.find_for_groupe_instructeurs([gi_2.id, gi_1.id], nil)).to eq({ csv: { statut: {}, time_span_type: { 'everything' => export } }, xlsx: { statut: {}, time_span_type: {} }, ods: { statut: {}, time_span_type: {} } }) }
|
it { expect(Export.find_for_groupe_instructeurs([gi_2.id, gi_1.id], nil)).to eq({ csv: { statut: {}, time_span_type: { 'everything' => export } }, xlsx: { statut: {}, time_span_type: {} }, ods: { statut: {}, time_span_type: {} }, zip: { statut: {}, time_span_type: {} } }) }
|
||||||
it { expect(Export.find_for_groupe_instructeurs([gi_1.id, gi_2.id, gi_3.id], nil)).to eq({ csv: { statut: {}, time_span_type: {} }, xlsx: { statut: {}, time_span_type: {} }, ods: { statut: {}, time_span_type: {} } }) }
|
it { expect(Export.find_for_groupe_instructeurs([gi_1.id, gi_2.id, gi_3.id], nil)).to eq({ csv: { statut: {}, time_span_type: {} }, xlsx: { statut: {}, time_span_type: {} }, ods: { statut: {}, time_span_type: {} }, zip: { statut: {}, time_span_type: {} } }) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue