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

JS-124 - Move Dismiss jurors to pool management #849

Merged
merged 6 commits into from
Dec 3, 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
49 changes: 37 additions & 12 deletions client/js/dismiss-jurors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

var csrfToken = $('#csrfToken');
var totalCheckedPools = $('#total-checked-pools');
var totalPools = $('#total-pools-count')
var checkAllPools = $('#check-all-pools');
var poolRows = $('input[aria-label^=check-pool]');
var checkAllJurors = $('#check-all-jurors');
Expand All @@ -12,46 +13,70 @@

// pools related logic
if (checkAllPools && checkAllPools.length) {
if (totalCheckedPools.text() === totalPools.text()) {
checkAllPools[0].checked = true;
}
checkAllPools[0].addEventListener('change', function() {
var isCheckingAll = this.checked;

poolRows.each(function(_, element) {
element.checked = isCheckingAll;
});
checkPoolRequest(this.id, isCheckingAll).then(function() {
poolRows.each(function(_, element) {
element.checked = isCheckingAll;
});

totalCheckedPools.text(isCheckingAll ? poolRows.length : '0');
totalCheckedPools.text(isCheckingAll ? totalPools.text() : '0');
});
});
}

if (poolRows && poolRows.length) {
poolRows.each(function(_, element) {
element.addEventListener('change', function() {
if (this.checked) {
element.addEventListener('change', async function() {
var poolNumber = this.id.split('-')[1];
var isCheckingPool = this.checked;

await checkPoolRequest(poolNumber, isCheckingPool);

if (isCheckingPool) {
totalCheckedPools.text(+totalCheckedPools.text() + 1);
} else {
totalCheckedPools.text(+totalCheckedPools.text() - 1);
}
updateCheckAllPoolsCheckbox(this.checked);

updateCheckAllPoolsCheckbox(isCheckingPool);
});
});
}

function updateCheckAllPoolsCheckbox(checking) {
if (checking) {
if (+totalCheckedPools.text() === poolRows.length) {
if (totalCheckedPools.text() === totalPools.text()) {
checkAllPools[0].checked = true;
}
} else {
checkAllPools[0].checked = false;
}
}

function checkPoolRequest(poolNumber, isChecking) {
var action = isChecking ? 'check' : 'uncheck';

return $.ajax({
url: '/pool-management/dismiss-jurors/pools/check?poolNumber=' + poolNumber + '&action=' + action,
method: 'POST',
data: {
_csrf: csrfToken.val(),
},
});
}


// jurors related logic
if (checkAllJurors && checkAllJurors.length) {
checkAllJurors[0].addEventListener('change', function() {
var isCheckingAll = this.checked;

request(this.id, isCheckingAll).then(function() {
checkJurorRequest(this.id, isCheckingAll).then(function() {
jurorRows.each(function(_, element) {
element.checked = isCheckingAll;
});
Expand All @@ -67,7 +92,7 @@
var jurorNumber = this.id.split('-')[1];
var isCheckingJuror = this.checked;

await request(jurorNumber, isCheckingJuror);
await checkJurorRequest(jurorNumber, isCheckingJuror);

if (isCheckingJuror) {
totalCheckedJurors.text(+totalCheckedJurors.text() + 1);
Expand All @@ -90,11 +115,11 @@
}
}

function request(jurorNumber, isChecking) {
function checkJurorRequest(jurorNumber, isChecking) {
var action = isChecking ? 'check' : 'uncheck';

return $.ajax({
url: '/juror-management/dismiss-jurors/jurors/check?jurorNumber=' + jurorNumber + '&action=' + action,
url: '/pool-management/dismiss-jurors/jurors/check?jurorNumber=' + jurorNumber + '&action=' + action,
method: 'POST',
data: {
_csrf: csrfToken.val(),
Expand Down
5 changes: 0 additions & 5 deletions client/templates/juror-management/manage-jurors.njk
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
classes: "govuk-button--secondary",
href: url('create-juror-record.get')
}) }}
{{ govukButton({
text: "Dismiss jurors",
classes: "govuk-button--secondary",
href: url('juror-management.dismiss-jurors.pools.get')
}) }}
{% endif %}
{{ govukButton({
text: "Refresh",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"/pool-management/summoning-progress"
]
%}
{% set courtOnlyRoutes = [
"/pool-management/dismiss-jurors/pools"
]
%}

{% set allNavBarElements = [
{
Expand Down Expand Up @@ -50,6 +54,14 @@
id: "summoningProgressAnchor"
}
},
{
text: "Dismiss jurors",
href: '/pool-management/dismiss-jurors/pools',
active: false,
attributes: {
id: "dismissJurorsAnchor"
}
},
{
text: "Search",
href: "/pool-management/search",
Expand All @@ -66,6 +78,10 @@
{% if authentication.owner === "400" %}
{% set navBarElements = (navBarElements.push(item), navBarElements) %}
{% endif %}
{% elif courtOnlyRoutes.includes(item.href)%}
{% if authentication.owner !== "400" %}
{% set navBarElements = (navBarElements.push(item), navBarElements) %}
{% endif %}
{% else %}
{% set navBarElements = (navBarElements.push(item), navBarElements) %}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{% from "custom-components/time-input-12-hour/macro.njk" import timeInput12Hour %}
{% from "includes/csrf.njk" import csrfProtection %}

{% block page_title %}{{ serviceName }} - Juror management - Dismiss jurors - Check out{% endblock %}
{% block page_identifier %}Juror management - Dismiss jurors - Check out{% endblock %}
{% block page_title %}{{ serviceName }} - Pool management - Dismiss jurors - Check out{% endblock %}
{% block page_identifier %}Pool management - Dismiss jurors - Check out{% endblock %}

{% block content %}

Expand All @@ -22,7 +22,7 @@

{% include "includes/errors.njk" %}

<form action="{{ url('juror-management.dismiss-jurors.check-out.post') }}" method="POST">
<form action="{{ url('pool-management.dismiss-jurors.check-out.post') }}" method="POST">

{{ govukTable({
caption: "Some jurors have not been checked out",
Expand Down Expand Up @@ -99,7 +99,7 @@
type: "submit"
}) }}

<a class="govuk-link" href="{{ url('juror-management.dismiss-jurors.jurors.get') }}">
<a class="govuk-link" href="{{ url('pool-management.dismiss-jurors.jurors.get') }}">
Back to select jurors
</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
{% from "govuk/components/button/macro.njk" import govukButton %}
{% from "includes/csrf.njk" import csrfProtection %}

{% block page_title %}{{ serviceName }} - Juror management - Complete service{% endblock %}
{% block page_identifier %}Juror management - Complete service{% endblock %}
{% block page_title %}{{ serviceName }} - Pool management - Complete service{% endblock %}
{% block page_identifier %}Pool management - Complete service{% endblock %}

{% block content %}

Expand All @@ -16,7 +16,7 @@

{% include "includes/errors.njk" %}

<form action="{{ url('juror-management.dismiss-jurors.complete-service.post') }}" method="POST">
<form action="{{ url('pool-management.dismiss-jurors.complete-service.post') }}" method="POST">

<h1 class="govuk-heading-l">Complete service</h1>

Expand All @@ -40,7 +40,7 @@
type: "submit"
}) }}

<a class="govuk-link" href="{{ url('juror-management.dismiss-jurors.pools.get') }}">Cancel</a>
<a class="govuk-link" href="{{ url('pool-management.dismiss-jurors.pools.get') }}">Cancel</a>
</div>

</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
{% from "govuk/components/pagination/macro.njk" import govukPagination %}
{% from "includes/csrf.njk" import csrfProtection %}

{% block page_title %}{{ serviceName }} - Juror management - Dismiss jurors - Jurors{% endblock %}
{% block page_identifier %}Juror management - Dismiss jurors - Jurors{% endblock %}
{% block page_title %}{{ serviceName }} - Pool management - Dismiss jurors - Jurors{% endblock %}
{% block page_identifier %}Pool management - Dismiss jurors - Jurors{% endblock %}

{% block beforeContent %}
{% include "includes/back-link.njk" %}
Expand Down Expand Up @@ -42,7 +42,7 @@
items: pagination.items
}) }}

{% set postAction = url("juror-management.dismiss-jurors.jurors.post") %}
{% set postAction = url("pool-management.dismiss-jurors.jurors.post") %}
<form action="{{ postAction }}" method="POST">
{{ csrfProtection(csrftoken) }}

Expand All @@ -52,7 +52,7 @@
type: "submit"
}) }}

<a class="govuk-link" href="{{ url('juror-management.dismiss-jurors.pools.get') }}">Cancel</a>
<a class="govuk-link" href="{{ url('pool-management.dismiss-jurors.pools.get') }}">Cancel</a>
</div>
</form>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
{% from "govuk/components/checkboxes/macro.njk" import govukCheckboxes %}
{% from "govuk/components/input/macro.njk" import govukInput %}
{% from "includes/csrf.njk" import csrfProtection %}
{% from "custom-components/sortable-table/macro.njk" import modSortableTable %}
{% from "govuk/components/pagination/macro.njk" import govukPagination %}

{% block page_title %}{{ serviceName }} - Juror management - Dismiss jurors - Pools{% endblock %}
{% block page_identifier %}Juror management - Dismiss jurors - Pools{% endblock %}
{% block page_title %}{{ serviceName }} - Pool management - Dismiss jurors - Pools{% endblock %}
{% block page_identifier %}Pool management - Dismiss jurors - Pools{% endblock %}

{% block content %}
{% set actionUrl = url("juror-management.dismiss-jurors.pools.post") %}
{% set cancelUrl = url("juror-management.manage-jurors.pools.get") %}
{% set actionUrl = url("pool-management.dismiss-jurors.pools.post") %}
{% set cancelUrl = url("pool-management.get") + "?status=created" %}


{% set jurorsToDismissError = undefined %}
{% if errors.items["jurorsToDismiss"] %}
Expand Down Expand Up @@ -63,7 +66,32 @@
</p>
{% endif %}

{% include "./pools-table.njk" %}
{% if totalPools > 0 %}
<div class="govuk-caption-m">
<span id="total-checked-pools">{{ totalCheckedPools }}</span> of <span id="total-pools-count">{{ totalPools }}</span> selected
</div>

{{ modSortableTable({
id: "poolsTable",
caption: "Pool list",
captionClasses: "govuk-visually-hidden",
head: poolsTable.head,
rows: poolsTable.rows
}) }}

{{ govukPagination({
previous: {
href: pageItems.prev
},
next: {
href: pageItems.next
},
items: pageItems.items
}) }}
{% else %}
<p class="govuk-body">No pools currently available to dismiss jurors from</p>
{% endif %}

</div>

<h2 class="govuk-heading-m">Number of available jurors from selected pools</h2>
Expand Down
9 changes: 9 additions & 0 deletions client/templates/pool-management/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{% from "govuk/components/button/macro.njk" import govukButton %}
{% from "moj/components/banner/macro.njk" import mojBanner %}
{% from "custom-components/sortable-table/macro.njk" import modSortableTable %}
{% from "moj/components/banner/macro.njk" import mojBanner %}

{% set currentApp = "Pool management" %}

Expand Down Expand Up @@ -41,6 +42,14 @@
}) }}
{% endif %}

{% if bannerMessage %}
{{ mojBanner({
type: "success",
text: bannerMessage,
iconFallbackText: "Success"
}) }}
{% endif %}

<div class="govuk-grid-row">
<div class="govuk-grid-column-one-half">
<h1 class="govuk-heading-l">{{ "Pool requests" if poolStatus === "requested" else "Active pools" }}</h1>
Expand Down
9 changes: 0 additions & 9 deletions server/config/validation/dismiss-jurors.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ module.exports.jurorsToDismiss = (jurorsAvailable) => {
jurorsAvailable,
},
},
'checked-pools': {
presence: {
allowEmpty: false,
message: {
details: 'Select at least one pool',
summary: 'Select at least one pool',
},
},
},
};
};

Expand Down
9 changes: 9 additions & 0 deletions server/objects/dismiss-jurors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
const { DAO } = require('./dataAccessObject');
const utils = require('../lib/utils');

module.exports.getDismissablePools = new DAO('moj/pool-request/active-pools-by-court', {
get: function(locCode) {
return {
uri: this.resource + '?locCode=' + locCode,
transform: utils.basicDataTransform
}
}
});

module.exports.getJurorsObject = new DAO('moj/juror-management/jurors-to-dismiss', {
post: function(params, locCode) {
const jurorsToInclude = params['jurors-to-include'] instanceof Array
Expand Down
Loading