Skip to content

Commit

Permalink
Merge pull request #4579 from alphagov/add-local-transaction-model
Browse files Browse the repository at this point in the history
Add local transaction model
  • Loading branch information
leenagupte authored Jan 14, 2025
2 parents 246279a + 5854ace commit 3830c00
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 186 deletions.
4 changes: 2 additions & 2 deletions app/controllers/electoral_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def show

private

def publication_class
LocalTransactionPresenter
def publication
content_item
end

def content_item_path
Expand Down
13 changes: 7 additions & 6 deletions app/controllers/local_transaction_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ def results
@interaction_details = interaction_details
@local_authority = LocalAuthorityPresenter.new(@interaction_details["local_authority"])
@country_name = @local_authority.country_name
content_item.set_country(@country_name)

if publication.unavailable?(@country_name)
if content_item.unavailable?
render :unavailable_service
elsif publication.devolved_administration_service?(@country_name)
elsif content_item.devolved_administration_service?
render :devolved_administration_service
else
render :results
Expand All @@ -58,8 +59,8 @@ def content_item_path
"/#{params[:slug]}"
end

def publication_class
LocalTransactionPresenter
def publication
content_item
end

def authority_results
Expand Down Expand Up @@ -105,11 +106,11 @@ def postcode
end

def lgsl
content_item_hash["details"]["lgsl_code"]
content_item.lgsl_code
end

def lgil
content_item_hash["details"]["lgil_code"] || content_item_hash["details"]["lgil_override"]
content_item.lgil_code || content_item.lgil_override
end

def interaction_details
Expand Down
48 changes: 48 additions & 0 deletions app/models/local_transaction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class LocalTransaction < ContentItem
attr_reader :country_name, :introduction,
:lgil_code, :lgil_override, :lgsl_code,
:more_information, :need_to_know

def initialize(content_store_response)
super(content_store_response)

@introduction = content_store_response.dig("details", "introduction")
@lgil_code = content_store_response.dig("details", "lgil_code")
@lgil_override = content_store_response.dig("details", "lgil_override")
@lgsl_code = content_store_response.dig("details", "lgsl_code")
@more_information = content_store_response.dig("details", "more_information")
@need_to_know = content_store_response.dig("details", "need_to_know")
end

def unavailable?
country_name_availability_for("type") == "unavailable"
end

def devolved_administration_service?
country_name_availability_for("type") == "devolved_administration_service"
end

def devolved_administration_service_alternative_url
return unless devolved_administration_service?

country_name_availability_for("alternative_url")
end

def set_country(country_name)
@country_name = country_name.downcase.gsub(" ", "_")
end

def slug
URI.parse(base_path).path.sub(%r{\A/}, "")
end

private

def country_name_availability_for(key)
content_store_response.dig("details", country_name_availability, key)
end

def country_name_availability
"#{country_name}_availability"
end
end
36 changes: 0 additions & 36 deletions app/presenters/local_transaction_presenter.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/electoral/address_picker.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<%= render layout: 'shared/base_page', locals: {
title: title,
publication: publication,
publication: content_item,
edition: @edition,
} do %>

Expand Down
8 changes: 4 additions & 4 deletions app/views/electoral/results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<% end %>

<%= render layout: 'shared/base_page', locals: {
title: publication.title,
publication: publication,
title: content_item.title,
publication: content_item,
edition: @edition,
} do %>

Expand All @@ -15,7 +15,7 @@
type: "local transaction",
text: Nokogiri::HTML(t('electoral.service.matched_postcode_html', postcode: @postcode.sanitized_postcode, electoral_service_name: @presenter.electoral_service_name, locale: :en)).text,
action: "complete",
tool_name: publication.title
tool_name: content_item.title
}.to_json
%>
<p class="govuk-body" data-module="ga4-auto-tracker" data-ga4-auto="<%= ga4_auto %>">
Expand All @@ -27,7 +27,7 @@
ga4_link = {
event_name: "information_click",
type: "local transaction",
tool_name: publication.title,
tool_name: content_item.title,
action: "information click"
}.to_json
%>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<%
add_view_stylesheet("local-transaction")
%>
<% content_for :title, "#{publication.title}: #{t('formats.local_transaction.search_result')} - GOV.UK" %>
<% content_for :title, "#{content_item.title}: #{t('formats.local_transaction.search_result')} - GOV.UK" %>

<%= render layout: "shared/base_page", locals: {
title: publication.title,
publication: publication,
title: content_item.title,
publication: content_item,
edition: @edition,
} do %>
<div class="interaction">
<p class="govuk-body">
<%= t("formats.local_transaction.info_on_country_website.#{@country_name.parameterize(separator: "_")}") %>
<%= t("formats.local_transaction.info_on_country_website.#{content_item.country_name}") %>
</p>
<div class="local-authority-result">
<p id="get-started" class="get-started group">
<%= render "govuk_publishing_components/components/button", {
text: t("formats.local_transaction.find_info_for", country_name: @country_name) ,
rel: "external",
margin_bottom: true,
href: publication.devolved_administration_service_alternative_url(@country_name),
href: content_item.devolved_administration_service_alternative_url,
} %>
</p>
</div>
Expand Down
20 changes: 10 additions & 10 deletions app/views/local_transaction/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
<% end %>

<%= render layout: 'shared/base_page', locals: {
title: publication.title,
publication: publication,
title: content_item.title,
publication: content_item,
edition: @edition,
} do %>

<% if publication.introduction.present? %>
<% if content_item.introduction.present? %>
<section class="intro">
<div class="get-started-intro">
<%= render "govuk_publishing_components/components/govspeak", {} do %>
<%= raw publication.introduction %>
<%= raw content_item.introduction %>
<% end %>
</div>
</section>
Expand All @@ -28,26 +28,26 @@
publication_format: 'local_transaction',
postcode: current_page?(electoral_services_path) ? @postcode.sanitized_postcode : @postcode,
margin_top: @location_error ? 5 : 0,
publication_title: publication.title,
publication_title: content_item.title,
}
%>

<% if publication.need_to_know.present? || publication.more_information.present? %>
<% if content_item.need_to_know.present? || content_item.more_information.present? %>
<section class="more">
<% if publication.need_to_know.present? %>
<% if content_item.need_to_know.present? %>
<%= render "govuk_publishing_components/components/heading", {
text: t('formats.local_transaction.what_you_need_to_know'),
margin_bottom: 4
} %>
<%= render "govuk_publishing_components/components/govspeak", {} do %>
<%= raw publication.need_to_know %>
<%= raw content_item.need_to_know %>
<% end %>
<% end %>

<% if publication.more_information.present? %>
<% if content_item.more_information.present? %>
<div class="more">
<%= render "govuk_publishing_components/components/govspeak", {} do %>
<%= raw publication.more_information %>
<%= raw content_item.more_information %>
<% end %>
</div>
<% end %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/local_transaction/multiple_authorities.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<% content_for :title, "#{publication.title}: #{t('formats.local_transaction.select_address')} - GOV.UK" %>
<% content_for :title, "#{content_item.title}: #{t('formats.local_transaction.select_address')} - GOV.UK" %>

<%= render layout: "shared/base_page", locals: {
title: publication.title,
publication: publication,
title: content_item.title,
publication: content_item,
edition: @edition,
} do %>
<p class="govuk-body">
Expand Down
16 changes: 8 additions & 8 deletions app/views/local_transaction/results.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<%
add_view_stylesheet("local-transaction")
%>
<% content_for :title, "#{publication.title}: #{t('formats.local_transaction.search_result')} - GOV.UK" %>
<% content_for :title, "#{content_item.title}: #{t('formats.local_transaction.search_result')} - GOV.UK" %>

<%= render layout: 'shared/base_page', locals: {
title: publication.title,
publication: publication,
title: content_item.title,
publication: content_item,
edition: @edition,
} do %>
<div class="interaction">
Expand All @@ -16,12 +16,12 @@
type: "local transaction",
text: Nokogiri::HTML(t('formats.local_transaction.matched_postcode_html', local_authority: @local_authority.name, locale: :en)).text,
action: "complete",
tool_name: publication.title
tool_name: content_item.title
}.to_json %>">
<%= t('formats.local_transaction.matched_postcode_html', local_authority: @local_authority.name) %>
</p>
<p class="govuk-body">
<%= link_to t('formats.local_transaction.search_for_a_different_postcode'), local_transaction_search_path(publication.slug), class: "govuk-link" %>
<%= link_to t('formats.local_transaction.search_for_a_different_postcode'), local_transaction_search_path(content_item.slug), class: "govuk-link" %>
</p>
<% if @interaction_details['local_interaction'] %>
<p class="govuk-body">
Expand All @@ -34,7 +34,7 @@
data-ga4-link="<%= {
"event_name": "information_click",
"type": "local transaction",
"tool_name": publication.title,
"tool_name": content_item.title,
"action": "information click"
}.to_json %>">
<%= render "govuk_publishing_components/components/button", {
Expand Down Expand Up @@ -65,11 +65,11 @@
<% end %>
</div>

<% if publication.more_information.present? %>
<% if content_item.more_information.present? %>
<section class="more">
<div class="more">
<%= render "govuk_publishing_components/components/govspeak", {} do %>
<%= raw publication.more_information %>
<%= raw content_item.more_information %>
<% end %>
</div>
</section>
Expand Down
4 changes: 2 additions & 2 deletions app/views/local_transaction/unavailable_service.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<%
add_view_stylesheet("local-transaction")
%>
<% content_for :title, "#{publication.title}: #{t('formats.local_transaction.search_result')} - GOV.UK" %>
<% content_for :title, "#{content_item.title}: #{t('formats.local_transaction.search_result')} - GOV.UK" %>

<%= render layout: 'shared/base_page', locals: {
title: t('formats.local_transaction.service_not_available', country_name: @country_name),
publication: publication,
publication: content_item,
edition: @edition,
} do %>
<div class="interaction">
Expand Down
Loading

0 comments on commit 3830c00

Please sign in to comment.