generate pdf export inside pieces_justificatives_service
This commit is contained in:
parent
c25f3c79d9
commit
fba0d78153
7 changed files with 41 additions and 34 deletions
|
@ -213,7 +213,6 @@ module Instructeurs
|
|||
def telecharger_pjs
|
||||
return head(:forbidden) if !dossier.attachments_downloadable?
|
||||
|
||||
generate_pdf_for_instructeur_export
|
||||
files = ActiveStorage::DownloadableFile.create_list_from_dossier(dossier)
|
||||
|
||||
zipline(files, "dossier-#{dossier.id}.zip")
|
||||
|
@ -239,12 +238,6 @@ module Instructeurs
|
|||
.find(params[:dossier_id])
|
||||
end
|
||||
|
||||
def generate_pdf_for_instructeur_export
|
||||
@include_infos_administration = true
|
||||
pdf = render_to_string(template: 'dossiers/show', formats: [:pdf])
|
||||
dossier.pdf_export_for_instructeur.attach(io: StringIO.open(pdf), filename: "export-#{dossier.id}.pdf", content_type: 'application/pdf')
|
||||
end
|
||||
|
||||
def commentaire_params
|
||||
params.require(:commentaire).permit(:body, :piece_jointe)
|
||||
end
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
class ActiveStorage::DownloadableFile
|
||||
def self.create_list_from_dossier(dossier)
|
||||
pjs = PiecesJustificativesService.liste_pieces_justificatives(dossier)
|
||||
files = pjs.map do |piece_justificative|
|
||||
pjs.map do |piece_justificative|
|
||||
[
|
||||
piece_justificative,
|
||||
self.timestamped_filename(piece_justificative)
|
||||
"dossier-#{dossier.id}/#{self.timestamped_filename(piece_justificative)}"
|
||||
]
|
||||
end
|
||||
files << [dossier.pdf_export_for_instructeur, self.timestamped_filename(dossier.pdf_export_for_instructeur)]
|
||||
files
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -22,19 +20,23 @@ class ActiveStorage::DownloadableFile
|
|||
timestamp = attachment.created_at.strftime("%d-%m-%Y-%H-%M")
|
||||
id = attachment.id % 10000
|
||||
|
||||
"#{folder}/#{basename}-#{timestamp}-#{id}#{extension}"
|
||||
[folder, "#{basename}-#{timestamp}-#{id}#{extension}"].join
|
||||
end
|
||||
|
||||
def self.folder(attachment)
|
||||
if attachment.name == 'pdf_export_for_instructeur'
|
||||
return ''
|
||||
end
|
||||
|
||||
case attachment.record_type
|
||||
when 'Dossier'
|
||||
'dossier'
|
||||
'dossier/'
|
||||
when 'DossierOperationLog', 'BillSignature'
|
||||
'horodatage'
|
||||
'horodatage/'
|
||||
when 'Commentaire'
|
||||
'messagerie'
|
||||
'messagerie/'
|
||||
else
|
||||
'pieces_justificatives'
|
||||
'pieces_justificatives/'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
class PiecesJustificativesService
|
||||
def self.liste_pieces_justificatives(dossier)
|
||||
dossier_export = generate_dossier_export(dossier)
|
||||
pjs_champs = pjs_for_champs(dossier)
|
||||
pjs_commentaires = pjs_for_commentaires(dossier)
|
||||
pjs_dossier = pjs_for_dossier(dossier)
|
||||
|
||||
(pjs_champs + pjs_commentaires + pjs_dossier)
|
||||
([dossier_export] + pjs_champs + pjs_commentaires + pjs_dossier)
|
||||
.filter(&:attached?)
|
||||
end
|
||||
|
||||
|
@ -43,6 +44,17 @@ class PiecesJustificativesService
|
|||
|
||||
private
|
||||
|
||||
def self.generate_dossier_export(dossier)
|
||||
pdf = ApplicationController
|
||||
.render(template: 'dossiers/show', formats: [:pdf],
|
||||
assigns: {
|
||||
include_infos_administration: true,
|
||||
dossier: dossier
|
||||
})
|
||||
dossier.pdf_export_for_instructeur.attach(io: StringIO.open(pdf), filename: "export-#{dossier.id}.pdf", content_type: 'application/pdf')
|
||||
dossier.pdf_export_for_instructeur
|
||||
end
|
||||
|
||||
def self.pjs_for_champs(dossier)
|
||||
allowed_champs = dossier.champs + dossier.champs_private
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue