From 29dea52a7e840ce6f2964881be658e7af6845bb6 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Mon, 8 Apr 2024 10:13:05 +0200 Subject: [PATCH] chore: add truncate option to show and download component --- app/components/attachment/show_component.rb | 5 +-- .../show_component/show_component.html.haml | 2 +- app/components/dsfr/download_component.rb | 4 ++- .../download_component.html.haml | 2 +- .../dossiers/pieces_jointes.html.haml | 34 +++++++++---------- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/app/components/attachment/show_component.rb b/app/components/attachment/show_component.rb index 4bc8416e7..ca109617a 100644 --- a/app/components/attachment/show_component.rb +++ b/app/components/attachment/show_component.rb @@ -1,10 +1,11 @@ class Attachment::ShowComponent < ApplicationComponent - def initialize(attachment:, new_tab: false) + def initialize(attachment:, new_tab: false, truncate: false) @attachment = attachment @new_tab = new_tab + @truncate = truncate end - attr_reader :attachment, :new_tab + attr_reader :attachment, :new_tab, :truncate def should_display_link? (attachment.virus_scanner.safe? || !attachment.virus_scanner.started?) && !attachment.watermark_pending? diff --git a/app/components/attachment/show_component/show_component.html.haml b/app/components/attachment/show_component/show_component.html.haml index 49b9768df..f8bd81f44 100644 --- a/app/components/attachment/show_component/show_component.html.haml +++ b/app/components/attachment/show_component/show_component.html.haml @@ -1,6 +1,6 @@ %div{ id: dom_id(attachment, :show), class: class_names("attachment-error": error?, "fr-mb-2w": !should_display_link?) } - if should_display_link? - = render Dsfr::DownloadComponent.new(attachment: attachment, virus_not_analyzed: !attachment.virus_scanner.started?, new_tab: new_tab) + = render Dsfr::DownloadComponent.new(attachment: attachment, virus_not_analyzed: !attachment.virus_scanner.started?, new_tab: new_tab, truncate: truncate) - else .attachment-filename.fr-mb-1w.fr-mr-1w= attachment.filename.to_s diff --git a/app/components/dsfr/download_component.rb b/app/components/dsfr/download_component.rb index ef1e8862f..326c0865b 100644 --- a/app/components/dsfr/download_component.rb +++ b/app/components/dsfr/download_component.rb @@ -5,14 +5,16 @@ class Dsfr::DownloadComponent < ApplicationComponent attr_reader :ephemeral_link attr_reader :virus_not_analyzed attr_reader :new_tab + attr_reader :truncate - def initialize(attachment:, name: nil, url: nil, ephemeral_link: false, virus_not_analyzed: false, new_tab: false) + def initialize(attachment:, name: nil, url: nil, ephemeral_link: false, virus_not_analyzed: false, new_tab: false, truncate: false) @attachment = attachment @name = name || attachment.filename.to_s @url = url @ephemeral_link = ephemeral_link @virus_not_analyzed = virus_not_analyzed @new_tab = new_tab + @truncate = truncate end def title diff --git a/app/components/dsfr/download_component/download_component.html.haml b/app/components/dsfr/download_component/download_component.html.haml index 71d53624a..cd30a9f57 100644 --- a/app/components/dsfr/download_component/download_component.html.haml +++ b/app/components/dsfr/download_component/download_component.html.haml @@ -1,7 +1,7 @@ .fr-download %p = link_to url, {class: "fr-download__link", title: title}.merge(new_tab ? { target: '_blank' } : { download: '' }) do - = name + = truncate ? name.truncate(20) : name %span.fr-download__detail = helpers.download_details(attachment) - if ephemeral_link diff --git a/app/views/instructeurs/dossiers/pieces_jointes.html.haml b/app/views/instructeurs/dossiers/pieces_jointes.html.haml index ce6cf923b..0575dcd4b 100644 --- a/app/views/instructeurs/dossiers/pieces_jointes.html.haml +++ b/app/views/instructeurs/dossiers/pieces_jointes.html.haml @@ -15,22 +15,22 @@ .fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button } Visualiser .champ-libelle - = champ.libelle - = render Attachment::ShowComponent.new(attachment: attachment, new_tab: true) + = champ.libelle.truncate(25) + = render Attachment::ShowComponent.new(attachment: attachment, new_tab: true, truncate: true) - - 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 + - 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(blob.url) + .fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button } + Visualiser + .champ-libelle + = champ.libelle.truncate(25) + = render Attachment::ShowComponent.new(attachment: attachment, truncate: true) + + - else .thumbnail - = image_tag(blob.url) - .fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button } - Visualiser - .champ-libelle - = champ.libelle - = render Attachment::ShowComponent.new(attachment: attachment, new_tab: true) - - - else - .thumbnail - = image_tag('apercu-indisponible.png') - .champ-libelle - = champ.libelle - = render Attachment::ShowComponent.new(attachment: attachment, new_tab: true) + = image_tag('apercu-indisponible.png') + .champ-libelle + = champ.libelle.truncate(25) + = render Attachment::ShowComponent.new(attachment: attachment, truncate: true)