-
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.
Add View License Returns page (#967)
https://eaflood.atlassian.net/browse/WATER-4444 The existing service handling view license is slow because it loads all the data for the tabs in one render. Work has been done previously to refactor the summary page to load only the summary information. This change will introduce a returns controller, service and presenter to handle the view license returns page. This will share the same view as the summary page and load the same 'common data' established in [previous work](#957). --------- Co-authored-by: Alan Cruikshanks <[email protected]>
- Loading branch information
1 parent
f1c4f95
commit 16caae5
Showing
23 changed files
with
555 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use strict' | ||
|
||
/** | ||
* Formats common data for the `/licences/{id}/*` view licence pages | ||
* @module ViewLicenceReturnsPresenter | ||
*/ | ||
|
||
const { formatLongDate } = require('../base.presenter') | ||
|
||
/** | ||
* Formats common data for the `/licences/{id}/*` view licence pages | ||
* | ||
* @returns {Object} The data formatted for the view template | ||
*/ | ||
function go (returnsData) { | ||
const returns = _formatReturnToTableRow(returnsData.returns) | ||
|
||
return { | ||
activeTab: 'returns', | ||
returns | ||
} | ||
} | ||
|
||
function _formatPurpose (purpose) { | ||
const [firstPurpose] = purpose | ||
|
||
return firstPurpose.alias ? firstPurpose.alias : firstPurpose.tertiary.description | ||
} | ||
|
||
function _formatReturnToTableRow (returns) { | ||
return returns.map((r) => { | ||
return { | ||
dates: `${formatLongDate(new Date(r.startDate))} to ${formatLongDate(new Date(r.endDate))}`, | ||
description: r.metadata.description, | ||
dueDate: formatLongDate(new Date(r.dueDate)), | ||
id: r.id, | ||
purpose: _formatPurpose(r.metadata.purposes), | ||
reference: r.returnReference, | ||
status: _formatStatus(r.status) | ||
} | ||
}) | ||
} | ||
|
||
function _formatStatus (status) { | ||
if (status === 'completed') { | ||
return 'COMPLETE' | ||
} | ||
|
||
if (status === 'due') { | ||
return 'OVERDUE' | ||
} | ||
|
||
return 'NO STATUS' | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
File renamed without changes.
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,46 @@ | ||
'use strict' | ||
|
||
/** | ||
* Fetches all return logs for a licence which is needed for the view '/licences/{id}/returns` page | ||
* @module FetchLicenceReturnsService | ||
*/ | ||
|
||
const ReturnLogModel = require('../../models/return-log.model') | ||
|
||
const DatabaseConfig = require('../../../config/database.config') | ||
|
||
/** | ||
* Fetches all return logs for a licence which is needed for the view '/licences/{id}/returns` page | ||
* | ||
* @param {string} licenceId - The UUID for the licence to fetch | ||
* | ||
* @returns {Promise<Object>} the data needed to populate the view licence page's returns tab | ||
*/ | ||
async function go (licenceId, page) { | ||
const { results, total } = await _fetch(licenceId, page) | ||
|
||
return { returns: results, pagination: { total } } | ||
} | ||
|
||
async function _fetch (licenceId, page) { | ||
return ReturnLogModel.query() | ||
.select([ | ||
'returnLogs.id', | ||
'returnLogs.dueDate', | ||
'returnLogs.endDate', | ||
'returnLogs.metadata', | ||
'returnLogs.returnReference', | ||
'returnLogs.startDate', | ||
'returnLogs.status' | ||
]) | ||
.innerJoinRelated('licence') | ||
.where('licence.id', licenceId) | ||
.orderBy([ | ||
{ column: 'dueDate', order: 'desc' } | ||
]) | ||
.page(page - 1, DatabaseConfig.defaultPageSize) | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
File renamed without changes.
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,37 @@ | ||
'use strict' | ||
|
||
/** | ||
* Orchestrates fetching and presenting the data needed for the licence summary page | ||
* @module ViewLicenceSummaryService | ||
*/ | ||
|
||
const FetchLicenceReturnsService = require('./fetch-licence-returns.service') | ||
const ViewLicenceService = require('./view-licence.service') | ||
const ViewLicenceReturnsPresenter = require('../../presenters/licences/view-licence-returns.presenter') | ||
const PaginatorPresenter = require('../../presenters/paginator.presenter') | ||
|
||
/** | ||
* Orchestrates fetching and presenting the data needed for the licence summary page | ||
* | ||
* @param {string} licenceId - The UUID of the licence | ||
* | ||
* @returns {Promise<Object>} an object representing the `pageData` needed by the licence summary template. | ||
*/ | ||
async function go (licenceId, auth, page) { | ||
const commonData = await ViewLicenceService.go(licenceId, auth) | ||
|
||
const returnsData = await FetchLicenceReturnsService.go(licenceId, page) | ||
const pageData = ViewLicenceReturnsPresenter.go(returnsData) | ||
|
||
const pagination = PaginatorPresenter.go(returnsData.pagination.total, Number(page), `/system/licences/${licenceId}/returns`) | ||
|
||
return { | ||
...pageData, | ||
...commonData, | ||
pagination | ||
} | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{% from "govuk/components/pagination/macro.njk" import govukPagination %} | ||
{% from "govuk/components/table/macro.njk" import govukTable %} | ||
{% from "govuk/components/tag/macro.njk" import govukTag %} | ||
|
||
{% macro formatStatus(status) %} | ||
{% if status === 'COMPLETE' %} | ||
{{ govukTag({ | ||
text: status, | ||
classes: "govuk-tag--green" | ||
}) }} | ||
|
||
{% elseif status === 'OVERDUE' %} | ||
{{ govukTag({ | ||
text: status, | ||
classes: "govuk-tag--red" | ||
}) }} | ||
{% else %} | ||
{{ status }} | ||
{% endif %} | ||
{% endmacro %} | ||
|
||
<table class="govuk-table"> | ||
<h2 class="govuk-heading-l">Returns</h2> | ||
{% if returns %} | ||
<thead class="govuk-table__head"> | ||
<tr class="govuk-table__row"> | ||
<th scope="col" class="govuk-table__header">Return reference and dates</th> | ||
<th scope="col" class="govuk-table__header">Purpose and description</th> | ||
<th scope="col" class="govuk-table__header">Due date</th> | ||
<th scope="col" class="govuk-table__header">Status</th> | ||
</tr> | ||
</thead> | ||
<tbody class="govuk-table__body"> | ||
{% for return in returns %} | ||
<tr class="govuk-table__row govuk-body-s"> | ||
<th class="govuk-table__cell"> | ||
<a href="/return/internal?returnId={{ return.id }}" class="govuk-link">{{ return.reference }} </a> | ||
<p class="govuk-body-s"> {{ return.dates }}</p> | ||
</th> | ||
<td class="govuk-table__cell">{{ return.purpose }} <p class="govuk-body-s"> {{ return.description }}</p></td> | ||
<td class="govuk-table__cell">{{ return.dueDate }}</td> | ||
<td class="govuk-table__cell">{{ formatStatus(return.status) }}</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
{% else %} | ||
<p>No returns found</p> | ||
{% endif %} | ||
</table> | ||
|
||
{% if returns and pagination.numberOfPages > 1 %} | ||
{{ govukPagination(pagination.component) }} | ||
{% endif %} | ||
|
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
Oops, something went wrong.