Merge pull request #8194 from mfo/US/fix-download-target

amelioration(liens-de-telechargement): permet de specifier si le lien  de téléchargement se fait sur l'onglet actuel ou vers un nouvel onglet
This commit is contained in:
mfo 2022-12-05 16:23:53 +01:00 committed by GitHub
commit b68e150dd1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 6 deletions

View file

@ -1,9 +1,10 @@
class Attachment::ShowComponent < ApplicationComponent
def initialize(attachment:)
def initialize(attachment:, new_tab: false)
@attachment = attachment
@new_tab = new_tab
end
attr_reader :attachment
attr_reader :attachment, :new_tab
def should_display_link?
(attachment.virus_scanner.safe? || !attachment.virus_scanner.started?) && !attachment.watermark_pending?

View file

@ -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) do |c|
= render Dsfr::DownloadComponent.new(attachment: attachment, new_tab: new_tab) do |c|
- if !attachment.virus_scanner.started?
- c.right do
= "(#{t(".virus_not_analyzed")})"

View file

@ -4,11 +4,13 @@ class Dsfr::DownloadComponent < ApplicationComponent
attr_reader :attachment
attr_reader :html_class
attr_reader :name
attr_reader :new_tab
def initialize(attachment:, name: nil, url: nil)
def initialize(attachment:, name: nil, url: nil, new_tab: false)
@attachment = attachment
@name = name || attachment.filename.to_s
@url = url
@new_tab = new_tab
end
def title

View file

@ -1,6 +1,6 @@
.fr-download
%p
= link_to url, download: "", class: "fr-download__link", title: title do
= link_to url, {class: "fr-download__link", title: title}.merge(new_tab ? { target: '_blank' } : { download: '' }) do
= name
%span.fr-download__detail
= helpers.download_details(attachment)

View file

@ -3,6 +3,6 @@
.fr-downloads-group
%ul
- pj.attachments.each do |attachment|
%li= render Attachment::ShowComponent.new(attachment:)
%li= render Attachment::ShowComponent.new(attachment:, new_tab: true)
- else
Pièce justificative non fournie