Skip to content

Commit

Permalink
Merge pull request #61 from Christine-horrocks/katylouise/WEBDEV-682_…
Browse files Browse the repository at this point in the history
…proposed-neg-statutory-instruments

[WEBDEV-682] Proposed Negative SIs
  • Loading branch information
katylouise authored Sep 19, 2018
2 parents 3114a2d + c7f1e3f commit 04f72b4
Show file tree
Hide file tree
Showing 36 changed files with 2,490 additions and 326 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,4 @@ RUBY VERSION
ruby 2.5.1p57

BUNDLED WITH
1.16.1
1.16.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class ProposedNegativeStatutoryInstrumentsController < ApplicationController
# Controller rendering proposed negative statutory instruments index and show pages
before_action :build_request

ROUTE_MAP = {
index: proc { ParliamentHelper.parliament_request.proposed_negative_statutory_instrument_index },
show: proc { |params| ParliamentHelper.parliament_request.proposed_negative_statutory_instrument_by_id.set_url_params({ proposed_negative_statutory_instrument_id: params[:proposed_negative_statutory_instrument_id] }) }
}.freeze

def index
@proposed_negative_statutory_instruments = FilterHelper.filter(@request, 'ProposedNegativeStatutoryInstrumentPaper')
serializer = PageSerializer::ProposedNegativeStatutoryInstrumentsIndexPageSerializer.new(proposed_negative_statutory_instruments: @proposed_negative_statutory_instruments, request_id: app_insights_request_id, data_alternates: @alternates, request_original_url: request.original_url)

render_page(serializer)
end

def show
@proposed_negative_statutory_instrument = FilterHelper.filter(@request, 'ProposedNegativeStatutoryInstrumentPaper')
@proposed_negative_statutory_instrument = @proposed_negative_statutory_instrument.first

serializer = PageSerializer::ProposedNegativeStatutoryInstrumentsShowPageSerializer.new(proposed_negative_statutory_instrument: @proposed_negative_statutory_instrument, request_id: app_insights_request_id, data_alternates: @alternates, request_original_url: request.original_url)

render_page(serializer)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ParagraphComponentSerializer < ComponentSerializer::BaseComponentSerialize
# @example Initialising a paragraph component
# string_or_translation_key = 'Here is some paragraph text'
# link = 'beta.parliament.uk'
# ComponentSerializer::ParagraphComponentSerializer.new([{ content: string_or_translation_key, link: link }]).to_h
# ComponentSerializer::ParagraphComponentSerializer.new(content: [{ content: string_or_translation_key, link: link }]).to_h
def initialize(content: nil)
@content = content
end
Expand Down
51 changes: 51 additions & 0 deletions app/serializers/page_serializer/laid_thing_show_page_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module PageSerializer
class LaidThingShowPageSerializer < PageSerializer::BasePageSerializer
# Initialise a Laid Thing show page serializer.
#
# @param [<Grom::Node>] laid_thing a Grom::Node object of type LaidThing.
# @param [String] request_id AppInsights request id
# @param [Array<Hash>] data_alternates array containing the href and type of the alternative data urls
# @param [String] request_original_url original url of the request
def initialize(laid_thing:, request_id: nil, data_alternates: nil, request_original_url: nil)
@laid_thing = laid_thing
@work_package = @laid_thing.work_package
@laying_body = @laid_thing&.laying&.body
@laying_person = @laid_thing&.laying&.person
@procedure = @work_package&.procedure

super(request_id: request_id, data_alternates: data_alternates, request_original_url: request_original_url)
end

private

def content; end

def parent_child_objects
[].tap do |components|
components << object_heading_paragraph(3, 'laid-thing.work-package', "<a href='/work-packages/#{@work_package&.graph_id}'>#{@work_package&.graph_id}</a>")
components << object_heading_paragraph(4, 'laid-thing.procedure', "<a href='/procedures/#{@procedure&.graph_id}'>#{@procedure&.name}</a>")
components << object_heading_paragraph(3, 'laid-thing.laying', @laid_thing&.laying&.graph_id)
components << object_heading_paragraph(4, 'laid-thing.laid-date', l(@laid_thing&.laying&.date))
components << object_heading_paragraph(4, 'laid-thing.laying-body', @laying_body&.name)
components << object_heading_paragraph(4, 'laid-thing.laying-person', @laying_person&.display_name)
components << object_heading_paragraph(3, 'laid-thing.web-link', "<a href='#{@laid_thing.web_link}'>#{@laid_thing.web_link}</a>")
end.flatten
end

def object_heading_paragraph(heading_size, heading_content, paragraph_content)
[].tap do |components|
components << ComponentSerializer::HeadingComponentSerializer.new(content: heading_content, size: heading_size).to_h
components << ComponentSerializer::ParagraphComponentSerializer.new(content: [{ content: paragraph_content }]).to_h
end
end

def section_objects
[].tap do |components|
components << ComponentSerializer::HeadingComponentSerializer.new(content: 'laid-thing.objects', size: 2).to_h
components << parent_child_objects
components << ComponentSerializer::HeadingComponentSerializer.new(content: connected_statutory_instruments_title, size: 3).to_h
components << ComponentSerializer::ListComponentSerializer.new(display: 'generic', display_data: [display_data(component: 'list')], components: connected_statutory_instruments).to_h
end.flatten
end
end
end
43 changes: 43 additions & 0 deletions app/serializers/page_serializer/list_page_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module PageSerializer
class ListPageSerializer < PageSerializer::BasePageSerializer
# Initialise a list page serializer.
#
# @param [String] page_title title of the page
# @param [String] request_id AppInsights request id
# @param [Array<Hash>] data_alternates array containing the href and type of the alternative data urls
# @param [String] request_original_url original url of the request
def initialize(page_title: nil, request_id: nil, data_alternates: nil, request_original_url: nil)
@page_title = page_title
@data_alternates = data_alternates

super(request_id: request_id, data_alternates: data_alternates, request_original_url: request_original_url)
end

private

attr_reader :page_title

def meta
super(title: page_title)
end

def content
[].tap do |content|
content << ComponentSerializer::SectionComponentSerializer.new(components: section_primary_components, type: 'primary').to_h
content << ComponentSerializer::SectionComponentSerializer.new(components: section_components, type: 'section').to_h
end
end

def section_primary_components
[ComponentSerializer::Heading1ComponentSerializer.new({ heading_content: page_title }).to_h]
end

def section_components
[ComponentSerializer::ListComponentSerializer.new(display: 'generic', display_data: [display_data(component: 'list', variant: 'block')], components: list_components).to_h]
end

def list_components
raise StandardError, 'You must implement #list_components'
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module PageSerializer
class ProposedNegativeStatutoryInstrumentsIndexPageSerializer < ListPageSerializer
# Initialise a Proposed Negative Statutory Instruments index page serializer.
#
# @param [Array<Grom::Node>] proposed_negative_statutory_instruments an array of Grom::Node objects of type ProposedNegativeStatutoryInstrumentPaper.
# @param [String] request_id AppInsights request id
# @param [Array<Hash>] data_alternates array containing the href and type of the alternative data urls
# @param [String] request_original_url original url of the request
def initialize(proposed_negative_statutory_instruments:, request_id: nil, data_alternates: nil, request_original_url: nil)
@proposed_negative_statutory_instruments = proposed_negative_statutory_instruments
@data_alternates = data_alternates
@title = 'proposed-negative-statutory-instruments.index.title'

super(page_title: @title, request_id: request_id, data_alternates: data_alternates, request_original_url: request_original_url)
end

private

def list_components
@proposed_negative_statutory_instruments.map do |statutory_instrument|
ComponentSerializer::LinkComponentSerializer.new(link: "proposed-negative-statutory-instruments/#{statutory_instrument.graph_id}", content: statutory_instrument.name).to_h
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module PageSerializer
class ProposedNegativeStatutoryInstrumentsShowPageSerializer < LaidThingShowPageSerializer
# Initialise a Proposed Negative Statutory Instruments show page serializer.
#
# @param [<Grom::Node>] proposed_negative_statutory_instrument a Grom::Node object of type ProposedNegativeStatutoryInstrumentPaper.
# @param [String] request_id AppInsights request id
# @param [Array<Hash>] data_alternates array containing the href and type of the alternative data urls
# @param [String] request_original_url original url of the request
def initialize(proposed_negative_statutory_instrument:, request_id: nil, data_alternates: nil, request_original_url: nil)
@proposed_negative_statutory_instrument = proposed_negative_statutory_instrument
@following_statutory_instruments = @proposed_negative_statutory_instrument.statutory_instrument_papers

super(laid_thing: @proposed_negative_statutory_instrument, request_id: request_id, data_alternates: data_alternates, request_original_url: request_original_url)
end

private

def meta
super(title: title)
end

def title
@proposed_negative_statutory_instrument.name
end

def content
[].tap do |components|
components << ComponentSerializer::SectionComponentSerializer.new(components: section_primary_components, type: 'primary').to_h
components << ComponentSerializer::SectionComponentSerializer.new(components: section_objects, type: 'section').to_h
end
end

def section_primary_components
[ComponentSerializer::Heading1ComponentSerializer.new({ subheading_content: 'proposed-negative-statutory-instruments.show.subheading', heading_content: title }).to_h]
end

def connected_statutory_instruments
@following_statutory_instruments.map do |stat_instrument|
ComponentSerializer::LinkComponentSerializer.new(
link: "/statutory-instruments/#{stat_instrument.graph_id}",
content: stat_instrument.name
).to_h
end
end

def connected_statutory_instruments_title
'proposed-negative-statutory-instruments.show.preceding-title'
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module PageSerializer
class StatutoryInstrumentsIndexPageSerializer < PageSerializer::BasePageSerializer
class StatutoryInstrumentsIndexPageSerializer < ListPageSerializer
# Initialise a Statutory Instruments index page serializer.
#
# @param [Array<Grom::Node>] statutory_instruments an array of Grom::Node objects of type StatutoryInstrumentPaper.
Expand All @@ -9,38 +9,16 @@ class StatutoryInstrumentsIndexPageSerializer < PageSerializer::BasePageSerializ
def initialize(statutory_instruments:, request_id: nil, data_alternates: nil, request_original_url: nil)
@statutory_instruments = statutory_instruments
@data_alternates = data_alternates
@title = 'statutory-instruments.index.title'

super(request_id: request_id, data_alternates: data_alternates, request_original_url: request_original_url)
super(page_title: @title, request_id: request_id, data_alternates: data_alternates, request_original_url: request_original_url)
end

private

def meta
super(title: title)
end

def title
'statutory-instruments.index.title'
end

def content
[].tap do |content|
content << ComponentSerializer::SectionComponentSerializer.new(components: section_primary_components, type: 'primary').to_h
content << ComponentSerializer::SectionComponentSerializer.new(components: section_components, type: 'section').to_h
end
end

def section_primary_components
[ComponentSerializer::Heading1ComponentSerializer.new({ heading_content: title }).to_h]
end

def section_components
[ComponentSerializer::ListComponentSerializer.new(display: 'generic', display_data: [display_data(component: 'list', variant: 'block')], components: statutory_instruments).to_h]
end

def statutory_instruments
def list_components
@statutory_instruments.map do |statutory_instrument|
ComponentSerializer::LinkComponentSerializer.new(link: statutory_instruments_path(statutory_instrument.graph_id), content: statutory_instrument.name).to_h
ComponentSerializer::LinkComponentSerializer.new(link: "statutory-instruments/#{statutory_instrument.graph_id}", content: statutory_instrument.name).to_h
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
module PageSerializer
class StatutoryInstrumentsShowPageSerializer < PageSerializer::BasePageSerializer
# Initialise a Statutory Instruments index page serializer.
class StatutoryInstrumentsShowPageSerializer < LaidThingShowPageSerializer
# Initialise a Statutory Instruments show page serializer.
#
# @param [<Grom::Node>] statutory_instrument a Grom::Node object of type StatutoryInstrumentPaper.
# @param [String] request_id AppInsights request id
# @param [Array<Hash>] data_alternates array containing the href and type of the alternative data urls
# @param [String] request_original_url original url of the request
def initialize(statutory_instrument:, request_id: nil, data_alternates: nil, request_original_url: nil)
@statutory_instrument = statutory_instrument
@work_package = @statutory_instrument.work_package
@preceding_proposed_negative_statutory_instruments = @statutory_instrument.proposed_negative_statutory_instrument_papers
@laying_body = @statutory_instrument&.laying&.body
@laying_person = @statutory_instrument&.laying&.person
@procedure = @work_package&.procedure

super(request_id: request_id, data_alternates: data_alternates, request_original_url: request_original_url)
super(laid_thing: @statutory_instrument, request_id: request_id, data_alternates: data_alternates, request_original_url: request_original_url)
end

private
Expand Down Expand Up @@ -54,41 +50,17 @@ def literals
end.compact
end

def section_objects
[].tap do |components|
components << ComponentSerializer::HeadingComponentSerializer.new(content: 'statutory-instruments.show.objects', size: 2).to_h
components << parent_child_objects
components << ComponentSerializer::HeadingComponentSerializer.new(content: 'statutory-instruments.show.following-title', size: 3).to_h
components << ComponentSerializer::ListComponentSerializer.new(display: 'generic', display_data: [display_data(component: 'list')], components: proposed_negative_statutory_instruments).to_h
end.flatten
end

def parent_child_objects
[].tap do |components|
components << object_heading_paragraph(3, 'statutory-instruments.show.work-package', "<a href='/work-packages/#{@work_package&.graph_id}'>#{@work_package&.graph_id}</a>")
components << object_heading_paragraph(4, 'statutory-instruments.show.procedure', "<a href='/procedures/#{@procedure&.graph_id}'>#{@procedure&.name}</a>")
components << object_heading_paragraph(3, 'statutory-instruments.show.laying', @statutory_instrument&.laying&.graph_id)
components << object_heading_paragraph(4, 'statutory-instruments.show.laid-date', l(@statutory_instrument&.laying&.date))
components << object_heading_paragraph(4, 'statutory-instruments.show.laying-body', @laying_body&.name)
components << object_heading_paragraph(4, 'statutory-instruments.show.laying-person', @laying_person&.display_name)
components << object_heading_paragraph(3, 'statutory-instruments.show.web-link', "<a href='#{@statutory_instrument.web_link}'>#{@statutory_instrument.web_link}</a>")
end.flatten
end

def object_heading_paragraph(heading_size, heading_content, paragraph_content)
[].tap do |components|
components << ComponentSerializer::HeadingComponentSerializer.new(content: heading_content, size: heading_size).to_h
components << ComponentSerializer::ParagraphComponentSerializer.new(content: [{ content: paragraph_content }]).to_h
end
end

def proposed_negative_statutory_instruments
def connected_statutory_instruments
@preceding_proposed_negative_statutory_instruments.map do |stat_instrument|
ComponentSerializer::LinkComponentSerializer.new(
link: "/proposed-negative-statutory-instruments/#{stat_instrument.graph_id}",
content: stat_instrument.name
).to_h
end
end

def connected_statutory_instruments_title
'statutory-instruments.show.following-title'
end
end
end
Loading

0 comments on commit 04f72b4

Please sign in to comment.