chore: add truncate option to show and download component
This commit is contained in:
parent
7c6c3608c9
commit
29dea52a7e
5 changed files with 25 additions and 22 deletions
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue