Skip to content
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

Fix missing view licence returns status tags #1110

Merged
merged 6 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions app/presenters/licences/view-licence-returns.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,36 @@ function _formatPurpose (purpose) {
}

function _formatReturnToTableRow (returns) {
return returns.map((r) => {
return returns.map((returnLog) => {
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)
dates: `${formatLongDate(new Date(returnLog.startDate))} to ${formatLongDate(new Date(returnLog.endDate))}`,
description: returnLog.metadata.description,
dueDate: formatLongDate(new Date(returnLog.dueDate)),
id: returnLog.id,
purpose: _formatPurpose(returnLog.metadata.purposes),
reference: returnLog.returnReference,
status: _formatStatus(returnLog)
}
})
}

function _formatStatus (status) {
function _formatStatus (returnLog) {
const { status, dueDate } = returnLog

// If the return is completed we are required to display it as 'complete'. This also takes priority over the other
// statues
if (status === 'completed') {
return 'COMPLETE'
return 'complete'
}

if (status === 'due') {
return 'OVERDUE'
// Work out if the return is overdue (status is still 'due' and it is past the due date)
const today = new Date()
if (status === 'due' && dueDate < today) {
return 'overdue'
}

return 'NO STATUS'
// For all other cases we can just return the status and the return-status-tag macro will know how to display it
return status
}

function _noReturnsMessage (hasReturns, hasRequirements) {
Expand Down
4 changes: 2 additions & 2 deletions app/services/licences/fetch-licence-returns.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* @module FetchLicenceReturnsService
*/

const ReturnLogModel = require('../../models/return-log.model')
const ReturnLogModel = require('../../models/return-log.model.js')

const DatabaseConfig = require('../../../config/database.config')
const DatabaseConfig = require('../../../config/database.config.js')

/**
* Fetches all return logs for a licence which is needed for the view '/licences/{id}/returns` page
Expand Down
25 changes: 6 additions & 19 deletions app/views/licences/tabs/returns.njk
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
{% 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 %}
{% from "macros/return-status-tag.njk" import statusTag %}

<h2 class="govuk-heading-l">Returns</h2>

Expand All @@ -33,6 +17,10 @@
{% set returnRows = [] %}

{% for returnItem in returns %}
{% set returnStatusTag %}
{{ statusTag(returnItem.status, true) }}
{% endset %}

{% set returnRows = (returnRows.push([
{
html: referenceColumn(returnItem)
Expand All @@ -44,7 +32,7 @@
text: returnItem.dueDate
},
{
html: formatStatus(returnItem.status)
html: returnStatusTag
}
]), returnRows) %}
{% endfor %}
Expand All @@ -71,4 +59,3 @@
{% if pagination.numberOfPages > 1 %}
{{ govukPagination(pagination.component) }}
{% endif %}

30 changes: 30 additions & 0 deletions app/views/macros/return-status-tag.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% from "govuk/components/tag/macro.njk" import govukTag %}

{% macro statusTag(status, inline=false) %}
{% if status === 'overdue' %}
{% set color = 'govuk-tag--orange' %}
{% elif status === 'void' %}
{% set color = 'govuk-tag--grey' %}
{% elif status === 'due' %}
{% set color = 'govuk-tag--blue' %}
{% elif status === 'received' %}
{% set color = 'govuk-tag--green' %}
{% elif status === 'complete' %}
{% set color = 'govuk-tag--green' %}
{% else %}
{% set color = 'govuk-tag--blue' %}
{% endif %}

{% if inline %}
{% set fontSize = "" %}
{% else %}
{% set fontSize = "govuk-!-font-size-27" %}
{% endif %}

{{
govukTag({
text: status,
classes: color + ' ' + fontSize
})
}}
{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ describe('View Licence returns presenter', () => {

const returnItem = {
id: 'mock-id-1',
dueDate: '2012-11-28T00:00:00.000Z',
dueDate: new Date('2012-11-28'),
status: 'completed',
startDate: '2020/01/02',
endDate: '2020/02/01',
startDate: new Date('2020/01/02'),
endDate: new Date('2020/02/01'),
metadata: {
purposes: [
{
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('View Licence returns presenter', () => {
reference: '1068',
purpose: 'SPRAY IRRIGATION',
dueDate: '28 November 2012',
status: 'COMPLETE',
status: 'complete',
dates: '2 January 2020 to 1 February 2020',
description: 'empty description'
},
Expand All @@ -78,7 +78,7 @@ describe('View Licence returns presenter', () => {
reference: '1069',
purpose: 'SPRAY IRRIGATION',
dueDate: '28 November 2012',
status: 'OVERDUE',
status: 'overdue',
dates: '2 January 2020 to 1 February 2020',
description: 'empty description'
}
Expand Down
Loading