Skip to content

Commit

Permalink
Merge pull request #92 from cazwazacz/cazwazacz/877-878-879_update-gr…
Browse files Browse the repository at this point in the history
…oup-layings

[WEBDEV-877][WEBDEV-878][WEBDEV-879] Update Group Layings page
  • Loading branch information
Christine-horrocks authored Oct 24, 2018
2 parents 641082e + 1029549 commit 5848f4f
Show file tree
Hide file tree
Showing 7 changed files with 505 additions and 579 deletions.
14 changes: 8 additions & 6 deletions app/controllers/groups/layings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@ class LayingsController < ApplicationController

def index
@group, @layings = FilterHelper.filter(@api_request, 'Group', 'Laying')
@layings = @layings.sort_by(:date, :graph_id).reverse
@group = @group.first

list_components = @layings.map do |laying|
laying_type = I18n.t('layings.type.si')
heading_text = laying.laid_thing.try(:laidThingName)
heading_url = statutory_instrument_path(laying.laid_thing.graph_id)

if laying.laid_thing.is_a?(Parliament::Grom::Decorator::ProposedNegativeStatutoryInstrumentPaper)
laying_type = I18n.t('layings.type.pnsi')
heading_url = proposed_negative_statutory_instrument_path(laying.laid_thing.graph_id)
end

paragraph_content = [].tap do |content|
content << { content: 'groups.layings.date', date: I18n.l(Time.parse(laying.date.to_s)) } if laying.date
content << { content: 'groups.layings.type', type: laying_type } if laying.type
list_description_items = [].tap do |items|
items << { term: { content: 'laid-thing.laid-date' }, description: [{ content: I18n.l(laying&.date) }] }
end

CardFactory.new(
heading_text: laying.laid_thing.try(:laidThingName),
heading_url: heading_url,
paragraph_content: paragraph_content
small: laying_type,
heading_text: heading_text,
heading_url: heading_url,
description_list_content: list_description_items
).build_card
end

Expand Down
8 changes: 7 additions & 1 deletion app/services/card_factory.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class CardFactory
def initialize(heading_text: nil, heading_url: nil, paragraph_content: nil, description_list_content: nil)
def initialize(small: nil, heading_text: nil, heading_url: nil, paragraph_content: nil, description_list_content: nil)
@small = small
@heading_text = heading_text
@heading_url = heading_url
@paragraph_content = paragraph_content
Expand All @@ -14,12 +15,17 @@ def build_card

def card_data
{}.tap do |hash|
hash[:small] = card_small if @small
hash[:heading] = card_heading if @heading_text
hash[:paragraph] = card_paragraph if @paragraph_content
hash[:list_description] = card_description_list if @description_list_content
end
end

def card_small
ComponentSerializer::SmallComponentSerializer.new({ content: @small }).to_h
end

def card_heading
ComponentSerializer::HeadingComponentSerializer.new(content: @heading_text, size: 2, link: @heading_url).to_h
end
Expand Down
109 changes: 92 additions & 17 deletions spec/controllers/groups/layings_controller_spec.rb

Large diffs are not rendered by default.

Loading

0 comments on commit 5848f4f

Please sign in to comment.