Skip to content

Commit

Permalink
Add link to download a PDF
Browse files Browse the repository at this point in the history
This updates the component which renders the links to the uploads to
include a link to the document.
  • Loading branch information
thomasleese committed Jan 10, 2024
1 parent 893cdbd commit d40fc04
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions app/components/check_your_answers_summary/component.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module CheckYourAnswersSummary
class Component < ViewComponent::Base
def initialize(
Expand Down Expand Up @@ -63,11 +65,9 @@ def value_for(field)
end

def href_for(field)
return if (path = field[:href]).blank?

return path if path.is_a?(String)

Rails.application.routes.url_helpers.polymorphic_path(path)
if (path = field[:href]).present?
path.is_a?(String) ? path : url_helpers.polymorphic_path(path)
end
end

def row_for_field(field)
Expand Down Expand Up @@ -135,13 +135,21 @@ def format_document(document, field)
.order(:created_at)
.select { |upload| upload.attachment.present? }

malware_scan_active =
FeatureFlags::FeatureFlag.active?(:fetch_malware_scan_result)

[
format_array(uploads, field),
if malware_scan_active && scope.scan_result_suspect.exists?
"<em>One or more upload has been deleted by the virus scanner.</em>"
elsif request.path.starts_with?("/assessor") &&
convert_to_pdf_active && !uploads.all?(&:is_pdf?)
helpers.govuk_link_to(
"Download as PDF (opens in a new tab)",
url_helpers.assessor_interface_application_form_document_pdf_path(
document,
field[:translation] ? "translated" : "original",
),
target: :_blank,
rel: :noopener,
)
end,
].compact_blank.join("<br /><br />").html_safe
end
Expand All @@ -150,5 +158,19 @@ def format_document(document, field)
def format_array(list, field)
list.map { |v| format_value(v, field) }.join("<br />").html_safe
end

def url_helpers
@url_helpers ||= Rails.application.routes.url_helpers
end

def malware_scan_active
@malware_scan_active ||=
FeatureFlags::FeatureFlag.active?(:fetch_malware_scan_result)
end

def convert_to_pdf_active
@convert_to_pdf_active =
FeatureFlags::FeatureFlag.active?(:convert_documents_to_pdf)
end
end
end

0 comments on commit d40fc04

Please sign in to comment.