Skip to content

Commit

Permalink
0.1.0 Initial public beta release (#339)
Browse files Browse the repository at this point in the history
* fixed indentation on definition tags

* fixed broken fix

* fixed undo mistake

* fixed space issue

* ammended house views to use component partial, removed redundant partials

* [WEBSITE-774] Member text fixes

* [WEBSITE-753] Fixed incorrect links

* [WEBSITE-773] Content removed from MP and Lord pages

* [WEBSITE-606] Page titles

* feature(page-titles): assign each view a page title

* fix(page-titles): revert Gemfile

* fix(page-titles): revert gemfile

* feature(page-titles): remove duplication

* fix(page-titles): use display_name on page titles

* fix(page-titles): fix failing test for parties

* feature(page-titles): match page titles with H1s

* feature(page-titles): match page titles with H1s

* [WEBSITE-760] Added check for current party member count in houses party view (#311)

* [WEBSITE-797] Completed refactor of checking house ids (#313)

* Refactored helper module to include four methods.
* Refactored views to use helper to check for commons or lords and to retrieve ids.
* Refactored tests where necessary.

* fix(page-titles): add missing equal sign

* [WEBSITE-811] Remove additional list elements from house views (#315)

* [WEBSITE-811] Remove additional list elements from house views

* [WEBSITE-811] Updated vcr cassettes

* [WEBSITE-794] Error checking in constituencies current_member view; error handling in houses party method (#318)

* Error handling in houses_controller, method :party to handle no party id.
* Error handling in view constituencies/current_member - added check for @seat_incumbency being nil.

* [WEBSITE-800 Content change to Current MPs page (#317)

* [WEBSITE-800 Content change to Current MPs page

* [WEBSITE-804] Content change to House/party pages

* [WEBSITE-802] Content changes to Commons parties page

* [WEBSITE-813] Removed asset version variable from secrets.yml (#316)

* [WEBSITE-832] Fix to current constituencies partial to check if current member exists (#319)

* [WEBSITE-813] Update pugin version (#320)

* [WEBSITE-833] Content changes to beta homepage

* [WEBSITE-817][WEBSITE-818][WEBSITE-819][WEBSITE-833]

* [WEBSITE-817][WEBSITE-818][WEBSITE-819][WEBSITE-833] Changes to front-page and parties (#321)

* [WEBSITE-833] Content changes to beta homepage

* [WEBSITE-817][WEBSITE-818][WEBSITE-819][WEBSITE-833]

* [WEBSITE-795] custom error handling component

* [WEBSITE-795] custom error handling component

* [WEBSITE-816][WEBSITE-815][WEBSITE-828][WEBSITE-829]

* [WEBSITE-816][WEBSITE-815][WEBSITE-828][WEBSITE-829] (#324)

* [WEBSITE-833] Content changes to beta homepage

* [WEBSITE-817][WEBSITE-818][WEBSITE-819][WEBSITE-833]

* [WEBSITE-816][WEBSITE-815][WEBSITE-828][WEBSITE-829]

* [WEBSITE-799] Page content changes

* [WEBSITE-793] Documentation (#323)

* Added yard documentation to all helper modules and their methods.
* Tidied up and enhanced tests where necessary.
* Altered text on current constituencies view for the case where there is no current member.

* [WEBSITE-827][WEBSITE-831][WEBSITE-825][WEBSITE-826][WEBSITE-804]

* fixed cassette

* [WEBSITE-827][WEBSITE-831][WEBSITE-825][WEBSITE-826][WEBSITE-804] (#326)

* [WEBSITE-833] Content changes to beta homepage

* [WEBSITE-817][WEBSITE-818][WEBSITE-819][WEBSITE-833]

* [WEBSITE-816][WEBSITE-815][WEBSITE-828][WEBSITE-829]

* [WEBSITE-827][WEBSITE-831][WEBSITE-825][WEBSITE-826][WEBSITE-804]

* fixed cassette

* fixed constituency translation

* added vcr cassette

* fixed constituency translation (#327)

* [WEBSITE-833] Content changes to beta homepage

* [WEBSITE-817][WEBSITE-818][WEBSITE-819][WEBSITE-833]

* [WEBSITE-816][WEBSITE-815][WEBSITE-828][WEBSITE-829]

* [WEBSITE-827][WEBSITE-831][WEBSITE-825][WEBSITE-826][WEBSITE-804]

* fixed cassette

* fixed constituency translation

* added vcr cassette

* Update dependencies in preparation for release

* [WEBSITE-795] fix to displaying person error (#330)

* [WEBSITE-787] fix for cassettes

* [WEBSITE-795][WEBSITE-787][WEBSITE-622]

* fixed pluralisation on parties

* Made a few small fixes (#335)

* Added @seat_incumbency variable to constituencies/members so that current MPs show in view.
* Added correct i18n translation to constituencies_current view.

* [WEBSITE-764] Custom error handling on a-z listing pages (#338)

* Addition of RequestHelper
* Addition of code in RequestHelper to handle specific 204 error
* Controller updates
* Test updates

* Update partiament-ruby for SSL support (#340)
  • Loading branch information
mattrayner authored Mar 24, 2017
1 parent 2c572e9 commit 2bfadaf
Show file tree
Hide file tree
Showing 213 changed files with 25,544 additions and 4,575 deletions.
5 changes: 5 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PARLIAMENT_BASE_URL=http://localhost:3030
DATA_URI_PREFIX=http://id.ukpds.org
GTM_KEY=GTM-NNXTVV8
ASSET_LOCATION_URL=https://s3-eu-west-1.amazonaws.com/web1devci.pugin-website
ASSET_VERSION=1.2.6
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ passenger.3000.pid
.env.sample.*

/spec/examples.txt

.yardoc
/doc/
7 changes: 4 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ gem 'json-ld', '2.1.0'
gem 'vcard', '0.2.15'

# Parliament Ruby is a wrapper for the internal Parliament data API

gem 'parliament-ruby', '0.5.19'
gem 'parliament-ruby', '0.6.1'

# Pugin is the front-end component library used by Parliament
gem 'pugin', git: 'https://github.com/ukparliament/parliament.uk-pugin-components-rails', branch: 'master'
gem 'pugin', '0.5.0'

# HAML is used for front-end template rendering
gem 'haml', '4.0.7'
Expand All @@ -38,6 +37,8 @@ group :development do
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'web-console'

gem 'pry'
end

group :test do
Expand Down
33 changes: 17 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
GIT
remote: https://github.com/ukparliament/parliament.uk-pugin-components-rails
revision: 0ca441e14a6d81a9d9940d5342d7ebe4c2fbd393
branch: master
specs:
pugin (0.2.0)
haml (~> 4.0)
rails (~> 5.0.1)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -53,13 +44,14 @@ GEM
ast (2.3.0)
builder (3.2.3)
byebug (9.0.6)
capybara (2.12.1)
capybara (2.13.0)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
coderay (1.1.1)
concurrent-ruby (1.0.5)
crack (0.4.3)
safe_yaml (~> 1.0.0)
Expand Down Expand Up @@ -101,17 +93,24 @@ GEM
minitest (5.10.1)
multi_json (1.12.1)
nio4r (1.2.1)
nokogiri (1.7.0.1)
nokogiri (1.7.1)
mini_portile2 (~> 2.1.0)
parliament-ruby (0.5.19)
parliament-ruby (0.6.1)
grom (~> 0.3.5)
parser (2.4.0.0)
ast (~> 2.2)
passenger (5.1.2)
rack
rake (>= 0.8.1)
powerpack (0.1.1)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
public_suffix (2.0.5)
pugin (0.5.0)
haml (~> 4.0)
rails (~> 5.0)
rack (2.0.1)
rack-test (0.6.3)
rack (>= 1.0)
Expand Down Expand Up @@ -174,11 +173,12 @@ GEM
safe_yaml (1.0.4)
shoulda-matchers (3.1.1)
activesupport (>= 4.0.0)
simplecov (0.13.0)
simplecov (0.14.1)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slop (3.6.0)
spring (2.0.1)
activesupport (>= 4.2)
sprockets (3.7.1)
Expand All @@ -191,7 +191,7 @@ GEM
subcontractor (0.8.0)
thor (0.19.4)
thread_safe (0.3.6)
tilt (2.0.6)
tilt (2.0.7)
turbolinks (5.0.1)
turbolinks-source (~> 5)
turbolinks-source (5.0.0)
Expand Down Expand Up @@ -225,9 +225,10 @@ DEPENDENCIES
foreman
haml (= 4.0.7)
json-ld (= 2.1.0)
parliament-ruby (= 0.5.19)
parliament-ruby (= 0.6.1)
passenger
pugin!
pry
pugin (= 0.5.0)
rails (= 5.0.1)
rails-controller-testing
rspec-rails
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Parliament.uk prototype
Parliament.uk prototype is a [Rails 5][rails] application designed to be the beginnings of a new [parliament.uk][parliament] website and api.
Parliament.uk prototype is a [Rails 5][rails] application designed to be the beginnings of a new [parliament.uk][parliament] website and API.

[![License][shield-license]][info-license]

Expand Down Expand Up @@ -36,28 +36,28 @@ cp .env.sample .env
```

### Running the application
There are two options for running the parliament.uk prototype, either with a local version of the member api at the same time, or as a standalone rails application.
There are two options for running the parliament.uk prototype, either with a local version of the member API at the same time, or as a standalone rails application.

#### Member Service API?
Along with this prototype there is a paired [member-service-api][member-service-api] project. This api's role is to consume data from a triple store and generate .ttl files which our parliament.uk prototype can consume.
Along with this prototype there is a paired [member-service-api][member-service-api] project. This API's role is to consume data from a triple store and generate .ttl files which our parliament.uk prototype can consume.

#### Running with Foreman and a Local Version of the API
> **NOTE:** In order to use [foreman][foreman] to run the api and application together, we are assuming you have the [member-service-api][member-service-api] project cloned and set-up in the same location as the parliament.uk-prototype project. For example, your folders should look something like the following:
> **NOTE:** In order to use [foreman][foreman] to run the API and application together, we are assuming you have the [member-service-api][member-service-api] project cloned and set-up in the same location as the parliament.uk-prototype project. For example, your folders should look something like the following:
> ```
> / (projects root)
> /parliament.uk-prototype/ (prototype)
> /member-service-api/ (api)
> ```
> With this setup, foreman runs the api directly from within the member-service-api directory.
> With this setup, foreman runs the API directly from within the member-service-api directory.
```bash
bundle exec foreman start
```

The application and api should now be viewable in your local browser at http://localhost:3000 (application) and http://localhost:3030 (api). With this setup, you can make changes to the local api repository and test them right away.
The application and API should now be viewable in your local browser at http://localhost:3000 (application) and http://localhost:3030 (API). With this setup, you can make changes to the local API repository and test them right away.

##### Foreman?
[Foreman][foreman] allows us to run multiple applications concurrently, making local development of the Parliament.uk prototype much faster. Using foreman you can make changes to both the member-api and prototype in tandem without the need for deployment delays.
[Foreman][foreman] allows us to run multiple applications concurrently, making local development of the Parliament.uk prototype much faster. Using foreman you can make changes to both the member-service-api and prototype in tandem without the need for deployment delays.


#### Running the application standalone, without an API
Expand Down
10 changes: 7 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
require 'vcard/vcard'
require 'parliament'
require 'houses_id_helper'
require 'houses_helper'
require 'request_helper'

# Base class for all other controllers
class ApplicationController < ActionController::Base
include VCardHelper
include Parliament
include HouseIdHelper
include HousesHelper
include RequestHelper

# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

layout 'pugin/layouts/pugin'

rescue_from Parliament::NoContentError do |error|
# Rescues from a Parliament::NoContentResponseError and raises an ActionController::RoutingError
rescue_from Parliament::NoContentResponseError do |error|
raise ActionController::RoutingError, error.message
end
end
48 changes: 48 additions & 0 deletions app/controllers/concerns/houses_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Namespace for helpers of the HousesController.
module HousesHelper
# Checks if house is the House of Commons and sets @commons_id and @lords_id if not already set.
#
# @param [Grom::Node] house a Grom::Node with type http://id.ukpds.org/schema/House.
# @return [Boolean] boolean depending on whether the house has the same id as the House of Commons.
def self.commons?(house)
set_ids

house.graph_id == @commons_id
end

# Checks if house is the House of Lords and sets @commons_id and @lords_id if not already set.
#
# @param [Grom::Node] house a Grom::Node with type http://id.ukpds.org/schema/House.
# @return [Boolean] boolean depending on whether the house has the same id as the House of Lords.
def self.lords?(house)
!commons?(house)
end

# Sets and returns the id for the House of Commons.
#
# @return [String] @commons_id the id for the House of Commons.
def self.commons_id
set_ids

@commons_id
end

# Sets and returns the id for the House of Lords.
#
# @return [String] @lords_id the id for the House of Lords.
def self.lords_id
set_ids

@lords_id
end

private_class_method

def self.set_ids
return if @commons_id && @lords_id
houses = Parliament::Request.new.houses.get.filter('http://id.ukpds.org/schema/House').sort_by(:name)

@commons_id = houses.first.graph_id
@lords_id = houses.last.graph_id
end
end
14 changes: 0 additions & 14 deletions app/controllers/concerns/houses_id_helper.rb

This file was deleted.

24 changes: 24 additions & 0 deletions app/controllers/concerns/request_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Namespace for Parliament::Request helper methods.
module RequestHelper
# Handle Parliament::NoContentResponseError errors within a given request.
#
# @param [Parliament::Request] request a built Parliament::Request object that can just be called with #get
# @param [Block] block a block to be executed if a Parliament error is raised.
#
# @return [Hash] a return object in the format:
# { success: true, response: #<Parliament::Response> } for a successful request or
# { success: false, response: nil } for a response that threw an error.
def self.handler(request, &block)
return_object = { success: false, response: nil }

begin
response = request.get
return_object = { success: true, response: response }
rescue Parliament::NoContentResponseError => e
Rails.logger.warn "Received 204 status from #{e}"
block&.call
end

return_object
end
end
20 changes: 20 additions & 0 deletions app/controllers/concerns/v_card_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Namespace for helper methods to generate a vcard.
module VCardHelper
# Generates a vcard for the given contact point.
#
# @param [Grom::Node] contact_point a Grom::Node with type: http://id.ukpds.org/schema/ContactPoint.
# @return [Vcard::Vcard] a vcard with person, postal address and contact details set.
def create_vcard(contact_point)
Vcard::Vcard::Maker.make2 do |maker|
maker.add_name do |name|
Expand All @@ -9,12 +14,22 @@ def create_vcard(contact_point)
end
end

# Sets the contact details of a vcard.
#
# @param [Grom::Node] contact_point a Grom::Node with type: http://id.ukpds.org/schema/ContactPoint.
# @param [Vcard::Vcard::Maker] maker a Vcard builder.
# @return [Vcard::Vcard::Maker] a Vcard maker with contact details set.
def contacts_set(contact_point, maker)
maker.add_email(contact_point.email) unless contact_point.email == ''
maker.add_tel(contact_point.phone_number) unless contact_point.phone_number == ''
maker.add_tel(contact_point.fax_number) { |f| f.location = 'fax' } unless contact_point.fax_number == ''
end

# Sets the postal address of a vcard.
#
# @param [Grom::Node] contact_point a Grom::Node with type: http://id.ukpds.org/schema/ContactPoint.
# @param [Vcard::Vcard::Maker] maker a Vcard builder.
# @return [Vcard::Vcard::Maker, Boolean] a Vcard maker with postal address set or false if the contact point has no postal addresses.
def postal_address_set(contact_point, maker)
return false if contact_point.postal_addresses.empty?
address = contact_point.postal_addresses.first.full_address
Expand All @@ -23,6 +38,11 @@ def postal_address_set(contact_point, maker)
end
end

# Sets the person details of a vcard.
#
# @param [Grom::Node] contact_point a Grom::Node with type: http://id.ukpds.org/schema/ContactPoint.
# @param [Object] name a Vcard::Name.
# @return [Vcard::Vcard::Maker, Boolean] a Vcard maker with person details set or false if the contact point is not associated with a person.
def person_set(contact_point, name)
return false if contact_point.incumbency.nil? || contact_point.incumbency.member.nil?
name.given = contact_point.incumbency.member.given_name
Expand Down
17 changes: 11 additions & 6 deletions app/controllers/constituencies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def members
)
@constituency = @constituency.first
@seat_incumbencies = @seat_incumbencies.reverse_sort_by(:start_date)
@current_incumbency = @seat_incumbencies.shift if !@seat_incumbencies.empty? && @seat_incumbencies.first.current?
end

def current_member
Expand All @@ -86,20 +87,24 @@ def letters
letter = params[:letter]

letter_data = Parliament::Request.new.constituencies.a_z_letters.get

@constituencies = Parliament::Request.new.constituencies(letter).get.sort_by(:name)
@letters = letter_data.map(&:value)

request = Parliament::Request.new.constituencies(letter)
response = RequestHelper.handler(request) { @constituencies = [] }

@constituencies = response[:response].sort_by(:name) if response[:success]
end

def current_letters
letter = params[:letter]

letter_data = Parliament::Request.new.constituencies.current.a_z_letters.get
data = Parliament::Request.new.constituencies.current(letter).get

@constituencies = data.filter('http://id.ukpds.org/schema/ConstituencyGroup')
@constituencies = @constituencies.sort_by(:name)
@letters = letter_data.map(&:value)

request = Parliament::Request.new.constituencies.current(letter)
response = RequestHelper.handler(request) { @constituencies = [] }

@constituencies = response[:response].filter('http://id.ukpds.org/schema/ConstituencyGroup').sort_by(:name) if response[:success]
end

def a_to_z
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
class HomeController < ApplicationController
def index
houses_id
end
def index; end
end
Loading

0 comments on commit 2bfadaf

Please sign in to comment.