Skip to content

Commit

Permalink
Use components for consultation attachments
Browse files Browse the repository at this point in the history
- output attachments in consultations using the data from the content item, rather than the pre-rendered markup from the content item
  • Loading branch information
andysellick committed May 10, 2024
1 parent 5d6f042 commit e8c8d5d
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 43 deletions.
53 changes: 37 additions & 16 deletions app/presenters/consultation_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,52 @@ def final_outcome_detail
content_item["details"]["final_outcome_detail"]
end

def final_outcome_documents
content_item["details"]["final_outcome_documents"]&.join("")
# Download the full outcome, top of page
def final_outcome_attachments_for_components
documents.select { |doc| final_outcome_attachments.include? doc["id"] }
end

def final_outcome_attachments
content_item["details"]["final_outcome_attachments"]
# Feedback received, middle of page
def public_feedback_attachments_for_components
documents.select { |doc| public_feedback_attachments.include? doc["id"] }
end

# Documents, bottom of page
def documents_attachments_for_components
documents.select { |doc| featured_attachments.include? doc["id"] }
end

def attachments_with_details
items = [].push(*final_outcome_attachments_for_components)
items.push(*public_feedback_attachments_for_components)
items.push(*documents_attachments_for_components)
items.select { |doc| doc["accessible"] == false && doc["alternative_format_contact_email"] }.count
end

def public_feedback_documents
content_item["details"]["public_feedback_documents"]&.join("")
def documents
return [] unless content_item["details"]["attachments"]

docs = content_item["details"]["attachments"].select { |a| !a.key?("locale") || a["locale"] == locale }
docs.each do |doc|
doc["type"] = "html" unless doc["content_type"]
doc["type"] = "external" if doc["attachment_type"] == "external"
doc["preview_url"] = "#{doc['url']}/preview" if doc["preview_url"]
doc["alternative_format_contact_email"] = nil if doc["accessible"] == true
end
end

def final_outcome_attachments
content_item["details"]["final_outcome_attachments"] || []
end

def public_feedback_attachments
content_item["details"]["public_feedback_attachments"] || []
end

def featured_attachments
content_item["details"]["featured_attachments"] || []
end

def public_feedback_detail
content_item["details"]["public_feedback_detail"]
end
Expand All @@ -80,14 +110,6 @@ def held_on_another_website_url
content_item["details"]["held_on_another_website_url"]
end

def documents
content_item["details"]["documents"]&.join("")
end

def featured_attachments
content_item["details"]["featured_attachments"]
end

def ways_to_respond?
open? && ways_to_respond && (respond_online_url || email || postal_address)
end
Expand All @@ -113,8 +135,7 @@ def attachment_url
end

def add_margin?
final_outcome? || public_feedback_detail ||
public_feedback_documents.present? || public_feedback_attachments.any?
final_outcome? || public_feedback_detail || public_feedback_attachments.any?
end

private
Expand Down
24 changes: 14 additions & 10 deletions app/views/content_items/consultation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@
<% elsif @content_item.final_outcome? %>
<%= render 'govuk_publishing_components/components/notice', title: t("consultation.concluded") %>

<%= render "attachments",
title: t("consultation.download_outcome"),
legacy_pre_rendered_documents: @content_item.final_outcome_documents,
attachments: @content_item.final_outcome_attachments %>

<%= render "attachments_list",
title: t("consultation.download_outcome"),
attachments_for_components: @content_item.final_outcome_attachments_for_components
%>
<%= render 'govuk_publishing_components/components/heading', text: t("consultation.detail_of_outcome"), mobile_top_margin: true %>
<div class="consultation-outcome-detail">
<%= render 'govuk_publishing_components/components/govspeak', {
Expand All @@ -68,11 +67,10 @@
</div>
<% end %>

<%= render "attachments",
title: t("consultation.feedback_received"),
legacy_pre_rendered_documents: @content_item.public_feedback_documents,
attachments: @content_item.public_feedback_attachments %>

<%= render "attachments_list",
title: t("consultation.feedback_received"),
attachments_for_components: @content_item.public_feedback_attachments_for_components
%>
<% if @content_item.public_feedback_detail %>
<%= render 'govuk_publishing_components/components/heading', {
mobile_top_margin: true,
Expand Down Expand Up @@ -146,10 +144,16 @@
<%= raw(@content_item.govspeak_body[:content]) %>
<% end %>

<%= render "attachments_list",
title: t("consultation.documents"),
attachments_for_components: @content_item.documents_attachments_for_components
%>
<% if false %>
<%= render "attachments",
title: t("consultation.documents"),
legacy_pre_rendered_documents: @content_item.documents,
attachments: @content_item.featured_attachments %>
<% end %>
</div>

<% if @content_item.ways_to_respond? %>
Expand Down
Loading

0 comments on commit e8c8d5d

Please sign in to comment.