Skip to content

Commit

Permalink
Merge branch 'main' into MAN-227-enable-github-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
achimber-moj committed Jan 6, 2025
2 parents bdd7824 + f14cf93 commit e1744c4
Show file tree
Hide file tree
Showing 142 changed files with 10,782 additions and 3,003 deletions.
16 changes: 8 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ jobs:
name: Update npm
command: 'sudo npm install -g npm@10'
- restore_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
key: dependency-cache-v2-{{ checksum "package-lock.json" }}
- run:
name: Install Dependencies
command: npm ci --no-audit
- save_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
key: dependency-cache-v2-{{ checksum "package-lock.json" }}
paths:
- node_modules
- ~/.cache
Expand All @@ -61,7 +61,7 @@ jobs:
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
key: dependency-cache-v2-{{ checksum "package-lock.json" }}
- run:
name: unit tests
command: npm run test:ci
Expand All @@ -82,7 +82,7 @@ jobs:
name: Install missing OS dependency
command: sudo apt-get install libxss1
- restore_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
key: dependency-cache-v2-{{ checksum "package-lock.json" }}
- run:
name: Run the node app.
command: npm run start-feature
Expand Down Expand Up @@ -125,7 +125,7 @@ workflows:
- main
- hmpps/deploy_env:
name: deploy_dev
env: "dev"
env: 'dev'
jira_update: true
pipeline_id: <<pipeline.id>>
pipeline_number: <<pipeline.number>>
Expand All @@ -142,7 +142,7 @@ workflows:
helm_timeout: 5m
- hmpps/deploy_env:
name: deploy_preprod
env: "preprod"
env: 'preprod'
jira_update: true
jira_env_type: staging
pipeline_id: <<pipeline.id>>
Expand Down Expand Up @@ -183,7 +183,7 @@ workflows:
security:
triggers:
- schedule:
cron: "5 9 * * 1-5"
cron: '5 9 * * 1-5'
filters:
branches:
only:
Expand All @@ -202,7 +202,7 @@ workflows:
security-weekly:
triggers:
- schedule:
cron: "11 9 * * 1"
cron: '11 9 * * 1'
filters:
branches:
only:
Expand Down
8 changes: 0 additions & 8 deletions .eslintignore

This file was deleted.

21 changes: 13 additions & 8 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@
],
"rules": {
"@typescript-eslint/no-use-before-define": 0,
"@typescript-eslint/no-unused-vars": 0,
"class-methods-use-this": 0,
"no-useless-constructor": 0,
"@typescript-eslint/no-unused-vars": [
1,
{
"argsIgnorePattern": "res|next|^err|_",
"ignoreRestSiblings": true
}
],
"import/prefer-default-export": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/semi": 0,
"import/no-unresolved": "error",
"prettier/prettier": [
Expand Down Expand Up @@ -85,7 +81,16 @@
"comma-dangle": ["error", "always-multiline"],
"import/no-extraneous-dependencies": [
"error",
{ "devDependencies": ["**/*.test.js", "**/*.test.ts", "**/testutils/**", "cypress.config.ts", "e2e_tests/**", "playwright.config.ts"] }
{
"devDependencies": [
"**/*.test.js",
"**/*.test.ts",
"**/testutils/**",
"cypress.config.ts",
"e2e_tests/**",
"playwright.config.ts"
]
}
],
"no-only-tests/no-only-tests": "error",
"prettier/prettier": [
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
trivy:
uses: ministryofjustice/hmpps-github-actions/.github/workflows/security_trivy.yml@86eaa5068ee47ca59d2ac6e6351ecd5dcbd2d28a # v1
uses: ministryofjustice/hmpps-github-actions/.github/workflows/security_trivy.yml@eba268344a0ec5f4a268bf7e963e645fbc72a2f9 # v1
with:
channel_id: probation-integration-notifications
secrets:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,4 @@ integration_tests/screenshots/
/playwright-report/
/blob-report/
/playwright/.cache/
.DS_Store
File renamed without changes.
2 changes: 1 addition & 1 deletion .zap/traverse.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function listChildren(node, level) {
var j
let j
for (j = 0; j < node.getChildCount(); j++) {
print(Array(level + 1).join(' ') + node.getChildAt(j).getNodeName())
listChildren(node.getChildAt(j), level + 1)
Expand Down
52 changes: 52 additions & 0 deletions assets/js/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* eslint-disable no-restricted-globals */
const lastAppointment = () => {
const repeatingFrequency = document.querySelector('div[data-repeating-frequency]')
if (repeatingFrequency) {
const repeatingFrequencyRadios = repeatingFrequency.querySelectorAll('input[type="radio"]')
const repeatingCount = document.querySelector('div[data-repeating-count] input')
const lastAppointmentElm = document.querySelector('div[data-last-appointment')
const lastAppointmentHandler = async () => {
const repeatingFrequencyRadioSelected = repeatingFrequency.querySelector('input:checked')
if (parseInt(repeatingCount.value, 10) > 0 && repeatingFrequencyRadioSelected) {
const divider = location.href.includes('?') ? '&' : '?'
const url = `${location.href}${divider}repeating-frequency=${encodeURI(repeatingFrequencyRadioSelected.value)}&repeating-count=${repeatingCount.value}`
const headers = {
Accept: '*/*',
'Content-Type': 'application/x-www-form-urlencoded',
}
const response = await fetch(url, {
method: 'GET',
cache: 'no-cache',
credentials: 'same-origin',
headers,
})
const html = await response.text()
const parser = new DOMParser()
const doc = parser.parseFromString(html, 'text/html')
const element = doc.querySelector('div[data-last-appointment]').innerHTML
document.querySelector('div[data-last-appointment]').innerHTML = element
} else {
lastAppointmentElm.innerHTML = ''
}
}
repeatingFrequencyRadios.forEach(input => input.addEventListener('click', lastAppointmentHandler))
repeatingCount.addEventListener('keyup', lastAppointmentHandler)
}
}
const resetConditionals = () => {
const handleReset = () => {
document.querySelectorAll('.govuk-radios__conditional input').forEach(radioBtn => {
// eslint-disable-next-line no-param-reassign
radioBtn.checked = false
})
}
const elm = document.querySelector('[data-reset-conditional-radios]')
if (elm) {
// eslint-disable-next-line no-shadow
document.querySelectorAll('[data-reset-conditional-radios]').forEach(elm => {
elm.addEventListener('click', handleReset)
})
}
}
lastAppointment()
resetConditionals()
47 changes: 24 additions & 23 deletions assets/js/backendSortableTable.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable func-names,no-plusplus */
MOJFrontend.BackendSortableTable = function (params) {
this.table = $(params.table)

Expand All @@ -16,11 +17,11 @@ MOJFrontend.BackendSortableTable = function (params) {
}

MOJFrontend.BackendSortableTable.prototype.check = function () {
//Empty function
// Empty function
}

MOJFrontend.BackendSortableTable.prototype.setupOptions = function (params) {
params = params || {}
MOJFrontend.BackendSortableTable.prototype.setupOptions = function (nullableParams) {
const params = nullableParams || {}
this.statusMessage = params.statusMessage || 'Sort by %heading% (%direction%)'
this.ascendingText = params.ascendingText || 'ascending'
this.descendingText = params.descendingText || 'descending'
Expand All @@ -30,7 +31,7 @@ MOJFrontend.BackendSortableTable.prototype.createHeadingButtons = function () {
const headings = this.table.find('thead th')
let heading
let i = 0
for (let head of headings) {
for (const head of headings) {
heading = $(head)
if (heading.attr('aria-sort')) {
this.createHeadingButton(heading, i)
Expand All @@ -44,19 +45,21 @@ MOJFrontend.BackendSortableTable.prototype.setNaturalOrder = function () {
let heading
this.naturalSortColumn = 0
this.naturalSortDirection = 'ascending'
for (let head of headings) {
let i = 0
for (const head of headings) {
heading = $(head)
if (heading.attr('aria-sort-natural')) {
this.naturalSortColumn = i
this.naturalSortDirection = heading.attr('aria-sort-natural')
break
}
i++
}
}

MOJFrontend.BackendSortableTable.prototype.createHeadingButton = function (heading, i) {
const text = heading.text()
const button = $('<button type="button" data-index="' + i + '">' + text + '</button>')
const button = $(`<button type="button" data-index="${i}">${text}</button>`)
heading.text('')
heading.append(button)
}
Expand All @@ -77,7 +80,7 @@ MOJFrontend.BackendSortableTable.prototype.onSortButtonClick = function (e) {
}

const columnName = $(e.currentTarget).parent().attr('col-name')
const sortBy = columnName + '.' + backendSortDirection
const sortBy = `${columnName}.${backendSortDirection}`

window.location = `/${action}?sortBy=${sortBy}`
}
Expand All @@ -97,15 +100,14 @@ MOJFrontend.BackendSortableTable.prototype.sort = function (rows, columnNumber,
return 1
}
return this.sortNatural(rowA, rowB)
} else {
if (valueB < valueA) {
return -1
}
if (valueB > valueA) {
return 1
}
return this.sortNatural(rowA, rowB)
}
if (valueB < valueA) {
return -1
}
if (valueB > valueA) {
return 1
}
return this.sortNatural(rowA, rowB)
}, this),
)
}
Expand All @@ -123,15 +125,14 @@ MOJFrontend.BackendSortableTable.prototype.sortNatural = function (rowA, rowB) {
return 1
}
return 0
} else {
if (valueB < valueA) {
return -1
}
if (valueB > valueA) {
return 1
}
return 0
}
if (valueB < valueA) {
return -1
}
if (valueB > valueA) {
return 1
}
return 0
}

MOJFrontend.BackendSortableTable.prototype.getCellValue = function (cell) {
Expand Down
3 changes: 2 additions & 1 deletion assets/js/govukFrontendInit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { initAll } from '/assets/govuk/govuk-frontend.min.js'
// eslint-disable-next-line import/no-unresolved,import/extensions
import { initAll } from './govuk/govuk-frontend.min.js'

initAll()
2 changes: 1 addition & 1 deletion assets/js/mojFrontendInit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
window.MOJFrontend.initAll()
const $backendSortableTables = document.querySelectorAll('[data-module="moj-backend-sortable-table"]')
MOJFrontend.nodeListForEach($backendSortableTables, function ($table) {
MOJFrontend.nodeListForEach($backendSortableTables, function f($table) {
const best = new MOJFrontend.BackendSortableTable({
table: $table,
})
Expand Down
48 changes: 48 additions & 0 deletions assets/js/predictors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const openText = 'Open'
const closeText = 'Close'

const openAllButton = document.querySelector('[data-js="predictor-timeline__toggle-all"]')
const openCloseButtons = document.querySelectorAll('[data-js="predictor-timeline__toggle-section"]')
const sections = document.querySelectorAll('[data-js="predictor-timeline__section"]')
const sectionHiddenClass = 'predictor-timeline-section--hidden'

function toggleButton(button, newState) {
const label = button.querySelector('[data-js="score-action-label"]')
if (newState === 'open') {
button.setAttribute('aria-expanded', 'true')
label.innerText = closeText
} else {
button.setAttribute('aria-expanded', 'false')
label.innerText = openText
}
}

function openCloseButtonClick(e) {
e.preventDefault()
const button = e.currentTarget
const isCurrentlyOpen = button.getAttribute('aria-expanded') === 'true'
toggleButton(button, isCurrentlyOpen ? 'close' : 'open')
const sectionId = button.getAttribute('aria-controls')
const section = document.getElementById(sectionId)
if (isCurrentlyOpen) {
section.classList.add(sectionHiddenClass)
} else {
section.classList.remove(sectionHiddenClass)
}
}

function openAllButtonClicked(e) {
e.preventDefault()
sections.forEach(section => section.classList.remove(sectionHiddenClass))
openCloseButtons.forEach(button => toggleButton(button, 'open'))
openAllButton.setAttribute('aria-expanded', 'true')
}

function addPredictorTimelineListeners() {
openCloseButtons.forEach(button => button.addEventListener('click', openCloseButtonClick))
if (openAllButton) {
openAllButton.addEventListener('click', openAllButtonClicked)
}
}

addPredictorTimelineListeners()
Loading

0 comments on commit e1744c4

Please sign in to comment.