UNPKG

@ministryofjustice/hmpps-digital-prison-reporting-frontend

Version:

The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.

70 lines (69 loc) 3.77 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.setInitialHref = exports.toSentenceCase = exports.createListActions = exports.createListItemProductMin = exports.createListItemProduct = exports.itemActionsHtml = void 0; const UserReports_1 = require("../types/UserReports"); const localsHelper_1 = __importDefault(require("./localsHelper")); const itemActionsHtml = (retryHref, executionId, type, status) => { const text = status === UserReports_1.RequestStatus.EXPIRED ? 'Refresh' : 'Retry'; return `<div class="dpr-icon-wrapper__item-actions"> <a class='dpr-user-list-action govuk-link--no-visited-state govuk-!-margin-bottom-1' href="${retryHref}">${text}</a> <a class="dpr-user-list-action govuk-link--no-visited-state dpr-remove-${type}-report-button"" href="#" data-execution-id='${executionId}'>Remove</a> </div>`; }; exports.itemActionsHtml = itemActionsHtml; const getTypeTagColor = (type) => { return type === UserReports_1.ReportType.DASHBOARD ? 'govuk-tag--purple' : ''; }; const createListItemProduct = (productName, reportName, type, ts) => { const tsClass = !ts ? 'dpr-display-none' : ''; const tagColor = getTypeTagColor(type); const reportType = (0, exports.toSentenceCase)(type); return `<div> <p class="govuk-body govuk-!-margin-bottom-1"><strong>${reportName}</strong></p> <p class="govuk-body-s govuk-!-margin-bottom-3">${productName}</p> <strong class="govuk-tag ${tagColor} dpr-request-status-tag--small govuk-!-margin-bottom-4'">${reportType}</strong> <p class="govuk-body-xs govuk-!-margin-bottom-0 govuk-!-margin-top-3 ${tsClass}">${ts}</p> </div>`; }; exports.createListItemProduct = createListItemProduct; const createListItemProductMin = (reportName, type) => { const tagColor = getTypeTagColor(type); const reportType = (0, exports.toSentenceCase)(type); return `<div> <p class="govuk-body-s govuk-!-margin-bottom-2"><strong>${reportName}</strong></p> <strong class="govuk-tag ${tagColor} dpr-request-status-tag--small">${reportType}</strong> </div>`; }; exports.createListItemProductMin = createListItemProductMin; const createListActions = (href, type, loadType, bookmarkHtml, authorised = true) => { if (!authorised) { return `<strong class="govuk-tag govuk-tag--red dpr-request-status-tag dpr-request-status-tag--small dpr-unauthorised-report" aria-label="You are unauthorised to view this report">Unauthorised</strong>`; } let actionText = `Request ${type}`; if (loadType && loadType === UserReports_1.LoadType.SYNC) { actionText = `Load ${type}`; } let requestAction = `<a class='dpr-user-list-action govuk-link--no-visited-state govuk-!-margin-bottom-1' href="${href}">${actionText}</a>`; if (bookmarkHtml) { requestAction = `${requestAction}${bookmarkHtml}`; } return requestAction; }; exports.createListActions = createListActions; const toSentenceCase = (text) => { return text.charAt(0).toUpperCase() + text.substring(1).toLowerCase(); }; exports.toSentenceCase = toSentenceCase; const setInitialHref = (loadType, type, reportId, id, res) => { const { pathSuffix, dpdPathFromQuery, routePrefix } = localsHelper_1.default.getValues(res); const dpdPathQueryParam = dpdPathFromQuery ? pathSuffix : ''; let href = `${routePrefix}/async/${type}/${reportId}/${id}/request${dpdPathQueryParam}`; if (loadType && loadType === UserReports_1.LoadType.SYNC) { href = `${routePrefix}/sync/${type}/${reportId}/${id}/load-report${dpdPathQueryParam}`; } return href; }; exports.setInitialHref = setInitialHref;