From affb1820d801ed74cfae13e5f3ef5b6935de8779 Mon Sep 17 00:00:00 2001 From: Lisa Durand Date: Tue, 7 May 2024 16:41:20 +0200 Subject: [PATCH] add PDF preview in view for gallery --- app/assets/images/apercu-indisponible.png | Bin 5467 -> 5193 bytes app/assets/images/pdf-placeholder.png | Bin 3581 -> 0 bytes app/jobs/image_processor_job.rb | 5 ++--- .../champs/piece_justificative_champ.rb | 4 +--- app/models/champs/titre_identite_champ.rb | 4 +--- .../concerns/blob_image_processor_concern.rb | 2 +- .../dossiers/pieces_jointes.html.haml | 6 +++--- .../piece_justificative/_show.html.haml | 6 +++--- spec/jobs/image_processor_job_spec.rb | 4 ++-- 9 files changed, 13 insertions(+), 18 deletions(-) delete mode 100644 app/assets/images/pdf-placeholder.png diff --git a/app/assets/images/apercu-indisponible.png b/app/assets/images/apercu-indisponible.png index 6bebd9f59de194d5d5eab6847ac31e31c5d5a4d4..e6c56638a09003ae21f4e970de493cdce4097c94 100644 GIT binary patch literal 5193 zcmeHLX*64HyN;=Eq!Se#)YJi0L#tZzT>4T|OHnGcMbnz6m$$FL->J83 z{yYql0097i!xrYIb^rih*8Tt<;6>uQG`{jK!hz<_AppQ}x&6UsVRwF=7vu}E`_lw~ z#Y-;nZUmvm*2VxpE%M;b10euFY{tUW_)Y{Lby^>Jesto%?2i}SUykQyeMptMf6iIs zNII%ftVSS3HW7F>E&-kn=Q|~uDSIVBD78a0wbsi=nIBbS4irg2#+K{<>ECsDFe#AjK ztBV`UCU)&Lg0k(yxw|aeF77U^ELkQlBGChLFzsnuBxB*C5u%qn5VtkpzE{^O@zg`! zNb4Po42Ls6Q4v650$}d#-YyMpt1Na_QkUVjKFf&JFu1;7)>!Ar^fcNYdVNumIK!T4^O5iEp8pKQxY4S$15~62a z&-3vU(?#Zrfg;U+T{NA|;?3F%i)!)0{{`nCy5HyGkI?mLP5#rb47fWCVO2CBL7+8= z(i2)e-5zNlA1L?hBme&|=#%qjL0kLK+DF90wpFEO5O4QB@(|R_=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wBBxwCx^umK~P`cKTYC!dN)&#EOmJ{ zxfh7#F($mMa8$`Wq^T~$|3wk%b)@mah3KZe>67Wl3F8eA2ZyIf2+L zChIKv)8N~p-(RJnreP57@Z%zPE=O^{Zu;sMh9IbF07!D`#l1k?rCl zREkPz0G_^~+7Wou@I<{0)@1UUda|6qjYsB9t82qIUKd(<2QvL9PrDfsoifM0FhBLf zY0zp)fNS`tnnHz@Mzi`rT0empaX^S(z|hjtLd#AA>`PgX^zu{l?T&`%P_)J}YGKy< t2R$dMMEV}`ieKMk|5FV6w-o_*VDideY`b{M&Z~t2u9(|g#G2iT{TB-GlW+h4 diff --git a/app/assets/images/pdf-placeholder.png b/app/assets/images/pdf-placeholder.png deleted file mode 100644 index 58da75f9f728e70eb30af89f205a263ddc1aa1bb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3581 zcmeH~S5%YP7RQqqAv6K02Eh~EcOzWwd}|Lv3P{PP7V zakw}L1d_79h;{{mz)$uEOaz!Ay)|kF9%7*ve+dVH6i@6Au)XW?C14U9?s~xnRMvTP z7BHax){fR7(5uH1+r9^Zm7dw7tuIG|7e>!It4@!zCKt}TC+DRO=EzYG8OgeE6kXi? z9@yj{?*&2w464v_FT7k^B?GR#UrQgK&5VC$lv&}^IlPD+XixVeeRckDx7KHE>{w@4 z*IqCv=Z`%+2!TL=&`>CeOajTs%7Bm%2nvk?kzp{9EEtSH{^R@`2I2el1L3!c#L-`| zSR+qQ&yFXhrKN^v&YY1V&`7#UEEcO{xF+O+?2-B;>0?GrCbNUb!yUl*iBrm5*Og={vvhf(QvIpU5!Ga?9rC=D1Y*pKZ@|_^S~S4J@HBhHV@n zck{FAoVMA8^a^?2tyADlZuD^^Qu~aXSH%Yh|5xo$Xlf?8q67*xMWMayAP`k`q_zq; z;gGCsYBCAMBE#BjP&xO}i8m35ZWm;8t{9AvMy|LByr_xPen3J=lVKFVC5LQo5QD9f z$+}Juh=m5SodUS18jv@~5#4SIvS}xPM4n1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G#i@MW8kVN& z=0)gSTU#q-I}4UG@?uuLQKR2I6ob*+7?kO*?7itP3J*QYu{-=D)9-GjH|M6{&VB`S zfFXDSkJ$d+rju0&4nK(?cu);^wS?i@zIwo?6-B3&-D`a%^1tXAb_{ljuI3gS6T@91 zzKKyYuRMX!{w?N4P$Owk_qT)p#oWa7?_NW#%WwSqp^52Ne0)N@B&}lo909SeC)Yjc z@Ui$l&_(-YYjS&gn=j%wzp)X$daat*(FB7o>S+LI01!|# z-E!U-!21XI|B>yRuM&O$pb{Vu>~FHK27p%d6z`hPtsgC3k6D^{KSPWc&gS>T=g$J! zxPPcTdQ%ORN)`ELi%Mex==o;Z-`}4h5D0qkSpE+ldMa<@ch;N6-o}sriopO{HvX6d z2)oU6-1bJ;s;Q-AaAZ`}1tr0qLJG0904r$H!8Qaa=+DUEfnS1YkBW@UXlrZpljZH; zaq~cSx~bUimlw@rPBb<)R-%y=IYN4%lqv8~>syn*Z_IqF+2<Bi$`xRs*z{ zRbvfz*zfe^WKur|NlZmpmzi)fSV6;ByjEcl3P)M2$rXeMvIKmm2ZI}PILEJj#hyKp zUvxUc!$HS^$~zKaOYRXom$9+?R8Dxn0+RW|(~FK#)&PTO`sFSkF`WALm#3@X2@Z2PQBZ+dik|MFmpUN(y%X=plWXN z>7~S`wjT { 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