Skip to content

Commit

Permalink
Cya epic (#234)
Browse files Browse the repository at this point in the history
* SIR-888: water-pollution/your-details (#205)

Looks good to me :)

* SIR-887 : Story – WP – Check your answers (#208)

* SIR-888: water-pollution/your-details (#205)

Looks good to me :)

* WIP - WP CYA Page

* Technical implementation for SIR-887

* Fixed all lint errors

* Refactored code and added comments

* Refactored code and logic update

* Added unit tests for check your answers page

* SIR-1102 map widget for check your answers (#207)

* linting that i missed

* Fixed unit test case issues

* fixing unit tests

* reverting date test am and AM having issues

* CYA routing boilerplate

* changing to form-layout otherwise post doesn''t work

* Fixed sonar issues part 1

* Fixed lint issues

* Fixed sonar issues part 2

* Fixed sonar issues part 3

* Added test coverage part 1

* Added test coverage part 2

* Added test coverage part 3

* Additional logic added for UI renderning

* Added null check

* Reduced code complexity for sonar

* Reduced code complexity for sonar

* Updated logic complexity

* Additional test cases for more coverage

* Updated code based on review comments

* Check your answers routing (#210)

* SIR-1066 pollution-substance routing from CYA

* updating var name for sonarcloud

* test coverage

* SIR-892 pollution-appearance routing from CYA (#211)

* SIR-892 pollution-appearance routing from CYA

* SIR-890 change location from CYA (#212)

* SIR-890 change location from CYA

* removing .only from unit tests

* sonarcloud

* SIR-1068 CYA routing for WP source (#217)

---------

Co-authored-by: Tedd <[email protected]>

* SIR-893 images-and-videos CYA routing

* SIR-891 - observed date time from cya (#220)

* SIR-891 - observed date time from cya

* sonarcloud stuff

* further test coverage for dates

* SIR-889 : Story – WP – Check your answers – Watercourse & Extent (#218)

* CYA - Watercourse & Extent redirection implementation

* CYA - Prepopulate answers for watercourse & Extent pages

* WIP - Updated test case

* WIP - CYA Test cases

* Added test cases for CYA watercourse & extent

* SIR-894 : Story – WP – Check your answers – Dead animals (#222)

* Technical implementation for SIR-894

* Removed console logs

* fixing test missed from merge

* SIR-895 : Story – WP – Check your answers – Other text (#225)

* Technical implementation for SIR-895

* Added logs to check data on server

* Added logs to check data on server

* Added logs to check data on server

* Removed logs

---------

Co-authored-by: Tedd Mason <[email protected]>

* Reset the referer flag in case if the user restarts the WP journey before report submission (#228)

---------

Co-authored-by: sujithvg <[email protected]>
  • Loading branch information
teddmason and sujithvg authored Dec 10, 2024
1 parent e5049bc commit 8d6251e
Show file tree
Hide file tree
Showing 66 changed files with 2,752 additions and 510 deletions.
72 changes: 46 additions & 26 deletions client/js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ const dropPin = (coordinate) => {
geometry: point
})
vectorSource.addFeature(marker)
pointElement.value = JSON.stringify(coordinate)
if (pointElement) {
pointElement.value = JSON.stringify(coordinate)
}
}

const panToPoint = (point, extentBuffer = 250) => {
Expand All @@ -145,7 +147,7 @@ const panToOSValue = (value) => {
}
}

const initialiseMap = () => {
const initialiseMap = options => {
(
async () => {
await setToken()
Expand All @@ -159,35 +161,53 @@ const initialiseMap = () => {
const oSLayer = new TileLayer({
source: osSource
})
map = new Map({
target: 'map',
interactions: defaultInteractions({

const interactions = options?.disableControls
? []
: defaultInteractions({
altShiftDragRotate: false,
pinchRotate: false
}),
controls: defaultControls().extend([
new ScaleLine({
units: 'metric',
minWidth: 100
})
]),
layers: [
oSLayer,
vectorLayer
],
view: new View({
projection: OSGB36,
showFullExtent: false,
extent,
center,
zoom,
maxZoom
})

const controls = defaultControls().extend([
new ScaleLine({
units: 'metric',
minWidth: 100
})
])

const view = new View({
projection: OSGB36,
showFullExtent: false,
extent,
center: options?.point || center,
zoom: options?.zoom || zoom,
maxZoom
})
// add Marker interaction
map.on('click', (e) => {
dropPin(e.coordinate)

const layers = [
oSLayer,
vectorLayer
]

map = new Map({
target: 'map',
interactions,
controls,
layers,
view
})

if (options?.point) {
dropPin(options.point)
}

if (!options?.disableControls) {
// add Marker interaction
map.on('click', (e) => {
dropPin(e.coordinate)
})
}
}
)()
}
Expand Down
3 changes: 3 additions & 0 deletions client/js/pages/check-your-answers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { initialiseMap } from '../map.js'

export { initialiseMap }
3 changes: 2 additions & 1 deletion client/js/pages/location-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ const getLocation = async () => {
]
}

initialiseMap()
initialiseLocationSearch()

export { initialiseMap }
21 changes: 21 additions & 0 deletions client/sass/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,27 @@ margin-bottom: 0;
}
}

.map--check-your-answers {
height: auto;

.ol-viewport {
height: 200px !important;
}

.ol-zoom, .ol-scale-line, .ol-attribution {
display: none;
}

}

.vertical-align-top {
vertical-align: top;
}

.map--cell {
height: 220px;
}

//////////////////////////////////////////////////
// OS MAP STYLES END /////////////////////////////
//////////////////////////////////////////////////
22 changes: 22 additions & 0 deletions server/plugins/on-post-handler.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
import constants from '../utils/constants.js'

const onPostHandler = {
plugin: {
name: 'on-post-handler',
register: (server, _options) => {
server.ext('onPostHandler', async (request, h) => {
if (request.response.variety === 'view' && request.method === 'get') {
request.response.headers['cache-control'] = 'no-cache, no-store, must-revalidate'
handleReferer(request)
}
return h.continue
})
}
}
}

const handleReferer = request => {
if (request.headers.referer) {
// If referer was a check route then set the session referer
// Route then decides whether to redirect to referer or not
const setReferer = constants.setReferer.find(item => request.headers.referer.indexOf(item) > -1)
const clearReferer = constants.clearReferer.find(item => request.headers.referer.indexOf(item) > -1)
if (setReferer) {
request.yar.set(constants.redisKeys.REFERER, `/${setReferer}`)
} else if (clearReferer) {
request.yar.clear(constants.redisKeys.REFERER)
} else {
// do nothing for sonarcloud
}
} else {
// If no referer then clear referer key because user has broken the journey
request.yar.clear(constants.redisKeys.REFERER)
}
}

export default onPostHandler
3 changes: 2 additions & 1 deletion server/plugins/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import config from '../utils/config.js'
import constants from '../utils/constants.js'
import fs from 'fs'
import dirname from '../../dirname.cjs'
import { findErrorMessageById } from '../utils/template-helpers.js'
import { findErrorMessageById, getAnswer } from '../utils/template-helpers.js'
const { version } = JSON.parse(fs.readFileSync('./package.json'))
const analyticsAccount = config.analyticsAccount

Expand All @@ -25,6 +25,7 @@ export default {
})
// Add global functions for view templates
env.addGlobal('findErrorMessageById', findErrorMessageById)
env.addGlobal('getAnswer', getAnswer)
return next()
}
}
Expand Down
7 changes: 7 additions & 0 deletions server/routes/__tests__/water-pollution.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@ describe(url, () => {
it(`Should return success response and correct view for ${url}`, async () => {
await submitGetRequest({ url }, header)
})
it(`Happy: Reset the CYA journey if user restarts the WP journey before report submission ${url}`, async () => {
const sessionData = {
referer: '/water-pollution/check-your-answers'
}
const response = await submitGetRequest({ url }, header, constants.statusCodes.OK, sessionData)
expect(response.request.yar.get(constants.redisKeys.REFERER)).toEqual(null)
})
})
})
Loading

0 comments on commit 8d6251e

Please sign in to comment.