Skip to content

Commit

Permalink
Added treaties controller, serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
katylouise committed Jan 23, 2019
1 parent 4e4deb2 commit ca1dd42
Show file tree
Hide file tree
Showing 66 changed files with 7,035 additions and 743 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ gem 'parliament-opensearch', '~> 0.4', require: false
gem 'parliament-grom-decorators', '~> 1.0.2'

# Parliament routing
gem 'parliament-routes', '~> 0.6.30'
gem 'parliament-routes', '~> 0.6.31'

gem 'parliament-ntriple', '~> 0.3', require: false

Expand Down
28 changes: 14 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ GEM
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.5.2)
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
airbrake (7.4.0)
airbrake-ruby (~> 2.12)
Expand Down Expand Up @@ -77,15 +77,15 @@ GEM
erubi (1.8.0)
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.12.2)
faraday_middleware (0.13.0)
faraday (>= 0.7.4, < 1.0)
feedjira (2.2.0)
faraday (>= 0.9)
faraday_middleware (>= 0.9)
loofah (>= 2.0)
sax-machine (>= 1.0)
ffi (1.10.0)
globalid (0.4.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
grom (1.0.1)
activesupport (>= 5.0.0.1)
Expand All @@ -94,7 +94,7 @@ GEM
hamster (3.0.0)
concurrent-ruby (~> 1.0)
hashdiff (0.3.8)
i18n (1.5.1)
i18n (1.5.3)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.2)
json (2.1.0)
Expand All @@ -115,23 +115,23 @@ GEM
mini_mime (1.0.1)
mini_portile2 (2.4.0)
minitest (5.11.3)
msgpack (1.2.4)
msgpack (1.2.6)
multipart-post (2.0.0)
nio4r (2.3.1)
nokogiri (1.10.0)
nokogiri (1.10.1)
mini_portile2 (~> 2.4.0)
nokogumbo (2.0.1)
nokogiri (~> 1.8, >= 1.8.4)
parallel (1.12.1)
parliament-grom-decorators (1.0.5)
parallel (1.13.0)
parliament-grom-decorators (1.0.6)
parliament-ntriple (0.5.0)
grom (~> 1.0)
parliament-opensearch (0.7.0)
activesupport (>= 5.0.0.1)
feedjira (~> 2.1, >= 2.1.2)
parliament-routes (0.6.30)
parliament-routes (0.6.31)
parliament-ruby (0.10.2)
parser (2.5.3.0)
parser (2.6.0.0)
ast (~> 2.4.0)
powerpack (0.1.2)
public_suffix (3.0.3)
Expand Down Expand Up @@ -188,7 +188,7 @@ GEM
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-rails (3.8.1)
rspec-rails (3.8.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
Expand All @@ -197,7 +197,7 @@ GEM
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubocop (0.62.0)
rubocop (0.63.1)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
Expand Down Expand Up @@ -230,7 +230,7 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
term-ansicolor (1.7.0)
term-ansicolor (1.7.1)
tins (~> 1.0)
thor (0.19.4)
thread_safe (0.3.6)
Expand Down Expand Up @@ -266,7 +266,7 @@ DEPENDENCIES
parliament-grom-decorators (~> 1.0.2)
parliament-ntriple (~> 0.3)
parliament-opensearch (~> 0.4)
parliament-routes (~> 0.6.30)
parliament-routes (~> 0.6.31)
parliament-ruby (~> 0.8)
puma (~> 3.11)
rack-rewrite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PaperTypesController < ApplicationController

request.group_laid_papers_paper_type_statutory_instruments.set_url_params({ group_id: params[:group_id] }) if paper_type == 'statutory-instruments'
request.group_laid_papers_paper_type_proposed_negative_statutory_instruments.set_url_params({ group_id: params[:group_id] }) if paper_type == 'proposed-negative-statutory-instruments'
request.group_laid_papers_paper_type_treaties.set_url_params({ group_id: params[:group_id] }) if paper_type == 'treaties'

request
end
Expand Down Expand Up @@ -41,6 +42,7 @@ def show
paper_type = params.fetch(:paper_type)
heading_translation = 'groups.made_available.availability_types.paper_types.show.si_title' if paper_type == 'statutory-instruments'
heading_translation = 'groups.made_available.availability_types.paper_types.show.pnsi_title' if paper_type == 'proposed-negative-statutory-instruments'
heading_translation = 'groups.made_available.availability_types.paper_types.show.treaty_title' if paper_type == 'treaties'

heading = ComponentSerializer::Heading1ComponentSerializer.new(heading: I18n.t(heading_translation, group: @group.try(:groupName)), subheading: @group.try(:groupName), subheading_link: group_path)

Expand Down
22 changes: 22 additions & 0 deletions app/controllers/treaties/work_packages_controller.rb
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
37 changes: 37 additions & 0 deletions app/controllers/treaties_controller.rb
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
2 changes: 2 additions & 0 deletions app/controllers/work_packages/paper_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class PaperTypesController < ApplicationController

request.work_packages_paper_types_statutory_instruments if paper_type == 'statutory-instruments'
request.work_packages_paper_types_proposed_negative_statutory_instruments if paper_type == 'proposed-negative-statutory-instruments'
request.work_packages_paper_types_treaties if paper_type == 'treaties'

request
end,
Expand Down Expand Up @@ -42,6 +43,7 @@ def show
paper_type = params.fetch(:paper_type)
heading_translation = 'work_packages.paper_types.show.si_title' if paper_type == 'statutory-instruments'
heading_translation = 'work_packages.paper_types.show.psni_title' if paper_type == 'proposed-negative-statutory-instruments'
heading_translation = 'work_packages.paper_types.show.treaty_title' if paper_type == 'treaties'

heading = ComponentSerializer::Heading1ComponentSerializer.new(heading: I18n.t(heading_translation))

Expand Down
20 changes: 12 additions & 8 deletions app/factories/laid_thing_list_components_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ def heading_text(statutory_instrument)
statutory_instrument.try(:laidThingName)
end

def heading_url(statutory_instrument)
if statutory_instrument.is_a?(Parliament::Grom::Decorator::StatutoryInstrumentPaper)
statutory_instrument_path(statutory_instrument.graph_id)
elsif statutory_instrument.is_a?(Parliament::Grom::Decorator::ProposedNegativeStatutoryInstrumentPaper)
proposed_negative_statutory_instrument_path(statutory_instrument.graph_id)
def heading_url(laid_thing)
if laid_thing.is_a?(Parliament::Grom::Decorator::StatutoryInstrumentPaper)
statutory_instrument_path(laid_thing.graph_id)
elsif laid_thing.is_a?(Parliament::Grom::Decorator::ProposedNegativeStatutoryInstrumentPaper)
proposed_negative_statutory_instrument_path(laid_thing.graph_id)
elsif laid_thing.is_a?(Parliament::Grom::Decorator::Treaty)
treaty_path(laid_thing.graph_id)
end
end

Expand Down Expand Up @@ -74,11 +76,13 @@ def description_list_content(statutory_instrument)
end
end

def laying_type(statutory_instrument)
if statutory_instrument.is_a?(Parliament::Grom::Decorator::StatutoryInstrumentPaper)
def laying_type(laid_thing)
if laid_thing.is_a?(Parliament::Grom::Decorator::StatutoryInstrumentPaper)
'statutory-instruments.type'
elsif statutory_instrument.is_a?(Parliament::Grom::Decorator::ProposedNegativeStatutoryInstrumentPaper)
elsif laid_thing.is_a?(Parliament::Grom::Decorator::ProposedNegativeStatutoryInstrumentPaper)
'proposed-negative-statutory-instruments.type'
elsif laid_thing.is_a?(Parliament::Grom::Decorator::Treaty)
'treaties.type'
end
end
end
Expand Down
16 changes: 14 additions & 2 deletions app/factories/paper_types_list_components_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ class << self
# @return [Array] array of Card components populated with the paper type data
def build_components(group: nil)
heading_links = if group
{ pnsi_link: group_made_available_availability_types_laid_papers_paper_type_path(group_id: group.graph_id, paper_type: 'proposed-negative-statutory-instruments'), si_link: group_made_available_availability_types_laid_papers_paper_type_path(group_id: group.graph_id, paper_type: 'statutory-instruments') }
{
pnsi_link: group_made_available_availability_types_laid_papers_paper_type_path(group_id: group.graph_id, paper_type: 'proposed-negative-statutory-instruments'),
si_link: group_made_available_availability_types_laid_papers_paper_type_path(group_id: group.graph_id, paper_type: 'statutory-instruments'),
treaty_link: group_made_available_availability_types_laid_papers_paper_type_path(group_id: group.graph_id, paper_type: 'treaties')
}
else
{ pnsi_link: work_packages_paper_type_path('proposed-negative-statutory-instruments'), si_link: work_packages_paper_type_path('statutory-instruments') }
{
pnsi_link: work_packages_paper_type_path('proposed-negative-statutory-instruments'),
si_link: work_packages_paper_type_path('statutory-instruments'),
treaty_link: work_packages_paper_type_path('treaties')
}
end

[
Expand All @@ -22,6 +30,10 @@ def build_components(group: nil)
CardFactory.new(
heading_text: I18n.t('statutory_instruments.type').pluralize,
heading_url: heading_links[:si_link]
).build_card,
CardFactory.new(
heading_text: I18n.t('treaties.type').pluralize,
heading_url: heading_links[:treaty_link]
).build_card
]
end
Expand Down
41 changes: 41 additions & 0 deletions app/serializers/page_serializer/treaties_show_page_serializer.rb
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
9 changes: 9 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ en:
show:
si_title: "%{group} - procedural activity for statutory instruments"
pnsi_title: "%{group} - procedural activity for proposed negative statutory instruments"
treaty_title: "%{group} - procedural activity for treaties"
statutory_instruments:
type: "Statutory instrument"
index:
Expand Down Expand Up @@ -106,6 +107,7 @@ en:
show:
si_title: "Procedural activity for statutory instruments"
psni_title: "Procedural activity for proposed negative statutory instruments"
treaty_title: "Procedural activity for treaties"
current:
si_title: "Current procedural activity for statutory instruments"
psni_title: "Current procedural activity for proposed negative statutory instruments"
Expand All @@ -119,3 +121,10 @@ en:
laid_papers:
index:
title: "Laid papers"
treaties:
type: "Treaties"
index:
title: "Treaties"
work_packages:
index:
title: "%{treaty} - procedural activity"
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@
{"content"=>"<a href=\"/groups/XouN12Ow/made-available/availability-types/laid-papers/paper-types/statutory-instruments\">Statutory instruments</a>",
"size"=>2},
"name"=>"heading"}},
"name"=>"card__generic"},
{"data"=>
{"heading"=>
{"data"=>
{"content"=>"<a href=\"/groups/XouN12Ow/made-available/availability-types/laid-papers/paper-types/treaties\">Treaties</a>",
"size"=>2},
"name"=>"heading"}},
"name"=>"card__generic"}]

expect(PageSerializer::ListPageSerializer).to have_received(:new).with(request: request, heading_component: heading, list_components: list_components, data_alternates: data_alternates)
Expand Down Expand Up @@ -161,5 +168,24 @@
expect(assigns(:api_request).query_url).to eq("#{ENV['PARLIAMENT_BASE_URL']}/group_laid_papers_paper_type_proposed_negative_statutory_instruments?group_id=XouN12Ow")
end
end

context 'treaties' do
before(:each) do
allow(PageSerializer::ListPageSerializer).to receive(:new)
allow(ComponentSerializer::Heading1ComponentSerializer).to receive(:new) { heading }

allow(controller.request).to receive(:env).and_return({'ApplicationInsights.request.id' => '|1234abcd.'})

get :show, params: { group_id: 'XouN12Ow', paper_type: 'treaties' }
end

it 'calls the Heading1ComponentSerializer correctly' do
expect(ComponentSerializer::Heading1ComponentSerializer).to have_received(:new).with(heading: 'groupName - 1 - procedural activity for treaties', subheading: 'groupName - 1', subheading_link: '/groups/XouN12Ow')
end

it 'makes a request to the correct data endpoint for treaties' do
expect(assigns(:api_request).query_url).to eq("#{ENV['PARLIAMENT_BASE_URL']}/group_laid_papers_paper_type_treaties?group_id=XouN12Ow")
end
end
end
end
Loading

0 comments on commit ca1dd42

Please sign in to comment.