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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue