diff --git a/app/assets/images/apercu-indisponible.png b/app/assets/images/apercu-indisponible.png index 6bebd9f59..e6c56638a 100644 Binary files a/app/assets/images/apercu-indisponible.png and b/app/assets/images/apercu-indisponible.png differ diff --git a/app/assets/images/pdf-placeholder.png b/app/assets/images/pdf-placeholder.png deleted file mode 100644 index 58da75f9f..000000000 Binary files a/app/assets/images/pdf-placeholder.png and /dev/null differ diff --git a/app/jobs/image_processor_job.rb b/app/jobs/image_processor_job.rb index 1c37040fe..8017d2b35 100644 --- a/app/jobs/image_processor_job.rb +++ b/app/jobs/image_processor_job.rb @@ -16,7 +16,7 @@ class ImageProcessorJob < ApplicationJob return if ActiveStorage::Attachment.find_by(blob_id: blob.id)&.record_type == "ActiveStorage::VariantRecord" auto_rotate(blob) if ["image/jpeg", "image/jpg"].include?(blob.content_type) - create_variants(blob) if blob.variant_required? + create_representations(blob) if blob.representation_required? add_watermark(blob) if blob.watermark_pending? end @@ -34,10 +34,9 @@ class ImageProcessorJob < ApplicationJob end end - def create_variants(blob) + def create_representations(blob) blob.attachments.each do |attachment| next unless attachment&.representable? - attachment.representation(resize_to_limit: [300, 300]).processed attachment.representation(resize_to_limit: [400, 400]).processed end end diff --git a/app/models/champs/piece_justificative_champ.rb b/app/models/champs/piece_justificative_champ.rb index b6dfb0bef..dcd8e56ce 100644 --- a/app/models/champs/piece_justificative_champ.rb +++ b/app/models/champs/piece_justificative_champ.rb @@ -1,9 +1,7 @@ class Champs::PieceJustificativeChamp < Champ FILE_MAX_SIZE = 200.megabytes - has_many_attached :piece_justificative_file do |attachable| - attachable.variant :medium, resize: '400x400' - end + has_many_attached :piece_justificative_file # TODO: if: -> { validate_champ_value? || validation_context == :prefill } validates :piece_justificative_file, diff --git a/app/models/champs/titre_identite_champ.rb b/app/models/champs/titre_identite_champ.rb index 667feca7e..6d95f4d43 100644 --- a/app/models/champs/titre_identite_champ.rb +++ b/app/models/champs/titre_identite_champ.rb @@ -2,9 +2,7 @@ class Champs::TitreIdentiteChamp < Champ FILE_MAX_SIZE = 20.megabytes ACCEPTED_FORMATS = ['image/png', 'image/jpeg'] - has_many_attached :piece_justificative_file do |attachable| - attachable.variant :medium, resize: '400x400' - end + has_many_attached :piece_justificative_file # TODO: if: -> { validate_champ_value? || validation_context == :prefill } validates :piece_justificative_file, content_type: ACCEPTED_FORMATS, size: { less_than: FILE_MAX_SIZE } diff --git a/app/models/concerns/blob_image_processor_concern.rb b/app/models/concerns/blob_image_processor_concern.rb index 46b56b955..3b92ad4e4 100644 --- a/app/models/concerns/blob_image_processor_concern.rb +++ b/app/models/concerns/blob_image_processor_concern.rb @@ -7,7 +7,7 @@ module BlobImageProcessorConcern watermarked_at.present? end - def variant_required? + def representation_required? attachments.any? { _1.record.class == Champs::TitreIdentiteChamp || _1.record.class == Champs::PieceJustificativeChamp } end diff --git a/app/views/instructeurs/dossiers/pieces_jointes.html.haml b/app/views/instructeurs/dossiers/pieces_jointes.html.haml index a0b1816a1..1d08707a3 100644 --- a/app/views/instructeurs/dossiers/pieces_jointes.html.haml +++ b/app/views/instructeurs/dossiers/pieces_jointes.html.haml @@ -5,13 +5,13 @@ .fr-container .gallery.gallery-pieces-jointes{ "data-controller": "lightbox" } - @champs_with_pieces_jointes.each do |champ| - - champ.piece_justificative_file.each do |attachment| + - champ.piece_justificative_file.with_all_variant_records.each do |attachment| .gallery-item - blob = attachment.blob - if blob.content_type.in?(AUTHORIZED_PDF_TYPES) = link_to blob.url, id: blob.id, data: { iframe: true, src: blob.url }, class: 'gallery-link', type: blob.content_type, title: "#{champ.libelle} -- #{blob.filename}" do .thumbnail - = image_tag("pdf-placeholder.png") + = image_tag(attachment.representation(resize_to_limit: [400, 400]).processed.url, loading: :lazy) .fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button } Visualiser .champ-libelle @@ -21,7 +21,7 @@ - elsif blob.content_type.in?(AUTHORIZED_IMAGE_TYPES) = link_to image_url(blob.url), title: "#{champ.libelle} -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do .thumbnail - = image_tag(attachment.variant(:medium), loading: :lazy) + = image_tag(attachment.representation(resize_to_limit: [400, 400]).processed.url, loading: :lazy) .fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button } Visualiser .champ-libelle diff --git a/app/views/shared/champs/piece_justificative/_show.html.haml b/app/views/shared/champs/piece_justificative/_show.html.haml index 50218e54b..670e9e011 100644 --- a/app/views/shared/champs/piece_justificative/_show.html.haml +++ b/app/views/shared/champs/piece_justificative/_show.html.haml @@ -5,20 +5,20 @@ %li= render Attachment::ShowComponent.new(attachment:, new_tab: true) - else .gallery-items-list - - champ.piece_justificative_file.attachments.each do |attachment| + - champ.piece_justificative_file.attachments.with_all_variant_records.each do |attachment| .gallery-item - blob = attachment.blob - if blob.content_type.in?(AUTHORIZED_PDF_TYPES) = link_to blob.url, id: blob.id, data: { iframe: true, src: blob.url }, class: 'gallery-link', type: blob.content_type, title: "#{champ.libelle} -- #{blob.filename}" do .thumbnail - = image_tag("pdf-placeholder.png") + = image_tag(attachment.representation(resize_to_limit: [400, 400]).processed.url, loading: :lazy) .fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button } = 'Visualiser' - elsif blob.content_type.in?(AUTHORIZED_IMAGE_TYPES) = link_to image_url(blob.url), title: "#{champ.libelle} -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do .thumbnail - = image_tag(attachment.variant(:medium), loading: :lazy) + = image_tag(attachment.representation(resize_to_limit: [400, 400]).processed.url, loading: :lazy) .fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button } = 'Visualiser' - else diff --git a/spec/jobs/image_processor_job_spec.rb b/spec/jobs/image_processor_job_spec.rb index 9c520babd..e32999273 100644 --- a/spec/jobs/image_processor_job_spec.rb +++ b/spec/jobs/image_processor_job_spec.rb @@ -89,11 +89,11 @@ describe ImageProcessorJob, type: :job do context "when representation is required" do before do - allow(blob).to receive(:variant_required?).and_return(true) + allow(blob).to receive(:representation_required?).and_return(true) end it "it creates blob representation" do - expect { described_class.perform_now(blob) }.to change { ActiveStorage::VariantRecord.count }.by(2) + expect { described_class.perform_now(blob) }.to change { ActiveStorage::VariantRecord.count }.by(1) end end end