Skip to content

Commit

Permalink
As a court officer I want to generate a Panel member status report (F…
Browse files Browse the repository at this point in the history
…E) (#380)

* do initial implementation of the panel members status report

* add large totals capabilities to printed reports and displayed reports

* update a header id for a new data_type
  • Loading branch information
ricardofreitasrocha authored May 24, 2024
1 parent 97096c1 commit 9dfc315
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 5 deletions.
4 changes: 4 additions & 0 deletions client/scss/mod-custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@
display: flex;
}

.mod-flex-grow {
flex-grow: 1;
}

.mod-items-start {
align-items: start;
}
Expand Down
20 changes: 20 additions & 0 deletions client/templates/reporting/standard-reports/standard-report.njk
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{% from "custom-components/autocomplete/macro.njk" import modAutocomplete %}
{% from "custom-components/date-picker/macro.njk" import datePicker %}
{% from "moj/components/banner/macro.njk" import mojBanner %}
{% from "custom-components/mod-large-tag/macro.njk" import modLargeTag %}

{% block page_title %}{{ serviceName }} - Reports - {{ title }}{% endblock %}
{% block page_identifier %}Reports - {{ title }}{% endblock %}
Expand Down Expand Up @@ -70,6 +71,25 @@
{% endfor %}
</div>

{% if largeTotals.length > 0 %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">

<div class="mod-flex mod-gap-x-2">
{% for largeTotal in largeTotals %}
{{ modLargeTag({
id: largeTotal.label,
classes: "govuk-!-margin-bottom-1 mod-large-tag__blue mod-flex-grow",
label: largeTotal.label,
value: largeTotal.value
})}}
{% endfor %}
</div>

</div>
</div>
{% endif %}

{% if bespokeReportFile %}
{% include bespokeReportFile %}
{% else %}
Expand Down
6 changes: 3 additions & 3 deletions client/templates/trial-management/trial-detail.njk
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@
},
{
text: "Panel list (summary)",
href: url("reports.panel-summary.report.get", {'filter': trial.trial_number}),
href: url("reports.panel-summary.report.get", { "filter": trial.trial_number }),
classes: "govuk-button--secondary"
},
{
text: "Panel list (detailed)",
href: url("reports.panel-detail.report.get", {'filter': trial.trial_number}),
href: url("reports.panel-detail.report.get", { "filter": trial.trial_number }),
classes: "govuk-button--secondary"
},
{
text: "Panel member status report",
href: "#",
href: url("reports.panel-members-status.report.get", { "filter": trial.trial_number }),
classes: "govuk-button--secondary"
},
{
Expand Down
9 changes: 9 additions & 0 deletions server/lib/reports/default-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@
font: 'LibreBarcode',
fontSize: 30,
},
largeTotalsLabel: {
fontSize: 10,
marginTop: 5,
bold: true,
},
largeTotalsValue: {
fontSize: 16,
marginBottom: 5,
},
},
};
};
Expand Down
6 changes: 6 additions & 0 deletions server/lib/reports/single-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@
return _tables;
};

const largeTotals = (data) => {
if (!data) return [];
return [data];
};

/**
* @typedef {object} Content
* @property {string} title document title to show on top of the document
Expand Down Expand Up @@ -194,6 +199,7 @@
const _documentContent = [
{ ...documentTitle(content.title) },
{ ...documentMetadata(content.metadata) },
...largeTotals(content.largeTotals),
...documentContent(content.tables),
];

Expand Down
27 changes: 26 additions & 1 deletion server/routes/reporting/standard-report/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const { dailyUtilisationDAO, dailyUtilisationJurorsDAO } = require('../../../obj
// groupHeader?: boolean, // display the group header or not.. in some reports we dont have to
// totals?: boolean, // same on this one.. some reports dont need the totals
// },
// printLandscape?: boolean,
// printLandscape: boolean, // force report printing to landscape
// largeTotals?: (data) => {label: string, value: string}[], // large totals for the report
// }};
module.exports.reportKeys = (app, req = null) => {
const courtUser = req ? isCourtUser(req) : false;
Expand Down Expand Up @@ -367,6 +368,30 @@ const { dailyUtilisationDAO, dailyUtilisationJurorsDAO } = require('../../../obj
totals: true,
},
},
'panel-members-status': {
title: 'Panel members status report',
apiKey: 'PanelMembersStatusReport',
search: 'trial',
headings: [
'trialNumber',
'reportDate',
'names',
'reportTime',
'courtRoom',
'courtName',
'judge',
],
largeTotals: (data) => {
return [
{ label: 'Panelled', value: data.length },
{ label: 'Empanelled', value: data.filter(juror => juror.panelStatus === 'Juror').length },
// eslint-disable-next-line max-len
{ label: 'Not used', value: data.filter(juror => (juror.panelStatus === 'Not Used' || juror.panelStatus === 'Returned')).length },
{ label: 'Challenged', value: data.filter(juror => juror.panelStatus === 'Challenged').length },
{ label: 'Returned jurors', value: data.filter(juror => juror.panelStatus === 'Returned').length },
];
},
},
};
};
})();
1 change: 1 addition & 0 deletions server/routes/reporting/standard-report/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
standardReportRoutes(app, 'daily-utilisation');
standardReportRoutes(app, 'daily-utilisation-jurors');
standardReportRoutes(app, 'unconfirmed-attendance');
standardReportRoutes(app, 'panel-members-status');
};

})();
34 changes: 34 additions & 0 deletions server/routes/reporting/standard-report/standard-report-print.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,39 @@ async function standardReportPrint(app, req, res, reportKey, data) {
];
}

const buildLargeTotals = () => {
if (!reportData.largeTotals) return {};

const body = reportData.largeTotals(tableData.data).reduce((acc, total) => {
acc.push(
{
border: [false, false, false, false],
fillColor: '#eeeeee',
marginLeft: 5,
stack: [
{
text: total.label,
style: 'largeTotalsLabel',
},
{
text: total.value,
style: 'largeTotalsValue',
},
],
}
);
return acc;
}, []);

return {
margin: [0, 20, 0, -20],
table: {
widths: Array(body.length).fill('*'),
body: [body],
},
};
};

try {
const document = await generateDocument({
title: reportData.title,
Expand All @@ -131,6 +164,7 @@ async function standardReportPrint(app, req, res, reportKey, data) {
left: [...buildReportHeadings(reportData.headings.filter((v, index) => index % 2 === 0)).filter(item => item)],
right: [...buildReportHeadings(reportData.headings.filter((v, index) => index % 2 === 1)).filter(item => item)],
},
largeTotals: buildLargeTotals(),
tables: reportBody,
}, {
pageOrientation: reportData.printLandscape ? 'landscape' : 'portrait',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
let row = tableHeadings.map(header => {
let output = tableDataMappers[header.dataType](data[snakeToCamel(header.id)]);

if (header.id === 'juror_number') {
if (header.id === 'juror_number' || header.id === 'juror_number_from_trial') {
return ({
html: `<a href=${
app.namedRoutes.build('juror-record.overview.get', {jurorNumber: output})
Expand Down Expand Up @@ -380,6 +380,7 @@
url: buildBackLinkUrl(),
},
bannerMessage,
largeTotals: reportType.largeTotals ? reportType.largeTotals(tableData.data) : [],
});
} catch (e) {
console.error(e);
Expand Down

0 comments on commit 9dfc315

Please sign in to comment.