-
Notifications
You must be signed in to change notification settings - Fork 34
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
feat/image-quality-playback #1161
Merged
Merged
Changes from 22 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
41c6761
updated designer to allow users to select image quality playback option
ziggy-cyb 446c013
Added template for upload playback
ziggy-cyb 89a1832
Added page controllers for upload field pages
ziggy-cyb 7199531
Added new UploadPageController to controllers list
ziggy-cyb 784df1f
Updated UploadPageController to include form validation logic
ziggy-cyb 2acb45d
Updated playback image page controller to run the standard post route…
ziggy-cyb a5905b0
Reverted PageControllerBase
ziggy-cyb 45dc8e2
Updated upload service to process warnings in document upload responses
ziggy-cyb 6e5be90
Moved makeRouteHandler functions to be accessible outside of getters
ziggy-cyb 2b3cc8b
Updated UploadPageController to use new playback page route handler f…
ziggy-cyb 8d0c004
Added unit tests for UploadPageController
ziggy-cyb 21e7fd1
Made some content tweaks to OCR playback page
ziggy-cyb 59ba1fd
Tidied up UploadPageController post route handler using takeover resp…
ziggy-cyb fe23ceb
Updates to make sure playback page is only shown when upload page con…
ziggy-cyb 483354a
Chanhged the name of the title for the playback page
ziggy-cyb e509dd0
Removed innecessary test after upload files pre-handler changed
ziggy-cyb 3bbfc78
Changed options in file upload field edit
ziggy-cyb ac911a7
Added documentation for the document upload api
ziggy-cyb 6a0ab30
Removed stray console logs
ziggy-cyb a72660a
Cleaned up page controllers
ziggy-cyb 03d6b51
Changed warningFromApi to just warning
ziggy-cyb 3caecb9
Added comment explaining the getRetryUploadViewModel function
ziggy-cyb 23769c5
Removed unnecessary back link declaration
ziggy-cyb d564725
Updated upload service to update file name if using the upload page c…
ziggy-cyb ba823fd
Updated playback upload page controller to incorporate joi
ziggy-cyb 746da12
Updated playback page controller to mirror functionality of repeating…
ziggy-cyb 76e796c
Updated UploadService to set state properly if the UploadPageControll…
ziggy-cyb e279dc4
Changed how upload service updates the file upload state
ziggy-cyb ab86b0b
Moved image playback response handling to upload page controller
ziggy-cyb 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
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,32 @@ | ||
# Document upload | ||
|
||
the form builder supports the use of an external document upload service. This allows users to upload files, but gives developers the flexibility to decide how they want to process the files. | ||
|
||
## Setup | ||
|
||
In order to start using file upload files in your form, you will need to specify an endpoint to send your files to. This can be done by setting the following environment variables: | ||
|
||
| Variable name | Definition | example | | ||
| ----------------------- | ------------------------------------------------------ | ------------------------------- | | ||
| DOCUMENT_UPLOAD_API_URL | the root endpoint of service used to upload your files | https://document-upload-api.com | | ||
|
||
The service you're using for your document upload api will need an endpoint of /files that accepts POST requests with a file in the body. Currently, there is no support for authenticating against this endpoint, so this endpoint will need to be open. | ||
|
||
### Responses | ||
|
||
The upload service which handles communication with the api can handle the following responses: | ||
|
||
| Code | Payload | Handled by | | ||
| ---- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| 201 | | Updating the value of the upload field to the location url returned | | ||
| 201 | `qualityWarning` | Updating the upload field as above, as well as routing to the upload playback page if using the UploadPageController. See below for more details. | | ||
| 400 | | Redirects back to the upload field page displaying a file type error | | ||
| 413 | | Redirects back to the upload field page displaying a file size error | | ||
| 422 | | Redirects back to the upload field page displaying a file virus error | | ||
|
||
#### UploadPageController | ||
|
||
We have introduced a specific UploadPageController, which can be used if you want to integrate image quality checking into your document upload api. | ||
By adding the property `controller: UploadPageController` to the page in your form json, if a successful response is returned from the api but with the payload "qualityWarning", the user will be presented a playback page. | ||
This page will strongly suggest the user upload a new image, and give the user the option to continue anyway or upload a new image. | ||
If the UploadPageController is not specified on the page, the quality warning will be ignored, and the user will be routed to the next page in the form as normal. |
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
106 changes: 106 additions & 0 deletions
106
runner/src/server/plugins/engine/pageControllers/PlaybackUploadPageController.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,106 @@ | ||
import { PageController } from "server/plugins/engine/pageControllers/PageController"; | ||
import { FormModel } from "server/plugins/engine/models"; | ||
import { Page } from "@xgovformbuilder/model"; | ||
import { FormComponent } from "server/plugins/engine/components"; | ||
import { HapiRequest, HapiResponseToolkit } from "server/types"; | ||
export class PlaybackUploadPageController extends PageController { | ||
inputComponent: FormComponent; | ||
standardViewModel = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
name: "retryUpload", | ||
fieldset: { | ||
legend: { | ||
text: "Would you like to upload a new image?", | ||
isPageHeading: false, | ||
classes: "govuk-fieldset__legend--s", | ||
}, | ||
}, | ||
items: [ | ||
{ | ||
value: "true", | ||
text: "Yes - I would like to upload a new image", | ||
}, | ||
{ | ||
value: "false", | ||
text: "No - I am happy with the image", | ||
}, | ||
], | ||
}; | ||
|
||
constructor(model: FormModel, pageDef: Page, inputComponent: FormComponent) { | ||
super(model, pageDef); | ||
this.inputComponent = inputComponent; | ||
} | ||
|
||
/** | ||
* Gets the radio button view model for the "Would you like to upload a new image?" question | ||
* @param error - if the user hasn't chosen an option and tries to continue, add the required field error to the field | ||
* @returns the view model for the radio button component | ||
* */ | ||
getRetryUploadViewModel(error?: string) { | ||
if (error) { | ||
return { | ||
errorMessage: { | ||
text: error, | ||
}, | ||
...this.standardViewModel, | ||
}; | ||
} | ||
return this.standardViewModel; | ||
} | ||
|
||
makeGetRouteHandler() { | ||
return async (request: HapiRequest, h: HapiResponseToolkit) => { | ||
const { cacheService } = request.services([]); | ||
|
||
const state = await cacheService.getState(request); | ||
const { progress = [] } = state; | ||
let sectionTitle = this.section?.title; | ||
return h.view("upload-playback", { | ||
sectionTitle: sectionTitle, | ||
showTitle: true, | ||
pageTitle: "Check your image", | ||
backLink: progress[progress.length - 1] ?? this.backLinkFallback, | ||
radios: this.getRetryUploadViewModel(), | ||
}); | ||
}; | ||
} | ||
|
||
makePostRouteHandler() { | ||
return async (request: HapiRequest, h: HapiResponseToolkit) => { | ||
const { cacheService } = request.services([]); | ||
|
||
const state = await cacheService.getState(request); | ||
const { progress = [] } = state; | ||
const payload = request.payload; | ||
if (!payload.retryUpload) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we do a joi validation here? |
||
const errorText = "Select if you would like to continue"; | ||
const errors = { | ||
titleText: "Fix the following errors", | ||
errorList: [ | ||
{ | ||
text: errorText, | ||
href: "#retry-upload", | ||
}, | ||
], | ||
}; | ||
let sectionTitle = this.section?.title; | ||
return h.view("upload-playback", { | ||
sectionTitle: sectionTitle, | ||
showTitle: true, | ||
pageTitle: "Check your image", | ||
uploadErrors: errors, | ||
backLink: progress[progress.length - 2] ?? this.backLinkFallback, | ||
radios: this.getRetryUploadViewModel(errorText), | ||
}); | ||
} | ||
|
||
if (payload.retryUpload === "true") { | ||
return h.redirect(`/${this.model.basePath}${this.path}`); | ||
} | ||
|
||
delete payload.retryUpload; | ||
|
||
return super.makePostRouteHandler()(request, h); | ||
}; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
runner/src/server/plugins/engine/pageControllers/UploadPageController.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,54 @@ | ||
import { PageController } from "server/plugins/engine/pageControllers/PageController"; | ||
import { FormModel } from "server/plugins/engine/models"; | ||
import { HapiRequest, HapiResponseToolkit } from "server/types"; | ||
import { PlaybackUploadPageController } from "server/plugins/engine/pageControllers/PlaybackUploadPageController"; | ||
import { FormComponent } from "server/plugins/engine/components"; | ||
|
||
function isUploadField(component: FormComponent) { | ||
return component.type === "FileUploadField"; | ||
} | ||
|
||
export class UploadPageController extends PageController { | ||
playback: PlaybackUploadPageController; | ||
inputComponent: FormComponent; | ||
constructor(model: FormModel, pageDef: any) { | ||
super(model, pageDef); | ||
const inputComponent = this.components?.items?.find(isUploadField); | ||
if (!inputComponent) { | ||
throw Error( | ||
"UploadPageController initialisation failed, no file upload component was found" | ||
); | ||
} | ||
this.playback = new PlaybackUploadPageController( | ||
model, | ||
pageDef, | ||
inputComponent as FormComponent | ||
); | ||
this.inputComponent = inputComponent as FormComponent; | ||
} | ||
|
||
makeGetRouteHandler() { | ||
return async (request: HapiRequest, h: HapiResponseToolkit) => { | ||
const { query } = request; | ||
const { view } = query; | ||
|
||
if (view === "playback") { | ||
return this.playback.makeGetRouteHandler()(request, h); | ||
} | ||
|
||
return super.makeGetRouteHandler()(request, h); | ||
}; | ||
} | ||
|
||
makePostRouteHandler() { | ||
return async (request: HapiRequest, h: HapiResponseToolkit) => { | ||
const { query } = request; | ||
|
||
if (query?.view === "playback") { | ||
return this.playback.makePostRouteHandler()(request, h); | ||
} | ||
|
||
return super.makePostRouteHandler()(request, h); | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
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.
why do we need to declare twice?