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
|
class Attachment::ShowComponent < ApplicationComponent
|
||||||
def initialize(attachment:, new_tab: false)
|
def initialize(attachment:, new_tab: false, truncate: false)
|
||||||
@attachment = attachment
|
@attachment = attachment
|
||||||
@new_tab = new_tab
|
@new_tab = new_tab
|
||||||
|
@truncate = truncate
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :attachment, :new_tab
|
attr_reader :attachment, :new_tab, :truncate
|
||||||
|
|
||||||
def should_display_link?
|
def should_display_link?
|
||||||
(attachment.virus_scanner.safe? || !attachment.virus_scanner.started?) && !attachment.watermark_pending?
|
(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?) }
|
%div{ id: dom_id(attachment, :show), class: class_names("attachment-error": error?, "fr-mb-2w": !should_display_link?) }
|
||||||
- if 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
|
- else
|
||||||
.attachment-filename.fr-mb-1w.fr-mr-1w= attachment.filename.to_s
|
.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 :ephemeral_link
|
||||||
attr_reader :virus_not_analyzed
|
attr_reader :virus_not_analyzed
|
||||||
attr_reader :new_tab
|
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
|
@attachment = attachment
|
||||||
@name = name || attachment.filename.to_s
|
@name = name || attachment.filename.to_s
|
||||||
@url = url
|
@url = url
|
||||||
@ephemeral_link = ephemeral_link
|
@ephemeral_link = ephemeral_link
|
||||||
@virus_not_analyzed = virus_not_analyzed
|
@virus_not_analyzed = virus_not_analyzed
|
||||||
@new_tab = new_tab
|
@new_tab = new_tab
|
||||||
|
@truncate = truncate
|
||||||
end
|
end
|
||||||
|
|
||||||
def title
|
def title
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
.fr-download
|
.fr-download
|
||||||
%p
|
%p
|
||||||
= link_to url, {class: "fr-download__link", title: title}.merge(new_tab ? { target: '_blank' } : { download: '' }) do
|
= 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
|
%span.fr-download__detail
|
||||||
= helpers.download_details(attachment)
|
= helpers.download_details(attachment)
|
||||||
- if ephemeral_link
|
- if ephemeral_link
|
||||||
|
|
|
@ -15,22 +15,22 @@
|
||||||
.fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button }
|
.fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button }
|
||||||
Visualiser
|
Visualiser
|
||||||
.champ-libelle
|
.champ-libelle
|
||||||
= champ.libelle
|
= champ.libelle.truncate(25)
|
||||||
= render Attachment::ShowComponent.new(attachment: attachment, new_tab: true)
|
= render Attachment::ShowComponent.new(attachment: attachment, new_tab: true, truncate: true)
|
||||||
|
|
||||||
- elsif blob.content_type.in?(AUTHORIZED_IMAGE_TYPES)
|
- 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
|
= 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
|
.thumbnail
|
||||||
= image_tag(blob.url)
|
= image_tag('apercu-indisponible.png')
|
||||||
.fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button }
|
.champ-libelle
|
||||||
Visualiser
|
= champ.libelle.truncate(25)
|
||||||
.champ-libelle
|
= render Attachment::ShowComponent.new(attachment: attachment, truncate: true)
|
||||||
= 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)
|
|
||||||
|
|
Loading…
Reference in a new issue