@ministryofjustice/hmpps-digital-prison-reporting-frontend 4.22.2 → 4.22.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dpr/DprPollingStatusClass.mjs +2 -2
- package/dpr/components/_async/async-filters-form/types.d.js +1 -1
- package/dpr/components/_async/async-filters-form/types.d.js.map +1 -1
- package/dpr/components/_async/async-filters-form/types.d.ts +0 -1
- package/dpr/components/_catalogue/catalogue-list/utils.js +1 -1
- package/dpr/components/_catalogue/catalogue-list/utils.js.map +3 -3
- package/dpr/components/_catalogue/catalogue-list/utils.ts +2 -1
- package/dpr/components/_charts/utils.test.ts +0 -3
- package/dpr/components/bookmark-toggle/clientClass.mjs +3 -4
- package/dpr/components/bookmark-toggle/view.njk +1 -1
- package/dpr/components/user-reports/bookmarks/utils.js +1 -1
- package/dpr/components/user-reports/bookmarks/utils.js.map +3 -3
- package/dpr/components/user-reports/bookmarks/utils.ts +13 -3
- package/dpr/components/user-reports/requested/clientClass.mjs +18 -6
- package/dpr/components/user-reports/utils.js.map +2 -2
- package/dpr/components/user-reports/utils.test.ts +24 -24
- package/dpr/components/user-reports/utils.ts +2 -0
- package/dpr/components/user-reports/viewed/clientClass.mjs +3 -2
- package/dpr/middleware/setUpDprResources.js +1 -1
- package/dpr/middleware/setUpDprResources.js.map +3 -3
- package/dpr/middleware/setUpDprResources.test.ts +1 -0
- package/dpr/middleware/setUpDprResources.ts +3 -1
- package/dpr/routes/journeys/my-reports/bookmarks/controller.js +1 -1
- package/dpr/routes/journeys/my-reports/bookmarks/controller.js.map +3 -3
- package/dpr/routes/journeys/my-reports/bookmarks/controller.ts +6 -9
- package/dpr/routes/journeys/my-reports/bookmarks/routes.js +1 -1
- package/dpr/routes/journeys/my-reports/bookmarks/routes.js.map +2 -2
- package/dpr/routes/journeys/my-reports/bookmarks/routes.ts +0 -3
- package/dpr/routes/journeys/my-reports/bookmarks/service.js +3 -3
- package/dpr/routes/journeys/my-reports/bookmarks/service.js.map +3 -3
- package/dpr/routes/journeys/my-reports/bookmarks/service.ts +4 -1
- package/dpr/routes/journeys/my-reports/recently-viewed/controller.js +1 -1
- package/dpr/routes/journeys/my-reports/recently-viewed/controller.js.map +2 -2
- package/dpr/routes/journeys/my-reports/recently-viewed/controller.ts +1 -0
- package/dpr/routes/journeys/my-reports/requested-reports/service.js +1 -1
- package/dpr/routes/journeys/my-reports/requested-reports/service.js.map +3 -3
- package/dpr/routes/journeys/my-reports/requested-reports/service.ts +37 -1
- package/dpr/routes/journeys/request-report/filters/utils.js +1 -1
- package/dpr/routes/journeys/request-report/filters/utils.js.map +2 -2
- package/dpr/routes/journeys/request-report/filters/utils.ts +3 -1
- package/dpr/routes/journeys/request-report/tests.cy.js +1 -1
- package/dpr/routes/journeys/request-report/tests.cy.js.map +2 -2
- package/dpr/routes/journeys/request-report/tests.cy.ts +22 -1
- package/package.json +1 -1
|
@@ -311,6 +311,7 @@ export const updateExpiredStatus = async ({ req, res, services }: AsyncReportUti
|
|
|
311
311
|
|
|
312
312
|
export const init = async ({ services, res, maxRows = 6 }: { services: Services; res: Response; maxRows?: number }) => {
|
|
313
313
|
const { requestedReports, recentlyViewedReports, bookmarkingEnabled } = LocalsHelper.getValues(res)
|
|
314
|
+
|
|
314
315
|
const requestedReportsList = await renderList({
|
|
315
316
|
res,
|
|
316
317
|
reportsData: requestedReports,
|
|
@@ -318,6 +319,7 @@ export const init = async ({ services, res, maxRows = 6 }: { services: Services;
|
|
|
318
319
|
maxRows,
|
|
319
320
|
type: 'requested',
|
|
320
321
|
})
|
|
322
|
+
|
|
321
323
|
const viewedReportsList = await renderList({
|
|
322
324
|
res,
|
|
323
325
|
reportsData: recentlyViewedReports,
|
|
@@ -11,7 +11,8 @@ class DprRecentlyViewedList extends DprPollingStatusClass {
|
|
|
11
11
|
this.POLLING_FREQUENCY = '60000' // 1 min
|
|
12
12
|
|
|
13
13
|
this.viewedList = document.getElementById('dpr-recently-viewed-component')
|
|
14
|
-
|
|
14
|
+
const viewedReportData = this.viewedList.getAttribute('data-request-data')
|
|
15
|
+
this.viewedReportData = viewedReportData ? JSON.parse(viewedReportData) : undefined
|
|
15
16
|
this.csrfToken = this.viewedList.getAttribute('data-csrf-token')
|
|
16
17
|
this.removeActions = document.querySelectorAll('.dpr-remove-viewed-report-button')
|
|
17
18
|
|
|
@@ -31,7 +32,7 @@ class DprRecentlyViewedList extends DprPollingStatusClass {
|
|
|
31
32
|
|
|
32
33
|
async checkIsExpired() {
|
|
33
34
|
await Promise.all(
|
|
34
|
-
|
|
35
|
+
this.viewedReportData.map(async (metaData) => {
|
|
35
36
|
const { status, reportUrl } = metaData
|
|
36
37
|
if (status !== 'EXPIRED') {
|
|
37
38
|
const response = await this.getExpiredStatus(reportUrl, metaData, this.csrfToken)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var y=Object.create;var d=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var F=(t,e)=>{for(var o in e)d(t,o,{get:e[o],enumerable:!0})},P=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of w(e))!v.call(t,r)&&r!==o&&d(t,r,{get:()=>e[r],enumerable:!(i=E(e,r))||i.enumerable});return t};var S=(t,e,o)=>(o=t!=null?y(C(t)):{},P(e||!t||!t.__esModule?d(o,"default",{value:t,enumerable:!0}):o,t)),V=t=>P(d({},"__esModule",{value:!0}),t);var B={};F(B,{default:()=>A,errorRequestHandler:()=>h,populateDefinitions:()=>b,populateRequestedReports:()=>k,setupResources:()=>D});module.exports=V(B);var c=S(require("../utils/definitionUtils")),m=S(require("../utils/localsHelper"));const H=(t,e)=>t[e]?t[e].toString():null,Q=t=>H(t,"dataProductDefinitionsPath"),x=t=>{const e=Q(t);return e||null},h=t=>(e,o,i,r)=>e.status===401||e.status===403?i.render("dpr/routes/authError.njk",{layoutPath:t,message:"Sorry, there is a problem with authenticating your request"}):e.status>=400?i.render("dpr/routes/serviceProblem.njk",{layoutPath:t}):r(),D=(t,e,o)=>async(i,r,a)=>{I(i,r);try{return await b(t,i,r,o),await k(t,r),a()}catch(s){return h(e)(s,i,r,a)}},I=(t,e)=>{const o=t.flash("DPR_ERRORS");o&&o[0]&&(e.locals.validationErrors=JSON.parse(o[0]))},b=async(t,e,o,i)=>{const{token:r,dprUser:a}=m.default.getValues(o),s=x(e.query),n=e.body?.dataProductDefinitionsPath,l=s||n;l&&(o.locals.dpdPathFromQuery=!0);const
|
|
1
|
+
"use strict";var y=Object.create;var d=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var F=(t,e)=>{for(var o in e)d(t,o,{get:e[o],enumerable:!0})},P=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of w(e))!v.call(t,r)&&r!==o&&d(t,r,{get:()=>e[r],enumerable:!(i=E(e,r))||i.enumerable});return t};var S=(t,e,o)=>(o=t!=null?y(C(t)):{},P(e||!t||!t.__esModule?d(o,"default",{value:t,enumerable:!0}):o,t)),V=t=>P(d({},"__esModule",{value:!0}),t);var B={};F(B,{default:()=>A,errorRequestHandler:()=>h,populateDefinitions:()=>b,populateRequestedReports:()=>k,setupResources:()=>D});module.exports=V(B);var c=S(require("../utils/definitionUtils")),m=S(require("../utils/localsHelper"));const H=(t,e)=>t[e]?t[e].toString():null,Q=t=>H(t,"dataProductDefinitionsPath"),x=t=>{const e=Q(t);return e||null},h=t=>(e,o,i,r)=>e.status===401||e.status===403?i.render("dpr/routes/authError.njk",{layoutPath:t,message:"Sorry, there is a problem with authenticating your request"}):e.status>=400?i.render("dpr/routes/serviceProblem.njk",{layoutPath:t}):r(),D=(t,e,o)=>async(i,r,a)=>{I(i,r);try{return await b(t,i,r,o),await k(t,r),a()}catch(s){return h(e)(s,i,r,a)}},I=(t,e)=>{const o=t.flash("DPR_ERRORS");o&&o[0]&&(e.locals.validationErrors=JSON.parse(o[0]))},b=async(t,e,o,i)=>{const{token:r,dprUser:a}=m.default.getValues(o),s=x(e.query),n=e.body?.dataProductDefinitionsPath,l=s||n;l&&(o.locals.dpdPathFromQuery=!0);const R=i?.dataProductDefinitionsPath;R&&(o.locals.dpdPathFromConfig=!0),o.locals.definitionsPath=l||R,o.locals.pathSuffix=`?dataProductDefinitionsPath=${o.locals.definitionsPath}`;let u;r&&(u=await t.productCollectionStoreService.getSelectedProductCollectionId(a.id)),o.locals.definitions=await Promise.all([t.reportingService.getDefinitions(r,o.locals.definitionsPath),u&&t.productCollectionService.getProductCollection(r,u)]).then(([g,p])=>{if(p&&p){const q=p.products.map(f=>f.productId);return g.filter(f=>q.includes(f.id))}return g})??[]},k=async(t,e)=>{const{dprUser:o}=m.default.getValues(e);if(o.id){const{definitions:i,definitionsPath:r}=e.locals,a=await t.recentlyViewedService.getAllReports(o.id);await t.requestedReportService.cleanList(o.id,a);const s=await t.requestedReportService.getAllReports(o.id);if(e.locals.requestedReports=r?s.filter(n=>c.default.getCurrentVariantDefinition(i,n.reportId,n.id)):s,e.locals.recentlyViewedReports=r?a.filter(n=>c.default.getCurrentVariantDefinition(i,n.reportId,n.id)):a,e.locals.downloadingEnabled=t.downloadPermissionService.enabled,e.locals.bookmarkingEnabled=t.bookmarkService.enabled,e.locals.collectionsEnabled=t.productCollectionService.enabled,e.locals.requestMissingEnabled=t.missingReportService.enabled,e.locals.saveDefaultsEnabled=t.defaultFilterValuesService.enabled,e.locals.bookmarkingEnabled){const n=await t.bookmarkService.getAllBookmarks(o.id);e.locals.bookmarks=r?n.filter(l=>c.default.getCurrentVariantDefinition(i,l.reportId,l.id)):n}}};var A=D;0&&(module.exports={errorRequestHandler,populateDefinitions,populateRequestedReports,setupResources});
|
|
2
2
|
//# sourceMappingURL=setUpDprResources.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/dpr/middleware/setUpDprResources.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { RequestHandler, Response, Request, ErrorRequestHandler, NextFunction } from 'express'\nimport type { ParsedQs } from 'qs'\nimport { HTTPError } from 'superagent'\nimport { Services } from '../types/Services'\nimport { RequestedReport, StoredReportData } from '../types/UserReports'\nimport DefinitionUtils from '../utils/definitionUtils'\nimport { BookmarkStoreData } from '../types/Bookmark'\nimport { DprConfig } from '../types/DprConfig'\nimport localsHelper from '../utils/localsHelper'\n\nconst getQueryParamAsString = (query: ParsedQs, name: string) => (query[name] ? query[name].toString() : null)\nconst getDefinitionsPath = (query: ParsedQs) => getQueryParamAsString(query, 'dataProductDefinitionsPath')\n\nconst deriveDefinitionsPath = (query: ParsedQs): string | null => {\n const definitionsPath = getDefinitionsPath(query)\n if (definitionsPath) {\n return definitionsPath\n }\n\n return null\n}\n\nexport const errorRequestHandler =\n (layoutPath: string): ErrorRequestHandler =>\n (error: HTTPError, _req: Request, res: Response, next: NextFunction) => {\n if (error.status === 401 || error.status === 403) {\n return res.render('dpr/routes/authError.njk', {\n layoutPath,\n message: 'Sorry, there is a problem with authenticating your request',\n })\n }\n if (error.status >= 400) {\n return res.render('dpr/routes/serviceProblem.njk', {\n layoutPath,\n })\n }\n return next()\n }\n\nexport const setupResources = (services: Services, layoutPath: string, config?: DprConfig): RequestHandler => {\n return async (req, res, next) => {\n populateValidationErrors(req, res)\n try {\n await populateDefinitions(services, req, res, config)\n await populateRequestedReports(services, res)\n return next()\n } catch (error) {\n return errorRequestHandler(layoutPath)(error, req, res, next)\n }\n }\n}\n\nconst populateValidationErrors = (req: Request, res: Response) => {\n const errors = req.flash(`DPR_ERRORS`)\n if (errors && errors[0]) {\n res.locals['validationErrors'] = JSON.parse(errors[0])\n }\n}\n\nexport const populateDefinitions = async (services: Services, req: Request, res: Response, config?: DprConfig) => {\n // Get the DPD path from the query\n const { token, dprUser } = localsHelper.getValues(res)\n\n const dpdPathFromQuery = deriveDefinitionsPath(req.query)\n const dpdPathFromBody = req.body?.dataProductDefinitionsPath\n const definitionsPathFromQuery = dpdPathFromQuery || dpdPathFromBody\n\n if (definitionsPathFromQuery) {\n res.locals['dpdPathFromQuery'] = true\n }\n\n // Get the DPD path from the config\n const dpdPathFromConfig = config?.dataProductDefinitionsPath\n if (dpdPathFromConfig) {\n res.locals['dpdPathFromConfig'] = true\n }\n\n // query takes presedence over config\n res.locals['definitionsPath'] = definitionsPathFromQuery || dpdPathFromConfig\n res.locals['pathSuffix'] = `?dataProductDefinitionsPath=${res.locals['definitionsPath']}`\n\n let selectedProductCollectionId: string | undefined\n if (token) {\n selectedProductCollectionId = await services.productCollectionStoreService.getSelectedProductCollectionId(\n dprUser.id,\n )\n }\n\n res.locals['definitions'] =\n (await Promise.all([\n services.reportingService.getDefinitions(token, res.locals['definitionsPath']),\n selectedProductCollectionId &&\n services.productCollectionService.getProductCollection(token, selectedProductCollectionId),\n ]).then(([defs, selectedProductCollection]) => {\n if (selectedProductCollection && selectedProductCollection) {\n const productIds = selectedProductCollection.products.map((product) => product.productId)\n return defs.filter((def) => productIds.includes(def.id))\n }\n return defs\n })) ?? []\n}\n\nexport const populateRequestedReports = async (services: Services, res: Response) => {\n const { dprUser } = localsHelper.getValues(res)\n if (dprUser.id) {\n const { definitions, definitionsPath } = res.locals\n\n const requested = await services.requestedReportService.getAllReports(dprUser.id)\n res.locals['requestedReports'] = !definitionsPath\n ? requested\n : requested.filter((report: RequestedReport) => {\n return DefinitionUtils.getCurrentVariantDefinition(definitions, report.reportId, report.id)\n })\n\n
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,wBAAAC,EAAA,wBAAAC,EAAA,6BAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAP,GAMA,IAAAQ,EAA4B,uCAG5BC,EAAyB,oCAEzB,MAAMC,EAAwB,CAACC,EAAi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CA,EAAI,OAAO,gBAAqBY,GAA4BC,EAC5Db,EAAI,OAAO,WAAgB,+BAA+BA,EAAI,OAAO,eAAkB,GAEvF,IAAIc,EACAP,IACFO,EAA8B,MAAMZ,EAAS,8BAA8B,+BACzEM,EAAQ,EACV,GAGFR,EAAI,OAAO,YACR,MAAM,QAAQ,IAAI,CACjBE,EAAS,iBAAiB,eAAeK,EAAOP,EAAI,OAAO,eAAkB,EAC7Ec,GACEZ,EAAS,yBAAyB,qBAAqBK,EAAOO,CAA2B,CAC7F,CAAC,EAAE,KAAK,CAAC,CAACC,EAAMC,CAAyB,IAAM,CAC7C,GAAIA,GAA6BA,EAA2B,CAC1D,MAAMC,EAAaD,EAA0B,SAAS,IAAKE,GAAYA,EAAQ,SAAS,EACxF,OAAOH,EAAK,OAAQI,GAAQF,EAAW,SAASE,EAAI,EAAE,CAAC,CACzD,CACA,OAAOJ,CACT,CAAC,GAAM,CAAC,CACZ,EAEa7B,EAA2B,MAAOgB,EAAoBF,IAAkB,CACnF,KAAM,CAAE,QAAAQ,CAAQ,EAAI,EAAAC,QAAa,UAAUT,CAAG,EAC9C,GAAIQ,EAAQ,GAAI,CACd,KAAM,CAAE,YAAAY,EAAa,gBAAAxB,CAAgB,EAAII,EAAI,OAEvCqB,
|
|
6
|
-
"names": ["setUpDprResources_exports", "__export", "setUpDprResources_default", "errorRequestHandler", "populateDefinitions", "populateRequestedReports", "setupResources", "__toCommonJS", "import_definitionUtils", "import_localsHelper", "getQueryParamAsString", "query", "name", "getDefinitionsPath", "deriveDefinitionsPath", "definitionsPath", "layoutPath", "error", "_req", "res", "next", "services", "config", "req", "populateValidationErrors", "errors", "token", "dprUser", "localsHelper", "dpdPathFromQuery", "dpdPathFromBody", "definitionsPathFromQuery", "dpdPathFromConfig", "selectedProductCollectionId", "defs", "selectedProductCollection", "productIds", "product", "def", "definitions", "
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { RequestHandler, Response, Request, ErrorRequestHandler, NextFunction } from 'express'\nimport type { ParsedQs } from 'qs'\nimport { HTTPError } from 'superagent'\nimport { Services } from '../types/Services'\nimport { RequestedReport, StoredReportData } from '../types/UserReports'\nimport DefinitionUtils from '../utils/definitionUtils'\nimport { BookmarkStoreData } from '../types/Bookmark'\nimport { DprConfig } from '../types/DprConfig'\nimport localsHelper from '../utils/localsHelper'\n\nconst getQueryParamAsString = (query: ParsedQs, name: string) => (query[name] ? query[name].toString() : null)\nconst getDefinitionsPath = (query: ParsedQs) => getQueryParamAsString(query, 'dataProductDefinitionsPath')\n\nconst deriveDefinitionsPath = (query: ParsedQs): string | null => {\n const definitionsPath = getDefinitionsPath(query)\n if (definitionsPath) {\n return definitionsPath\n }\n\n return null\n}\n\nexport const errorRequestHandler =\n (layoutPath: string): ErrorRequestHandler =>\n (error: HTTPError, _req: Request, res: Response, next: NextFunction) => {\n if (error.status === 401 || error.status === 403) {\n return res.render('dpr/routes/authError.njk', {\n layoutPath,\n message: 'Sorry, there is a problem with authenticating your request',\n })\n }\n if (error.status >= 400) {\n return res.render('dpr/routes/serviceProblem.njk', {\n layoutPath,\n })\n }\n return next()\n }\n\nexport const setupResources = (services: Services, layoutPath: string, config?: DprConfig): RequestHandler => {\n return async (req, res, next) => {\n populateValidationErrors(req, res)\n try {\n await populateDefinitions(services, req, res, config)\n await populateRequestedReports(services, res)\n return next()\n } catch (error) {\n return errorRequestHandler(layoutPath)(error, req, res, next)\n }\n }\n}\n\nconst populateValidationErrors = (req: Request, res: Response) => {\n const errors = req.flash(`DPR_ERRORS`)\n if (errors && errors[0]) {\n res.locals['validationErrors'] = JSON.parse(errors[0])\n }\n}\n\nexport const populateDefinitions = async (services: Services, req: Request, res: Response, config?: DprConfig) => {\n // Get the DPD path from the query\n const { token, dprUser } = localsHelper.getValues(res)\n\n const dpdPathFromQuery = deriveDefinitionsPath(req.query)\n const dpdPathFromBody = req.body?.dataProductDefinitionsPath\n const definitionsPathFromQuery = dpdPathFromQuery || dpdPathFromBody\n\n if (definitionsPathFromQuery) {\n res.locals['dpdPathFromQuery'] = true\n }\n\n // Get the DPD path from the config\n const dpdPathFromConfig = config?.dataProductDefinitionsPath\n if (dpdPathFromConfig) {\n res.locals['dpdPathFromConfig'] = true\n }\n\n // query takes presedence over config\n res.locals['definitionsPath'] = definitionsPathFromQuery || dpdPathFromConfig\n res.locals['pathSuffix'] = `?dataProductDefinitionsPath=${res.locals['definitionsPath']}`\n\n let selectedProductCollectionId: string | undefined\n if (token) {\n selectedProductCollectionId = await services.productCollectionStoreService.getSelectedProductCollectionId(\n dprUser.id,\n )\n }\n\n res.locals['definitions'] =\n (await Promise.all([\n services.reportingService.getDefinitions(token, res.locals['definitionsPath']),\n selectedProductCollectionId &&\n services.productCollectionService.getProductCollection(token, selectedProductCollectionId),\n ]).then(([defs, selectedProductCollection]) => {\n if (selectedProductCollection && selectedProductCollection) {\n const productIds = selectedProductCollection.products.map((product) => product.productId)\n return defs.filter((def) => productIds.includes(def.id))\n }\n return defs\n })) ?? []\n}\n\nexport const populateRequestedReports = async (services: Services, res: Response) => {\n const { dprUser } = localsHelper.getValues(res)\n if (dprUser.id) {\n const { definitions, definitionsPath } = res.locals\n\n const recent = await services.recentlyViewedService.getAllReports(dprUser.id)\n await services.requestedReportService.cleanList(dprUser.id, recent)\n const requested = await services.requestedReportService.getAllReports(dprUser.id)\n\n res.locals['requestedReports'] = !definitionsPath\n ? requested\n : requested.filter((report: RequestedReport) => {\n return DefinitionUtils.getCurrentVariantDefinition(definitions, report.reportId, report.id)\n })\n\n res.locals['recentlyViewedReports'] = !definitionsPath\n ? recent\n : recent.filter((report: StoredReportData) => {\n return DefinitionUtils.getCurrentVariantDefinition(definitions, report.reportId, report.id)\n })\n\n res.locals['downloadingEnabled'] = services.downloadPermissionService.enabled\n res.locals['bookmarkingEnabled'] = services.bookmarkService.enabled\n res.locals['collectionsEnabled'] = services.productCollectionService.enabled\n res.locals['requestMissingEnabled'] = services.missingReportService.enabled\n res.locals['saveDefaultsEnabled'] = services.defaultFilterValuesService.enabled\n\n if (res.locals['bookmarkingEnabled']) {\n const bookmarks = await services.bookmarkService.getAllBookmarks(dprUser.id)\n res.locals['bookmarks'] = !definitionsPath\n ? bookmarks\n : bookmarks.filter((bookmark: BookmarkStoreData) => {\n return DefinitionUtils.getCurrentVariantDefinition(definitions, bookmark.reportId, bookmark.id)\n })\n }\n }\n}\n\nexport default setupResources\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,wBAAAC,EAAA,wBAAAC,EAAA,6BAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAP,GAMA,IAAAQ,EAA4B,uCAG5BC,EAAyB,oCAEzB,MAAMC,EAAwB,CAACC,EAAiBC,IAAkBD,EAAMC,CAAI,EAAID,EAAMC,CAAI,EAAE,SAAS,EAAI,KACnGC,EAAsBF,GAAoBD,EAAsBC,EAAO,4BAA4B,EAEnGG,EAAyBH,GAAmC,CAChE,MAAMI,EAAkBF,EAAmBF,CAAK,EAChD,OAAII,GAIG,IACT,EAEaZ,EACVa,GACD,CAACC,EAAkBC,EAAeC,EAAeC,IAC3CH,EAAM,SAAW,KAAOA,EAAM,SAAW,IACpCE,EAAI,OAAO,2BAA4B,CAC5C,WAAAH,EACA,QAAS,4DACX,CAAC,EAECC,EAAM,QAAU,IACXE,EAAI,OAAO,gCAAiC,CACjD,WAAAH,CACF,CAAC,EAEII,EAAK,EAGHd,EAAiB,CAACe,EAAoBL,EAAoBM,IAC9D,MAAOC,EAAKJ,EAAKC,IAAS,CAC/BI,EAAyBD,EAAKJ,CAAG,EACjC,GAAI,CACF,aAAMf,EAAoBiB,EAAUE,EAAKJ,EAAKG,CAAM,EACpD,MAAMjB,EAAyBgB,EAAUF,CAAG,EACrCC,EAAK,CACd,OAASH,EAAO,CACd,OAAOd,EAAoBa,CAAU,EAAEC,EAAOM,EAAKJ,EAAKC,CAAI,CAC9D,CACF,EAGII,EAA2B,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gBAAAxB,CAAgB,EAAII,EAAI,OAEvCqB,EAAS,MAAMnB,EAAS,sBAAsB,cAAcM,EAAQ,EAAE,EAC5E,MAAMN,EAAS,uBAAuB,UAAUM,EAAQ,GAAIa,CAAM,EAClE,MAAMC,EAAY,MAAMpB,EAAS,uBAAuB,cAAcM,EAAQ,EAAE,EAoBhF,GAlBAR,EAAI,OAAO,iBAAuBJ,EAE9B0B,EAAU,OAAQC,GACT,EAAAC,QAAgB,4BAA4BJ,EAAaG,EAAO,SAAUA,EAAO,EAAE,CAC3F,EAHDD,EAKJtB,EAAI,OAAO,sBAA4BJ,EAEnCyB,EAAO,OAAQE,GACN,EAAAC,QAAgB,4BAA4BJ,EAAaG,EAAO,SAAUA,EAAO,EAAE,CAC3F,EAHDF,EAKJrB,EAAI,OAAO,mBAAwBE,EAAS,0BAA0B,QACtEF,EAAI,OAAO,mBAAwBE,EAAS,gBAAgB,QAC5DF,EAAI,OAAO,mBAAwBE,EAAS,yBAAyB,QACrEF,EAAI,OAAO,sBAA2BE,EAAS,qBAAqB,QACpEF,EAAI,OAAO,oBAAyBE,EAAS,2BAA2B,QAEpEF,EAAI,OAAO,mBAAuB,CACpC,MAAMyB,EAAY,MAAMvB,EAAS,gBAAgB,gBAAgBM,EAAQ,EAAE,EAC3ER,EAAI,OAAO,UAAgBJ,EAEvB6B,EAAU,OAAQC,GACT,EAAAF,QAAgB,4BAA4BJ,EAAaM,EAAS,SAAUA,EAAS,EAAE,CAC/F,EAHDD,CAIN,CACF,CACF,EAEA,IAAO1C,EAAQI",
|
|
6
|
+
"names": ["setUpDprResources_exports", "__export", "setUpDprResources_default", "errorRequestHandler", "populateDefinitions", "populateRequestedReports", "setupResources", "__toCommonJS", "import_definitionUtils", "import_localsHelper", "getQueryParamAsString", "query", "name", "getDefinitionsPath", "deriveDefinitionsPath", "definitionsPath", "layoutPath", "error", "_req", "res", "next", "services", "config", "req", "populateValidationErrors", "errors", "token", "dprUser", "localsHelper", "dpdPathFromQuery", "dpdPathFromBody", "definitionsPathFromQuery", "dpdPathFromConfig", "selectedProductCollectionId", "defs", "selectedProductCollection", "productIds", "product", "def", "definitions", "recent", "requested", "report", "DefinitionUtils", "bookmarks", "bookmark"]
|
|
7
7
|
}
|
|
@@ -106,14 +106,16 @@ export const populateRequestedReports = async (services: Services, res: Response
|
|
|
106
106
|
if (dprUser.id) {
|
|
107
107
|
const { definitions, definitionsPath } = res.locals
|
|
108
108
|
|
|
109
|
+
const recent = await services.recentlyViewedService.getAllReports(dprUser.id)
|
|
110
|
+
await services.requestedReportService.cleanList(dprUser.id, recent)
|
|
109
111
|
const requested = await services.requestedReportService.getAllReports(dprUser.id)
|
|
112
|
+
|
|
110
113
|
res.locals['requestedReports'] = !definitionsPath
|
|
111
114
|
? requested
|
|
112
115
|
: requested.filter((report: RequestedReport) => {
|
|
113
116
|
return DefinitionUtils.getCurrentVariantDefinition(definitions, report.reportId, report.id)
|
|
114
117
|
})
|
|
115
118
|
|
|
116
|
-
const recent = await services.recentlyViewedService.getAllReports(dprUser.id)
|
|
117
119
|
res.locals['recentlyViewedReports'] = !definitionsPath
|
|
118
120
|
? recent
|
|
119
121
|
: recent.filter((report: StoredReportData) => {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var k=Object.create;var i=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var y=(e,r)=>{for(var o in r)i(e,o,{get:r[o],enumerable:!0})},d=(e,r,o,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of v(r))!h.call(e,t)&&t!==o&&i(e,t,{get:()=>r[t],enumerable:!(s=n(r,t))||s.enumerable});return e};var S=(e,r,o)=>(o=e!=null?k(u(e)):{},d(r||!e||!e.__esModule?i(o,"default",{value:e,enumerable:!0}):o,e)),f=e=>d(i({},"__esModule",{value:!0}),e);var g={};y(g,{BookmarkController:()=>a,default:()=>b});module.exports=f(g);var l=S(require("../../../../utils/localsHelper"));class a{constructor(r,o){this.POST=async(r,o)=>{const{dprUser:s}=l.default.getValues(o),{reportId:t,id:c,reportType:m,type:p}=r.body;p==="add"?await this.services.bookmarkService.addBookmark(s.id,t,c,m):await this.services.bookmarkService.removeBookmark(s.id,c,t),o.end()};this.layoutPath=r,this.services=o}}var b=a;0&&(module.exports={BookmarkController});
|
|
2
2
|
//# sourceMappingURL=controller.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/dpr/routes/journeys/my-reports/bookmarks/controller.ts"],
|
|
4
|
-
"sourcesContent": ["import { RequestHandler } from 'express'\nimport { Services } from '../../../../types/Services'\nimport LocalsHelper from '../../../../utils/localsHelper'\n\nclass BookmarkController {\n layoutPath: string\n\n services: Services\n\n constructor(layoutPath: string, services: Services) {\n this.layoutPath = layoutPath\n this.services = services\n }\n\n POST: RequestHandler = async (req, res) => {\n const { dprUser } = LocalsHelper.getValues(res)\n const { reportId, id, reportType } = req.body\n await this.services.bookmarkService.addBookmark(dprUser.id, reportId, id, reportType)\n
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAEA,IAAAK,EAAyB,6CAEzB,MAAMH,CAAmB,CAKvB,YAAYI,EAAoBC,EAAoB,CAKpD,UAAuB,MAAOC,EAAKC,IAAQ,CACzC,KAAM,CAAE,QAAAC,CAAQ,EAAI,EAAAC,QAAa,UAAUF,CAAG,EACxC,CAAE,SAAAG,EAAU,GAAAC,EAAI,WAAAC,
|
|
6
|
-
"names": ["controller_exports", "__export", "BookmarkController", "controller_default", "__toCommonJS", "import_localsHelper", "layoutPath", "services", "req", "res", "dprUser", "LocalsHelper", "reportId", "id", "reportType"]
|
|
4
|
+
"sourcesContent": ["import { RequestHandler } from 'express'\nimport { Services } from '../../../../types/Services'\nimport LocalsHelper from '../../../../utils/localsHelper'\n\nclass BookmarkController {\n layoutPath: string\n\n services: Services\n\n constructor(layoutPath: string, services: Services) {\n this.layoutPath = layoutPath\n this.services = services\n }\n\n POST: RequestHandler = async (req, res) => {\n const { dprUser } = LocalsHelper.getValues(res)\n const { reportId, id, reportType, type } = req.body\n if (type === 'add') {\n await this.services.bookmarkService.addBookmark(dprUser.id, reportId, id, reportType)\n } else {\n await this.services.bookmarkService.removeBookmark(dprUser.id, id, reportId)\n }\n res.end()\n }\n}\n\nexport { BookmarkController }\nexport default BookmarkController\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAEA,IAAAK,EAAyB,6CAEzB,MAAMH,CAAmB,CAKvB,YAAYI,EAAoBC,EAAoB,CAKpD,UAAuB,MAAOC,EAAKC,IAAQ,CACzC,KAAM,CAAE,QAAAC,CAAQ,EAAI,EAAAC,QAAa,UAAUF,CAAG,EACxC,CAAE,SAAAG,EAAU,GAAAC,EAAI,WAAAC,EAAY,KAAAC,CAAK,EAAIP,EAAI,KAC3CO,IAAS,MACX,MAAM,KAAK,SAAS,gBAAgB,YAAYL,EAAQ,GAAIE,EAAUC,EAAIC,CAAU,EAEpF,MAAM,KAAK,SAAS,gBAAgB,eAAeJ,EAAQ,GAAIG,EAAID,CAAQ,EAE7EH,EAAI,IAAI,CACV,EAbE,KAAK,WAAaH,EAClB,KAAK,SAAWC,CAClB,CAYF,CAGA,IAAOJ,EAAQD",
|
|
6
|
+
"names": ["controller_exports", "__export", "BookmarkController", "controller_default", "__toCommonJS", "import_localsHelper", "layoutPath", "services", "req", "res", "dprUser", "LocalsHelper", "reportId", "id", "reportType", "type"]
|
|
7
7
|
}
|
|
@@ -14,15 +14,12 @@ class BookmarkController {
|
|
|
14
14
|
|
|
15
15
|
POST: RequestHandler = async (req, res) => {
|
|
16
16
|
const { dprUser } = LocalsHelper.getValues(res)
|
|
17
|
-
const { reportId, id, reportType } = req.body
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const { dprUser } = LocalsHelper.getValues(res)
|
|
24
|
-
const { id, reportId } = req.body
|
|
25
|
-
await this.services.bookmarkService.removeBookmark(dprUser.id, id, reportId)
|
|
17
|
+
const { reportId, id, reportType, type } = req.body
|
|
18
|
+
if (type === 'add') {
|
|
19
|
+
await this.services.bookmarkService.addBookmark(dprUser.id, reportId, id, reportType)
|
|
20
|
+
} else {
|
|
21
|
+
await this.services.bookmarkService.removeBookmark(dprUser.id, id, reportId)
|
|
22
|
+
}
|
|
26
23
|
res.end()
|
|
27
24
|
}
|
|
28
25
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var f=Object.create;var m=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var
|
|
1
|
+
"use strict";var f=Object.create;var m=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var v=(r,o)=>{for(var t in o)m(r,t,{get:o[t],enumerable:!0})},i=(r,o,t,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of S(o))!k.call(r,e)&&e!==t&&m(r,e,{get:()=>o[e],enumerable:!(s=a(o,e))||s.enumerable});return r};var n=(r,o,t)=>(t=r!=null?f(g(r)):{},i(o||!r||!r.__esModule?m(t,"default",{value:r,enumerable:!0}):t,r)),x=r=>i(m({},"__esModule",{value:!0}),r);var R={};v(R,{default:()=>P,routes:()=>c});module.exports=x(R);var u=require("express"),l=n(require("./controller")),p=n(require("./list/routes"));function c({layoutPath:r,services:o}){const t=(0,u.Router)({mergeParams:!0}),s=new l.default(r,o);return t.post("/",s.POST),t.use("/list",(0,p.default)({layoutPath:r,services:o})),t}var P=c;0&&(module.exports={routes});
|
|
2
2
|
//# sourceMappingURL=routes.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/dpr/routes/journeys/my-reports/bookmarks/routes.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable no-param-reassign */\nimport { Router } from 'express'\nimport { Services } from '../../../../types/Services'\nimport BookmarkController from './controller'\nimport listRoutes from './list/routes'\n\nexport function routes({ layoutPath, services }: { layoutPath: string; services: Services }) {\n const router = Router({ mergeParams: true })\n\n const controller = new BookmarkController(layoutPath, services)\n
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,WAAAC,IAAA,eAAAC,EAAAJ,GACA,IAAAK,EAAuB,mBAEvBC,EAA+B,2BAC/BC,EAAuB,4BAEhB,SAASJ,EAAO,CAAE,WAAAK,EAAY,SAAAC,CAAS,EAA+C,CAC3F,MAAMC,KAAS,UAAO,CAAE,YAAa,EAAK,CAAC,EAErCC,EAAa,IAAI,EAAAC,QAAmBJ,EAAYC,CAAQ,
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-param-reassign */\nimport { Router } from 'express'\nimport { Services } from '../../../../types/Services'\nimport BookmarkController from './controller'\nimport listRoutes from './list/routes'\n\nexport function routes({ layoutPath, services }: { layoutPath: string; services: Services }) {\n const router = Router({ mergeParams: true })\n\n const controller = new BookmarkController(layoutPath, services)\n router.post('/', controller.POST)\n router.use(`/list`, listRoutes({ layoutPath, services }))\n return router\n}\n\nexport default routes\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,WAAAC,IAAA,eAAAC,EAAAJ,GACA,IAAAK,EAAuB,mBAEvBC,EAA+B,2BAC/BC,EAAuB,4BAEhB,SAASJ,EAAO,CAAE,WAAAK,EAAY,SAAAC,CAAS,EAA+C,CAC3F,MAAMC,KAAS,UAAO,CAAE,YAAa,EAAK,CAAC,EAErCC,EAAa,IAAI,EAAAC,QAAmBJ,EAAYC,CAAQ,EAC9D,OAAAC,EAAO,KAAK,IAAKC,EAAW,IAAI,EAChCD,EAAO,IAAI,WAAS,EAAAG,SAAW,CAAE,WAAAL,EAAY,SAAAC,CAAS,CAAC,CAAC,EACjDC,CACT,CAEA,IAAOR,EAAQC",
|
|
6
6
|
"names": ["routes_exports", "__export", "routes_default", "routes", "__toCommonJS", "import_express", "import_controller", "import_routes", "layoutPath", "services", "router", "controller", "BookmarkController", "listRoutes"]
|
|
7
7
|
}
|
|
@@ -8,10 +8,7 @@ export function routes({ layoutPath, services }: { layoutPath: string; services:
|
|
|
8
8
|
const router = Router({ mergeParams: true })
|
|
9
9
|
|
|
10
10
|
const controller = new BookmarkController(layoutPath, services)
|
|
11
|
-
|
|
12
11
|
router.post('/', controller.POST)
|
|
13
|
-
router.delete('/', controller.DELETE)
|
|
14
|
-
|
|
15
12
|
router.use(`/list`, listRoutes({ layoutPath, services }))
|
|
16
13
|
return router
|
|
17
14
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var S=Object.create;var k=Object.defineProperty;var
|
|
2
|
-
<input class='bookmark-input' type='checkbox' id='${t}-${e}-${i}' data-report-id='${t}' data-id='${e}' data-report-type='${n}' data-csrf-token='${r}' ${b} />
|
|
1
|
+
"use strict";var S=Object.create;var k=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var R=(a,s)=>{for(var o in s)k(a,o,{get:s[o],enumerable:!0})},c=(a,s,o,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let e of C(s))!y.call(a,e)&&e!==o&&k(a,e,{get:()=>s[e],enumerable:!(t=$(s,e))||t.enumerable});return a};var p=(a,s,o)=>(o=a!=null?S(v(a)):{},c(s||!a||!a.__esModule?k(o,"default",{value:a,enumerable:!0}):o,a)),w=a=>c(k({},"__esModule",{value:!0}),a);var T={};R(T,{BookmarkService:()=>m,default:()=>x});module.exports=w(T);var u=p(require("../../../../services/reportStoreService")),h=p(require("../../../../utils/logger"));class m extends u.default{constructor(o,t){super(o);this.isBookmarked=async(o,t,e)=>{if(!this.enabled)return!1;const r=await this.getState(e),i=this.isBookmarkedCheck(r,o,t);let n;return i&&(n=this.getBookmark(r,o,t)),n?.automatic?void 0:i};this.isBookmarkedCheck=(o,t,e)=>o.bookmarks.some(r=>r.id===t&&r.reportId===e);this.getBookmark=(o,t,e)=>o.bookmarks.find(r=>r.id===t&&r.reportId===e);this.enabled=!!t.bookmarking,this.enabled||h.default.info("Bookmarking: disabled ")}async getAllBookmarks(o){return this.enabled?(await this.getState(o)).bookmarks:[]}async addBookmark(o,t,e,r,i){if(!this.enabled)return;const n=await this.getState(o);this.isBookmarkedCheck(n,e,t)||n.bookmarks.unshift({reportId:t,id:e,type:r,automatic:i}),await this.saveState(o,n)}async removeBookmark(o,t,e){if(!this.enabled)return;const r=await this.getState(o),i=r.bookmarks.findIndex(n=>n.id===t&&n.reportId===e);i>=0&&r.bookmarks.splice(i,1),await this.saveState(o,r)}async createBookMarkToggleHtml({userConfig:o,reportId:t,id:e,csrfToken:r,ctxId:i,reportType:n,isMissing:d,nestedBaseUrl:B}){let g="Add bookmark",l=!1,b=null;if(o?.bookmarks){const f=this.getBookmark(o,e,t);f&&(b="checked",g="Remove bookmark",l=!!f.automatic)}return l||d?"":`<button class='dpr-bookmark dpr-bookmark-table' data-dpr-module='bookmark-toggle'>
|
|
2
|
+
<input class='bookmark-input' type='checkbox' id='${t}-${e}-${i}' data-report-id='${t}' data-id='${e}' data-report-type='${n}' data-csrf-token='${r}' data-base-url="${B}" ${b} />
|
|
3
3
|
<label tabindex='0' id='${e}-${t}-${i}-bookmark-label' for='${t}-${e}-${i}'><span class='dpr-bookmark-label govuk-body-s'>${g}</span></label>
|
|
4
|
-
</button>`}}var
|
|
4
|
+
</button>`}}var x=m;0&&(module.exports={BookmarkService});
|
|
5
5
|
//# sourceMappingURL=service.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/dpr/routes/journeys/my-reports/bookmarks/service.ts"],
|
|
4
|
-
"sourcesContent": ["import ReportStoreService from '../../../../services/reportStoreService'\nimport ReportDataStore from '../../../../data/reportDataStore'\nimport { ReportType } from '../../../../types/UserReports'\nimport { ReportStoreConfig } from '../../../../types/ReportStore'\nimport logger from '../../../../utils/logger'\nimport { BookmarkStoreData } from '../../../../types/Bookmark'\nimport { ServiceFeatureConfig } from '../../../../types/DprConfig'\n\nclass BookmarkService extends ReportStoreService {\n enabled: boolean\n\n constructor(reportDataStore: ReportDataStore, serviceFeatureConfig: ServiceFeatureConfig) {\n super(reportDataStore)\n this.enabled = Boolean(serviceFeatureConfig.bookmarking)\n if (!this.enabled) logger.info(`Bookmarking: disabled `)\n }\n\n async getAllBookmarks(userId: string): Promise<BookmarkStoreData[]> {\n if (!this.enabled) return []\n\n const userConfig = await this.getState(userId)\n return userConfig.bookmarks\n }\n\n async addBookmark(\n userId: string,\n reportId: string,\n id: string,\n type: ReportType,\n automatic?: boolean,\n ): Promise<void> {\n if (!this.enabled) return\n\n const userConfig = await this.getState(userId)\n if (!this.isBookmarkedCheck(userConfig, id, reportId)) {\n userConfig.bookmarks.unshift({ reportId, id, type, automatic })\n }\n await this.saveState(userId, userConfig)\n }\n\n async removeBookmark(userId: string, id: string, reportId: string): Promise<void> {\n if (!this.enabled) return\n\n const userConfig = await this.getState(userId)\n const index = userConfig.bookmarks.findIndex((bookmark) => {\n const bmVarId = bookmark.id\n return bmVarId === id && bookmark.reportId === reportId\n })\n if (index >= 0) {\n userConfig.bookmarks.splice(index, 1)\n }\n await this.saveState(userId, userConfig)\n }\n\n isBookmarked = async (id: string, reportId: string, userId: string): Promise<boolean | undefined> => {\n if (!this.enabled) return false\n\n const userConfig = await this.getState(userId)\n const isBookmarked = this.isBookmarkedCheck(userConfig, id, reportId)\n let bookmark\n if (isBookmarked) {\n bookmark = this.getBookmark(userConfig, id, reportId)\n }\n\n return bookmark?.automatic ? undefined : isBookmarked\n }\n\n private isBookmarkedCheck = (userConfig: ReportStoreConfig, id: string, reportId: string): boolean => {\n return userConfig.bookmarks.some((bookmark) => {\n const bmVarId = bookmark.id\n return bmVarId === id && bookmark.reportId === reportId\n })\n }\n\n private getBookmark = (userConfig: ReportStoreConfig, id: string, reportId: string) => {\n return userConfig.bookmarks.find((bookmark) => {\n const bmVarId = bookmark.id\n return bmVarId === id && bookmark.reportId === reportId\n })\n }\n\n async createBookMarkToggleHtml({\n userConfig,\n reportId,\n id,\n csrfToken,\n ctxId,\n reportType,\n isMissing,\n }: {\n userConfig: ReportStoreConfig\n reportId: string\n id: string\n csrfToken: string\n ctxId: string\n reportType: ReportType\n isMissing: boolean\n }) {\n let tooltip = 'Add bookmark'\n let automatic = false\n let checked = null\n if (userConfig?.bookmarks) {\n const bookmark = this.getBookmark(userConfig, id, reportId)\n if (bookmark) {\n checked = 'checked'\n tooltip = 'Remove bookmark'\n automatic = Boolean(bookmark.automatic)\n }\n }\n\n return automatic || isMissing\n ? ''\n : `<button class='dpr-bookmark dpr-bookmark-table' data-dpr-module='bookmark-toggle'>\n <input class='bookmark-input' type='checkbox' id='${reportId}-${id}-${ctxId}' data-report-id='${reportId}' data-id='${id}' data-report-type='${reportType}' data-csrf-token='${csrfToken}' ${checked} />\n <label tabindex='0' id='${id}-${reportId}-${ctxId}-bookmark-label' for='${reportId}-${id}-${ctxId}'><span class='dpr-bookmark-label govuk-body-s'>${tooltip}</span></label>\n</button>`\n }\n}\n\nexport { BookmarkService }\nexport default BookmarkService\n"],
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAA+B,sDAI/BC,EAAmB,uCAInB,MAAMJ,UAAwB,EAAAK,OAAmB,CAG/C,YAAYC,EAAkCC,EAA4C,CAC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N,EAAW,UAAU,OAAOM,EAAO,CAAC,EAEtC,MAAM,KAAK,UAAUP,EAAQC,CAAU,CACzC,CA6BA,MAAM,yBAAyB,CAC7B,WAAAA,EACA,SAAAF,EACA,GAAAD,EACA,UAAAU,EACA,MAAAC,EACA,WAAAC,EACA,UAAAC,CACF,
|
|
6
|
-
"names": ["service_exports", "__export", "BookmarkService", "service_default", "__toCommonJS", "import_reportStoreService", "import_logger", "ReportStoreService", "reportDataStore", "serviceFeatureConfig", "id", "reportId", "userId", "userConfig", "isBookmarked", "bookmark", "logger", "type", "automatic", "index", "csrfToken", "ctxId", "reportType", "isMissing", "tooltip", "checked"]
|
|
4
|
+
"sourcesContent": ["import ReportStoreService from '../../../../services/reportStoreService'\nimport ReportDataStore from '../../../../data/reportDataStore'\nimport { ReportType } from '../../../../types/UserReports'\nimport { ReportStoreConfig } from '../../../../types/ReportStore'\nimport logger from '../../../../utils/logger'\nimport { BookmarkStoreData } from '../../../../types/Bookmark'\nimport { ServiceFeatureConfig } from '../../../../types/DprConfig'\n\nclass BookmarkService extends ReportStoreService {\n enabled: boolean\n\n constructor(reportDataStore: ReportDataStore, serviceFeatureConfig: ServiceFeatureConfig) {\n super(reportDataStore)\n this.enabled = Boolean(serviceFeatureConfig.bookmarking)\n if (!this.enabled) logger.info(`Bookmarking: disabled `)\n }\n\n async getAllBookmarks(userId: string): Promise<BookmarkStoreData[]> {\n if (!this.enabled) return []\n\n const userConfig = await this.getState(userId)\n return userConfig.bookmarks\n }\n\n async addBookmark(\n userId: string,\n reportId: string,\n id: string,\n type: ReportType,\n automatic?: boolean,\n ): Promise<void> {\n if (!this.enabled) return\n\n const userConfig = await this.getState(userId)\n if (!this.isBookmarkedCheck(userConfig, id, reportId)) {\n userConfig.bookmarks.unshift({ reportId, id, type, automatic })\n }\n await this.saveState(userId, userConfig)\n }\n\n async removeBookmark(userId: string, id: string, reportId: string): Promise<void> {\n if (!this.enabled) return\n\n const userConfig = await this.getState(userId)\n const index = userConfig.bookmarks.findIndex((bookmark) => {\n const bmVarId = bookmark.id\n return bmVarId === id && bookmark.reportId === reportId\n })\n if (index >= 0) {\n userConfig.bookmarks.splice(index, 1)\n }\n await this.saveState(userId, userConfig)\n }\n\n isBookmarked = async (id: string, reportId: string, userId: string): Promise<boolean | undefined> => {\n if (!this.enabled) return false\n\n const userConfig = await this.getState(userId)\n const isBookmarked = this.isBookmarkedCheck(userConfig, id, reportId)\n let bookmark\n if (isBookmarked) {\n bookmark = this.getBookmark(userConfig, id, reportId)\n }\n\n return bookmark?.automatic ? undefined : isBookmarked\n }\n\n private isBookmarkedCheck = (userConfig: ReportStoreConfig, id: string, reportId: string): boolean => {\n return userConfig.bookmarks.some((bookmark) => {\n const bmVarId = bookmark.id\n return bmVarId === id && bookmark.reportId === reportId\n })\n }\n\n private getBookmark = (userConfig: ReportStoreConfig, id: string, reportId: string) => {\n return userConfig.bookmarks.find((bookmark) => {\n const bmVarId = bookmark.id\n return bmVarId === id && bookmark.reportId === reportId\n })\n }\n\n async createBookMarkToggleHtml({\n userConfig,\n reportId,\n id,\n csrfToken,\n ctxId,\n reportType,\n isMissing,\n nestedBaseUrl,\n }: {\n userConfig: ReportStoreConfig\n reportId: string\n id: string\n csrfToken: string\n ctxId: string\n reportType: ReportType\n isMissing: boolean\n nestedBaseUrl: string | undefined\n }) {\n let tooltip = 'Add bookmark'\n let automatic = false\n let checked = null\n\n if (userConfig?.bookmarks) {\n const bookmark = this.getBookmark(userConfig, id, reportId)\n if (bookmark) {\n checked = 'checked'\n tooltip = 'Remove bookmark'\n automatic = Boolean(bookmark.automatic)\n }\n }\n\n return automatic || isMissing\n ? ''\n : `<button class='dpr-bookmark dpr-bookmark-table' data-dpr-module='bookmark-toggle'>\n <input class='bookmark-input' type='checkbox' id='${reportId}-${id}-${ctxId}' data-report-id='${reportId}' data-id='${id}' data-report-type='${reportType}' data-csrf-token='${csrfToken}' data-base-url=\"${nestedBaseUrl}\" ${checked} />\n <label tabindex='0' id='${id}-${reportId}-${ctxId}-bookmark-label' for='${reportId}-${id}-${ctxId}'><span class='dpr-bookmark-label govuk-body-s'>${tooltip}</span></label>\n</button>`\n }\n}\n\nexport { BookmarkService }\nexport default BookmarkService\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAA+B,sDAI/BC,EAAmB,uCAInB,MAAMJ,UAAwB,EAAAK,OAAmB,CAG/C,YAAYC,EAAkCC,EAA4C,CACxF,MAAMD,CAAe,EA0CvB,kBAAe,MAAOE,EAAYC,EAAkBC,IAAiD,CACnG,GAAI,CAAC,KAAK,QAAS,MAAO,GAE1B,MAAMC,EAAa,MAAM,KAAK,SAASD,CAAM,EACvCE,EAAe,KAAK,kBAAkBD,EAAYH,EAAIC,CAAQ,EACpE,IAAII,EACJ,OAAID,IACFC,EAAW,KAAK,YAAYF,EAAYH,EAAIC,CAAQ,GAG/CI,GAAU,UAAY,OAAYD,CAC3C,EAEA,KAAQ,kBAAoB,CAACD,EAA+BH,EAAYC,IAC/DE,EAAW,UAAU,KAAME,GAChBA,EAAS,KACNL,GAAMK,EAAS,WAAaJ,CAChD,EAGH,KAAQ,YAAc,CAACE,EAA+BH,EAAYC,IACzDE,EAAW,UAAU,KAAME,GAChBA,EAAS,KACNL,GAAMK,EAAS,WAAaJ,CAChD,EAjED,KAAK,QAAU,EAAQF,EAAqB,YACvC,KAAK,SAAS,EAAAO,QAAO,KAAK,wBAAwB,CACzD,CAEA,MAAM,gBAAgBJ,EAA8C,CAClE,OAAK,KAAK,SAES,MAAM,KAAK,SAASA,CAAM,GAC3B,UAHQ,CAAC,CAI7B,CAEA,MAAM,YACJA,EACAD,EACAD,EACAO,EACAC,EACe,CACf,GAAI,CAAC,KAAK,QAAS,OAEnB,MAAML,EAAa,MAAM,KAAK,SAASD,CAAM,EACxC,KAAK,kBAAkBC,EAAYH,EAAIC,CAAQ,GAClDE,EAAW,UAAU,QAAQ,CAAE,SAAAF,EAAU,GAAAD,EAAI,KAAAO,EAAM,UAAAC,CAAU,CAAC,EAEhE,MAAM,KAAK,UAAUN,EAAQC,CAAU,CACzC,CAEA,MAAM,eAAeD,EAAgBF,EAAYC,EAAiC,CAChF,GAAI,CAAC,KAAK,QAAS,OAEnB,MAAME,EAAa,MAAM,KAAK,SAASD,CAAM,EACvCO,EAAQN,EAAW,UAAU,UAAWE,GAC5BA,EAAS,KACNL,GAAMK,EAAS,WAAaJ,CAChD,EACGQ,GAAS,GACXN,EAAW,UAAU,OAAOM,EAAO,CAAC,EAEtC,MAAM,KAAK,UAAUP,EAAQC,CAAU,CACzC,CA6BA,MAAM,yBAAyB,CAC7B,WAAAA,EACA,SAAAF,EACA,GAAAD,EACA,UAAAU,EACA,MAAAC,EACA,WAAAC,EACA,UAAAC,EACA,cAAAC,CACF,EASG,CACD,IAAIC,EAAU,eACVP,EAAY,GACZQ,EAAU,KAEd,GAAIb,GAAY,UAAW,CACzB,MAAME,EAAW,KAAK,YAAYF,EAAYH,EAAIC,CAAQ,EACtDI,IACFW,EAAU,UACVD,EAAU,kBACVP,EAAY,EAAQH,EAAS,UAEjC,CAEA,OAAOG,GAAaK,EAChB,GACA;AAAA,sDAC8CZ,CAAQ,IAAID,CAAE,IAAIW,CAAK,qBAAqBV,CAAQ,cAAcD,CAAE,uBAAuBY,CAAU,sBAAsBF,CAAS,oBAAoBI,CAAa,KAAKE,CAAO;AAAA,4BAC3MhB,CAAE,IAAIC,CAAQ,IAAIU,CAAK,yBAAyBV,CAAQ,IAAID,CAAE,IAAIW,CAAK,mDAAmDI,CAAO;AAAA,UAE3J,CACF,CAGA,IAAOtB,EAAQD",
|
|
6
|
+
"names": ["service_exports", "__export", "BookmarkService", "service_default", "__toCommonJS", "import_reportStoreService", "import_logger", "ReportStoreService", "reportDataStore", "serviceFeatureConfig", "id", "reportId", "userId", "userConfig", "isBookmarked", "bookmark", "logger", "type", "automatic", "index", "csrfToken", "ctxId", "reportType", "isMissing", "nestedBaseUrl", "tooltip", "checked"]
|
|
7
7
|
}
|
|
@@ -87,6 +87,7 @@ class BookmarkService extends ReportStoreService {
|
|
|
87
87
|
ctxId,
|
|
88
88
|
reportType,
|
|
89
89
|
isMissing,
|
|
90
|
+
nestedBaseUrl,
|
|
90
91
|
}: {
|
|
91
92
|
userConfig: ReportStoreConfig
|
|
92
93
|
reportId: string
|
|
@@ -95,10 +96,12 @@ class BookmarkService extends ReportStoreService {
|
|
|
95
96
|
ctxId: string
|
|
96
97
|
reportType: ReportType
|
|
97
98
|
isMissing: boolean
|
|
99
|
+
nestedBaseUrl: string | undefined
|
|
98
100
|
}) {
|
|
99
101
|
let tooltip = 'Add bookmark'
|
|
100
102
|
let automatic = false
|
|
101
103
|
let checked = null
|
|
104
|
+
|
|
102
105
|
if (userConfig?.bookmarks) {
|
|
103
106
|
const bookmark = this.getBookmark(userConfig, id, reportId)
|
|
104
107
|
if (bookmark) {
|
|
@@ -111,7 +114,7 @@ class BookmarkService extends ReportStoreService {
|
|
|
111
114
|
return automatic || isMissing
|
|
112
115
|
? ''
|
|
113
116
|
: `<button class='dpr-bookmark dpr-bookmark-table' data-dpr-module='bookmark-toggle'>
|
|
114
|
-
<input class='bookmark-input' type='checkbox' id='${reportId}-${id}-${ctxId}' data-report-id='${reportId}' data-id='${id}' data-report-type='${reportType}' data-csrf-token='${csrfToken}' ${checked} />
|
|
117
|
+
<input class='bookmark-input' type='checkbox' id='${reportId}-${id}-${ctxId}' data-report-id='${reportId}' data-id='${id}' data-report-type='${reportType}' data-csrf-token='${csrfToken}' data-base-url="${nestedBaseUrl}" ${checked} />
|
|
115
118
|
<label tabindex='0' id='${id}-${reportId}-${ctxId}-bookmark-label' for='${reportId}-${id}-${ctxId}'><span class='dpr-bookmark-label govuk-body-s'>${tooltip}</span></label>
|
|
116
119
|
</button>`
|
|
117
120
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var d=Object.create;var o=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var n=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var R=(e,r)=>{for(var s in r)o(e,s,{get:r[s],enumerable:!0})},a=(e,r,s,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of v(r))!m.call(e,t)&&t!==s&&o(e,t,{get:()=>r[t],enumerable:!(i=l(r,t))||i.enumerable});return e};var u=(e,r,s)=>(s=e!=null?d(n(e)):{},a(r||!e||!e.__esModule?o(s,"default",{value:e,enumerable:!0}):s,e)),S=e=>a(o({},"__esModule",{value:!0}),e);var w={};R(w,{RecentlyViewedReportsController:()=>c,default:()=>f});module.exports=S(w);var p=u(require("../../../../utils/localsHelper"));class c{constructor(r){this.DELETE=async(r,s)=>{const{dprUser:i}=p.default.getValues(s),{id:t}=r.params;await this.services.recentlyViewedService.removeReport(t,i.id),await this.services.requestedReportService.removeReport(t,i.id),s.end()};this.services=r}}var f=c;0&&(module.exports={RecentlyViewedReportsController});
|
|
2
2
|
//# sourceMappingURL=controller.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/dpr/routes/journeys/my-reports/recently-viewed/controller.ts"],
|
|
4
|
-
"sourcesContent": ["import { RequestHandler } from 'express'\nimport { Services } from '../../../../types/Services'\nimport LocalsHelper from '../../../../utils/localsHelper'\n\nclass RecentlyViewedReportsController {\n services: Services\n\n constructor(services: Services) {\n this.services = services\n }\n\n DELETE: RequestHandler = async (req, res) => {\n const { dprUser } = LocalsHelper.getValues(res)\n const { id } = req.params\n await this.services.recentlyViewedService.removeReport(id, dprUser.id)\n res.end()\n }\n}\n\nexport { RecentlyViewedReportsController }\nexport default RecentlyViewedReportsController\n"],
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qCAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAEA,IAAAK,EAAyB,6CAEzB,MAAMH,CAAgC,CAGpC,YAAYI,EAAoB,CAIhC,YAAyB,MAAOC,EAAKC,IAAQ,CAC3C,KAAM,CAAE,QAAAC,CAAQ,EAAI,EAAAC,QAAa,UAAUF,CAAG,EACxC,CAAE,GAAAG,CAAG,EAAIJ,EAAI,OACnB,MAAM,KAAK,SAAS,sBAAsB,aAAaI,EAAIF,EAAQ,EAAE,
|
|
4
|
+
"sourcesContent": ["import { RequestHandler } from 'express'\nimport { Services } from '../../../../types/Services'\nimport LocalsHelper from '../../../../utils/localsHelper'\n\nclass RecentlyViewedReportsController {\n services: Services\n\n constructor(services: Services) {\n this.services = services\n }\n\n DELETE: RequestHandler = async (req, res) => {\n const { dprUser } = LocalsHelper.getValues(res)\n const { id } = req.params\n await this.services.recentlyViewedService.removeReport(id, dprUser.id)\n await this.services.requestedReportService.removeReport(id, dprUser.id)\n res.end()\n }\n}\n\nexport { RecentlyViewedReportsController }\nexport default RecentlyViewedReportsController\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qCAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAEA,IAAAK,EAAyB,6CAEzB,MAAMH,CAAgC,CAGpC,YAAYI,EAAoB,CAIhC,YAAyB,MAAOC,EAAKC,IAAQ,CAC3C,KAAM,CAAE,QAAAC,CAAQ,EAAI,EAAAC,QAAa,UAAUF,CAAG,EACxC,CAAE,GAAAG,CAAG,EAAIJ,EAAI,OACnB,MAAM,KAAK,SAAS,sBAAsB,aAAaI,EAAIF,EAAQ,EAAE,EACrE,MAAM,KAAK,SAAS,uBAAuB,aAAaE,EAAIF,EAAQ,EAAE,EACtED,EAAI,IAAI,CACV,EATE,KAAK,SAAWF,CAClB,CASF,CAGA,IAAOH,EAAQD",
|
|
6
6
|
"names": ["controller_exports", "__export", "RecentlyViewedReportsController", "controller_default", "__toCommonJS", "import_localsHelper", "services", "req", "res", "dprUser", "LocalsHelper", "id"]
|
|
7
7
|
}
|
|
@@ -13,6 +13,7 @@ class RecentlyViewedReportsController {
|
|
|
13
13
|
const { dprUser } = LocalsHelper.getValues(res)
|
|
14
14
|
const { id } = req.params
|
|
15
15
|
await this.services.recentlyViewedService.removeReport(id, dprUser.id)
|
|
16
|
+
await this.services.requestedReportService.removeReport(id, dprUser.id)
|
|
16
17
|
res.end()
|
|
17
18
|
}
|
|
18
19
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var y=Object.create;var R=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var E=(i,e)=>{for(var t in e)R(i,t,{get:e[t],enumerable:!0})},f=(i,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of I(e))!v.call(i,r)&&r!==t&&R(i,r,{get:()=>e[r],enumerable:!(s=x(e,r))||s.enumerable});return i};var m=(i,e,t)=>(t=i!=null?y(D(i)):{},f(e||!i||!i.__esModule?R(t,"default",{value:i,enumerable:!0}):t,i)),C=i=>f(R({},"__esModule",{value:!0}),i);var b={};E(b,{RequestedReportService:()=>l,default:()=>P});module.exports=C(b);var o=require("../../../../types/UserReports"),h=m(require("../../../../services/reportStoreService")),q=require("../../../../utils/urlHelper"),S=m(require("../../../../utils/logger"));class l extends h.default{constructor(e){super(e)}async addReport(e,t){const s=await this.getState(e);s.requestedReports.unshift(t),await this.saveState(e,s)}async removeReport(e,t){const s=await this.getState(t),r=this.findIndexByExecutionId(e,s.requestedReports);s.requestedReports.splice(r,1),await this.saveState(t,s)}async getReportByExecutionId(e,t){return(await this.getState(t)).requestedReports.find(r=>r.executionId===e)}async getReportByTableId(e,t){return(await this.getState(t)).requestedReports.find(r=>r.tableId===e)}async getAllReports(e){return(await this.getState(e)).requestedReports}async getAllReportsById(e,t){return(await this.getState(t)).requestedReports.filter(r=>r.id&&r.id===e||r.variantId&&r.variantId===e)}async updateLastViewed(e,t){const s=await this.getState(t),r=this.findIndexByExecutionId(e,s.requestedReports),a=s.requestedReports[r];a.timestamp.lastViewed=new Date,s.requestedReports[r]=a,await this.saveState(t,s)}async updateStatus(e,t,s,r){const a=await this.getState(t),d=this.findIndexByExecutionId(e,a.requestedReports);let n=a.requestedReports[d];n&&(n=this.updateDataByStatus(n,s,r)),a.requestedReports[d]=n,await this.saveState(t,a)}async setToExpired(e,t){const s=await this.getState(t),r=this.findIndexByExecutionId(e,s.requestedReports);let a=s.requestedReports[r];a&&(a={...a,status:o.RequestStatus.EXPIRED,timestamp:{...a.timestamp,expired:new Date}},s.requestedReports[r]=a,await this.saveState(t,s))}async cleanList(e,t){const a=(await this.getState(e)).requestedReports.filter(n=>n.timestamp.lastViewed!==void 0);let d=0;await Promise.all(a.map(async n=>{const{executionId:p}=n;!t.find(g=>{const{executionId:c}=g;return c&&c===p})&&p&&(await this.removeReport(p,e),d+=1)})),d>0&&S.default.info(`RequestedReports: Removed ${d} stale reports from list`)}setReportUrl(e){const{tableId:t,url:s,dpdPathFromQuery:r,dataProductDefinitionsPath:a,type:d}=e;let n,p;if(s&&s.polling?.pathname){let u=Array.from(new Array(2));u=s.polling.pathname.replace("/request-report","/view-report/async").split("/"),u[u.length-2]=t,u[u.length-1]=d;const g=u.join("/"),c=s.report?.search?s.report.search:"",w=a&&r?`${(0,q.getDpdPathSuffix)(a)}`:"";n=`${g}${c||w}`,p=`${s.origin}${n}`}return{pathname:n,fullUrl:p}}updateDataByStatus(e,t,s){const r=new Date;switch(t&&(e.status=t),t){case o.RequestStatus.FAILED:e.timestamp.failed=r,s&&(e.errorMessage=s);break;case o.RequestStatus.EXPIRED:e.timestamp.expired=r;break;case o.RequestStatus.ABORTED:e.timestamp.aborted=r;break;case o.RequestStatus.FINISHED:{e.timestamp.completed=r,e.url&&(e.url.report={...e.url.report,...this.setReportUrl(e)});break}case o.RequestStatus.SUBMITTED:e.timestamp.requested=r;break;case o.RequestStatus.STARTED:case o.RequestStatus.PICKED:break;default:e.timestamp.lastViewed=r;break}return e}}var P=l;0&&(module.exports={RequestedReportService});
|
|
2
2
|
//# sourceMappingURL=service.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/dpr/routes/journeys/my-reports/requested-reports/service.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable no-param-reassign */\nimport UserDataStore from '../../../../data/reportDataStore'\nimport { RequestedReport, RequestStatus } from '../../../../types/UserReports'\nimport ReportStoreService from '../../../../services/reportStoreService'\nimport { getDpdPathSuffix } from '../../../../utils/urlHelper'\n\nclass RequestedReportService extends ReportStoreService {\n constructor(userDataStore: UserDataStore) {\n super(userDataStore)\n }\n\n async addReport(userId: string, reportStateData: RequestedReport) {\n const userConfig = await this.getState(userId)\n userConfig.requestedReports.unshift(reportStateData)\n await this.saveState(userId, userConfig)\n }\n\n async removeReport(id: string, userId: string) {\n const userConfig = await this.getState(userId)\n const index = this.findIndexByExecutionId(id, userConfig.requestedReports)\n userConfig.requestedReports.splice(index, 1)\n await this.saveState(userId, userConfig)\n }\n\n async getReportByExecutionId(id: string, userId: string) {\n const userConfig = await this.getState(userId)\n return userConfig.requestedReports.find((report) => report.executionId === id)\n }\n\n async getReportByTableId(id: string, userId: string) {\n const userConfig = await this.getState(userId)\n return userConfig.requestedReports.find((report) => report.tableId === id)\n }\n\n async getAllReports(userId: string): Promise<RequestedReport[]> {\n const userConfig = await this.getState(userId)\n return userConfig.requestedReports\n }\n\n async getAllReportsById(id: string, userId: string) {\n const userConfig = await this.getState(userId)\n return userConfig.requestedReports.filter((requested) => {\n return (requested.id && requested.id === id) || (requested.variantId && requested.variantId === id)\n })\n }\n\n async updateLastViewed(id: string, userId: string) {\n const userConfig = await this.getState(userId)\n const index = this.findIndexByExecutionId(id, userConfig.requestedReports)\n const report: RequestedReport = userConfig.requestedReports[index]\n report.timestamp.lastViewed = new Date()\n userConfig.requestedReports[index] = report\n await this.saveState(userId, userConfig)\n }\n\n async updateStatus(id: string, userId: string, status?: RequestStatus, errorMessage?: string) {\n const userConfig = await this.getState(userId)\n const index = this.findIndexByExecutionId(id, userConfig.requestedReports)\n let report: RequestedReport = userConfig.requestedReports[index]\n if (report) report = this.updateDataByStatus(report, status, errorMessage)\n userConfig.requestedReports[index] = report\n await this.saveState(userId, userConfig)\n }\n\n async setToExpired(id: string, userId: string) {\n const userConfig = await this.getState(userId)\n const index = this.findIndexByExecutionId(id, userConfig.requestedReports)\n let report: RequestedReport = userConfig.requestedReports[index]\n if (report) {\n report = {\n ...report,\n status: RequestStatus.EXPIRED,\n timestamp: {\n ...report.timestamp,\n expired: new Date(),\n },\n }\n userConfig.requestedReports[index] = report\n await this.saveState(userId, userConfig)\n }\n }\n\n setReportUrl(report: RequestedReport) {\n const { tableId, url, dpdPathFromQuery, dataProductDefinitionsPath, type } = report\n\n let pathname\n let fullUrl\n\n if (url && url.polling?.pathname) {\n let reportUrlArr = Array.from(new Array(2))\n reportUrlArr = url.polling.pathname.replace('/request-report', '/view-report/async').split('/')\n reportUrlArr[reportUrlArr.length - 2] = tableId\n reportUrlArr[reportUrlArr.length - 1] = type\n const reportUrl = reportUrlArr.join('/')\n\n const search = url.report?.search ? url.report.search : ''\n const dpdPath =\n dataProductDefinitionsPath && dpdPathFromQuery ? `${getDpdPathSuffix(dataProductDefinitionsPath)}` : ''\n const searchPath = search || dpdPath\n pathname = `${reportUrl}${searchPath}`\n fullUrl = `${url.origin}${pathname}`\n }\n\n return {\n pathname,\n fullUrl,\n }\n }\n\n updateDataByStatus(report: RequestedReport, status?: RequestStatus | undefined, errorMessage?: string) {\n const ts = new Date()\n if (status) report.status = status\n switch (status) {\n case RequestStatus.FAILED:\n report.timestamp.failed = ts\n if (errorMessage) report.errorMessage = errorMessage\n break\n case RequestStatus.EXPIRED:\n report.timestamp.expired = ts\n break\n case RequestStatus.ABORTED:\n report.timestamp.aborted = ts\n break\n case RequestStatus.FINISHED: {\n report.timestamp.completed = ts\n if (report.url) {\n report.url.report = {\n ...report.url.report,\n ...this.setReportUrl(report),\n }\n }\n break\n }\n case RequestStatus.SUBMITTED:\n report.timestamp.requested = ts\n break\n case RequestStatus.STARTED:\n case RequestStatus.PICKED:\n break\n default:\n report.timestamp.lastViewed = ts\n break\n }\n\n return report\n }\n}\n\nexport { RequestedReportService }\nexport default RequestedReportService\n"],
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAEA,IAAAK,
|
|
6
|
-
"names": ["service_exports", "__export", "RequestedReportService", "service_default", "__toCommonJS", "import_UserReports", "import_reportStoreService", "import_urlHelper", "ReportStoreService", "userDataStore", "userId", "reportStateData", "userConfig", "id", "index", "report", "requested", "status", "errorMessage", "tableId", "url", "dpdPathFromQuery", "dataProductDefinitionsPath", "type", "pathname", "fullUrl", "reportUrlArr", "reportUrl", "search", "dpdPath", "ts"]
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-param-reassign */\nimport UserDataStore from '../../../../data/reportDataStore'\nimport { RequestedReport, RequestStatus, StoredReportData } from '../../../../types/UserReports'\nimport ReportStoreService from '../../../../services/reportStoreService'\nimport { getDpdPathSuffix } from '../../../../utils/urlHelper'\nimport logger from '../../../../utils/logger'\n\nclass RequestedReportService extends ReportStoreService {\n constructor(userDataStore: UserDataStore) {\n super(userDataStore)\n }\n\n async addReport(userId: string, reportStateData: RequestedReport) {\n const userConfig = await this.getState(userId)\n userConfig.requestedReports.unshift(reportStateData)\n await this.saveState(userId, userConfig)\n }\n\n async removeReport(id: string, userId: string) {\n const userConfig = await this.getState(userId)\n const index = this.findIndexByExecutionId(id, userConfig.requestedReports)\n userConfig.requestedReports.splice(index, 1)\n await this.saveState(userId, userConfig)\n }\n\n async getReportByExecutionId(id: string, userId: string) {\n const userConfig = await this.getState(userId)\n return userConfig.requestedReports.find((report) => report.executionId === id)\n }\n\n async getReportByTableId(id: string, userId: string) {\n const userConfig = await this.getState(userId)\n return userConfig.requestedReports.find((report) => report.tableId === id)\n }\n\n async getAllReports(userId: string): Promise<RequestedReport[]> {\n const userConfig = await this.getState(userId)\n return userConfig.requestedReports\n }\n\n async getAllReportsById(id: string, userId: string) {\n const userConfig = await this.getState(userId)\n return userConfig.requestedReports.filter((requested) => {\n return (requested.id && requested.id === id) || (requested.variantId && requested.variantId === id)\n })\n }\n\n async updateLastViewed(id: string, userId: string) {\n const userConfig = await this.getState(userId)\n const index = this.findIndexByExecutionId(id, userConfig.requestedReports)\n const report: RequestedReport = userConfig.requestedReports[index]\n report.timestamp.lastViewed = new Date()\n userConfig.requestedReports[index] = report\n await this.saveState(userId, userConfig)\n }\n\n async updateStatus(id: string, userId: string, status?: RequestStatus, errorMessage?: string) {\n const userConfig = await this.getState(userId)\n const index = this.findIndexByExecutionId(id, userConfig.requestedReports)\n let report: RequestedReport = userConfig.requestedReports[index]\n if (report) report = this.updateDataByStatus(report, status, errorMessage)\n userConfig.requestedReports[index] = report\n await this.saveState(userId, userConfig)\n }\n\n async setToExpired(id: string, userId: string) {\n const userConfig = await this.getState(userId)\n const index = this.findIndexByExecutionId(id, userConfig.requestedReports)\n let report: RequestedReport = userConfig.requestedReports[index]\n if (report) {\n report = {\n ...report,\n status: RequestStatus.EXPIRED,\n timestamp: {\n ...report.timestamp,\n expired: new Date(),\n },\n }\n userConfig.requestedReports[index] = report\n await this.saveState(userId, userConfig)\n }\n }\n\n /**\n * Removes old stale data from requested reports\n * - When a report is viewed it is given a lastViewed ts.\n * - If the requested data has a lastViewed ts and\n * - has no corresponding viewed entry\n * - then that requested data is stale and can be removed\n *\n * @param {string} userId\n * @param {StoredReportData[]} viewedReports\n * @memberof RequestedReportService\n */\n async cleanList(userId: string, viewedReports: StoredReportData[]) {\n const userConfig = await this.getState(userId)\n const allRequested = userConfig.requestedReports\n const viewedRequestedReports = allRequested.filter((requestedReport) => {\n return requestedReport.timestamp.lastViewed !== undefined\n })\n\n let count = 0\n await Promise.all(\n viewedRequestedReports.map(async (viewedRequestReport) => {\n const { executionId } = viewedRequestReport\n const viewedReport = viewedReports.find((report) => {\n const { executionId: viewedExecutionId } = report\n return viewedExecutionId && viewedExecutionId === executionId\n })\n if (!viewedReport && executionId) {\n await this.removeReport(executionId, userId)\n count += 1\n }\n }),\n )\n if (count > 0) logger.info(`RequestedReports: Removed ${count} stale reports from list`)\n }\n\n setReportUrl(report: RequestedReport) {\n const { tableId, url, dpdPathFromQuery, dataProductDefinitionsPath, type } = report\n\n let pathname\n let fullUrl\n\n if (url && url.polling?.pathname) {\n let reportUrlArr = Array.from(new Array(2))\n reportUrlArr = url.polling.pathname.replace('/request-report', '/view-report/async').split('/')\n reportUrlArr[reportUrlArr.length - 2] = tableId\n reportUrlArr[reportUrlArr.length - 1] = type\n const reportUrl = reportUrlArr.join('/')\n\n const search = url.report?.search ? url.report.search : ''\n const dpdPath =\n dataProductDefinitionsPath && dpdPathFromQuery ? `${getDpdPathSuffix(dataProductDefinitionsPath)}` : ''\n const searchPath = search || dpdPath\n pathname = `${reportUrl}${searchPath}`\n fullUrl = `${url.origin}${pathname}`\n }\n\n return {\n pathname,\n fullUrl,\n }\n }\n\n updateDataByStatus(report: RequestedReport, status?: RequestStatus | undefined, errorMessage?: string) {\n const ts = new Date()\n if (status) report.status = status\n switch (status) {\n case RequestStatus.FAILED:\n report.timestamp.failed = ts\n if (errorMessage) report.errorMessage = errorMessage\n break\n case RequestStatus.EXPIRED:\n report.timestamp.expired = ts\n break\n case RequestStatus.ABORTED:\n report.timestamp.aborted = ts\n break\n case RequestStatus.FINISHED: {\n report.timestamp.completed = ts\n if (report.url) {\n report.url.report = {\n ...report.url.report,\n ...this.setReportUrl(report),\n }\n }\n break\n }\n case RequestStatus.SUBMITTED:\n report.timestamp.requested = ts\n break\n case RequestStatus.STARTED:\n case RequestStatus.PICKED:\n break\n default:\n report.timestamp.lastViewed = ts\n break\n }\n\n return report\n }\n}\n\nexport { RequestedReportService }\nexport default RequestedReportService\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAEA,IAAAK,EAAiE,yCACjEC,EAA+B,sDAC/BC,EAAiC,uCACjCC,EAAmB,uCAEnB,MAAMN,UAA+B,EAAAO,OAAmB,CACtD,YAAYC,EAA8B,CACxC,MAAMA,CAAa,CACrB,CAEA,MAAM,UAAUC,EAAgBC,EAAkC,CAChE,MAAMC,EAAa,MAAM,KAAK,SAASF,CAAM,EAC7CE,EAAW,iBAAiB,QAAQD,CAAe,EACnD,MAAM,KAAK,UAAUD,EAAQE,CAAU,CACzC,CAEA,MAAM,aAAaC,EAAYH,EAAgB,CAC7C,MAAME,EAAa,MAAM,KAAK,SAASF,CAAM,EACvCI,EAAQ,KAAK,uBAAuBD,EAAID,EAAW,gBAAgB,EACzEA,EAAW,iBAAiB,OAAOE,EAAO,CAAC,EAC3C,MAAM,KAAK,UAAUJ,EAAQE,CAAU,CACzC,CAEA,MAAM,uBAAuBC,EAAYH,EAAgB,CAEvD,OADmB,MAAM,KAAK,SAASA,CAAM,GAC3B,iBAAiB,KAAMK,GAAWA,EAAO,cAAgBF,CAAE,CAC/E,CAEA,MAAM,mBAAmBA,EAAYH,EAAgB,CAEnD,OADmB,MAAM,KAAK,SAASA,CAAM,GAC3B,iBAAiB,KAAMK,GAAWA,EAAO,UAAYF,CAAE,CAC3E,CAEA,MAAM,cAAcH,EAA4C,CAE9D,OADmB,MAAM,KAAK,SAASA,CAAM,GAC3B,gBACpB,CAEA,MAAM,kBAAkBG,EAAYH,EAAgB,CAElD,OADmB,MAAM,KAAK,SAASA,CAAM,GAC3B,iBAAiB,OAAQM,GACjCA,EAAU,IAAMA,EAAU,KAAOH,GAAQG,EAAU,WAAaA,EAAU,YAAcH,CACjG,CACH,CAEA,MAAM,iBAAi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SAAU,CAC3BvB,EAAO,UAAU,UAAYuB,EACzBvB,EAAO,MACTA,EAAO,IAAI,OAAS,CAClB,GAAGA,EAAO,IAAI,OACd,GAAG,KAAK,aAAaA,CAAM,CAC7B,GAEF,KACF,CACA,KAAK,gBAAc,UACjBA,EAAO,UAAU,UAAYuB,EAC7B,MACF,KAAK,gBAAc,QACnB,KAAK,gBAAc,OACjB,MACF,QACEvB,EAAO,UAAU,WAAauB,EAC9B,KACJ,CAEA,OAAOvB,CACT,CACF,CAGA,IAAOb,EAAQD",
|
|
6
|
+
"names": ["service_exports", "__export", "RequestedReportService", "service_default", "__toCommonJS", "import_UserReports", "import_reportStoreService", "import_urlHelper", "import_logger", "ReportStoreService", "userDataStore", "userId", "reportStateData", "userConfig", "id", "index", "report", "requested", "status", "errorMessage", "viewedReports", "viewedRequestedReports", "requestedReport", "count", "viewedRequestReport", "executionId", "viewedExecutionId", "logger", "tableId", "url", "dpdPathFromQuery", "dataProductDefinitionsPath", "type", "pathname", "fullUrl", "reportUrlArr", "reportUrl", "search", "dpdPath", "ts"]
|
|
7
7
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */
|
|
2
2
|
import UserDataStore from '../../../../data/reportDataStore'
|
|
3
|
-
import { RequestedReport, RequestStatus } from '../../../../types/UserReports'
|
|
3
|
+
import { RequestedReport, RequestStatus, StoredReportData } from '../../../../types/UserReports'
|
|
4
4
|
import ReportStoreService from '../../../../services/reportStoreService'
|
|
5
5
|
import { getDpdPathSuffix } from '../../../../utils/urlHelper'
|
|
6
|
+
import logger from '../../../../utils/logger'
|
|
6
7
|
|
|
7
8
|
class RequestedReportService extends ReportStoreService {
|
|
8
9
|
constructor(userDataStore: UserDataStore) {
|
|
@@ -80,6 +81,41 @@ class RequestedReportService extends ReportStoreService {
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Removes old stale data from requested reports
|
|
86
|
+
* - When a report is viewed it is given a lastViewed ts.
|
|
87
|
+
* - If the requested data has a lastViewed ts and
|
|
88
|
+
* - has no corresponding viewed entry
|
|
89
|
+
* - then that requested data is stale and can be removed
|
|
90
|
+
*
|
|
91
|
+
* @param {string} userId
|
|
92
|
+
* @param {StoredReportData[]} viewedReports
|
|
93
|
+
* @memberof RequestedReportService
|
|
94
|
+
*/
|
|
95
|
+
async cleanList(userId: string, viewedReports: StoredReportData[]) {
|
|
96
|
+
const userConfig = await this.getState(userId)
|
|
97
|
+
const allRequested = userConfig.requestedReports
|
|
98
|
+
const viewedRequestedReports = allRequested.filter((requestedReport) => {
|
|
99
|
+
return requestedReport.timestamp.lastViewed !== undefined
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
let count = 0
|
|
103
|
+
await Promise.all(
|
|
104
|
+
viewedRequestedReports.map(async (viewedRequestReport) => {
|
|
105
|
+
const { executionId } = viewedRequestReport
|
|
106
|
+
const viewedReport = viewedReports.find((report) => {
|
|
107
|
+
const { executionId: viewedExecutionId } = report
|
|
108
|
+
return viewedExecutionId && viewedExecutionId === executionId
|
|
109
|
+
})
|
|
110
|
+
if (!viewedReport && executionId) {
|
|
111
|
+
await this.removeReport(executionId, userId)
|
|
112
|
+
count += 1
|
|
113
|
+
}
|
|
114
|
+
}),
|
|
115
|
+
)
|
|
116
|
+
if (count > 0) logger.info(`RequestedReports: Removed ${count} stale reports from list`)
|
|
117
|
+
}
|
|
118
|
+
|
|
83
119
|
setReportUrl(report: RequestedReport) {
|
|
84
120
|
const { tableId, url, dpdPathFromQuery, dataProductDefinitionsPath, type } = report
|
|
85
121
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var $=Object.create;var g=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var G=(e,t)=>{for(var
|
|
1
|
+
"use strict";var $=Object.create;var g=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var G=(e,t)=>{for(var r in t)g(e,r,{get:t[r],enumerable:!0})},T=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of J(t))!z.call(e,i)&&i!==r&&g(e,i,{get:()=>t[i],enumerable:!(s=j(t,i))||s.enumerable});return e};var h=(e,t,r)=>(r=e!=null?$(L(e)):{},T(t||!e||!e.__esModule?g(r,"default",{value:e,enumerable:!0}):r,e)),K=e=>T(g({},"__esModule",{value:!0}),e);var re={};G(re,{cancelRequest:()=>N,default:()=>te,getDefintionByType:()=>Q,getFiltersFromReqBody:()=>H,renderRequest:()=>k,request:()=>B,updateStore:()=>O});module.exports=K(re);var x=h(require("../../../../components/_async/async-filters-form/utils")),D=h(require("../../../../utils/localsHelper")),U=h(require("../../../../components/_filters/utils")),q=require("../../../../utils/reportStoreHelper"),E=h(require("../../../../utils/UserStoreItemBuilder")),f=require("../../../../types/UserReports"),w=h(require("../../../../utils/Personalisation/personalisationUtils")),C=require("../../../../components/_filters/filtersTypeEnum");const O=async({req:e,res:t,services:r,queryData:s,executionData:i,childExecutionData:o})=>{const{search:l,id:d,type:a}=e.body,{dprUser:n,definitionsPath:c,dpdPathFromQuery:u}=D.default.getValues(t);await(0,q.removeDuplicates)({storeService:r.requestedReportService,userId:n.id,id:d,search:l}),await(0,q.removeDuplicates)({storeService:r.recentlyViewedService,userId:n.id,id:d,search:l});const p=e.body,R={type:p.type,reportId:p.reportId,reportName:p.reportName,description:p.description,id:p.id,name:p.name};let m;switch(a){case f.ReportType.REPORT:m=new E.default(R,p).addExecutionData(i).addChildExecutionData(o).addFilters(s?.filterData).addSortData(s?.sortData).addDefinitionsPath(c,u).addRequestUrls(e).addQuery(s).addStatus(f.RequestStatus.SUBMITTED).addTimestamp().build();break;case f.ReportType.DASHBOARD:{m=new E.default(R,p).addExecutionData(i).addChildExecutionData(o).addFilters(s?.filterData).addDefinitionsPath(c,u).addRequestUrls(e).addQuery(s).addStatus(f.RequestStatus.SUBMITTED).addTimestamp().addMetrics(JSON.parse(e.body.sections)).build();break}default:break}m&&await r.requestedReportService.addReport(n.id,m)};async function W(e,t,r,s,i,o){return Promise.all(e.map(l=>t.requestAsyncReport(r,s,l.id,{...i&&i.query,...o&&{dataProductDefinitionsPath:o}}).then(d=>{const{executionId:a,tableId:n}=d;if(!a||!n)throw new Error("requestChildReports: No execution of tableId in response");return{executionId:a,tableId:n,variantId:l.id}})))}const X=async({req:e,res:t,token:r,dashboardService:s,reportingService:i})=>{const{definitionsPath:o,dpdPathFromQuery:l}=D.default.getValues(t),{reportId:d,id:a,type:n}=e.body;let c,u,p,R,m,y=[];n===f.ReportType.REPORT&&(m=await i.getDefinition(r,d,a,o),c=m?.variant.specification?.fields||[],u=x.default.setQueryFromFilters(e,c),{executionId:p,tableId:R}=await i.requestAsyncReport(r,d,a,{...u.query,dataProductDefinitionsPath:o}),y=m.variant.childVariants??[]),n===f.ReportType.DASHBOARD&&(m=await s.getDefinition(r,d,a,o),c=m?.filterFields||[],u=x.default.setQueryFromFilters(e,c),{executionId:p,tableId:R}=await s.requestAsyncDashboard(r,d,a,{...u.query,dataProductDefinitionsPath:o}));const S=await W(y,i,r,d,u,o);return{executionData:{executionId:p,tableId:R,...l&&{dataProductDefinitionsPath:o}},childExecutionData:S,queryData:u}},Y=async({token:e,reportId:t,definitionPath:r,services:s,definition:i})=>{const d=(await s.reportingService.getDefinitions(e,r)).find(p=>p.id===t)?.name,{name:a,description:n,sections:c,filterFields:u}=i;return{reportName:d,name:a,description:n,sections:c||[],fields:u||[]}},Z=async e=>({definition:e,reportName:e.name,name:e.variant.name,description:e.variant.description||e.description,template:e.variant.specification,fields:e?.variant?.specification?.fields||[],interactive:e?.variant?.interactive}),Q=async(e,t,r,s)=>{const{token:i,definitionsPath:o}=D.default.getValues(t),{reportId:l,id:d,variantId:a,type:n}=e.params;return await(n===f.ReportType.REPORT?s.reportingService:s.dashboardService).getDefinition(i,l,a||d,o)},ee=async(e,t,r,s,i,o)=>{const{reportId:l,id:d}=e.params;let a=await x.default.renderFilters(r,s);a.filters=w.default.setUserContextDefaults(t,a.filters);let n;return t.locals.saveDefaultsEnabled&&(n=await i.defaultFilterValuesService.get(o,l,d,C.FiltersType.REQUEST)),n&&(a=w.default.setFilterValuesFromSavedDefaults(a.filters,a.sortBy||[],n)),a.filters=U.default.setFilterValuesFromRequest(a.filters,e),{filtersData:a,defaultFilterValues:n}},B=async({req:e,res:t,services:r})=>{const{token:s}=D.default.getValues(t),i={req:e,res:t,token:s},{executionData:o,queryData:l,childExecutionData:d}=await X({...i,dashboardService:r.dashboardService,reportingService:r.reportingService});if(o.executionId&&o.tableId)await O({req:e,res:t,services:r,queryData:l,executionData:o,childExecutionData:d});else throw new Error("No execution data returned");return o},N=async({req:e,res:t,services:r})=>{const{token:s,dprUser:i,definitionsPath:o}=D.default.getValues(t),{reportId:l,id:d,executionId:a,type:n}=e.params;let c=r.reportingService;n===f.ReportType.REPORT&&(c=r.reportingService),n===f.ReportType.DASHBOARD&&(c=r.dashboardService);const u=await c.cancelAsyncRequest(s,l,d,a,o);u&&u.cancellationSucceeded&&await r.requestedReportService.updateStatus(a,i.id,f.RequestStatus.ABORTED)},k=async({req:e,res:t,services:r,next:s})=>{try{const{token:i,csrfToken:o,definitionsPath:l,dpdPathFromQuery:d,dprUser:a}=D.default.getValues(t),{reportId:n,type:c,id:u}=e.params,{definition:p}=t.locals,R=e.query.defaultsSaved,m={token:i,reportId:n,definitionPath:l,services:r};let y,S,v,M,F=[],P,A,I,b=[];if(c===f.ReportType.REPORT&&({name:y,reportName:S,description:v,fields:F,interactive:A}=await Z(p)),c===f.ReportType.DASHBOARD&&({name:y,reportName:S,description:v,sections:P,fields:F}=await Y({...m,definition:p})),F){const V=await ee(e,t,F,A||!1,r,a.id);b=V.defaultFilterValues||b,I=V.filtersData}const _={reportName:S,name:y,description:v,reportId:n,id:u,...d&&{definitionPath:l},csrfToken:o,template:M,sections:P,hasDefaults:b?.length>0,defaultsSaved:R,type:c,saveDefaultsEnabled:t.locals.saveDefaultsEnabled};return{title:`Request ${c}`,filtersDescription:`Customise your ${c} using the filters below and submit your request.`,filtersData:I,reportData:_}}catch(i){return s(i),!1}},H=e=>Object.keys(e.body).filter(t=>t.includes("filters.")).filter(t=>!!e.body[t]).map(t=>({name:t,value:e.body[t]}));var te={request:B,cancelRequest:N,renderRequest:k,getFiltersFromReqBody:H,getDefintionByType:Q};0&&(module.exports={cancelRequest,getDefintionByType,getFiltersFromReqBody,renderRequest,request,updateStore});
|
|
2
2
|
//# sourceMappingURL=utils.js.map
|