Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions app/prototype_v4_1/controllers/authentication.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
const version = 'v4_1'
const view = (template) => {
return `prototype_${version}/views/${template}`
}
const { path: prototypePath, view } = require('../lib/settings')

exports.signIn_get = (req, res) => {
delete req.session.data

res.render(view('authentication/sign-in'), {
actions: {
back: `/prototype_${version}`,
next: `/prototype_${version}/sign-in`
back: prototypePath,
next: `${prototypePath}/sign-in`
}
})
}
Expand All @@ -21,20 +18,20 @@ exports.signIn_post = (req, res) => {
res.render(view('authentication/sign-in'), {
errors,
actions: {
back: `/prototype_${version}`,
next: `/prototype_${version}/sign-in`
back: prototypePath,
next: `${prototypePath}/sign-in`
}
})
} else {
res.redirect(`/prototype_${version}/security-code`)
res.redirect(`${prototypePath}/security-code`)
}
}

exports.securityCode_get = (req, res) => {
res.render(view('authentication/security-code'), {
actions: {
back: `/prototype_${version}/sign-in`,
next: `/prototype_${version}/security-code`
back: `${prototypePath}/sign-in`,
next: `${prototypePath}/security-code`
}
})
}
Expand All @@ -46,21 +43,21 @@ exports.securityCode_post = (req, res) => {
res.render(view('authentication/security-code'), {
errors,
actions: {
back: `/prototype_${version}/sign-in`,
next: `/prototype_${version}/security-code`
back: `${prototypePath}/sign-in`,
next: `${prototypePath}/security-code`
}
})
} else {
res.redirect(`/prototype_${version}/sign-in-agreement`)
res.redirect(`${prototypePath}/sign-in-agreement`)
}
}

exports.signInAgreement_get = (req, res) => {
res.render(view('authentication/sign-in-agreement'), {
actions: {
back: `/prototype_${version}/security-code`,
accept: `/prototype_${version}/sign-in-agreement`,
decline: `/prototype_${version}/sign-in-agreement-declined`
back: `${prototypePath}/security-code`,
accept: `${prototypePath}/sign-in-agreement`,
decline: `${prototypePath}/sign-in-agreement-declined`
}
})
}
Expand All @@ -72,20 +69,20 @@ exports.signInAgreement_post = (req, res) => {
res.render(view('authentication/sign-in-agreement'), {
errors,
actions: {
back: `/prototype_${version}/security-code`,
accept: `/prototype_${version}/sign-in-agreement`,
decline: `/prototype_${version}/sign-in-agreement-declined`
back: `${prototypePath}/security-code`,
accept: `${prototypePath}/sign-in-agreement`,
decline: `${prototypePath}/sign-in-agreement-declined`
}
})
} else {
res.redirect(`/prototype_${version}/accept-terms`)
res.redirect(`${prototypePath}/accept-terms`)
}
}

exports.signInAgreementDeclined_get = (req, res) => {
res.render(view('authentication/sign-in-agreement-declined'), {
actions: {
back: `/prototype_${version}`
back: prototypePath
}
})
}
5 changes: 2 additions & 3 deletions app/prototype_v4_1/controllers/content.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const fs = require('fs')
const path = require('path')
const matter = require('gray-matter')

const version = 'v4_1'
const { view } = require('../lib/settings')

const contentDirectory = path.join(__dirname, '..', 'content')

Expand Down Expand Up @@ -60,7 +59,7 @@ const renderContent = (fileName) => (req, res, next) => {
return next(error)
}

res.render(`prototype_${version}/views/content/show`, {
res.render(view('content/show'), {
content: renderedMarkdown,
contentData
})
Expand Down
8 changes: 4 additions & 4 deletions app/prototype_v4_1/controllers/error.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const version = 'v4_1'
const { view } = require('../lib/settings')

exports.pageNotFound = (req, res) => {
res.status(404).render(`prototype_${version}/views/errors/404`)
res.status(404).render(view('errors/404'))
}

exports.unexpectedError = (req, res) => {
res.status(500).render(`prototype_${version}/views/errors/500`)
res.status(500).render(view('errors/500'))
}

exports.serviceUnavailable = (req, res) => {
res.status(503).render(`prototype_${version}/views/errors/503`)
res.status(503).render(view('errors/503'))
}
2 changes: 1 addition & 1 deletion app/prototype_v4_1/data/questions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ questions:
heading:
title: Terms of use
description: |
To continue, confirm that you have read and agree to the [NHS Check if you need a lung scan terms of use](/prototype_v4_1/terms-of-use).
To continue, confirm that you have read and agree to the [NHS Check if you need a lung scan terms of use](terms-of-use).
input:
label: Confirm you agree to the terms of use
options:
Expand Down
94 changes: 94 additions & 0 deletions app/prototype_v4_1/lib/page-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const defaultAnswers = {
acceptTerms: ['yes'],
phoneQuestionnaire: 'no',
smoker: 'yes_current',
dateOfBirth: {
day: '15',
month: '3',
year: '1964'
},
faceToFaceAppointment: 'no',
height: {
metric: '170'
},
weight: {
metric: '70'
},
gender: 'female',
sex: 'female',
ethnicity: 'white',
education: 'further_education',
respiratoryConditions: ['no'],
asbestosAtWork: 'no',
asbestosAtHome: 'no',
cancerDiagnosis: 'no',
cancerDiagnosisRelatives: 'yes',
cancerDiagnosisRelativesAge: 'no',
ageStartedSmoking: '18',
periodsStoppedSmoking: 'no',
smokingType: ['cigarettes'],
cigarettes: {
smokingStatus: 'yes',
smokingFrequency: 'daily',
smokingQuantity: '10',
smokingChange: ['greater'],
smokingChangeIncrease: {
frequency: 'weekly',
quantity: '5',
years: '10'
}
}
}

const cloneAnswers = () => JSON.parse(JSON.stringify(defaultAnswers))

const getDefaultAnswerProfile = (profile) => {
const answers = cloneAnswers()

if (profile === 'former') {
answers.smoker = 'yes_previous'
answers.ageStoppedSmoking = '55'
answers.cigarettes = {
smokingFrequency: 'daily',
smokingQuantity: '10',
smokingChange: ['greater'],
smokingChangeIncrease: {
frequency: 'weekly',
quantity: '5',
years: '10'
}
}
}

if (profile === 'shisha') {
answers.smokingType = ['shisha']
delete answers.cigarettes
answers.shisha = {
smokingStatus: 'yes',
smokingSetting: ['group'],
group: {
smokingFrequency: 'weekly',
smokingQuantity: '30_minutes_to_1_hour'
}
}
}

return answers
}

const getIndexRedirect = (returnUrl, prototypePath) => {
if (!returnUrl || typeof returnUrl !== 'string') {
return `${prototypePath}/check-your-answers`
}

if (!returnUrl.startsWith(`${prototypePath}/`) || returnUrl.includes('//')) {
return `${prototypePath}/page-index`
}

return returnUrl
}

module.exports = {
getDefaultAnswerProfile,
getIndexRedirect
}
13 changes: 2 additions & 11 deletions app/prototype_v4_1/lib/question-renderer.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
const { getQuestion } = require('./questions')
const settings = require('./settings')

const version = 'v4_1'

/**
* Build a prototype v4_1 view path.
*
* @param {string} template - Template path below the prototype views folder.
* @returns {string} Nunjucks template path.
*/
const view = (template) => {
return `prototype_${version}/views/${template}`
}
const { version, view } = settings

/**
* Render a YAML-backed question using optional runtime overrides.
Expand Down
24 changes: 24 additions & 0 deletions app/prototype_v4_1/lib/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const version = 'v4_1'
const name = `prototype_${version}`
const path = `/${name}`
const viewPath = `${name}/views`

const view = (template) => {
return `${viewPath}/${template}`
}

const locals = {
version,
name,
path,
viewPath
}

module.exports = {
locals,
name,
path,
version,
view,
viewPath
}
50 changes: 40 additions & 10 deletions app/prototype_v4_1/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ const express = require('express')
const fs = require('fs')
const path = require('path')
const router = express.Router()
const settings = require('./lib/settings')

const version = 'v4_1'
const { path: prototypePath, version, view } = settings
const viewsDirectory = path.join(__dirname, 'views')

const view = (template) => {
return `prototype_${version}/views/${template}`
}

const hasView = (template) => {
if (!template || template.includes('..')) {
return false
Expand All @@ -26,20 +23,26 @@ const hasView = (template) => {
const authenticationController = require('./controllers/authentication')
const contentController = require('./controllers/content')
const errorController = require('./controllers/error')
const { getDefaultAnswerProfile, getIndexRedirect } = require('./lib/page-index')
const questionController = require('./controllers/question')

router.use((req, res, next) => {
res.locals.prototype = settings.locals
next()
})

/// ------------------------------------------------------------------------ ///
/// Start page
/// ------------------------------------------------------------------------ ///

router.get(`/prototype_${version}`, (req, res) => {
res.redirect(`/prototype_${version}/start-page`)
router.get(prototypePath, (req, res) => {
res.redirect(`${prototypePath}/start-page`)
})

router.get(`/prototype_${version}/start-page`, (req, res) => {
res.render(view('index'), {
router.get(`${prototypePath}/start-page`, (req, res) => {
res.render(view('start'), {
actions: {
start: `/prototype_${version}/sign-in`
start: `${prototypePath}/sign-in`
}
})
})
Expand Down Expand Up @@ -218,6 +221,33 @@ router.get(`/prototype_${version}/server-error`, errorController.unexpectedError
router.get(`/prototype_${version}/503`, errorController.serviceUnavailable)
router.get(`/prototype_${version}/service-unavailable`, errorController.serviceUnavailable)

/// ------------------------------------------------------------------------ ///
/// Page index
/// ------------------------------------------------------------------------ ///

router.get(`/prototype_${version}/set-default-answers`, (req, res) => {
req.session.data = req.session.data || {}
req.session.data.answers = getDefaultAnswerProfile(req.query.profile)

res.redirect(getIndexRedirect(req.query.returnUrl, prototypePath))
})

router.get(`/prototype_${version}/page-index`, (req, res) => {
res.render(view('index'), {
actions: {
setDefaultAnswers: `/prototype_${version}/set-default-answers`
}
})
})

router.get(`/prototype_${version}/index`, (req, res) => {
res.redirect(`/prototype_${version}/page-index`)
})

router.get(`/prototype_${version}/index-allpages`, (req, res) => {
res.redirect(`/prototype_${version}/page-index`)
})

/// ------------------------------------------------------------------------ ///
/// Add your routes above
/// ------------------------------------------------------------------------ ///
Expand Down
6 changes: 3 additions & 3 deletions app/prototype_v4_1/views/authentication/security-code.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{% extends "prototype_v4/views/layouts/main.html" %}
{% extends prototype.viewPath + "/layouts/main.html" %}

{% set title = "Enter the security code" %}

{% block content %}
{% include "prototype_v4/views/includes/error-summary.html" %}
{% include prototype.viewPath + "/includes/error-summary.html" %}

<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-two-thirds">

{% include "prototype_v4/views/includes/page-heading.html" %}
{% include prototype.viewPath + "/includes/page-heading.html" %}

<p class="nhsuk-body">
We have sent a 6-digit security code to your phone number ending in 0887.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "prototype_v4/views/layouts/main.html" %}
{% extends prototype.viewPath + "/layouts/main.html" %}

{% set title = "Sorry, you cannot test the online service" %}

Expand All @@ -18,7 +18,7 @@
<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-two-thirds">

{% include "prototype_v4/views/includes/page-heading.html" %}
{% include prototype.viewPath + "/includes/page-heading.html" %}

{{ bodyTextMarkdown | markdownToHtml | safe }}

Expand Down
Loading