-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace view licence contact details page (#1238)
* Replace view licence contact details page https://eaflood.atlassian.net/browse/WATER-4559 We recently rebuilt the legacy view licence page, implementing the new version in our shiny new codebase water-abstraction-system. Substantial changes needed to be made to support the return requirements, so this was a great opportunity to also deal with the tech debt of the legacy view licence page. One of the pages that is linked to from the summary tab is the view licence contacts page. If we move that into our code base, we make another small dent in moving away from the legacy code.
- Loading branch information
Showing
17 changed files
with
755 additions
and
101 deletions.
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
91 changes: 91 additions & 0 deletions
91
app/presenters/licences/view-licence-contact-details.presenter.js
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,91 @@ | ||
'use strict' | ||
|
||
/** | ||
* Formats data for the `/licences/{id}/licence-contact` view licence contact details link page | ||
* @module ViewLicenceContactDetailsPresenter | ||
*/ | ||
|
||
/** | ||
* Formats data for the `/licences/{id}/licence-contact` view licence contact details link page | ||
* | ||
* @param {module:LicenceModel} licence - The licence and related licenceDocumentHeader | ||
* | ||
* @returns {object} The data formatted for the view template | ||
*/ | ||
function go (licence) { | ||
const { id: licenceId, licenceDocumentHeader, licenceRef } = licence | ||
|
||
return { | ||
licenceId, | ||
licenceRef, | ||
licenceContactDetails: _licenceContactDetails(licenceDocumentHeader), | ||
pageTitle: 'Licence contact details' | ||
} | ||
} | ||
|
||
function _licenceContactAddress (contact) { | ||
const contactAddressFields = [ | ||
'addressLine1', | ||
'addressLine2', | ||
'addressLine3', | ||
'addressLine4', | ||
'town', | ||
'county', | ||
'postcode', | ||
'country' | ||
] | ||
|
||
// NOTE: Maps over the `contactAddressFields` array to create an array of values from the `contact` object. Each | ||
// `contactAddressField` corresponds to a property in the `contact` object, mapping and creating a contactAddress | ||
// array. The `filter(Boolean)` function then removes falsy values from the `contactAddress` array. | ||
const contactAddress = contactAddressFields.map((contactAddressField) => { | ||
return contact[contactAddressField] | ||
}).filter(Boolean) | ||
|
||
return contactAddress | ||
} | ||
|
||
function _licenceContactName (contact) { | ||
if (contact.type === 'Person') { | ||
const { salutation, forename, initials, name } = contact | ||
|
||
// NOTE: Prioritise the initials and use the contact forename if initials is null | ||
const initialsOrForename = initials || forename | ||
|
||
const nameComponents = [ | ||
salutation, | ||
initialsOrForename, | ||
name | ||
] | ||
|
||
const filteredNameComponents = nameComponents.filter((item) => { | ||
return item | ||
}) | ||
|
||
return filteredNameComponents.join(' ') | ||
} | ||
|
||
return contact.name | ||
} | ||
|
||
function _licenceContactDetails (licenceDocumentHeader) { | ||
const licenceContactDetailsData = licenceDocumentHeader.metadata.contacts | ||
|
||
const roles = ['Licence holder', 'Returns to', 'Licence contact'] | ||
|
||
const filteredContactDetails = licenceContactDetailsData.filter((licenceContactDetail) => { | ||
return roles.includes(licenceContactDetail.role) | ||
}) | ||
|
||
return filteredContactDetails.map((contact) => { | ||
return { | ||
address: _licenceContactAddress(contact), | ||
role: contact.role, | ||
name: _licenceContactName(contact) | ||
} | ||
}) | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
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
42 changes: 42 additions & 0 deletions
42
app/services/licences/fetch-licence-contact-details.service.js
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,42 @@ | ||
'use strict' | ||
|
||
/** | ||
* Fetches data needed for the view '/licences/{id}/licence-contact` page | ||
* @module FetchLicenceContactDetailsService | ||
*/ | ||
|
||
const LicenceModel = require('../../models/licence.model.js') | ||
|
||
/** | ||
* Fetch the matching licence and return data needed for the licence contact details link page | ||
* | ||
* Was built to provide the data needed for the '/licences/{id}/licence-contact' page | ||
* | ||
* @param {string} licenceId - The UUID for the licence to fetch | ||
* | ||
* @returns {Promise<module:LicenceModel>} the matching `licenceModel` populated with the data needed for the view | ||
* licence contact details page | ||
*/ | ||
async function go (licenceId) { | ||
return _fetch(licenceId) | ||
} | ||
|
||
async function _fetch (licenceId) { | ||
return LicenceModel.query() | ||
.findById(licenceId) | ||
.select([ | ||
'id', | ||
'licenceRef' | ||
]) | ||
.withGraphFetched('licenceDocumentHeader') | ||
.modifyGraph('licenceDocumentHeader', (builder) => { | ||
builder.select([ | ||
'id', | ||
'metadata' | ||
]) | ||
}) | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
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
33 changes: 10 additions & 23 deletions
33
app/services/licences/view-licence-contact-details.service.js
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,41 @@ | ||
'use strict' | ||
|
||
/** | ||
* Orchestrates fetching and presenting the data needed for the view licence contact details tab | ||
* @module ViewLicenceContactsService | ||
*/ | ||
|
||
const CustomerContactsPresenter = require('../../presenters/licences/customer-contacts.presenter.js') | ||
const FetchCustomerContactsService = require('./fetch-customer-contacts.service.js') | ||
const FetchLicenceContactsService = require('./fetch-licence-contacts.service.js') | ||
const LicenceContactsPresenter = require('../../presenters/licences/licence-contacts.presenter.js') | ||
const ViewLicenceService = require('./view-licence.service.js') | ||
|
||
/** | ||
* Orchestrates fetching and presenting the data needed for the licence contact details page | ||
* | ||
* @param {string} licenceId - The UUID of the licence | ||
* @param {object} auth - The auth object taken from `request.auth` containing user details | ||
* | ||
* @returns {Promise<object>} an object representing the `pageData` needed by the licence contact details template. | ||
*/ | ||
async function go (licenceId, auth) { | ||
const commonData = await ViewLicenceService.go(licenceId, auth) | ||
|
||
const licenceContacts = await FetchLicenceContactsService.go(licenceId) | ||
const licenceContactsData = LicenceContactsPresenter.go(licenceContacts) | ||
|
||
const customerContacts = await FetchCustomerContactsService.go(licenceId) | ||
const customerContactsData = CustomerContactsPresenter.go(customerContacts) | ||
|
||
return { | ||
activeTab: 'contact-details', | ||
...commonData, | ||
...customerContactsData, | ||
...licenceContactsData | ||
} | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
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 @@ | ||
{% extends 'layout.njk' %} | ||
{% from "govuk/components/back-link/macro.njk" import govukBackLink %} | ||
{% from "govuk/components/summary-list/macro.njk" import govukSummaryList %} | ||
|
||
{% block breadcrumbs %} | ||
{{ govukBackLink({ | ||
text: 'Back to summary', | ||
href: '/system/licences/' + licenceId + '/summary' | ||
}) }} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<h1 class="govuk-heading-l"> | ||
<span class="govuk-caption-l">Licence {{ licenceRef }}</span> | ||
{{ pageTitle }} | ||
</h1> | ||
|
||
{% macro displayAddress(address) %} | ||
{% for item in address %} | ||
<p class="govuk-body govuk-!-margin-bottom-0"> {{ item }} </p> | ||
{% endfor %} | ||
{% endmacro %} | ||
|
||
{% for licenceContactDetail in licenceContactDetails %} | ||
{{ govukSummaryList({ | ||
card: { | ||
title: { | ||
text: licenceContactDetail.role | ||
} | ||
}, | ||
rows: [ | ||
{ | ||
key: { | ||
text: "Name", | ||
classes:"govuk-!-font-weight-regular" | ||
}, | ||
value: { | ||
text: licenceContactDetail.name | ||
} | ||
}, | ||
{ | ||
key: { | ||
text: "Address", | ||
classes:"govuk-!-font-weight-regular" | ||
}, | ||
value: { | ||
html: displayAddress(licenceContactDetail.address) | ||
} | ||
} | ||
] | ||
}) | ||
}} | ||
{% endfor %} | ||
{% endblock %} |
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.