From 1cdfc9ded0e83ae7ddfc8a5f304d106f15377fba Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 5 Dec 2022 15:59:50 +0100 Subject: [PATCH] =?UTF-8?q?amelioration(liens-de-telechargement):=20permet?= =?UTF-8?q?=20de=20specifier=20si=20le=20lien=20de=20t=C3=A9l=C3=A9chargem?= =?UTF-8?q?ent=20se=20fait=20sur=20l'onglet=20actuel=20ou=20vers=20un=20no?= =?UTF-8?q?uvel=20onglet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/attachment/show_component.rb | 5 +++-- .../attachment/show_component/show_component.html.haml | 2 +- app/components/dsfr/download_component.rb | 4 +++- .../dsfr/download_component/download_component.html.haml | 2 +- app/views/shared/champs/piece_justificative/_show.html.haml | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/components/attachment/show_component.rb b/app/components/attachment/show_component.rb index abb263a7b..4bc8416e7 100644 --- a/app/components/attachment/show_component.rb +++ b/app/components/attachment/show_component.rb @@ -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? diff --git a/app/components/attachment/show_component/show_component.html.haml b/app/components/attachment/show_component/show_component.html.haml index ecbe23e66..7a91132fa 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) 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")})" diff --git a/app/components/dsfr/download_component.rb b/app/components/dsfr/download_component.rb index edcc15d39..2b92ca77c 100644 --- a/app/components/dsfr/download_component.rb +++ b/app/components/dsfr/download_component.rb @@ -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 diff --git a/app/components/dsfr/download_component/download_component.html.haml b/app/components/dsfr/download_component/download_component.html.haml index f2ea95bcd..aed3645c3 100644 --- a/app/components/dsfr/download_component/download_component.html.haml +++ b/app/components/dsfr/download_component/download_component.html.haml @@ -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) diff --git a/app/views/shared/champs/piece_justificative/_show.html.haml b/app/views/shared/champs/piece_justificative/_show.html.haml index ca4d4bd43..2b2eac563 100644 --- a/app/views/shared/champs/piece_justificative/_show.html.haml +++ b/app/views/shared/champs/piece_justificative/_show.html.haml @@ -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