From 0b81c033fae553eeac6873d7368f1172cb1ccb5d Mon Sep 17 00:00:00 2001 From: Thource Date: Thu, 13 Feb 2025 13:58:37 +0000 Subject: [PATCH] Fix JS assets not loading --- assets/js/establishment-roll.js | 12 +++---- assets/js/govukFrontendInit.js | 3 -- assets/js/index.js | 2 -- assets/js/initMoj.js | 1 - assets/js/printPage.js | 18 +++++----- esbuild/esbuild.config.js | 5 ++- server/views/macros/hmppsPagedListFooter.njk | 14 -------- server/views/macros/hmppsPagedListHeader.njk | 17 --------- server/views/macros/hmppsPagination.njk | 31 ----------------- server/views/macros/hmppsSortSelector.njk | 36 -------------------- server/views/pages/establishmentRoll.njk | 4 --- server/views/partials/layout.njk | 5 +-- 12 files changed, 20 insertions(+), 128 deletions(-) delete mode 100644 assets/js/govukFrontendInit.js delete mode 100644 assets/js/initMoj.js delete mode 100644 server/views/macros/hmppsPagedListFooter.njk delete mode 100644 server/views/macros/hmppsPagedListHeader.njk delete mode 100644 server/views/macros/hmppsPagination.njk delete mode 100644 server/views/macros/hmppsSortSelector.njk diff --git a/assets/js/establishment-roll.js b/assets/js/establishment-roll.js index 7a874b8..fcf8675 100644 --- a/assets/js/establishment-roll.js +++ b/assets/js/establishment-roll.js @@ -1,9 +1,9 @@ -const landingRows = document.querySelectorAll('.establishment-roll__table__landing-row') -const spurRows = document.querySelectorAll('.establishment-roll__table__spur-row') -const wingRows = document.querySelectorAll('.establishment-roll__table__wing-row') -const totalsRow = document.querySelector('#roll-table-totals-row') +module.exports = () => { + const landingRows = document.querySelectorAll('.establishment-roll__table__landing-row') + const spurRows = document.querySelectorAll('.establishment-roll__table__spur-row') + const wingRows = document.querySelectorAll('.establishment-roll__table__wing-row') + const totalsRow = document.querySelector('#roll-table-totals-row') -function init() { ;[...landingRows, ...spurRows].forEach(row => { row.setAttribute('hidden', 'hidden') }) @@ -45,5 +45,3 @@ function init() { wingNameCell.replaceChildren(wingLink) }) } - -init() diff --git a/assets/js/govukFrontendInit.js b/assets/js/govukFrontendInit.js deleted file mode 100644 index ee1be48..0000000 --- a/assets/js/govukFrontendInit.js +++ /dev/null @@ -1,3 +0,0 @@ -import { initAll } from '/assets/govuk/govuk-frontend.min.js' - -initAll() diff --git a/assets/js/index.js b/assets/js/index.js index 35ec13a..a5d0cfd 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -1,12 +1,10 @@ import * as govukFrontend from 'govuk-frontend' import * as mojFrontend from '@ministryofjustice/frontend' import establishmentRoll from './establishment-roll' -import initMoj from './initMoj' import printPage from './printPage' govukFrontend.initAll() mojFrontend.initAll() establishmentRoll() printPage() -initMoj() diff --git a/assets/js/initMoj.js b/assets/js/initMoj.js deleted file mode 100644 index 5dd458d..0000000 --- a/assets/js/initMoj.js +++ /dev/null @@ -1 +0,0 @@ -window.MOJFrontend.initAll() diff --git a/assets/js/printPage.js b/assets/js/printPage.js index e9d8d56..7428c69 100644 --- a/assets/js/printPage.js +++ b/assets/js/printPage.js @@ -1,10 +1,12 @@ -const printLinks = document.querySelectorAll('.print-link') +module.exports = () => { + const printLinks = document.querySelectorAll('.print-link') -if (printLinks?.length) { - printLinks.forEach(el => - el.addEventListener('click', evt => { - evt.preventDefault() - window.print() - }), - ) + if (printLinks?.length) { + printLinks.forEach(el => + el.addEventListener('click', evt => { + evt.preventDefault() + window.print() + }), + ) + } } diff --git a/esbuild/esbuild.config.js b/esbuild/esbuild.config.js index cbcabaf..86945f9 100644 --- a/esbuild/esbuild.config.js +++ b/esbuild/esbuild.config.js @@ -30,7 +30,10 @@ const buildConfig = { assets: { outDir: path.join(cwd, 'dist/assets'), - entryPoints: glob.sync([path.join(cwd, 'assets/js/index.js'), path.join(cwd, 'assets/scss/application.scss')]), + entryPoints: glob.sync([ + path.join(cwd, 'assets/js/index.js'), + path.join(cwd, 'assets/scss/application.scss') + ]), copy: [ { from: path.join(cwd, 'assets/images/**/*'), diff --git a/server/views/macros/hmppsPagedListFooter.njk b/server/views/macros/hmppsPagedListFooter.njk deleted file mode 100644 index 020677c..0000000 --- a/server/views/macros/hmppsPagedListFooter.njk +++ /dev/null @@ -1,14 +0,0 @@ -{%- from './hmppsPagination.njk' import hmppsPagination -%} -{%- from './hmppsPaginationSummary.njk' import hmppsPaginationSummary -%} -{% macro hmppsPagedListFooter(listMetadata) %} - {% if listMetadata.pagination.totalElements %} - - {% endif %} -{% endmacro %} diff --git a/server/views/macros/hmppsPagedListHeader.njk b/server/views/macros/hmppsPagedListHeader.njk deleted file mode 100644 index c4a0219..0000000 --- a/server/views/macros/hmppsPagedListHeader.njk +++ /dev/null @@ -1,17 +0,0 @@ -{%- from './hmppsPagination.njk' import hmppsPagination -%} -{%- from './hmppsPaginationSummary.njk' import hmppsPaginationSummary -%} -{%- from './hmppsSortSelector.njk' import hmppsSortSelector -%} - -{% macro hmppsPagedListHeader(listMetadata, options = {}) %} -
-
- {% if listMetadata.sorting %} - {{ hmppsSortSelector(listMetadata.sorting) }} - {% endif %} - {{ hmppsPagination(listMetadata.pagination) }} -
-
- {{ hmppsPaginationSummary(listMetadata.pagination) }} -
-
-{% endmacro %} \ No newline at end of file diff --git a/server/views/macros/hmppsPagination.njk b/server/views/macros/hmppsPagination.njk deleted file mode 100644 index 818157f..0000000 --- a/server/views/macros/hmppsPagination.njk +++ /dev/null @@ -1,31 +0,0 @@ -{% macro hmppsPagination(params) %} -{% if params.totalPages > 1 %} - -{% endif %} -{% endmacro %} diff --git a/server/views/macros/hmppsSortSelector.njk b/server/views/macros/hmppsSortSelector.njk deleted file mode 100644 index 9da58f9..0000000 --- a/server/views/macros/hmppsSortSelector.njk +++ /dev/null @@ -1,36 +0,0 @@ -{% from "govuk/components/button/macro.njk" import govukButton %} - -{% macro hmppsSortSelector(params) %} -
-
- - - {% for key, val in params.queryParams %} - {% if val and val is iterable and val is not string %} - {% for i in val %} - - {% endfor %} - {% elseif val %} - - {% endif %} - {% endfor %} - {{ govukButton({ - text: "Sort", - classes: "hmpps-sort-selector__sort-button", - preventDoubleClick: true - }) }} -
-
- {% block pageScripts %} - - {% endblock %} -{% endmacro %} \ No newline at end of file diff --git a/server/views/pages/establishmentRoll.njk b/server/views/pages/establishmentRoll.njk index f863cc7..807fee2 100644 --- a/server/views/pages/establishmentRoll.njk +++ b/server/views/pages/establishmentRoll.njk @@ -171,7 +171,3 @@ {% endblock %} - -{% block pageScripts %} - -{% endblock %} diff --git a/server/views/partials/layout.njk b/server/views/partials/layout.njk index 601fefe..1fdd1e0 100644 --- a/server/views/partials/layout.njk +++ b/server/views/partials/layout.njk @@ -48,10 +48,7 @@ {% endblock %} {% block bodyEnd %} - - - - + {% block pageScripts %} {% endblock %}