Skip to content

Commit

Permalink
Merge branch 'main' into rosado/577-type-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeGoodall-GovUk authored Oct 31, 2024
2 parents 625addc + 38355dc commit b4d0153
Show file tree
Hide file tree
Showing 32 changed files with 314 additions and 158 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import { setupSession } from './src/serverSetup/session.js'
import { setupNunjucks } from './src/serverSetup/nunjucks.js'
import { setupSentry } from './src/serverSetup/sentry.js'
import { getDatasetSlugNameMapping } from './src/utils/datasetteQueries/getDatasetSlugNameMapping.js'
import { initDatasetSlugToReadableNameFilter } from './src/utils/datasetSlugToReadableName.js'

dotenv.config()

await initDatasetSlugToReadableNameFilter()
const app = express()

setupMiddlewares(app)
Expand Down
29 changes: 9 additions & 20 deletions src/assets/js/statusPage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// poll the server for the status of the job

import { finishedProcessingStatuses } from '../../utils/utils.js'
import { buttonTexts, buttonAriaLabels, headingTexts, messageTexts } from '../../content/statusPage.js'

export default class StatusPage {
constructor (pollingInterval, maxPollAttempts) {
Expand All @@ -15,20 +16,6 @@ export default class StatusPage {
this.continueButton = document.querySelector('#js-async-continue-button')
}

headingTexts = {
checkingFile: 'Checking File',
fileChecked: 'File Checked'
}

messageTexts = {
pleaseWait: 'Please wait'
}

buttonTexts = {
continue: 'Continue',
retrieveLatestStatus: 'Retrieve Latest Status'
}

beginPolling (statusEndpoint) {
this.pollAttempts = 0

Expand Down Expand Up @@ -58,24 +45,26 @@ export default class StatusPage {

updatePageToChecking () {
// update the page
this.heading.textContent = this.headingTexts.checkingFile
this.processingMessage.textContent = this.messageTexts.pleaseWait
this.heading.textContent = headingTexts.checking
this.processingMessage.textContent = messageTexts.checking
this.continueButton.style.display = 'none'
}

updatePageToComplete () {
// update the page
this.heading.textContent = this.headingTexts.fileChecked
this.heading.textContent = headingTexts.checked
this.processingMessage.style.display = 'none'
this.continueButton.textContent = this.buttonTexts.continue
this.continueButton.textContent = buttonTexts.checked
this.continueButton.ariaLabel = buttonAriaLabels.checked
this.continueButton.style.display = 'block'
}

updatePageForPollingTimeout () {
// update the page
this.heading.textContent = this.headingTexts.checkingFile
this.heading.textContent = headingTexts.checking
this.processingMessage.style.display = 'none'
this.continueButton.textContent = this.buttonTexts.retrieveLatestStatus
this.continueButton.textContent = buttonTexts.checking
this.continueButton.ariaLabel = buttonAriaLabels.checking
this.continueButton.style.display = 'block'
}
}
Expand Down
43 changes: 43 additions & 0 deletions src/assets/scss/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,46 @@ code * {
.padding-top {
padding-top: 40px;
}

.dl-scrollable {
max-width: 100%;
overflow-x: auto;
padding: 0px;
}


.dl-table {
overflow-y: auto;
overflow-x: hidden;
max-height: 80vh;
width: 100%;
margin-bottom: 0px;
border-collapse: separate;

th, td {
padding: govuk-spacing(1) govuk-spacing(2);
}
}


.dl-table__head {
position: sticky;
top: 0;
z-index: 1;

box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.4);
tr {
background-color: govuk-colour("light-grey");
}
}


.dl-table__header {
border: 1px solid $govuk-border-colour;
text-wrap: nowrap;
background-color: govuk-colour("light-grey");
}

.dl-table__cell--error {
border-left: govuk-spacing(1) solid $govuk-error-colour;
}
19 changes: 19 additions & 0 deletions src/content/statusPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const headingTexts = {
checking: 'Checking your data',
checked: 'Data Checked'
}

export const messageTexts = {
checking: 'Do not close this page',
checked: 'You can continue'
}

export const buttonTexts = {
checking: 'Retrieve Latest Status',
checked: 'Continue'
}

export const buttonAriaLabels = {
checking: 'Retrieve Latest Status of data check',
checked: 'Continue to next step'
}
13 changes: 13 additions & 0 deletions src/controllers/pageController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import hmpoFormWizard from 'hmpo-form-wizard'
import { logPageView, types } from '../utils/logging.js'
import logger from '../utils/logger.js'
import { datasetSlugToReadableName } from '../utils/datasetSlugToReadableName.js'
const { Controller } = hmpoFormWizard

/**
Expand Down Expand Up @@ -38,9 +39,14 @@ class PageController extends Controller {
const deepLinkInfo = req?.sessionModel?.get(this.checkToolDeepLinkSessionKey)
if (deepLinkInfo) {
req.form.options.deepLink = deepLinkInfo
req.form.options.datasetName = deepLinkInfo.datasetName
backLink = wizardBackLink(req.originalUrl, deepLinkInfo)
}

if (backLink) {
req.form.options.backLinkText = `Back to ${deepLinkInfo.datasetName} overview`
}

backLink = backLink ?? this.options.backLink
if (backLink) {
req.form.options.lastPage = backLink
Expand All @@ -52,6 +58,13 @@ class PageController extends Controller {
})
}

const dataset = req?.sessionModel?.get('dataset')
try {
req.form.options.datasetName = datasetSlugToReadableName(dataset)
} catch (e) {
logger.warn(`Failed to get readable dataset name from slug: ${dataset}`)
}

super.locals(req, res, next)
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/controllers/statusController.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import PageController from './pageController.js'
import { getRequestData } from '../services/asyncRequestApi.js'
import { finishedProcessingStatuses } from '../utils/utils.js'
import { headingTexts, messageTexts } from '../content/statusPage.js'

class StatusController extends PageController {
async locals (req, res, next) {
try {
req.form.options.data = await getRequestData(req.params.id)
req.form.options.processingComplete = finishedProcessingStatuses.includes(req.form.options.data.status)
req.form.options.headingTexts = headingTexts
req.form.options.messageTexts = messageTexts
req.form.options.pollingEndpoint = `/api/status/${req.form.options.data.id}`
super.locals(req, res, next)
} catch (error) {
Expand Down
5 changes: 2 additions & 3 deletions src/filters/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import validationMessageLookup from './validationMessageLookup.js'
import toErrorList from './toErrorList.js'
import prettifyColumnName from './prettifyColumnName.js'
import getFullServiceName from './getFullServiceName.js'
import { makeDatasetSlugToReadableNameFilter } from './makeDatasetSlugToReadableNameFilter.js'
import { checkToolDeepLink } from './checkToolDeepLink.js'
import pluralize from 'pluralize'
import { datasetSlugToReadableName } from '../utils/datasetSlugToReadableName.js'

/** maps dataset status (as returned by `fetchLpaOverview` middleware to a
* CSS class used by the govuk-tag component
Expand All @@ -27,8 +27,7 @@ export function statusToTagClass (status) {

const { govukMarkdown, govukDateTime } = xGovFilters

const addFilters = (nunjucksEnv, { datasetNameMapping }) => {
const datasetSlugToReadableName = makeDatasetSlugToReadableNameFilter(datasetNameMapping)
const addFilters = (nunjucksEnv) => {
nunjucksEnv.addFilter('datasetSlugToReadableName', datasetSlugToReadableName)

nunjucksEnv.addFilter('govukMarkdown', govukMarkdown)
Expand Down
19 changes: 19 additions & 0 deletions src/utils/datasetSlugToReadableName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { makeDatasetSlugToReadableNameFilter } from '../filters/makeDatasetSlugToReadableNameFilter.js'
import { getDatasetSlugNameMapping } from './datasetteQueries/getDatasetSlugNameMapping.js'

let datasetSlugToReadableName = (slug) => slug

const initDatasetSlugToReadableNameFilter = async () => {
try {
const mapping = await getDatasetSlugNameMapping()
datasetSlugToReadableName = makeDatasetSlugToReadableNameFilter(mapping)
} catch (error) {
console.error('Failed to load dataset mapping:', error)
datasetSlugToReadableName = (slug) => slug // Fallback to using the slug as-is
}
}

export {
datasetSlugToReadableName,
initDatasetSlugToReadableNameFilter
}
14 changes: 7 additions & 7 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export const dataSubjects = {
dataSets: [
{
value: 'article-4-direction',
text: 'Article 4 direction dataset',
text: 'Article 4 direction',
available: true
},
{
value: 'article-4-direction-area',
text: 'Article 4 direction area dataset',
text: 'Article 4 direction area',
available: true
}
]
Expand All @@ -41,12 +41,12 @@ export const dataSubjects = {
dataSets: [
{
value: 'conservation-area',
text: 'Conservation area dataset',
text: 'Conservation area',
available: true
},
{
value: 'conservation-area-document',
text: 'Conservation area document dataset',
text: 'Conservation area document',
available: true
}
]
Expand Down Expand Up @@ -76,18 +76,18 @@ export const dataSubjects = {
dataSets: [
{
value: 'tree',
text: 'Tree dataset',
text: 'Tree',
available: true,
requiresGeometryTypeSelection: true
},
{
value: 'tree-preservation-order',
text: 'Tree preservation order dataset',
text: 'Tree preservation order',
available: true
},
{
value: 'tree-preservation-zone',
text: 'Tree preservation zone dataset',
text: 'Tree preservation zone',
available: true
}
]
Expand Down
49 changes: 19 additions & 30 deletions src/views/check/confirmation.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,44 @@
{% extends "layouts/main.html" %}

{% set serviceType = 'Check' %}
{% set pageName = "Send us your data" %}
{% set pageName = "You can now publish your data" %}

{% block content %}

{% set example %}

## About the data

This dataset shows the locations of conservation areas. Conservation areas are designated to safeguard areas of special architectural and historic interest, the character and appearance of which it is desirable to preserve or enhance. Within these areas special planning controls operate which need to be considered when undertaking development.

## Data

[Conservations areas (CSV, 18KB)](/public/downloadable/conservationArea.csv)
{% set content %}

## Licensing
# What to do next

The data is provided under the [Open Government Licence](https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/).
## 1: Publish your data to your website

{% endset %}

{% set content %}
The page on your website must include:
- a link to the data
- a summary of what the data is about
- a statement that the data is provided under the Open Government Licence

## What you need to do next
## 2: Send an email

You need to send an email to [[email protected]](mailto:[email protected]).
Send an email to [[email protected]](mailto:[email protected]).

The email must include:
You must include:

- your full name
- the name of your local planning authority (LPA)
- a link to a webpage containing the data on your LPA website

The webpage must include:

- a link to the data
- a summary of what the data is about
- a statement that the data is provided under the Open Government Licence
Details about what to do next are also available [in the guidance](/guidance)

{{ govukDetails({
summaryText: "Example webpage",
text: example | govukMarkdown(headingsStartWith="m") | safe
}) }}
{% if options.deepLink %}
<p><a href="{{ options.deepLink.referrer }}">Return to {{ options.deepLink.dataset }} overview</a></p>
{% else %}
<p><a href="/">Return to Home</a></p>
{% endif %}

## Give feedback

[Give feedback about this service]({{feedbackLink}}) (takes 30 seconds).

{% endset %}

{% block content %}

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
{{ govukPanel({
Expand Down
4 changes: 2 additions & 2 deletions src/views/check/geometry-type.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
{% endif %}
<form novalidate method="post">

{% if options.deepLink %}
{{ datasetBanner(options.deepLink) }}
{% if options.datasetName %}
{{ datasetBanner(options.datasetName) }}
{% endif %}

{{ govukRadios({
Expand Down
4 changes: 2 additions & 2 deletions src/views/check/results/errors.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">

{% if options.deepLink %}
{{ datasetBanner(options.deepLink) }}
{% if options.datasetName %}
{{ datasetBanner(options.datasetName) }}
{% else %}
<span class="govuk-caption-l">{{options.requestParams.dataset}}</span>
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions src/views/check/results/no-errors.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
{% if options.deepLink %}
{{ datasetBanner(options.deepLink) }}
{% if options.datasetName %}
{{ datasetBanner(options.datasetName) }}
{% endif %}
<h1 class="govuk-heading-l">
{{pageName}}
Expand Down
Loading

0 comments on commit b4d0153

Please sign in to comment.