Skip to content

Commit

Permalink
FSR-1130 | refactor JS files (#761)
Browse files Browse the repository at this point in the history
* refactor js files to reduce duplication and size

* refactor js files to reduce duplication and size

* remove webpack commented code

* remove river-and-sea-levels-list page

* remove river-and-sea-levels-list page

* view fix

* update map dom id

* remove initAll fn

* govuk-frontend 5.4.0

* phase banner text update

* add dist/templates to core.js

* remove util from webpack

* add model conditionals to viewmodels

* fix target area map button text

* sass updates. btnClass fix

* mapButtonText

* webchat version update

---------

Co-authored-by: Ash <[email protected]>
  • Loading branch information
ashleyjtaylor and Ash committed Aug 23, 2024
1 parent 15eaa7f commit 8eccfa3
Show file tree
Hide file tree
Showing 68 changed files with 3,566 additions and 4,385 deletions.
4 changes: 1 addition & 3 deletions build/cp-assets
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
cp -r server/src/images server/dist/images
cp -r server/src/audio server/dist/audio
cp server/src/robots.txt server/dist/robots.txt
cp node_modules/govuk-frontend/govuk/all.js server/dist/js/all.js
node_modules/.bin/uglifyjs server/dist/js/all.js --output server/dist/js/all.js
cp server/src/robots.txt server/dist/robots.txt
4,666 changes: 1,915 additions & 2,751 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@babel/core": "^7.23.3",
"@babel/plugin-transform-runtime": "^7.23.4",
"@babel/preset-env": "^7.16.4",
"@defra/flood-webchat": "^0.0.1-beta.51",
"@defra/flood-webchat": "^1.0.1",
"@hapi/boom": "^10.0.1",
"@hapi/catbox-redis": "^7.0.2",
"@hapi/code": "^9.0.3",
Expand Down Expand Up @@ -63,7 +63,7 @@
"datatables.net-dt": "1.12.1",
"elm-pep": "^1.0.6",
"geojson": "0.5.0",
"govuk-frontend": "^4.8.0",
"govuk-frontend": "^5.4.0",
"hapi-pino": "^12.1.0",
"hapi-rate-limit": "^7.1.0",
"jquery": "^3.7.1",
Expand Down Expand Up @@ -98,6 +98,7 @@
"mockdate": "^3.0.5",
"node-html-parser": "^6.1.13",
"nodemon": "^3.0.1",
"proxyquire": "^2.1.3"
"proxyquire": "^2.1.3",
"webpack-bundle-analyzer": "^4.10.2"
}
}
1 change: 0 additions & 1 deletion server/models/views/alerts-and-warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class ViewModel {
Object.assign(this, {
q,
station,
map: station ? 'map-station' : 'map',
placeName: place?.name || '',
placeBbox: place?.bbox2k || [],
placeCentre: place?.center || [],
Expand Down
1 change: 1 addition & 0 deletions server/models/views/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ViewModel {
// Expose model values for client side javascript
this.expose = {
hasWarnings: this.hasActiveFloods,
mapButtonText: this.hasActiveFloods ? 'View map of flood warnings and alerts' : 'View map',
placeBbox: this.placeBbox,
outlookDays: tabs.days,
bingMaps: bingKeyMaps
Expand Down
1 change: 1 addition & 0 deletions server/models/views/national.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ViewModel {
metaDescription:
'View current flood warnings and alerts for England and the national flood forecast for the next 5 days. Also check river, sea, groundwater and rainfall levels.',
metaCanonical: '/',
mapButtonText: floods.hasActiveFloods ? 'View map of flood warning and alert areas' : 'View map',
hasActiveFloods: floods.hasActiveFloods,
highestSeverityId: floods.highestSeverityId,
dateFormatted: `${moment().tz(tz).format('h:mma')} on ${moment().tz(tz).format('D MMMM YYYY')}`,
Expand Down
3 changes: 2 additions & 1 deletion server/models/views/river-and-sea-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function disambiguationModel (q, places, rivers) {
...getDataJourneyClickStrings(),
pageTitle: `${q} - ${pageTitle}`,
place: places[0],
clientModel: getClientModel()
clientModel: getClientModel(),
disambiguation: true
}
}

Expand Down
4 changes: 1 addition & 3 deletions server/models/views/target-area.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class ViewModel {
? 'warning'
: 'alert'

const mapTitle = `View map of the flood ${type} area`

let fallbackText
if (type === 'alert') {
fallbackText = '<p>We\'ll update this page when there\'s a flood alert in the area, which means flooding to low lying land is possible.</p>'
Expand Down Expand Up @@ -62,6 +60,7 @@ class ViewModel {
pageTitle,
metaDescription,
metaCanonical,
mapButtonText: `View map of the flood ${type} area`,
placeName: area.name,
placeCentre: JSON.parse(area.centroid).coordinates,
featureId: area.id,
Expand All @@ -72,7 +71,6 @@ class ViewModel {
areaDescription,
targetArea: area.code,
feedback: false,
mapTitle,
floodRiskUrl,
bingMaps: bingKeyMaps,
signUpForFloodWarnings: true,
Expand Down
4 changes: 2 additions & 2 deletions server/plugins/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ module.exports = {
},
path: [
'server/views',
'node_modules/govuk-frontend/govuk',
'node_modules/govuk-frontend/govuk/components/'
'node_modules/govuk-frontend/dist/govuk',
'node_modules/govuk-frontend/dist/govuk/components'
],
isCached: true,
context: {
Expand Down
2 changes: 1 addition & 1 deletion server/routes/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = [{
directory: {
path: [
'server/dist',
'node_modules/govuk-frontend/govuk/assets',
'node_modules/govuk-frontend/dist/govuk/assets',
'node_modules/accessible-autocomplete/dist',
'node_modules/nunjucks/browser'
]
Expand Down
2 changes: 1 addition & 1 deletion server/routes/river-and-sea-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async function locationQueryHandler (request, h) {

const path = getDisambiguationPath(places[0], location)

return h.view(`${route}-list`, { model: disambiguationModel(location, places, rivers), path })
return h.view(route, { model: disambiguationModel(location, places, rivers), path })
}

if (places.length === 0) {
Expand Down
Loading

0 comments on commit 8eccfa3

Please sign in to comment.