Skip to content

Commit 4ec6477

Browse files
frankierobertopaulrobertlloyd
authored andcommitted
Use nhsuk-prototype-kit package
1 parent 95e54c0 commit 4ec6477

11 files changed

Lines changed: 710 additions & 448 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
.data
88
/node_modules
9-
/assets
9+
/public

app.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import sessionInDatabase from 'connect-pg-simple'
2+
import express from 'express'
3+
import session from 'express-session'
4+
import NHSPrototypeKit from 'nhsuk-prototype-kit'
5+
import { Pool } from 'pg'
6+
7+
import sessionDataDefaults from './app/data.js'
8+
import filters from './app/filters.js'
9+
import globals from './app/globals.js'
10+
import routes from './app/routes.js'
11+
12+
const { DATABASE_URL, NODE_ENV } = process.env
13+
14+
const app = express()
15+
16+
const prototype = await NHSPrototypeKit.init({
17+
app,
18+
buildOptions: {
19+
entryPoints: [
20+
'app/assets/stylesheets/*.scss',
21+
'app/assets/javascripts/*.js'
22+
]
23+
},
24+
filters,
25+
routes,
26+
serviceName: 'Manage vaccinations in schools',
27+
...(DATABASE_URL && {
28+
session: session({
29+
cookie: {
30+
maxAge: 1000 * 60 * 60 * 4, // 4 hours
31+
secure: process.env.NODE_ENV === 'production'
32+
},
33+
resave: false,
34+
saveUninitialized: false,
35+
secret: 'manage-vaccinations-in-schools-prototype',
36+
store: new (sessionInDatabase(session))({
37+
pool: new Pool({
38+
connectionString: DATABASE_URL,
39+
ssl: NODE_ENV === 'production' ? { rejectUnauthorized: false } : false
40+
})
41+
})
42+
})
43+
}),
44+
sessionDataDefaults,
45+
viewsPath: ['app/views', 'node_modules/nhsuk-decorated-components']
46+
})
47+
48+
prototype.app.set('view engine', 'njk')
49+
50+
for (const [key, value] of Object.entries(globals())) {
51+
prototype.nunjucks?.addGlobal(key, value)
52+
}
53+
54+
prototype.start(3000)

app.json

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
11
{
2-
"env": {
3-
"USE_AUTH": {
4-
"description": "Enable or disable password protection on production.",
5-
"value": "true"
6-
},
7-
"USE_AUTO_STORE_DATA": {
8-
"description": "Automatically store form data and send to all views",
9-
"value": "true"
10-
},
11-
"USE_DATABASE_SESSION_STORE": {
12-
"description": "Enable PostgreSQL session store.",
13-
"value": "true"
14-
},
15-
"USE_HTTPS": {
16-
"description": "Force HTTP to redirect to HTTPS on production",
17-
"value": "true"
18-
}
19-
},
202
"addons": ["heroku-postgresql:essential-0"]
213
}

app/filters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
* @returns {object} Filters
1818
*/
1919
export default (env) => {
20-
const filters = {}
20+
const filters = prototypeFilters
2121

2222
/**
2323
* Remove border from last summary row

app/globals.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import _ from 'lodash'
2+
import { decorate } from 'nhsuk-decorated-components'
23

34
import { healthQuestions } from './datasets/health-questions.js'
45
import {
@@ -25,6 +26,8 @@ import {
2526
export default () => {
2627
const globals = {}
2728

29+
globals.decorate = decorate
30+
2831
/**
2932
* Get boolean form field items
3033
*
@@ -319,7 +322,10 @@ export default () => {
319322
})
320323
}
321324

322-
summaryRows.at(-1).border = false
325+
// Remove border from final row
326+
if (summaryRows.at(-1)) {
327+
summaryRows.at(-1).border = false
328+
}
323329

324330
return summaryRows
325331
}
@@ -376,7 +382,10 @@ export default () => {
376382
})
377383
}
378384

379-
summaryRows.at(-1).border = false
385+
// Remove border from final row
386+
if (summaryRows.at(-1)) {
387+
summaryRows.at(-1).border = false
388+
}
380389

381390
return summaryRows
382391
}
@@ -660,7 +669,9 @@ export default () => {
660669
}
661670

662671
// Remove border from final row
663-
summaryRows.at(-1).border = false
672+
if (summaryRows.at(-1)) {
673+
summaryRows.at(-1).border = false
674+
}
664675

665676
return summaryRows
666677
}

app/views/_layouts/default.njk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% extends "rig/default.njk" %}
1+
{% extends "prototype-kit-template.njk" %}
22

33
{#- App macros -#}
44
{% from "_macros/action-list.njk" import appActionList %}
@@ -20,8 +20,8 @@
2020
<meta name="format-detection" content="telephone=no">
2121

2222
{% set assetsName = assetsName | default("application") %}
23-
<link rel="stylesheet" href="/assets/{{ assetsName }}.css" media="all">
24-
<script src="/assets/{{ assetsName }}.js" type="module"></script>
23+
<link rel="stylesheet" href="/assets/stylesheets/{{ assetsName }}.css" media="all">
24+
<script src="/assets/javascripts/{{ assetsName }}.js" type="module"></script>
2525
{% endblock %}
2626

2727
{% block header %}
@@ -130,7 +130,7 @@
130130
}, {
131131
text: "Clear session data",
132132
href: "/clear-session-data"
133-
} if useAutoStoreData, {
133+
}, {
134134
text: "Design history",
135135
href: "https://design-history.prevention-services.nhs.uk/manage-vaccinations-in-schools/"
136136
}]

app/views/patient-session/_record.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
{{ __("patientSession.preScreen.description", { patient: patient }) }}
7171
{% for question in patientSession.vaccine.preScreenQuestions %}
7272
- {{ question }}
73-
{%- endfor %}
73+
{% endfor %}
7474
{% endfilter %}
7575

7676
{{ checkboxes({

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ export default [
1111
}
1212
},
1313
{
14-
ignores: ['assets']
14+
ignores: ['public']
1515
}
1616
]

lib/create-data.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import process from 'node:process'
22

33
import { faker } from '@faker-js/faker'
44
import { addMinutes, isSameDay } from 'date-fns'
5-
import 'dotenv/config'
65

76
import clinicsData from '../app/datasets/clinics.js'
87
import programmesData from '../app/datasets/programmes.js'

0 commit comments

Comments
 (0)