From d194743df12056ef6a5bd391ac55fd69ca216699 Mon Sep 17 00:00:00 2001 From: Andy Sellick Date: Mon, 15 Jan 2024 14:09:31 +0000 Subject: [PATCH] Change forms pages to use different data - rework the list of documents on the forms pages to use the content item data in `details->attachments` to render the required content, in place of the data in `details->documents`, which is pre-rendered - will make putting tracking onto these elements easier --- app/presenters/publication_presenter.rb | 2 +- app/views/content_items/_attachments.html.erb | 22 +++++++++++-------- .../content_items/call_for_evidence.html.erb | 8 +++---- app/views/content_items/consultation.html.erb | 12 +++++----- app/views/content_items/publication.html.erb | 4 ++-- test/presenters/publication_presenter_test.rb | 2 +- 6 files changed, 27 insertions(+), 23 deletions(-) diff --git a/app/presenters/publication_presenter.rb b/app/presenters/publication_presenter.rb index 7514029e9b..817281de6d 100644 --- a/app/presenters/publication_presenter.rb +++ b/app/presenters/publication_presenter.rb @@ -11,7 +11,7 @@ def details end def documents - content_item["details"]["documents"].to_a.join("") + content_item["details"]["attachments"].select { |a| a["locale"] == locale } end def featured_attachments diff --git a/app/views/content_items/_attachments.html.erb b/app/views/content_items/_attachments.html.erb index ee8f901a6c..c2fc4385cf 100644 --- a/app/views/content_items/_attachments.html.erb +++ b/app/views/content_items/_attachments.html.erb @@ -1,17 +1,21 @@ -<% attachments ||= [] %> -<% attachment_details = attachments.filter_map { |id| @content_item&.attachment_details(id) } %> -<% if legacy_pre_rendered_documents.present? || attachment_details.any? %> +<% featured_attachments ||= [] %> +<% attachment_details = featured_attachments.filter_map { |id| @content_item&.attachment_details(id) } %> +<% if attachments.present? || attachment_details.any? %>
<%= render 'govuk_publishing_components/components/heading', text: title, mobile_top_margin: true %> - <% if legacy_pre_rendered_documents.present? %> - <%= render 'govuk_publishing_components/components/govspeak', { - direction: page_text_direction, - } do %> - <% add_gem_component_stylesheet("details") if legacy_pre_rendered_documents.include? "govuk\-details" %> - <%= raw(legacy_pre_rendered_documents) %> + <% add_gem_component_stylesheet("details") %> + <% if attachments.present? %> + <% attachments.each do |details| %> + <%= details.inspect %> +
+ <%= render 'govuk_publishing_components/components/attachment', { + heading_level: 3, + attachment: details + } %> +
<% end %> <% else %> <% attachment_details.each do |details| %> diff --git a/app/views/content_items/call_for_evidence.html.erb b/app/views/content_items/call_for_evidence.html.erb index 3ecef5dc98..c78c30940a 100644 --- a/app/views/content_items/call_for_evidence.html.erb +++ b/app/views/content_items/call_for_evidence.html.erb @@ -44,8 +44,8 @@ <%= render "attachments", title: t("call_for_evidence.download_outcome"), - legacy_pre_rendered_documents: @content_item.outcome_documents, - attachments: @content_item.outcome_attachments %> + attachments: @content_item.outcome_documents, + featured_attachments: @content_item.outcome_attachments %> <%= render 'govuk_publishing_components/components/heading', text: t("call_for_evidence.detail_of_outcome"), mobile_top_margin: true %>
@@ -118,8 +118,8 @@ <%= render "attachments", title: t("call_for_evidence.documents"), - legacy_pre_rendered_documents: @content_item.documents, - attachments: @content_item.featured_attachments %> + attachments: @content_item.documents, + featured_attachments: @content_item.featured_attachments %>
<% if @content_item.ways_to_respond? %> diff --git a/app/views/content_items/consultation.html.erb b/app/views/content_items/consultation.html.erb index cb96edacae..9d72ed512f 100644 --- a/app/views/content_items/consultation.html.erb +++ b/app/views/content_items/consultation.html.erb @@ -55,8 +55,8 @@ <%= render "attachments", title: t("consultation.download_outcome"), - legacy_pre_rendered_documents: @content_item.final_outcome_documents, - attachments: @content_item.final_outcome_attachments %> + attachments: @content_item.final_outcome_documents, + featured_attachments: @content_item.final_outcome_attachments %> <%= render 'govuk_publishing_components/components/heading', text: t("consultation.detail_of_outcome"), mobile_top_margin: true %>
@@ -70,8 +70,8 @@ <%= render "attachments", title: t("consultation.feedback_received"), - legacy_pre_rendered_documents: @content_item.public_feedback_documents, - attachments: @content_item.public_feedback_attachments %> + attachments: @content_item.public_feedback_documents, + featured_attachments: @content_item.public_feedback_attachments %> <% if @content_item.public_feedback_detail %> <%= render 'govuk_publishing_components/components/heading', { @@ -148,8 +148,8 @@ <%= render "attachments", title: t("consultation.documents"), - legacy_pre_rendered_documents: @content_item.documents, - attachments: @content_item.featured_attachments %> + attachments: @content_item.documents, + featured_attachments: @content_item.featured_attachments %>
<% if @content_item.ways_to_respond? %> diff --git a/app/views/content_items/publication.html.erb b/app/views/content_items/publication.html.erb index 66b40dd807..3d82244b49 100644 --- a/app/views/content_items/publication.html.erb +++ b/app/views/content_items/publication.html.erb @@ -51,8 +51,8 @@
<%= render "attachments", title: t("publication.documents", count: 5), # This should always be pluralised. - legacy_pre_rendered_documents: @content_item.documents, - attachments: @content_item.featured_attachments + attachments: @content_item.documents, + featured_attachments: @content_item.featured_attachments %>
diff --git a/test/presenters/publication_presenter_test.rb b/test/presenters/publication_presenter_test.rb index ad11cba5d3..da7fd3989e 100644 --- a/test/presenters/publication_presenter_test.rb +++ b/test/presenters/publication_presenter_test.rb @@ -10,7 +10,7 @@ def schema_name assert_equal schema_item["schema_name"], presented_item.schema_name assert_equal schema_item["title"], presented_item.title assert_equal schema_item["details"]["body"], presented_item.details - assert_equal schema_item["details"]["documents"].join(""), presented_item.documents + assert_equal schema_item["details"]["documents"], presented_item.documents_attachments end test "#published returns a formatted date of the day the content item became public" do