forked from XGovFormBuilder/digital-form-builder
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CAR-180 'Do Not Report' Page #235
Open
emilyjevans
wants to merge
1
commit into
v2
Choose a base branch
from
feat/CAR-180/Do-not-report-page
base: v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
runner/src/server/plugins/engine/pageControllers/NonSubmittingSummaryPageController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
import { HapiRequest, HapiResponseToolkit } from "server/types"; | ||
import { PageController } from "server/plugins/engine/pageControllers/PageController"; | ||
|
||
import { FormComponent } from "server/plugins/engine/components"; | ||
import { PageControllerBase } from "server/plugins/engine/pageControllers/PageControllerBase"; | ||
import { FormModel } from "server/plugins/engine/models"; | ||
import { NonSubmittingSummaryPage } from "@xgovformbuilder/model"; | ||
|
||
const DEFAULT_OPTIONS = { | ||
customText: {}, | ||
}; | ||
|
||
export class NonSubmittingSummaryPageController extends PageController { | ||
returnUrlParameter: string; | ||
options: NonSubmittingSummaryPage["options"]; | ||
|
||
constructor(model: FormModel, pageDef: NonSubmittingSummaryPage) { | ||
super(model, pageDef); | ||
|
||
const returnPath = `/${this.model.basePath}${this.path}`; | ||
this.returnUrlParameter = `?returnUrl=${encodeURIComponent(returnPath)}`; | ||
this.options = pageDef?.options ?? DEFAULT_OPTIONS; | ||
this.options.customText ??= DEFAULT_OPTIONS.customText; | ||
} | ||
/** | ||
* Returns an async function. This is called in plugin.ts when there is a GET request at `/{id}/{path*}`, | ||
*/ | ||
makeGetRouteHandler() { | ||
return async (request: HapiRequest, h: HapiResponseToolkit) => { | ||
this.langFromRequest(request); | ||
|
||
const viewModel = await this.summaryViewModel(request); | ||
|
||
return h.view("non-submitting-summary", viewModel); | ||
}; | ||
} | ||
|
||
/** | ||
* Returns an async function. This is called in plugin.ts when there is a POST request at `/{id}/{path*}`. | ||
* If a form is incomplete, a user will be redirected to the start page. | ||
*/ | ||
makePostRouteHandler() { | ||
return async (request: HapiRequest, h: HapiResponseToolkit) => { | ||
const { cacheService } = request.services([]); | ||
const model = this.model; | ||
const state = await cacheService.getState(request); | ||
|
||
request.yar.set("basePath", model.basePath); | ||
|
||
const nextPage = this.getNext(state); | ||
return h.redirect(nextPage); | ||
}; | ||
} | ||
|
||
get postRouteOptions() { | ||
return { | ||
ext: { | ||
onPreHandler: { | ||
method: async (_request: HapiRequest, h: HapiResponseToolkit) => { | ||
return h.continue; | ||
}, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
async summaryViewModel(request: HapiRequest) { | ||
const { cacheService } = request.services([]); | ||
const state = await cacheService.getState(request); | ||
const { progress = [] } = state; | ||
|
||
const { relevantPages } = this.model.getRelevantPages(state); | ||
|
||
const rowsBySection = relevantPages.reduce((prev, page) => { | ||
const sectionName = page.section?.name; | ||
const section = prev[sectionName] ?? []; | ||
let sectionState = sectionName ? state[sectionName] || {} : state; | ||
|
||
const toRow = this.formItemsToRowByPage({ | ||
page, | ||
sectionState, | ||
fullState: state, | ||
}); | ||
|
||
section.push(...page.components.formItems.map(toRow)); | ||
|
||
prev[sectionName] = section; | ||
return prev; | ||
}, {}); | ||
|
||
const summaryLists = Object.entries(rowsBySection).map( | ||
([section, rows]) => { | ||
const modelSection = this.model.sections.find( | ||
(mSection) => mSection.name === section | ||
); | ||
|
||
return { | ||
sectionTitle: !modelSection?.hideTitle ? modelSection?.title : "", | ||
section, | ||
rows, | ||
}; | ||
} | ||
); | ||
|
||
return { | ||
pageTitle: this.title, | ||
sectionTitle: this.section?.title, | ||
backLink: progress[progress.length - 1] ?? this.backLinkFallback, | ||
name: this.model.name, | ||
summaryLists, | ||
showTitle: true, | ||
customText: this.options.customText, | ||
}; | ||
} | ||
|
||
formItemsToRowByPage({ | ||
page, | ||
sectionState, | ||
fullState, | ||
}: { | ||
page: PageControllerBase; | ||
sectionState: { [key: string]: any }; | ||
fullState: { [key: string]: any }; | ||
}) { | ||
const pagePath = `/${page.model.basePath}${page.path}`; | ||
const returnPath = `${pagePath}${this.returnUrlParameter}`; | ||
const model = this.model; | ||
return function (component: FormComponent) { | ||
let valueText = component.getDisplayStringFromState(sectionState); | ||
|
||
if ( | ||
component.type === "FileUploadField" && | ||
model.showFilenamesOnSummaryPage | ||
) { | ||
valueText = | ||
fullState.originalFilenames?.[component.name]?.originalFilename; | ||
} | ||
|
||
return { | ||
key: { | ||
text: component.options.shortTitle ?? component.title, | ||
}, | ||
value: { | ||
text: valueText || "Not supplied", | ||
}, | ||
actions: { | ||
items: [ | ||
{ | ||
text: "Change", | ||
visuallyHiddenText: component.title, | ||
href: returnPath, | ||
}, | ||
], | ||
}, | ||
}; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{% from "partials/summary-detail.html" import summaryDetail %} | ||
|
||
{% from "components/checkboxes/macro.njk" import govukCheckboxes %} | ||
{% from "summary-list/macro.njk" import govukSummaryList %} | ||
{% extends 'layout.html' %} | ||
|
||
{% block content %} | ||
{% include "partials/heading.html" %} | ||
|
||
{% if customText.insetText %} | ||
<div class="govuk-inset-text"> | ||
{{ customText.insetText | safe }} | ||
</div> | ||
{% endif %} | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
|
||
<div class="govuk-summary-card"> | ||
<div class="govuk-summary-card__title-wrapper"> | ||
<h2 class="govuk-summary-card__title"> | ||
{{ customText.cardTitle | safe }} | ||
</h2> | ||
</div> | ||
<div class="govuk-summary-card__content"> | ||
{% for list in summaryLists %} | ||
{{ govukSummaryList(list) }} | ||
{% endfor %} | ||
</div> | ||
</div> | ||
{% if customText.details %} | ||
<p class="govuk-body"> | ||
{{ customText.details | safe }} | ||
</p> | ||
{% endif %} | ||
|
||
<a href="{{serviceStartPage}}"> | ||
<button data-prevent-double-click="true" class="govuk-button" data-module="govuk-button"> | ||
Back to start | ||
</button> | ||
</a> | ||
</div> | ||
|
||
</div> | ||
{% endblock %} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
questionSummaryTitle