forked from ukparliament/thorney
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added treaties controller, serializer
- Loading branch information
1 parent
4e4deb2
commit ca1dd42
Showing
66 changed files
with
7,035 additions
and
743 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Treaties | ||
class WorkPackagesController < ApplicationController | ||
before_action :build_request, :data_check | ||
|
||
ROUTE_MAP = { | ||
index: proc { |params| ParliamentHelper.parliament_request.treaty_work_packages.set_url_params({ treaty_id: params[:treaty_id] }) } | ||
}.freeze | ||
|
||
def index | ||
@work_packaged_thing, @work_packages = FilterHelper.filter(@api_request, 'WorkPackagedThing', 'WorkPackage') | ||
@work_packaged_thing = @work_packaged_thing.first | ||
|
||
list_components = WorkPackageListComponentsFactory.sort_and_build_components(work_packages: @work_packages, date_type: :laying_date) | ||
|
||
heading = ComponentSerializer::Heading1ComponentSerializer.new(heading: I18n.t('treaties.work_packages.index.title', treaty: @work_packaged_thing.try(:workPackagedThingName)), subheading: @work_packaged_thing.try(:workPackagedThingName), subheading_link: treaty_path) | ||
|
||
serializer = PageSerializer::ListPageSerializer.new(request: request, heading_component: heading, list_components: list_components, data_alternates: @alternates) | ||
|
||
render_page(serializer) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class TreatiesController < ApplicationController | ||
# Controller rendering treaties index and show pages | ||
before_action :build_request | ||
|
||
ROUTE_MAP = { | ||
index: proc { ParliamentHelper.parliament_request.treaty_index }, | ||
show: proc { |params| ParliamentHelper.parliament_request.treaty_by_id.set_url_params({ treaty_id: params[:treaty_id] }) }, | ||
lookup: proc { |params| ParliamentHelper.parliament_request.treaty_lookup.set_url_params({ property: params[:source], value: params[:id] }) } | ||
}.freeze | ||
|
||
def index | ||
@treaties = FilterHelper.filter(@api_request, 'Treaty') | ||
list_components = LaidThingListComponentsFactory.sort_and_build_components(statutory_instruments: @treaties) | ||
|
||
heading = ComponentSerializer::Heading1ComponentSerializer.new(heading: I18n.t('treaties.index.title')) | ||
|
||
serializer = PageSerializer::ListPageSerializer.new(request: request, heading_component: heading, list_components: list_components, data_alternates: @alternates) | ||
|
||
render_page(serializer) | ||
end | ||
|
||
def show | ||
@treaty = FilterHelper.filter(@api_request, 'Treaty') | ||
@treaty = @treaty.first | ||
|
||
serializer = PageSerializer::TreatiesShowPageSerializer.new(request: request, treaty: @treaty, data_alternates: @alternates) | ||
|
||
render_page(serializer) | ||
end | ||
|
||
def lookup | ||
@treaty = FilterHelper.filter(@api_request, 'Treaty') | ||
@treaty = @treaty.first | ||
|
||
redirect_to :action => 'show', 'treaty_id' => @treaty.graph_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/serializers/page_serializer/treaties_show_page_serializer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module PageSerializer | ||
class TreatiesShowPageSerializer < LaidThingShowPageSerializer | ||
# Initialise a Treaties show page serializer. | ||
# | ||
# @param [ActionDispatch::Request] request the current request object. | ||
# @param [<Grom::Node>] treaty a Grom::Node object of type Treaty. | ||
# @param [Array<Hash>] data_alternates array containing the href and type of the alternative data urls | ||
def initialize(request: nil, treaty:, data_alternates: nil) | ||
@treaty = treaty | ||
|
||
super(request: request, laid_thing: @treaty, data_alternates: data_alternates) | ||
end | ||
|
||
private | ||
|
||
def meta | ||
super(title: title) | ||
end | ||
|
||
def heading1_component | ||
ComponentSerializer::Heading1ComponentSerializer.new(heading_content).to_h | ||
end | ||
|
||
def heading_content | ||
{}.tap do |hash| | ||
hash[:subheading] = ContentDataHelper.content_data(content: 'treaties.show.subheading', link: treaties_path) | ||
hash[:heading] = title || t('no_name') | ||
end | ||
end | ||
|
||
def meta_info | ||
[].tap do |items| | ||
web_link = @laid_thing.try(:workPackagedThingHasWorkPackagedThingWebLink) | ||
items << create_description_list_item(term: 'laid-thing.web-link', descriptions: [link_to(web_link, web_link)]) if web_link | ||
items << create_description_list_item(term: 'laid-thing.laid-date', descriptions: [TimeHelper.time_translation(date_first: @laid_thing&.laying&.date)]) if @laid_thing&.laying&.date | ||
items << create_description_list_item(term: 'laid-thing.laying-person', descriptions: [@laying_person&.display_name]) if @laying_person | ||
items << create_description_list_item(term: 'laid-thing.laying-body', descriptions: [link_to(@laying_body.try(:groupName), group_path(@laying_body.graph_id))]) if @laying_body | ||
end.compact | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.