Skip to content

Commit

Permalink
Merge pull request #253 from alphagov/contacts
Browse files Browse the repository at this point in the history
Merge contacts frontend into government frontend
  • Loading branch information
NickColley authored Mar 2, 2017
2 parents 5fe1c5b + b646ef2 commit 15e5c5f
Show file tree
Hide file tree
Showing 19 changed files with 1,634 additions and 8 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Not all formats that this app can handle are rendered by it in production.
| Case study | [View on GOV.UK](https://www.gov.uk/government/case-studies/2013-elections-in-swaziland) | Migrated |
| Coming soon | | Rendered by Whitehall |
| Consultation | [View on GOV.UK](https://www.gov.uk/government/consultations/soft-drinks-industry-levy) | Migrated |
| Contacts | [View on GOV.UK](https://www.gov.uk/government/organisations/hm-revenue-customs/contact/alcohol-duties-national-registration-unit) | Currently rendered by Contacts frontend |
| Detailed guide | [View on GOV.UK](https://www.gov.uk/guidance/waste-exemption-nwfd-2-temporary-storage-at-the-place-of-production--2) | Migrated |
| Document collection | [View on GOV.UK](https://www.gov.uk/government/collections/statutory-guidance-schools) | Migrated on live. Draft rendered by Whitehall. |
| Fatality notice | [View on GOV.UK](https://www.gov.uk/government/fatalities/corporal-lee-churcher-dies-in-iraq) | Migrated |
Expand Down Expand Up @@ -69,6 +70,11 @@ Or to specify the location explicitly:

`GOVUK_CONTENT_SCHEMAS_PATH=/some/dir/govuk-content-schemas bundle exec rake`

#### Debugging Integration tests
If you want to see the page that is being tested in our integration tests, you can use
`save_and_open_page` to see what's rendered. This is helpful when a page is mostly comprised of
GOV.UK Publishing Components

### Visual regression tests

Use [Wraith](http://bbc-news.github.io/wraith/) ("A responsive screenshot
Expand Down Expand Up @@ -99,6 +105,8 @@ gallery of the output, located at `test/wraith/shots/gallery.html`.

#### Compare examples on master with examples on branch

Examples are referencing https://github.com/alphagov/govuk-content-schemas

With government-frontend running master on the development VM and while [pointing at the dummy content store](https://github.com/alphagov/govuk-content-schemas/blob/master/docs/running-frontend-against-examples.md), create a set of historical screenshots using:
```
cd test/wraith
Expand Down
151 changes: 151 additions & 0 deletions app/assets/javascripts/legacy-modules/webchat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
(function (global) {
'use strict'
var $ = global.jQuery
var windowLocationPathname = global.location.pathname
var windowOpen = global.open
if (typeof global.GOVUK === 'undefined') { global.GOVUK = {} }
var GOVUK = global.GOVUK

// Each page will have a different entryPointID, which is a queue id.
// Don't enable this plugin on pages that don't exist in this map, and
// uncomment the additional routes as we obtain them.
// Whether the actual template is displayed is in `contact_presenter#show_webchat?`.
var entryPointIDs = {}
entryPointIDs['/government/organisations/hm-revenue-customs/contact/child-benefit'] = 1027
entryPointIDs['/government/organisations/hm-revenue-customs/contact/income-tax-enquiries-for-individuals-pensioners-and-employees'] = 1030
entryPointIDs['/government/organisations/hm-revenue-customs/contact/vat-online-services-helpdesk'] = 1026
entryPointIDs['/government/organisations/hm-revenue-customs/contact/national-insurance-numbers'] = 1021
entryPointIDs['/government/organisations/hm-revenue-customs/contact/self-assessment-online-services-helpdesk'] = 1003
entryPointIDs['/government/organisations/hm-revenue-customs/contact/self-assessment'] = 1004
entryPointIDs['/government/organisations/hm-revenue-customs/contact/tax-credits-enquiries'] = 1016
entryPointIDs['/government/organisations/hm-revenue-customs/contact/vat-enquiries'] = 1028
entryPointIDs['/government/organisations/hm-revenue-customs/contact/customs-international-trade-and-excise-enquiries'] = 1034
entryPointIDs['/government/organisations/hm-revenue-customs/contact/trusts'] = 1036
entryPointIDs['/government/organisations/hm-revenue-customs/contact/employer-enquiries'] = 1023
entryPointIDs['/government/organisations/hm-revenue-customs/contact/construction-industry-scheme'] = 1048

var API_URL = 'https://online.hmrc.gov.uk/webchatprod/egain/chat/entrypoint/checkEligibility/'
var OPEN_CHAT_URL = function (entryPointID) {
return 'https://online.hmrc.gov.uk/webchatprod/templates/chat/hmrc7/chat.html?entryPointId=' + entryPointID + '&templateName=hmrc7&languageCode=en&countryCode=US&ver=v11'
}
var CODE_AGENTS_AVAILABLE = 0
var CODE_AGENTS_UNAVAILABLE = 1
var CODE_AGENTS_BUSY = 2
var POLL_INTERVAL = 15 * 1000
var AJAX_TIMEOUT = 5 * 1000

function Webchat (options) {
var $el = $(options.$el)
var location = options.location || windowLocationPathname

var $advisersUnavailable = $el.find('.js-webchat-advisers-unavailable')
var $advisersBusy = $el.find('.js-webchat-advisers-busy')
var $advisersAvailable = $el.find('.js-webchat-advisers-available')
var $advisersError = $el.find('.js-webchat-advisers-error')
var $openButton = $el.find('.js-webchat-open-button')

var entryPointID = entryPointIDs[location]
var pollingEnabled = true

if (entryPointID) {
pollAvailability()

$openButton.on('click', handleOpenChat)
}

function pollAvailability () {
checkAvailability()

setTimeout(function () {
if (pollingEnabled) {
pollAvailability()
}
}, POLL_INTERVAL)
}

function checkAvailability () {
$.ajax({
url: API_URL + entryPointID,
type: 'GET',
timeout: AJAX_TIMEOUT,
success: handleApiCallSuccess,
error: handleApiCallError
})
}

function handleApiCallSuccess (result) {
var $xml = $(result)
var response = parseInt($xml.find('checkEligibility').attr('responseType'), 10)

switch (response) {
case CODE_AGENTS_UNAVAILABLE:
handleAdvisersUnavailable()
break
case CODE_AGENTS_BUSY:
handleAdvisersBusy()
break
case CODE_AGENTS_AVAILABLE:
handleAdvisersAvailable()
break
default:
handleApiCallError()
break
}
}

function handleApiCallError () {
pollingEnabled = false
handleAdvisersError()
}

function handleOpenChat (evt) {
evt.preventDefault()
var url = OPEN_CHAT_URL(entryPointID)
windowOpen(url, 'newwin', 'width=200,height=100')

GOVUK.analytics.trackEvent('webchat', 'accepted')
}

function handleAdvisersError () {
$advisersError.removeClass('hidden')

$advisersAvailable.addClass('hidden')
$advisersBusy.addClass('hidden')
$advisersUnavailable.addClass('hidden')

GOVUK.analytics.trackEvent('webchat', 'error')
}

function handleAdvisersUnavailable () {
$advisersUnavailable.removeClass('hidden')

$advisersAvailable.addClass('hidden')
$advisersBusy.addClass('hidden')
$advisersError.addClass('hidden')

GOVUK.analytics.trackEvent('webchat', 'unavailable')
}

function handleAdvisersBusy () {
$advisersBusy.removeClass('hidden')

$advisersUnavailable.addClass('hidden')
$advisersAvailable.addClass('hidden')
$advisersError.addClass('hidden')

GOVUK.analytics.trackEvent('webchat', 'busy')
}

function handleAdvisersAvailable () {
$advisersAvailable.removeClass('hidden')

$advisersBusy.addClass('hidden')
$advisersError.addClass('hidden')
$advisersUnavailable.addClass('hidden')

GOVUK.analytics.trackEvent('webchat', 'offered')
}
}

GOVUK.Webchat = Webchat
})(window)
14 changes: 14 additions & 0 deletions app/assets/javascripts/webchat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable */
//= require ./legacy-modules/webchat.js
/*eslint-enable */

var $ = window.$

$(document).ready(function () {
var GOVUK = window.GOVUK
if (GOVUK.Webchat) {
$('.js-webchat').map(function () {
return new GOVUK.Webchat({ $el: $(this) })
})
}
})
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@
@import 'views/news-article';
@import 'views/corporate-information-page';
@import 'views/travel-advice';
@import "views/contact";
5 changes: 5 additions & 0 deletions app/assets/stylesheets/views/_contact.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.contact {
.add-title-margin {
@include responsive-top-margin;
}
}
177 changes: 177 additions & 0 deletions app/presenters/contact_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
class ContactPresenter < ContentItemPresenter
include TitleAndContext

def title_and_context
super.tap do |t|
t.delete(:average_title_length)
t.delete(:context)
end
end

def related_items
sections = []
sections << {
title: "Elsewhere on GOV.UK",
items: quick_links
} if quick_links.any?

sections << {
title: "Other contacts",
items: related_contacts_links
} if related_contacts_links.any?

{
sections: sections
}
end

def online_form_links
content_item["details"]["contact_form_links"].map do |link|
{
url: link['link'],
title: link['title'],
description: link['description'].html_safe
}
end
end

def online_form_body
content_item["details"]["more_info_contact_form"].html_safe
end

def phone
phone_number_groups.map do |group|
details = {
numbers: [
{
label: 'Telephone',
number: group['number']
},
{
label: 'Textphone',
number: group['textphone']
},
{
label: 'Outside UK',
number: group['international_phone']
},
{
label: 'Fax',
number: group['fax']
}
],
title: group['title'],
description: group['description'].strip.html_safe,
opening_times: group['open_hours'].strip.html_safe,
best_time_to_call: group['best_time_to_call'].strip.html_safe
}

details[:numbers].select! { |n| n[:number].present? }
details
end
end

def phone_body
content_item["details"]["more_info_phone_number"].html_safe
end

def post
post_address_groups.map do |group|
details = {
description: group['description'].strip.html_safe,
v_card: [
v_card_part('fn', group['title']),
v_card_part('street-address', group['street_address']),
v_card_part('locality', group['locality']),
v_card_part('postal-code', group['postal_code']),
v_card_part('region', group['region']),
v_card_part('country-name', group['world_location']),
]
}

details[:v_card].select! { |v| v[:value].present? }
details
end
end

def post_body
content_item["details"]["more_info_post_address"].html_safe
end

def email
email_address_groups.map do |group|
details = {
description: group['description'] ? group['description'].strip.html_safe : '',
email: group['email'].strip,
v_card: [v_card_part('fn', group['title'])],
}

details[:v_card].select! { |v| v[:value].present? }
details
end
end

def email_body
content_item["details"]["more_info_email_address"].html_safe
end

def show_webchat?
# These are the routes on which we plan to roll out webchat, in stages.
whitelisted_paths = [
'/government/organisations/hm-revenue-customs/contact/child-benefit',
'/government/organisations/hm-revenue-customs/contact/income-tax-enquiries-for-individuals-pensioners-and-employees',
'/government/organisations/hm-revenue-customs/contact/vat-online-services-helpdesk',
'/government/organisations/hm-revenue-customs/contact/national-insurance-numbers',
'/government/organisations/hm-revenue-customs/contact/self-assessment-online-services-helpdesk',
'/government/organisations/hm-revenue-customs/contact/self-assessment',
'/government/organisations/hm-revenue-customs/contact/tax-credits-enquiries',
'/government/organisations/hm-revenue-customs/contact/vat-enquiries',
'/government/organisations/hm-revenue-customs/contact/customs-international-trade-and-excise-enquiries',
'/government/organisations/hm-revenue-customs/contact/trusts',
'/government/organisations/hm-revenue-customs/contact/employer-enquiries',
'/government/organisations/hm-revenue-customs/contact/construction-industry-scheme',
]
whitelisted_paths.include?(content_item["base_path"])
end

private

def v_card_part(v_card_class, value)
{
v_card_class: v_card_class,
value: value.strip.html_safe
}
end

def email_address_groups
content_item["details"]["email_addresses"] || []
end

def post_address_groups
content_item["details"]["post_addresses"] || []
end

def phone_number_groups
content_item["details"]["phone_numbers"] || []
end

def related_contacts_links
related = content_item["links"]["related"] || []
related.map do |link|
{
title: link["title"],
url: link["base_path"]
}
end
end

def quick_links
quick = content_item["details"]["quick_links"] || []
quick.map do |link|
{
title: link["title"],
url: link["url"]
}
end
end
end
Loading

0 comments on commit 15e5c5f

Please sign in to comment.