Skip to content
Draft
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
37 changes: 30 additions & 7 deletions app/assets/javascript/add-another.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Component } from 'nhsuk-frontend'
* - Add `data-add-another-item="N"` to each item section (where N is the item index: 1, 2, 3, etc.)
* - Add `data-add-another-add` to the "Add another" button (hidden by default)
* - Add `data-add-another-remove="N"` to the "Remove" button within each section (hidden by default)
* - Optionally add `data-add-another-min="0"` to allow starting with no items visible (default is 1)
*
* @augments Component<HTMLElement>
*/
Expand All @@ -29,11 +30,13 @@ export class AddAnother extends Component {
this.$items = Array.from(this.$root.querySelectorAll('[data-add-another-item]'))
this.$addButton = this.$root.querySelector('[data-add-another-add]')
this.$addButtonWrapper = this.$addButton?.closest('.nhsuk-button-group')
this.minItems = parseInt(this.$root.dataset.addAnotherMin ?? '1', 10)

this.initializeItemVisibility()
this.setupAddButton()
this.setupRemoveButtons()
this.updateAddButtonVisibility()
this.updateAddButtonText()
this.updateRemoveButtonVisibility()
}

Expand Down Expand Up @@ -71,17 +74,18 @@ export class AddAnother extends Component {
*/
initializeItemVisibility() {
// Find the last item with values
let lastFilledIndex = 0
let lastFilledIndex = -1
this.$items.forEach(($item, index) => {
if (this.hasInputValues($item)) {
lastFilledIndex = index
}
})

// Show items up to and including the last filled one (minimum 1)
// Show items up to and including the last filled one (respecting minItems)
// Hide all items after that
const minVisibleIndex = this.minItems - 1
this.$items.forEach(($item, index) => {
if (index <= lastFilledIndex) {
if (index <= lastFilledIndex || index <= minVisibleIndex) {
$item.hidden = false
} else {
$item.hidden = true
Expand Down Expand Up @@ -152,6 +156,7 @@ export class AddAnother extends Component {
}

this.updateAddButtonVisibility()
this.updateAddButtonText()
this.updateRemoveButtonVisibility()
}

Expand All @@ -163,8 +168,8 @@ export class AddAnother extends Component {
removeItem(index) {
const visibleItems = this.getVisibleItems()

// Don't remove if only one item is visible
if (visibleItems.length <= 1) {
// Don't remove if at minimum items
if (visibleItems.length <= this.minItems) {
return
}

Expand All @@ -187,16 +192,34 @@ export class AddAnother extends Component {
}

this.updateAddButtonVisibility()
this.updateAddButtonText()
this.updateRemoveButtonVisibility()
}

/**
* Update the add button text based on number of visible items
* Uses data-add-another-text-first for the first item,
* data-add-another-text-another for subsequent items
*/
updateAddButtonText() {
if (!this.$addButton) return

const firstText = this.$addButton.dataset.addAnotherTextFirst
const anotherText = this.$addButton.dataset.addAnotherTextAnother

if (!firstText || !anotherText) return

const visibleItems = this.getVisibleItems()
this.$addButton.textContent = visibleItems.length === 0 ? firstText : anotherText
}

/**
* Update visibility of remove buttons based on number of visible items
* Remove buttons should only be visible when there are 2+ items
* Remove buttons should only be visible when there are more than minItems
*/
updateRemoveButtonVisibility() {
const visibleItems = this.getVisibleItems()
const showRemoveButtons = visibleItems.length >= 2
const showRemoveButtons = visibleItems.length > this.minItems

this.$items.forEach($item => {
const $removeButton = $item.querySelector('[data-add-another-remove]')
Expand Down
5 changes: 3 additions & 2 deletions app/data/session-data-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ module.exports = {
vaccineStock: vaccineStock,
lists: [],
nhsNumberKnown: "yes",
currentUserId: "2387441662601",
currentOrganisationId: "RW3",
currentUserId: "6424325235325",
currentOrganisationId: null,
currentMode: "reports",
vaccinationsRecorded: vaccinationsRecorded,

// These are the options for extracting CSV reports
Expand Down
1 change: 1 addition & 0 deletions app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ require('./routes/user-profile')(router)
require('./routes/vaccines')(router)
require('./routes/reports')(router)
require('./routes/records')(router)
require('./routes/pharmacies')(router)
require('./routes/prototype-admin')(router)
require('./routes/lists')(router)
require('./routes/support')(router)
Expand Down
110 changes: 110 additions & 0 deletions app/routes/pharmacies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
const { getPharmaciesBelongingToOrganisation, getPharmacyChains, getOrganisation } = require('../lib/ods');

const sortByNameThenPostcode = (getPostcode = (item) => item.postcode) => (a, b) => {
if (a.name < b.name) return -1
if (a.name > b.name) return 1
const postcodeA = getPostcode(a)
const postcodeB = getPostcode(b)
if (postcodeA < postcodeB) return -1
return 1
}

module.exports = router => {

router.get('/pharmacies', (req, res) => {
const data = req.session.data
const currentUser = res.locals.currentUser

const userOrganisationIds = currentUser.organisations.map((organisation) => organisation.id)

const organisations = data.organisations.filter((organisation) => userOrganisationIds.includes(organisation.id) )


res.render('pharmacies/index', {
organisations
})
})

router.get('/pharmacies/select', async (req, res) => {
const data = req.session.data
const id = req.params.id

let pharmacies = await getPharmaciesBelongingToOrganisation("P15J")

pharmacies = pharmacies.sort(sortByNameThenPostcode((item) => item.address.postcode))


res.render('pharmacies/select', {
pharmacies
})
})

router.get('/pharmacies/check-selection', async (req, res) => {
const data = req.session.data

let pharmacies = await getPharmaciesBelongingToOrganisation("P15J")

pharmacies = pharmacies.filter((pharmacy) => {
return data.pharmacyIds.includes(pharmacy.id)
}).sort(sortByNameThenPostcode())


res.render('pharmacies/check-selection', {
pharmacies
})
})

router.get('/pharmacies/users',(req, res) => {
const data = req.session.data
const users = data.users.slice(10, 20)

res.render('pharmacies/users/index', {
users
})
})

router.get('/pharmacies/add-lead-admins',(req, res) => {
const data = req.session.data
const users = data.users.slice(10, 20)

res.render('pharmacies/add-lead-admins', {
users
})
})

router.get('/pharmacies/users/:id',(req, res) => {
const data = req.session.data
const id = req.params.id
const user = data.users.find((user) => user.id === id)

res.render('pharmacies/users/user', {
user
})
})


router.get('/pharmacies/:id/add-users',(req, res) => {
const data = req.session.data
const users = data.users.slice(10, 20)
const id = req.params.id
const organisation = data.organisations.find((organisation) => organisation.id === id)

res.render('pharmacies/add-users', {
users,
organisation
})
})

router.get('/pharmacies/:id', (req, res) => {
const data = req.session.data
const id = req.params.id

const organisation = data.organisations.find((organisation) => organisation.id === id)

res.render('pharmacies/pharmacy', {
organisation
})
})


}
2 changes: 1 addition & 1 deletion app/views/home/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

{% include "includes/notification.html" %}

<h1 class="nhsuk-heading-l nhsuk-u-margin-bottom-6">{% if currentOrganisation %}{{ currentOrganisation.name }}{% else %}Overview{% endif %}</h1>
<h1 class="nhsuk-heading-l nhsuk-u-margin-bottom-6">{% if currentOrganisation %}{{ currentOrganisation.name }}{% else %}PCT Healthcare{% endif %}</h1>


{% if currentOrganisation and totalVaccinationsRecorded == 0 %}
Expand Down
15 changes: 15 additions & 0 deletions app/views/includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@
active: (currentSection == "home")
}), navigationItems) %}

<!-- Reports mode -->
{% if data.currentMode == "reports" %}
{% set navigationItems = (navigationItems.push({
href: "/pharmacies",
text: "Pharmacies",
active: (currentSection == "pharmacies")
}), navigationItems) %}

{% set navigationItems = (navigationItems.push({
href: "/pharmacies/users",
text: "Manage users",
active: (currentSection == "pharmacies-users")
}), navigationItems) %}
{% endif %}

{% if currentOrganisation %}
{% set navigationItems = (navigationItems.push({
href: "/record-vaccinations",
Expand Down
Loading
Loading