@acorex-platform/module-report-management-client 1.0.2 → 2.0.0-beta.0

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.
Files changed (63) hide show
  1. package/fesm2022/{acorex-platform-module-report-management-client-acorex-platform-module-report-management-client-eSjEqt5D.mjs → acorex-platform-module-report-management-client-acorex-platform-module-report-management-client-DKnaOM7_.mjs} +36 -53
  2. package/fesm2022/acorex-platform-module-report-management-client-acorex-platform-module-report-management-client-DKnaOM7_.mjs.map +1 -0
  3. package/fesm2022/acorex-platform-module-report-management-client-contracts-entities-report-category.mjs +0 -14
  4. package/fesm2022/acorex-platform-module-report-management-client-contracts-entities-report-category.mjs.map +1 -1
  5. package/fesm2022/acorex-platform-module-report-management-client-contracts-entities-report-generation-request.mjs +2 -16
  6. package/fesm2022/acorex-platform-module-report-management-client-contracts-entities-report-generation-request.mjs.map +1 -1
  7. package/fesm2022/acorex-platform-module-report-management-client-contracts-entities-report.mjs +179 -25
  8. package/fesm2022/acorex-platform-module-report-management-client-contracts-entities-report.mjs.map +1 -1
  9. package/fesm2022/{acorex-platform-module-report-management-client-contracts-entity-catalog-acorex-platform-module-report-management-client-contracts-entity-catalog-CboBAIna.mjs → acorex-platform-module-report-management-client-contracts-entity-catalog-acorex-platform-module-report-management-client-contracts-entity-catalog-CSABQXeE.mjs} +4 -20
  10. package/fesm2022/acorex-platform-module-report-management-client-contracts-entity-catalog-acorex-platform-module-report-management-client-contracts-entity-catalog-CSABQXeE.mjs.map +1 -0
  11. package/fesm2022/{acorex-platform-module-report-management-client-contracts-entity-catalog-report-category.entity-BQFdNXAm.mjs → acorex-platform-module-report-management-client-contracts-entity-catalog-report-category.entity-GPDKYKW_.mjs} +2 -2
  12. package/fesm2022/{acorex-platform-module-report-management-client-contracts-entity-catalog-report-category.entity-BQFdNXAm.mjs.map → acorex-platform-module-report-management-client-contracts-entity-catalog-report-category.entity-GPDKYKW_.mjs.map} +1 -1
  13. package/fesm2022/{acorex-platform-module-report-management-client-contracts-entity-catalog-report-generation-request.entity-D381cWLE.mjs → acorex-platform-module-report-management-client-contracts-entity-catalog-report-generation-request.entity-B3cCnjKO.mjs} +4 -4
  14. package/fesm2022/acorex-platform-module-report-management-client-contracts-entity-catalog-report-generation-request.entity-B3cCnjKO.mjs.map +1 -0
  15. package/fesm2022/acorex-platform-module-report-management-client-contracts-entity-catalog-report.entity-B_BWJu1a.mjs +292 -0
  16. package/fesm2022/acorex-platform-module-report-management-client-contracts-entity-catalog-report.entity-B_BWJu1a.mjs.map +1 -0
  17. package/fesm2022/acorex-platform-module-report-management-client-contracts-entity-catalog.mjs +1 -1
  18. package/fesm2022/acorex-platform-module-report-management-client-contracts.mjs +1866 -25
  19. package/fesm2022/acorex-platform-module-report-management-client-contracts.mjs.map +1 -1
  20. package/fesm2022/{acorex-platform-module-report-management-client-entity-reports-page-component.provider-CaxletoS.mjs → acorex-platform-module-report-management-client-entity-reports-page-component.provider-BqgxvuLq.mjs} +3 -3
  21. package/fesm2022/{acorex-platform-module-report-management-client-entity-reports-page-component.provider-CaxletoS.mjs.map → acorex-platform-module-report-management-client-entity-reports-page-component.provider-BqgxvuLq.mjs.map} +1 -1
  22. package/fesm2022/{acorex-platform-module-report-management-client-entity-reports-page.component-CK5bCQhm.mjs → acorex-platform-module-report-management-client-entity-reports-page.component-D9AfxSeN.mjs} +2 -2
  23. package/fesm2022/{acorex-platform-module-report-management-client-entity-reports-page.component-CK5bCQhm.mjs.map → acorex-platform-module-report-management-client-entity-reports-page.component-D9AfxSeN.mjs.map} +1 -1
  24. package/fesm2022/acorex-platform-module-report-management-client-local-entities.mjs +0 -2
  25. package/fesm2022/acorex-platform-module-report-management-client-local-entities.mjs.map +1 -1
  26. package/fesm2022/acorex-platform-module-report-management-client-report-definition-access.service-DUpwky68.mjs +67 -0
  27. package/fesm2022/acorex-platform-module-report-management-client-report-definition-access.service-DUpwky68.mjs.map +1 -0
  28. package/fesm2022/acorex-platform-module-report-management-client-report-filter-page.component-C8XSGSdz.mjs +255 -0
  29. package/fesm2022/acorex-platform-module-report-management-client-report-filter-page.component-C8XSGSdz.mjs.map +1 -0
  30. package/fesm2022/acorex-platform-module-report-management-client-report-layout-page-component.provider-BfBckWsh.mjs +28 -0
  31. package/fesm2022/acorex-platform-module-report-management-client-report-layout-page-component.provider-BfBckWsh.mjs.map +1 -0
  32. package/fesm2022/acorex-platform-module-report-management-client-report-layout-page.component-DFmdGIY9.mjs +876 -0
  33. package/fesm2022/acorex-platform-module-report-management-client-report-layout-page.component-DFmdGIY9.mjs.map +1 -0
  34. package/fesm2022/{acorex-platform-module-report-management-client-report-layout-switcher.util-C3OVIaEz.mjs → acorex-platform-module-report-management-client-report-layout-switcher.util-DRG-8RcA.mjs} +258 -41
  35. package/fesm2022/acorex-platform-module-report-management-client-report-layout-switcher.util-DRG-8RcA.mjs.map +1 -0
  36. package/fesm2022/{acorex-platform-module-report-management-client-report-popup-viewer.component-CKE8NG5T.mjs → acorex-platform-module-report-management-client-report-popup-viewer.component-BVI1z7F3.mjs} +6 -6
  37. package/fesm2022/{acorex-platform-module-report-management-client-report-popup-viewer.component-CKE8NG5T.mjs.map → acorex-platform-module-report-management-client-report-popup-viewer.component-BVI1z7F3.mjs.map} +1 -1
  38. package/fesm2022/{acorex-platform-module-report-management-client-report-viewer-page.component-CPlbhBa_.mjs → acorex-platform-module-report-management-client-report-viewer-page.component-CPHO4vlQ.mjs} +84 -26
  39. package/fesm2022/acorex-platform-module-report-management-client-report-viewer-page.component-CPHO4vlQ.mjs.map +1 -0
  40. package/fesm2022/acorex-platform-module-report-management-client.mjs +1 -1
  41. package/i18n/en-AU/report-management.json +260 -35
  42. package/i18n/en-US/report-management.json +260 -35
  43. package/i18n/fa-IR/report-management.json +260 -35
  44. package/package.json +2 -9
  45. package/types/acorex-platform-module-report-management-client-contracts.d.ts +395 -109
  46. package/types/acorex-platform-module-report-management-client.d.ts +5 -5
  47. package/fesm2022/acorex-platform-module-report-management-client-acorex-platform-module-report-management-client-eSjEqt5D.mjs.map +0 -1
  48. package/fesm2022/acorex-platform-module-report-management-client-contracts-entities-query-snapshot-policy.mjs +0 -157
  49. package/fesm2022/acorex-platform-module-report-management-client-contracts-entities-query-snapshot-policy.mjs.map +0 -1
  50. package/fesm2022/acorex-platform-module-report-management-client-contracts-entities-query-snapshot.mjs +0 -197
  51. package/fesm2022/acorex-platform-module-report-management-client-contracts-entities-query-snapshot.mjs.map +0 -1
  52. package/fesm2022/acorex-platform-module-report-management-client-contracts-entity-catalog-acorex-platform-module-report-management-client-contracts-entity-catalog-CboBAIna.mjs.map +0 -1
  53. package/fesm2022/acorex-platform-module-report-management-client-contracts-entity-catalog-query-snapshot-policy.entity-BUY06Dz0.mjs +0 -97
  54. package/fesm2022/acorex-platform-module-report-management-client-contracts-entity-catalog-query-snapshot-policy.entity-BUY06Dz0.mjs.map +0 -1
  55. package/fesm2022/acorex-platform-module-report-management-client-contracts-entity-catalog-query-snapshot.entity-CnnX3xZt.mjs +0 -137
  56. package/fesm2022/acorex-platform-module-report-management-client-contracts-entity-catalog-query-snapshot.entity-CnnX3xZt.mjs.map +0 -1
  57. package/fesm2022/acorex-platform-module-report-management-client-contracts-entity-catalog-report-generation-request.entity-D381cWLE.mjs.map +0 -1
  58. package/fesm2022/acorex-platform-module-report-management-client-contracts-entity-catalog-report.entity-Bwui0M8X.mjs +0 -124
  59. package/fesm2022/acorex-platform-module-report-management-client-contracts-entity-catalog-report.entity-Bwui0M8X.mjs.map +0 -1
  60. package/fesm2022/acorex-platform-module-report-management-client-report-layout-switcher.util-C3OVIaEz.mjs.map +0 -1
  61. package/fesm2022/acorex-platform-module-report-management-client-report-viewer-page.component-CPlbhBa_.mjs.map +0 -1
  62. package/types/acorex-platform-module-report-management-client-contracts-entities-query-snapshot-policy.d.ts +0 -5
  63. package/types/acorex-platform-module-report-management-client-contracts-entities-query-snapshot.d.ts +0 -5
@@ -1,15 +1,21 @@
1
+ import { INTERCHANGE_VIRTUAL_REPORT_EXPORT_KEY_PREFIX, INTERCHANGE_REPORT_ADAPTER_KIND, INTERCHANGE_EXTERNAL_SOURCE_KIND, interchangeDefinitionScopeRank } from '@acorex-platform/framework-shared/interchange';
2
+ import { resolveMultiLanguageString } from '@acorex-platform/framework-shared/core';
3
+ import { axpRegisterDataExecutionCapabilities } from '@acorex-platform/framework-shared/runtime';
4
+
1
5
  //#region ---- Report management command keys ----
2
6
  const AXMReportManagementCommandKeys = {
3
- RecalculateQuerySnapshots: 'ReportManagement:RecalculateQuerySnapshots',
4
- RefreshQuerySnapshots: 'ReportManagement:RefreshQuerySnapshots',
5
7
  ReportGeneration: {
6
8
  Create: 'ReportManagement:ReportGeneration:Create',
7
9
  Execute: 'ReportManagement:ReportGeneration:Execute',
8
10
  ReleaseInlineWatch: 'ReportManagement:ReportGeneration:ReleaseInlineWatch',
9
11
  },
12
+ Export: {
13
+ Run: 'ReportManagement:Export:Run',
14
+ ListTemplates: 'ReportManagement:Export:ListTemplates',
15
+ Clone: 'ReportManagement:Export:Clone',
16
+ Save: 'ReportManagement:Export:Save',
17
+ },
10
18
  };
11
- const AXM_RECALCULATE_QUERY_SNAPSHOTS_COMMAND_KEY = AXMReportManagementCommandKeys.RecalculateQuerySnapshots;
12
- const AXM_REFRESH_QUERY_SNAPSHOTS_COMMAND_KEY = AXMReportManagementCommandKeys.RefreshQuerySnapshots;
13
19
  //#endregion
14
20
 
15
21
  const AXPReportManagementFeatureKeys = {
@@ -109,20 +115,6 @@ const RootConfig = {
109
115
  titlePlural: `@${config.i18n}:reports.entities.report.plural`,
110
116
  icon: 'fa-light fa-file-chart-pie',
111
117
  },
112
- querySnapshotPolicy: {
113
- name: 'QuerySnapshotPolicy',
114
- fullName: `${config.module}.QuerySnapshotPolicy`,
115
- title: `@${config.i18n}:query-snapshots.entities.policy.title`,
116
- titlePlural: `@${config.i18n}:query-snapshots.entities.policy.plural`,
117
- icon: 'fa-light fa-sliders',
118
- },
119
- querySnapshot: {
120
- name: 'QuerySnapshot',
121
- fullName: `${config.module}.QuerySnapshot`,
122
- title: `@${config.i18n}:query-snapshots.entities.snapshot.title`,
123
- titlePlural: `@${config.i18n}:query-snapshots.entities.snapshot.plural`,
124
- icon: 'fa-light fa-camera',
125
- },
126
118
  reportGenerationRequest: {
127
119
  name: 'ReportGenerationRequest',
128
120
  fullName: `${config.module}.ReportGenerationRequest`,
@@ -153,7 +145,144 @@ const ReportManagementManifest = {
153
145
  };
154
146
  //#endregion
155
147
 
156
- //#region ---- Imports ----
148
+ //#endregion
149
+ //#region ---- Constants ----
150
+ const DEFAULT_WIDGET_TYPE = 'text-editor';
151
+ const INTERFACE_KEYS = new Set(['type', 'options', 'defaultValue', 'triggers', 'path', 'name']);
152
+ //#endregion
153
+ //#region ---- Parameter groups to metadata ----
154
+ /** Every parameter group becomes a metadata section and every parameter a field, in stored order. */
155
+ function readReportFilterForm(report) {
156
+ const groups = (report?.parameterGroups ?? []).map((group, groupIndex) => ({
157
+ name: group.name,
158
+ title: group.title,
159
+ ...(isBlank(group.description) ? {} : { description: group.description }),
160
+ order: groupIndex,
161
+ fields: (group.parameters ?? []).map((parameter, fieldIndex) => parameterToField(parameter, fieldIndex)),
162
+ }));
163
+ return { metaDataList: { groups } };
164
+ }
165
+ function parameterToField(parameter, order) {
166
+ const widget = parameter.widget ?? { type: DEFAULT_WIDGET_TYPE };
167
+ const stored = {
168
+ type: widget.type || DEFAULT_WIDGET_TYPE,
169
+ options: { ...(widget.options ?? {}) },
170
+ ...(widget.defaultValue !== undefined ? { defaultValue: widget.defaultValue } : {}),
171
+ ...(widget.triggers !== undefined ? { triggers: widget.triggers } : {}),
172
+ };
173
+ const extras = Object.fromEntries(Object.entries(widget).filter(([key]) => !INTERFACE_KEYS.has(key)));
174
+ const configuration = {};
175
+ if (parameter.visible !== undefined) {
176
+ configuration['visible'] = parameter.visible;
177
+ }
178
+ if (Object.keys(extras).length > 0) {
179
+ configuration['widget'] = extras;
180
+ }
181
+ return {
182
+ id: parameter.path,
183
+ name: parameter.path,
184
+ title: parameter.title,
185
+ ...(isBlank(parameter.description) ? {} : { description: parameter.description }),
186
+ interface: JSON.stringify(stored),
187
+ ...(Object.keys(configuration).length > 0 ? { configuration } : {}),
188
+ order,
189
+ };
190
+ }
191
+ //#endregion
192
+ //#region ---- Metadata to parameter groups ----
193
+ /** Writes the metadata sections back as `parameterGroups`, the only filter structure the report uses. */
194
+ function applyReportFilterForm(form) {
195
+ const groups = [...(form?.metaDataList?.groups ?? [])].sort((left, right) => (left.order ?? 0) - (right.order ?? 0));
196
+ return {
197
+ parameterGroups: groups.map((group) => {
198
+ const fields = [...(group.fields ?? [])].sort((left, right) => (left.order ?? 0) - (right.order ?? 0));
199
+ return {
200
+ name: group.name,
201
+ title: textOr(group.title, group.name),
202
+ ...(isBlank(group.description) ? {} : { description: group.description }),
203
+ parameters: fields.flatMap((field) => fieldToParameter(field)),
204
+ };
205
+ }),
206
+ };
207
+ }
208
+ function fieldToParameter(field) {
209
+ const path = typeof field?.name === 'string' ? field.name.trim() : '';
210
+ // A field that is not named yet cannot be a filter: the viewer keys its values by path.
211
+ if (!path) {
212
+ return [];
213
+ }
214
+ const configuration = (field.configuration ?? {});
215
+ const visible = configuration['visible'];
216
+ return [
217
+ {
218
+ path,
219
+ title: textOr(field.title, path),
220
+ ...(isBlank(field.description) ? {} : { description: field.description }),
221
+ ...(typeof visible === 'boolean' || typeof visible === 'string' ? { visible } : {}),
222
+ widget: interfaceToWidget(field.interface, configuration['widget']),
223
+ },
224
+ ];
225
+ }
226
+ function interfaceToWidget(value, extras) {
227
+ const stored = parseInterface(value);
228
+ const widget = {
229
+ ...(isRecord$2(extras) ? extras : {}),
230
+ type: typeof stored.type === 'string' && stored.type.trim() ? stored.type.trim() : DEFAULT_WIDGET_TYPE,
231
+ options: { ...(stored.options ?? {}) },
232
+ };
233
+ if (stored.defaultValue !== undefined) {
234
+ widget.defaultValue = stored.defaultValue;
235
+ }
236
+ if (stored.triggers !== undefined) {
237
+ widget.triggers = stored.triggers;
238
+ }
239
+ return widget;
240
+ }
241
+ /** The builder stores the picked widget as a JSON string (or an object) of `{ type, options, defaultValue }`. */
242
+ function parseInterface(value) {
243
+ if (typeof value === 'string') {
244
+ try {
245
+ const parsed = JSON.parse(value || '{}');
246
+ return isRecord$2(parsed) ? parsed : {};
247
+ }
248
+ catch {
249
+ // A plain widget name (not JSON) is the widget type itself.
250
+ return value.trim() ? { type: value.trim() } : {};
251
+ }
252
+ }
253
+ return isRecord$2(value) ? value : {};
254
+ }
255
+ //#endregion
256
+ //#region ---- Compare and pick ----
257
+ /** Two forms are the same when they store the same filters. Field ids and order numbers do not count. */
258
+ function sameReportFilterForm(left, right) {
259
+ return JSON.stringify(applyReportFilterForm(left)) === JSON.stringify(applyReportFilterForm(right));
260
+ }
261
+ function pickReportFilterForm(value, fallback) {
262
+ const list = value['metaDataList'];
263
+ return isRecord$2(list) && Array.isArray(list['groups']) ? { metaDataList: list } : fallback;
264
+ }
265
+ //#endregion
266
+ //#region ---- Helpers ----
267
+ /** The value when it has any text, otherwise the fallback. Typed so callers get a definite string / locale map. */
268
+ function textOr(value, fallback) {
269
+ return value !== undefined && !isBlank(value) ? value : fallback;
270
+ }
271
+ function isBlank(value) {
272
+ if (value == null) {
273
+ return true;
274
+ }
275
+ if (typeof value === 'string') {
276
+ return value.trim() === '';
277
+ }
278
+ if (typeof value === 'object') {
279
+ return !Object.values(value).some((item) => typeof item === 'string' && item.trim() !== '');
280
+ }
281
+ return false;
282
+ }
283
+ function isRecord$2(value) {
284
+ return value != null && typeof value === 'object' && !Array.isArray(value);
285
+ }
157
286
  //#endregion
158
287
 
159
288
  //#region ----- Imports -----
@@ -166,6 +295,1607 @@ function buildReportGenerationNotificationCorrelationId(runId) {
166
295
  }
167
296
  //#endregion
168
297
 
298
+ function resolveReportColumnTitle(column, locale = 'en-US') {
299
+ const title = resolveMultiLanguageString(column.title, locale).trim();
300
+ return title || column.field;
301
+ }
302
+ //#region ----- Virtual report export projection -----
303
+ function virtualReportExportKey(reportId) {
304
+ return `${INTERCHANGE_VIRTUAL_REPORT_EXPORT_KEY_PREFIX}${reportId}:default-table`;
305
+ }
306
+ /**
307
+ * Binding stored on the interchange request. Rows are not included:
308
+ * the export job reads the report query itself.
309
+ */
310
+ function reportExportSourceBinding(input) {
311
+ const layoutId = input.layoutId?.trim();
312
+ return {
313
+ reportId: input.reportId,
314
+ ...(layoutId ? { layoutId } : {}),
315
+ parameters: input.parameters ?? {},
316
+ };
317
+ }
318
+ function resolveReportExportTableLayout(report, layoutId) {
319
+ const requested = layoutId?.trim();
320
+ if (requested) {
321
+ const match = report.layouts.find((layout) => layout.id === requested);
322
+ if (match?.layout?.type === 'table') {
323
+ return match;
324
+ }
325
+ }
326
+ return findDefaultReportTableLayout(report);
327
+ }
328
+ function findDefaultReportTableLayout(report) {
329
+ const defaultLayout = report.layouts.find((layout) => layout.id === report.defaultLayoutId) ??
330
+ report.layouts.find((layout) => layout.isDefault) ??
331
+ report.layouts[0];
332
+ if (defaultLayout?.layout?.type === 'table') {
333
+ return defaultLayout;
334
+ }
335
+ return report.layouts.find((layout) => layout.layout?.type === 'table');
336
+ }
337
+ function visibleDefaultTableColumns(report) {
338
+ const layout = findDefaultReportTableLayout(report);
339
+ const table = layout?.layout;
340
+ if (table?.type !== 'table' || !Array.isArray(table.columns)) {
341
+ return [];
342
+ }
343
+ return table.columns.filter((column) => column.visible !== false);
344
+ }
345
+ function projectReportDefaultTableExportDefinition(report, format = 'excel') {
346
+ const columns = visibleDefaultTableColumns(report);
347
+ const fields = columns.map((column) => ({
348
+ path: column.field,
349
+ column: resolveReportColumnTitle(column),
350
+ }));
351
+ if (fields.length === 0) {
352
+ fields.push({ path: 'id', column: 'id' });
353
+ }
354
+ const key = virtualReportExportKey(report.id);
355
+ const tableLayout = findDefaultReportTableLayout(report);
356
+ const sheetName = tableLayout?.export?.excel?.sheetName || 'Report';
357
+ return {
358
+ id: key,
359
+ key,
360
+ title: report.title,
361
+ format,
362
+ formatOptions: {
363
+ excel: {
364
+ sheetNames: { ReportResult: sheetName },
365
+ includeHeaders: true,
366
+ freezeHeader: tableLayout?.export?.excel?.freezeHeader,
367
+ autoFitColumns: tableLayout?.export?.excel?.autoFitColumns !== false,
368
+ },
369
+ csv: {
370
+ delimiter: tableLayout?.export?.csv?.delimiter,
371
+ includeHeaders: tableLayout?.export?.csv?.includeHeaders !== false,
372
+ quoteValues: tableLayout?.export?.csv?.quoteValues !== false,
373
+ },
374
+ pdf: reportTablePdfFormatOptions(tableLayout),
375
+ },
376
+ source: {
377
+ type: INTERCHANGE_EXTERNAL_SOURCE_KIND,
378
+ adapter: INTERCHANGE_REPORT_ADAPTER_KIND,
379
+ binding: { reportId: report.id },
380
+ },
381
+ graph: {
382
+ entity: 'ReportResult',
383
+ fields,
384
+ },
385
+ stateInfo: { isSystem: true, isImmutable: true },
386
+ scopeInfo: {},
387
+ };
388
+ }
389
+ const REPORT_PDF_PAGE_SIZES = ['A4', 'Letter', 'Legal'];
390
+ /**
391
+ * Table PDF options for the interchange renderer.
392
+ * Page size stays inside the document-output set; A3 is omitted so the PDF defaults apply.
393
+ */
394
+ function reportTablePdfFormatOptions(tableLayout) {
395
+ const pdf = tableLayout?.export?.pdf;
396
+ const pageSize = REPORT_PDF_PAGE_SIZES.find((size) => size === pdf?.pageSize);
397
+ const orientation = pdf?.orientation === 'portrait' || pdf?.orientation === 'landscape' ? pdf.orientation : undefined;
398
+ return {
399
+ layout: 'table',
400
+ includeHeaders: true,
401
+ showTitle: true,
402
+ ...(pageSize ? { pageSize } : {}),
403
+ ...(orientation ? { orientation } : {}),
404
+ };
405
+ }
406
+ /**
407
+ * Interchange export actions for a table layout.
408
+ * PDF is queued like Excel and CSV; the selected document-output provider renders the file.
409
+ */
410
+ function reportTableInterchangeExportActions(layoutDefinition) {
411
+ if (layoutDefinition.layout?.type !== 'table') {
412
+ return [];
413
+ }
414
+ const actions = [];
415
+ if (layoutDefinition.export?.excel?.enabled !== false) {
416
+ actions.push({
417
+ name: 'export-report-excel',
418
+ title: '@report-management:report-viewer.actions.export-excel.title',
419
+ icon: 'fa-light fa-file-excel',
420
+ command: { name: 'export-report', options: { format: 'excel' } },
421
+ priority: 'secondary',
422
+ });
423
+ }
424
+ if (layoutDefinition.export?.csv?.enabled !== false) {
425
+ actions.push({
426
+ name: 'export-report-csv',
427
+ title: '@report-management:report-viewer.actions.export-csv.title',
428
+ icon: 'fa-light fa-file-csv',
429
+ command: { name: 'export-report', options: { format: 'csv' } },
430
+ priority: 'secondary',
431
+ });
432
+ }
433
+ if (layoutDefinition.export?.pdf?.enabled !== false) {
434
+ actions.push({
435
+ name: 'export-report-pdf',
436
+ title: '@report-management:report-viewer.actions.export-pdf.title',
437
+ icon: 'fa-light fa-file-pdf',
438
+ command: { name: 'export-report', options: { format: 'pdf' } },
439
+ priority: 'secondary',
440
+ });
441
+ }
442
+ return actions;
443
+ }
444
+ function overlayReportExportTemplates(virtual, stored, scope) {
445
+ const defaultKey = virtual.key;
446
+ const bySlot = new Map();
447
+ bySlot.set(defaultKey, virtual);
448
+ for (const definition of stored) {
449
+ const slotKey = definition.key === defaultKey ? defaultKey : definition.key || definition.id || defaultKey;
450
+ const current = bySlot.get(slotKey);
451
+ if (!current ||
452
+ interchangeDefinitionScopeRank(definition.scopeInfo, scope) >=
453
+ interchangeDefinitionScopeRank(current.scopeInfo, scope)) {
454
+ bySlot.set(slotKey, definition);
455
+ }
456
+ }
457
+ const defaultDefinition = bySlot.get(defaultKey);
458
+ bySlot.delete(defaultKey);
459
+ return [defaultDefinition, ...bySlot.values()];
460
+ }
461
+ //#endregion
462
+
463
+ //#region ----- Report export snapshot -----
464
+ function parameterFingerprint(parameters) {
465
+ try {
466
+ return JSON.stringify(parameters ?? {});
467
+ }
468
+ catch {
469
+ return '';
470
+ }
471
+ }
472
+ function resolveCurrentReportExportSnapshot(input) {
473
+ if (input.frozen) {
474
+ if (input.freezeItems?.length) {
475
+ return {
476
+ items: input.freezeItems,
477
+ parameters: { ...(input.freezeParameters ?? {}) },
478
+ frozen: true,
479
+ };
480
+ }
481
+ return input.snapshot?.frozen ? input.snapshot : null;
482
+ }
483
+ if (!input.snapshot || input.snapshot.frozen) {
484
+ return null;
485
+ }
486
+ if (parameterFingerprint(input.snapshot.parameters) !== parameterFingerprint(input.liveParameters)) {
487
+ return null;
488
+ }
489
+ return input.snapshot;
490
+ }
491
+ //#endregion
492
+
493
+ //#endregion
494
+
495
+ //#region ---- Field kinds ----
496
+ //#endregion
497
+ //#region ---- Enum and lock rules ----
498
+ const MAX_DEPTH = 8;
499
+ const TEXT_LENGTH_MULTILINE = 120;
500
+ const LOCALE_KEY = /^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/;
501
+ const HEX_OR_FUNCTION_COLOR = /^(?:#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})|(?:rgb|hsl)a?\([^)]+\))$/i;
502
+ const UNSAFE_PATH_KEY = /[.[\]]/;
503
+ const SUMMARY_OPERATIONS = ['sum', 'avg', 'count', 'min', 'max'];
504
+ /** First rule whose pattern matches the end of the key trail decides the choices. */
505
+ const ENUM_RULES = [
506
+ { pattern: /(?:^|\.)chartType$/, values: ['bar', 'line', 'pie', 'doughnut', 'area', 'scatter', 'radar', 'mixed'] },
507
+ { pattern: /colorScheme$/, values: ['default', 'primary', 'success', 'warning', 'danger', 'custom'] },
508
+ { pattern: /legend\.position$/, values: ['top', 'bottom', 'left', 'right'] },
509
+ { pattern: /bar\.orientation$/, values: ['vertical', 'horizontal'] },
510
+ { pattern: /bar\.mode$/, values: ['grouped', 'stacked'] },
511
+ { pattern: /line\.style$/, values: ['straight', 'curved', 'stepped'] },
512
+ { pattern: /area\.mode$/, values: ['normal', 'stacked', 'percentage'] },
513
+ { pattern: /(?:xAxis|yAxis)\.type$/, values: ['linear', 'logarithmic', 'datetime', 'category'] },
514
+ { pattern: /zoom\.mode$/, values: ['x', 'y', 'xy'] },
515
+ { pattern: /onClick\.action$/, values: ['drill-down', 'filter', 'custom'] },
516
+ { pattern: /selectable\.mode$/, values: ['single', 'multiple', 'none'] },
517
+ { pattern: /selection\.mode$/, values: ['single', 'multiple'] },
518
+ { pattern: /transformations\.type$/, values: ['filter', 'sort', 'group', 'pivot', 'format'] },
519
+ { pattern: /aggregation\.method$/, values: SUMMARY_OPERATIONS },
520
+ { pattern: /(?:^|\.)operation$/, values: [...SUMMARY_OPERATIONS, 'distinct'] },
521
+ { pattern: /(?:^|\.)displayIn$/, values: ['groupFooter', 'reportFooter'] },
522
+ { pattern: /(?:^|\.)condition$/, values: ['>', '<', '=', '!=', 'contains'] },
523
+ { pattern: /(?:^|\.)fontWeight$/, values: ['normal', 'bold'] },
524
+ { pattern: /columns\.align$/, values: ['left', 'center', 'right'] },
525
+ { pattern: /columns\.pin$/, values: ['start', 'end'] },
526
+ { pattern: /(?:^|\.)priority$/, values: ['primary', 'secondary'] },
527
+ { pattern: /(?:^|\.)dir$/, values: ['asc', 'desc'] },
528
+ { pattern: /pdf\.pageSize$/, values: ['A4', 'A3', 'Letter', 'Legal'] },
529
+ { pattern: /pdf\.orientation$/, values: ['portrait', 'landscape'] },
530
+ { pattern: /(?:^|\.)numberFormat$/, values: ['auto', 'currency', 'percent', 'decimal'] },
531
+ { pattern: /csv\.delimiter$/, values: [',', ';', '\t'] },
532
+ { pattern: /csv\.encoding$/, values: ['utf-8', 'utf-16', 'iso-8859-1'] },
533
+ ];
534
+ /**
535
+ * Properties that hold the name of something that already exists, so a picker fits better than free text.
536
+ * First rule whose pattern matches the key trail decides the kind.
537
+ */
538
+ const REFERENCE_RULES = [
539
+ { pattern: /(?:^|\.)(?:dataSource|baseDataSource)\.name$/, kind: 'query' },
540
+ { pattern: /^dataSource\.baseQuery$/, kind: 'query' },
541
+ { pattern: /(?:^|\.)command\.name$/, kind: 'command' },
542
+ { pattern: /^layout\.groupBy\.drillDown\.reportId$/, kind: 'report' },
543
+ { pattern: /^layout\.stimulsoftTemplateId$/, kind: 'template' },
544
+ { pattern: /^layout\.columns\.field$/, kind: 'column' },
545
+ {
546
+ pattern: /^layout\.options\.dataMapping\.(?:xField|yFields|groupBy|seriesField|sizeField|colorField|labelField|aggregation\.field)$/,
547
+ kind: 'column',
548
+ },
549
+ { pattern: /^layout\.groupBy\.displayField$/, kind: 'column' },
550
+ { pattern: /^layout\.(?:conditionalFormatting|summary)\.field$/, kind: 'column' },
551
+ { pattern: /^layout\.options\.hierarchy\.(?:parentField|keyField)$/, kind: 'column' },
552
+ { pattern: /^layout\.options\.sorting\.name$/, kind: 'column' },
553
+ { pattern: /^dataSource\.sortFields\.name$/, kind: 'column' },
554
+ { pattern: /^dataSource\.aggregations\.field$/, kind: 'column' },
555
+ { pattern: /^dataSource\.inputs\.parameterKey$/, kind: 'parameter' },
556
+ ];
557
+ /** Lists of plain names that are fields of the query rows. */
558
+ const COLUMN_LIST_TRAILS = new Set([
559
+ 'layout.options.dataMapping.yFields',
560
+ 'layout.groupBy.fields',
561
+ 'dataSource.groupBy',
562
+ ]);
563
+ /** Kinds that name a field of the query rows. The page offers the columns of the chosen query. */
564
+ function isReportLayoutColumnKind(kind) {
565
+ return kind === 'column' || kind === 'column-list';
566
+ }
567
+ /** Properties the page may show but must not change. */
568
+ const LOCKED_TRAILS = new Set(['layout.type', 'dataSource.type', 'layout.options.chartType']);
569
+ //#endregion
570
+ //#region ---- Label keys ----
571
+ /** Property names that have a translation under `layout-editor.fields`. Others fall back to their own name. */
572
+ const REPORT_LAYOUT_FIELD_LABEL_KEYS = new Set([
573
+ 'actions', 'aggregation', 'aggregations', 'align', 'alias', 'animation', 'area', 'autoFitColumns',
574
+ 'backgroundColor', 'bar', 'barWidth', 'baseDataSource', 'baseQuery', 'bindTo', 'chartSpecific', 'chartType',
575
+ 'color', 'colorField', 'colorScheme', 'columns', 'command', 'compression', 'condition', 'conditionalFormatting',
576
+ 'config', 'csv', 'customColors', 'customCssUrl', 'customHtml', 'dataMapping', 'dataSource', 'default',
577
+ 'defaultZoom', 'delimiter', 'description', 'dir', 'disabled', 'displayField', 'displayIn', 'drillDown',
578
+ 'duration', 'embedImages', 'enabled', 'encoding', 'excel', 'export', 'exportHiddenColumns', 'field', 'fields',
579
+ 'fileNameTemplate', 'font', 'fontSize', 'fontWeight', 'footer', 'footerEnabled', 'format', 'formats',
580
+ 'freezeHeader', 'gridLines', 'groupBy', 'header', 'headerColor', 'headerEnabled', 'height', 'hierarchy', 'icon',
581
+ 'includeFilters', 'includeFooter', 'includeHeader', 'includeHeaders', 'inputs', 'interactivity', 'innerRadius',
582
+ 'keyField', 'labelField', 'layout', 'layoutId', 'legend', 'line', 'linkDisplay', 'logoUrl', 'margin', 'max',
583
+ 'method', 'min', 'mode', 'name', 'numberFormat', 'onClick', 'opacity', 'operation', 'options', 'orientation',
584
+ 'pageSize', 'pagination', 'parameterKey', 'parameters', 'parentField', 'path', 'pdf', 'pie', 'pin', 'position',
585
+ 'print', 'priority', 'provider', 'quoteValues', 'reportId', 'selectable', 'selection', 'seriesColors',
586
+ 'seriesField', 'sheetName', 'show', 'showDate', 'showDownloadButton', 'showFullscreenButton', 'showLabels',
587
+ 'showOnHover', 'showPageBreaks', 'showPageNumbers', 'showParameters', 'showPoints', 'showPrintButton',
588
+ 'showZoomControls', 'sizeField', 'sortFields', 'sortable', 'sorting', 'startAngle', 'stickyHeader',
589
+ 'stimulsoftDataSourceName', 'stimulsoftTemplateId', 'stripedRows', 'style', 'summary', 'summaryRowEnabled',
590
+ 'tension', 'tickInterval', 'title', 'tooltips', 'transformations', 'type', 'value', 'visible',
591
+ 'watermarkOpacity', 'watermarkText', 'width', 'widget', 'xAxis', 'xField', 'yAxis', 'yFields', 'zoom',
592
+ ]);
593
+ /** `defaultZoom` → `default-zoom`, the segment used in translation keys. */
594
+ function reportLayoutFieldKebabKey(key) {
595
+ return key.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
596
+ }
597
+ /** `defaultZoom` → `Default Zoom`, shown when no translation exists for the property. */
598
+ function reportLayoutFieldFallbackLabel(key) {
599
+ const spaced = key.replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/[-_]+/g, ' ').trim();
600
+ return spaced.replace(/\b[a-z]/g, (letter) => letter.toUpperCase());
601
+ }
602
+ //#endregion
603
+ //#region ---- Inference ----
604
+ /**
605
+ * Reads every non-empty property of the stored sections and chooses an editor for it.
606
+ * Null, empty strings that carry no type hint and empty containers are skipped:
607
+ * nothing can be inferred from them, and the stored data keeps them untouched.
608
+ */
609
+ function inferReportLayoutFields(sections) {
610
+ return inferObjectFields(sections ?? {}, '', '', 0);
611
+ }
612
+ function inferObjectFields(value, pathPrefix, trailPrefix, depth) {
613
+ const fields = [];
614
+ for (const [key, item] of Object.entries(value)) {
615
+ if (UNSAFE_PATH_KEY.test(key)) {
616
+ continue;
617
+ }
618
+ const path = pathPrefix ? `${pathPrefix}.${key}` : key;
619
+ const trail = trailPrefix ? `${trailPrefix}.${key}` : key;
620
+ const field = inferField(key, path, trail, item, depth);
621
+ if (field) {
622
+ fields.push(field);
623
+ }
624
+ }
625
+ return fields;
626
+ }
627
+ function inferField(key, path, trail, value, depth) {
628
+ const base = { key, path, trail };
629
+ const locked = LOCKED_TRAILS.has(trail) ? { locked: true } : {};
630
+ if (typeof value === 'boolean') {
631
+ return { ...base, kind: 'toggle', ...locked };
632
+ }
633
+ if (typeof value === 'number') {
634
+ return { ...base, kind: 'number', ...locked };
635
+ }
636
+ if (typeof value === 'string') {
637
+ return { ...base, ...inferStringKind(key, trail, value), ...locked };
638
+ }
639
+ if (Array.isArray(value)) {
640
+ return inferArrayField(base, value, depth);
641
+ }
642
+ if (isRecord$1(value)) {
643
+ return inferRecordField(base, value, depth);
644
+ }
645
+ return null;
646
+ }
647
+ function inferStringKind(key, trail, value) {
648
+ const choices = enumValues(trail);
649
+ if (choices && choices.includes(value)) {
650
+ return { kind: 'select', options: choices };
651
+ }
652
+ const reference = REFERENCE_RULES.find((rule) => rule.pattern.test(trail));
653
+ if (reference) {
654
+ return { kind: reference.kind };
655
+ }
656
+ if (key === 'icon' && /^fa[-\s]/.test(value)) {
657
+ return { kind: 'icon' };
658
+ }
659
+ if (HEX_OR_FUNCTION_COLOR.test(value.trim())) {
660
+ return { kind: 'color' };
661
+ }
662
+ if (value.includes('\n') || value.length > TEXT_LENGTH_MULTILINE || key === 'customHtml') {
663
+ return { kind: 'multiline' };
664
+ }
665
+ return { kind: 'text' };
666
+ }
667
+ function inferArrayField(base, value, depth) {
668
+ const items = value.filter((item) => item != null);
669
+ if (items.length === 0) {
670
+ return null;
671
+ }
672
+ if (items.every((item) => typeof item === 'string')) {
673
+ return { ...base, kind: COLUMN_LIST_TRAILS.has(base.trail) ? 'column-list' : 'tags' };
674
+ }
675
+ if (items.every(isRecord$1) && depth < MAX_DEPTH) {
676
+ const fields = inferObjectFields(mergeSamples(items), '', base.trail, depth + 1);
677
+ return fields.length > 0 ? { ...base, kind: 'list', fields } : { ...base, kind: 'json' };
678
+ }
679
+ return { ...base, kind: 'json' };
680
+ }
681
+ function inferRecordField(base, value, depth) {
682
+ const keys = Object.keys(value);
683
+ if (keys.length === 0) {
684
+ return null;
685
+ }
686
+ if (isLocaleTextMap(value)) {
687
+ return { ...base, kind: 'locale-text' };
688
+ }
689
+ if (depth >= MAX_DEPTH) {
690
+ return { ...base, kind: 'json' };
691
+ }
692
+ const fields = inferObjectFields(value, base.path, base.trail, depth + 1);
693
+ return fields.length > 0 ? { ...base, kind: 'group', fields } : { ...base, kind: 'json' };
694
+ }
695
+ /**
696
+ * Rows of a list may each carry different optional keys.
697
+ * One sample row holds the first value found for every key, so the row template covers all of them.
698
+ */
699
+ function mergeSamples(rows) {
700
+ const merged = {};
701
+ const keys = new Set(rows.flatMap((row) => Object.keys(row)));
702
+ for (const key of keys) {
703
+ const values = rows.map((row) => row[key]).filter((item) => item != null);
704
+ if (values.length === 0) {
705
+ continue;
706
+ }
707
+ if (values.every(isRecord$1)) {
708
+ merged[key] = mergeSamples(values);
709
+ continue;
710
+ }
711
+ const arrays = values.filter((item) => Array.isArray(item) && item.length > 0);
712
+ merged[key] = arrays.length > 0 ? arrays[0] : values[0];
713
+ }
714
+ return merged;
715
+ }
716
+ /** Query the view reads its rows from, or an empty string while none is chosen. */
717
+ function reportLayoutQueryName(sections) {
718
+ const dataSource = sections?.['dataSource'];
719
+ if (!isRecord$1(dataSource) || dataSource['type'] !== 'query') {
720
+ return '';
721
+ }
722
+ const name = dataSource['name'];
723
+ return typeof name === 'string' ? name.trim() : '';
724
+ }
725
+ /**
726
+ * Field names already stored on column properties.
727
+ * A picker must keep offering them even when the query catalog does not list them.
728
+ */
729
+ function reportLayoutStoredColumns(sections, fields) {
730
+ const found = new Set();
731
+ collectStored(sections ?? {}, fields, found, isReportLayoutColumnKind);
732
+ return [...found];
733
+ }
734
+ /**
735
+ * Filter names already stored on the filter mapping.
736
+ * A picker must keep offering them even after the filter was removed from the report.
737
+ */
738
+ function reportLayoutStoredParameters(sections, fields) {
739
+ const found = new Set();
740
+ collectStored(sections ?? {}, fields, found, (kind) => kind === 'parameter');
741
+ return [...found];
742
+ }
743
+ function collectStored(container, fields, found, matches) {
744
+ for (const field of fields) {
745
+ const value = container[field.key];
746
+ if (matches(field.kind)) {
747
+ for (const item of Array.isArray(value) ? value : [value]) {
748
+ if (typeof item === 'string' && item.trim()) {
749
+ found.add(item);
750
+ }
751
+ }
752
+ }
753
+ else if (field.kind === 'group' && isRecord$1(value)) {
754
+ collectStored(value, field.fields ?? [], found, matches);
755
+ }
756
+ else if (field.kind === 'list' && Array.isArray(value)) {
757
+ for (const row of value) {
758
+ if (isRecord$1(row)) {
759
+ collectStored(row, field.fields ?? [], found, matches);
760
+ }
761
+ }
762
+ }
763
+ }
764
+ }
765
+ function enumValues(trail) {
766
+ return ENUM_RULES.find((rule) => rule.pattern.test(trail))?.values ?? null;
767
+ }
768
+ function isLocaleTextMap(value) {
769
+ const entries = Object.entries(value);
770
+ return entries.length > 0 && entries.every(([locale, text]) => LOCALE_KEY.test(locale) && (text == null || typeof text === 'string'));
771
+ }
772
+ function isRecord$1(value) {
773
+ return value != null && typeof value === 'object' && !Array.isArray(value);
774
+ }
775
+ //#endregion
776
+
777
+ //#endregion
778
+ //#region ---- Read ----
779
+ function readReportLayoutForm(report, preset) {
780
+ const layouts = report?.layouts ?? [];
781
+ const current = layouts.find((layout) => layoutMatchesPreset(layout, preset));
782
+ const table = current?.layout?.type === 'table' ? current.layout : undefined;
783
+ const chart = current?.layout?.type === 'chart' ? current.layout : undefined;
784
+ const pdf = current?.layout?.type === 'pdf' ? current.layout : undefined;
785
+ const query = current?.dataSource?.type === 'query' ? current.dataSource : undefined;
786
+ return {
787
+ enabled: current != null,
788
+ title: displayTitle(current?.title, preset),
789
+ description: current?.description ?? '',
790
+ isDefault: current != null
791
+ ? current.id === report?.defaultLayoutId || current.isDefault === true
792
+ : layouts.length === 0,
793
+ queryName: query?.name ?? '',
794
+ showQuery: current?.dataSource == null || current.dataSource.type === 'query',
795
+ dataSourceType: current?.dataSource?.type ?? 'query',
796
+ dataSourceDescription: current?.dataSource?.description ?? '',
797
+ queryInputs: (query?.inputs ?? []).map((input) => ({
798
+ parameterKey: input.parameterKey,
799
+ bindTo: input.bindTo,
800
+ })),
801
+ pagination: table?.options?.pagination !== false,
802
+ stickyHeader: table?.options?.stickyHeader !== false,
803
+ stripedRows: table?.options?.stripedRows !== false,
804
+ columns: (table?.columns ?? []).map(readColumn),
805
+ summaries: (table?.summary ?? []).map((summary) => ({
806
+ field: summary.field,
807
+ operation: summary.operation,
808
+ displayIn: summary.displayIn,
809
+ })),
810
+ xField: chart?.options?.dataMapping?.xField ?? '',
811
+ yFields: formatYFields(chart?.options?.dataMapping?.yFields),
812
+ groupBy: chart?.options?.dataMapping?.groupBy ?? '',
813
+ showDownloadButton: pdf?.options?.showDownloadButton !== false,
814
+ showPrintButton: pdf?.options?.showPrintButton !== false,
815
+ showZoomControls: pdf?.options?.showZoomControls !== false,
816
+ showFullscreenButton: pdf?.options?.showFullscreenButton !== false,
817
+ defaultZoom: pdf?.options?.defaultZoom ?? 100,
818
+ headerTitle: headerTitle(current?.layout),
819
+ headerShowDate: current?.layout?.header?.showDate === true,
820
+ footerShowDate: current?.layout?.footer?.showDate === true,
821
+ fileNameTemplate: current?.export?.fileNameTemplate ?? '',
822
+ pdfExportEnabled: current?.export?.pdf?.enabled === true,
823
+ excelExportEnabled: current?.export?.excel?.enabled === true,
824
+ excelSheetName: current?.export?.excel?.sheetName ?? '',
825
+ csvExportEnabled: current?.export?.csv?.enabled === true,
826
+ };
827
+ }
828
+ //#endregion
829
+ //#region ---- Apply ----
830
+ function applyReportLayoutForm(report, preset, form, createId = () => crypto.randomUUID()) {
831
+ const layouts = report.layouts ?? [];
832
+ let replaced = false;
833
+ let savedId = '';
834
+ const next = [];
835
+ for (const layout of layouts) {
836
+ if (!layoutMatchesPreset(layout, preset)) {
837
+ next.push(layout);
838
+ continue;
839
+ }
840
+ if (!form.enabled || replaced) {
841
+ continue;
842
+ }
843
+ const saved = buildLayout(layout, preset, form, layout.id);
844
+ savedId = saved.id;
845
+ next.push(saved);
846
+ replaced = true;
847
+ }
848
+ if (form.enabled && !replaced) {
849
+ const saved = buildLayout(undefined, preset, form, createId());
850
+ savedId = saved.id;
851
+ next.push(saved);
852
+ }
853
+ const defaultLayoutId = resolveDefaultLayoutId(report.defaultLayoutId, savedId, form.enabled, form.isDefault, next);
854
+ return {
855
+ layouts: next.map((layout) => ({ ...layout, isDefault: layout.id === defaultLayoutId })),
856
+ defaultLayoutId,
857
+ };
858
+ }
859
+ function sameReportLayoutForm(left, right) {
860
+ return (left.enabled === right.enabled &&
861
+ left.isDefault === right.isDefault &&
862
+ left.showQuery === right.showQuery &&
863
+ left.queryName.trim() === right.queryName.trim() &&
864
+ left.dataSourceType === right.dataSourceType &&
865
+ left.dataSourceDescription.trim() === right.dataSourceDescription.trim() &&
866
+ sameInputs(left.queryInputs, right.queryInputs) &&
867
+ left.pagination === right.pagination &&
868
+ left.stickyHeader === right.stickyHeader &&
869
+ left.stripedRows === right.stripedRows &&
870
+ left.xField.trim() === right.xField.trim() &&
871
+ left.yFields.trim() === right.yFields.trim() &&
872
+ left.groupBy.trim() === right.groupBy.trim() &&
873
+ left.showDownloadButton === right.showDownloadButton &&
874
+ left.showPrintButton === right.showPrintButton &&
875
+ left.showZoomControls === right.showZoomControls &&
876
+ left.showFullscreenButton === right.showFullscreenButton &&
877
+ left.defaultZoom === right.defaultZoom &&
878
+ left.headerTitle.trim() === right.headerTitle.trim() &&
879
+ left.headerShowDate === right.headerShowDate &&
880
+ left.footerShowDate === right.footerShowDate &&
881
+ left.fileNameTemplate.trim() === right.fileNameTemplate.trim() &&
882
+ left.pdfExportEnabled === right.pdfExportEnabled &&
883
+ left.excelExportEnabled === right.excelExportEnabled &&
884
+ left.excelSheetName.trim() === right.excelSheetName.trim() &&
885
+ left.csvExportEnabled === right.csvExportEnabled &&
886
+ sameText(left.title, right.title) &&
887
+ sameText(left.description, right.description) &&
888
+ sameColumns(left.columns, right.columns) &&
889
+ sameSummaries(left.summaries, right.summaries));
890
+ }
891
+ /** Keeps the known form fields when a widget container echoes a wider context object. */
892
+ function pickReportLayoutForm(value, fallback) {
893
+ return {
894
+ enabled: typeof value['enabled'] === 'boolean' ? value['enabled'] : fallback.enabled,
895
+ title: isText(value['title']) ? value['title'] : fallback.title,
896
+ description: isText(value['description']) ? value['description'] : fallback.description,
897
+ isDefault: typeof value['isDefault'] === 'boolean' ? value['isDefault'] : fallback.isDefault,
898
+ queryName: typeof value['queryName'] === 'string' ? value['queryName'] : fallback.queryName,
899
+ showQuery: fallback.showQuery,
900
+ dataSourceType: typeof value['dataSourceType'] === 'string' ? value['dataSourceType'] : fallback.dataSourceType,
901
+ dataSourceDescription: typeof value['dataSourceDescription'] === 'string' ? value['dataSourceDescription'] : fallback.dataSourceDescription,
902
+ queryInputs: Array.isArray(value['queryInputs']) ? normalizeInputs(value['queryInputs']) : fallback.queryInputs,
903
+ pagination: typeof value['pagination'] === 'boolean' ? value['pagination'] : fallback.pagination,
904
+ stickyHeader: typeof value['stickyHeader'] === 'boolean' ? value['stickyHeader'] : fallback.stickyHeader,
905
+ stripedRows: typeof value['stripedRows'] === 'boolean' ? value['stripedRows'] : fallback.stripedRows,
906
+ columns: Array.isArray(value['columns']) ? normalizeColumns(value['columns']) : fallback.columns,
907
+ summaries: Array.isArray(value['summaries']) ? normalizeSummaries(value['summaries']) : fallback.summaries,
908
+ xField: typeof value['xField'] === 'string' ? value['xField'] : fallback.xField,
909
+ yFields: typeof value['yFields'] === 'string' ? value['yFields'] : fallback.yFields,
910
+ groupBy: typeof value['groupBy'] === 'string' ? value['groupBy'] : fallback.groupBy,
911
+ showDownloadButton: typeof value['showDownloadButton'] === 'boolean' ? value['showDownloadButton'] : fallback.showDownloadButton,
912
+ showPrintButton: typeof value['showPrintButton'] === 'boolean' ? value['showPrintButton'] : fallback.showPrintButton,
913
+ showZoomControls: typeof value['showZoomControls'] === 'boolean' ? value['showZoomControls'] : fallback.showZoomControls,
914
+ showFullscreenButton: typeof value['showFullscreenButton'] === 'boolean' ? value['showFullscreenButton'] : fallback.showFullscreenButton,
915
+ defaultZoom: typeof value['defaultZoom'] === 'number' ? value['defaultZoom'] : fallback.defaultZoom,
916
+ headerTitle: typeof value['headerTitle'] === 'string' ? value['headerTitle'] : fallback.headerTitle,
917
+ headerShowDate: typeof value['headerShowDate'] === 'boolean' ? value['headerShowDate'] : fallback.headerShowDate,
918
+ footerShowDate: typeof value['footerShowDate'] === 'boolean' ? value['footerShowDate'] : fallback.footerShowDate,
919
+ fileNameTemplate: typeof value['fileNameTemplate'] === 'string' ? value['fileNameTemplate'] : fallback.fileNameTemplate,
920
+ pdfExportEnabled: typeof value['pdfExportEnabled'] === 'boolean' ? value['pdfExportEnabled'] : fallback.pdfExportEnabled,
921
+ excelExportEnabled: typeof value['excelExportEnabled'] === 'boolean' ? value['excelExportEnabled'] : fallback.excelExportEnabled,
922
+ excelSheetName: typeof value['excelSheetName'] === 'string' ? value['excelSheetName'] : fallback.excelSheetName,
923
+ csvExportEnabled: typeof value['csvExportEnabled'] === 'boolean' ? value['csvExportEnabled'] : fallback.csvExportEnabled,
924
+ };
925
+ }
926
+ //#endregion
927
+ //#region ---- Matching and mapping ----
928
+ function layoutMatchesPreset(layout, preset) {
929
+ if (layout.layout?.type !== preset.layoutType) {
930
+ return false;
931
+ }
932
+ if (preset.layoutType !== 'chart') {
933
+ return true;
934
+ }
935
+ return layout.layout.type === 'chart' && layout.layout.options?.chartType === preset.chartType;
936
+ }
937
+ function buildLayout(existing, preset, form, id) {
938
+ const layout = {
939
+ ...existing,
940
+ id,
941
+ title: storedTitle(form.title, preset),
942
+ icon: preset.icon,
943
+ layout: buildLayoutBody(existing?.layout, preset, form),
944
+ };
945
+ const description = storedOptionalText(form.description);
946
+ if (description == null) {
947
+ delete layout.description;
948
+ }
949
+ else {
950
+ layout.description = description;
951
+ }
952
+ const dataSource = buildDataSource(existing?.dataSource, preset, form);
953
+ if (dataSource == null) {
954
+ delete layout.dataSource;
955
+ }
956
+ else {
957
+ layout.dataSource = dataSource;
958
+ }
959
+ const exportOptions = buildExport(existing?.export, form);
960
+ if (exportOptions == null) {
961
+ delete layout.export;
962
+ }
963
+ else {
964
+ layout.export = exportOptions;
965
+ }
966
+ return layout;
967
+ }
968
+ function buildLayoutBody(existing, preset, form) {
969
+ if (preset.layoutType === 'table') {
970
+ const table = existing?.type === 'table' ? existing : undefined;
971
+ const summary = mergeSummaries(form.summaries);
972
+ const body = {
973
+ ...table,
974
+ type: 'table',
975
+ columns: mergeColumns(table?.columns, form.columns),
976
+ options: {
977
+ ...table?.options,
978
+ pagination: form.pagination,
979
+ stickyHeader: form.stickyHeader,
980
+ stripedRows: form.stripedRows,
981
+ },
982
+ };
983
+ if (summary.length > 0) {
984
+ body.summary = summary;
985
+ }
986
+ else {
987
+ delete body.summary;
988
+ }
989
+ return body;
990
+ }
991
+ if (preset.layoutType === 'chart') {
992
+ const chart = existing?.type === 'chart' ? existing : undefined;
993
+ return {
994
+ ...chart,
995
+ type: 'chart',
996
+ options: {
997
+ ...chart?.options,
998
+ chartType: preset.chartType ?? 'bar',
999
+ dataMapping: chartMapping(chart?.options?.dataMapping, form),
1000
+ },
1001
+ };
1002
+ }
1003
+ const pdf = existing?.type === 'pdf' ? existing : undefined;
1004
+ const header = buildHeaderFooter(pdf?.header, form.headerTitle, form.headerShowDate);
1005
+ const footer = buildHeaderFooter(pdf?.footer, '', form.footerShowDate);
1006
+ const body = {
1007
+ ...pdf,
1008
+ type: 'pdf',
1009
+ options: {
1010
+ ...pdf?.options,
1011
+ showDownloadButton: form.showDownloadButton,
1012
+ showPrintButton: form.showPrintButton,
1013
+ showZoomControls: form.showZoomControls,
1014
+ showFullscreenButton: form.showFullscreenButton,
1015
+ defaultZoom: form.defaultZoom,
1016
+ },
1017
+ };
1018
+ if (header) {
1019
+ body.header = header;
1020
+ }
1021
+ else {
1022
+ delete body.header;
1023
+ }
1024
+ if (footer) {
1025
+ body.footer = footer;
1026
+ }
1027
+ else {
1028
+ delete body.footer;
1029
+ }
1030
+ return body;
1031
+ }
1032
+ function buildDataSource(existing, preset, form) {
1033
+ const requested = form.dataSourceType.trim() || existing?.type || 'query';
1034
+ if (requested !== 'query') {
1035
+ if (existing?.type !== requested) {
1036
+ return existing;
1037
+ }
1038
+ const kept = { ...existing };
1039
+ const description = form.dataSourceDescription.trim();
1040
+ if (description) {
1041
+ kept.description = description;
1042
+ }
1043
+ else {
1044
+ delete kept.description;
1045
+ }
1046
+ return kept;
1047
+ }
1048
+ const name = form.queryName.trim();
1049
+ if (!name) {
1050
+ return undefined;
1051
+ }
1052
+ const query = existing?.type === 'query'
1053
+ ? { ...existing, type: 'query', name }
1054
+ : { type: 'query', name };
1055
+ const description = form.dataSourceDescription.trim();
1056
+ if (description) {
1057
+ query.description = description;
1058
+ }
1059
+ else {
1060
+ delete query.description;
1061
+ }
1062
+ const inputs = form.queryInputs
1063
+ .map((input) => ({ parameterKey: input.parameterKey.trim(), bindTo: input.bindTo.trim() }))
1064
+ .filter((input) => input.parameterKey.length > 0 && input.bindTo.length > 0);
1065
+ if (inputs.length > 0) {
1066
+ query.inputs = inputs;
1067
+ }
1068
+ else {
1069
+ delete query.inputs;
1070
+ }
1071
+ if (preset.layoutType === 'table') {
1072
+ query.pagination = form.pagination;
1073
+ }
1074
+ return query;
1075
+ }
1076
+ function mergeColumns(existing, rows) {
1077
+ const previous = new Map((existing ?? []).map((column) => [column.field, column]));
1078
+ return rows
1079
+ .map((row) => ({ ...row, field: row.field.trim(), title: row.title.trim() }))
1080
+ .filter((row) => row.field.length > 0)
1081
+ .map((row) => {
1082
+ const prior = previous.get(row.field);
1083
+ const column = {
1084
+ ...prior,
1085
+ field: row.field,
1086
+ title: row.title || prior?.title || row.field,
1087
+ visible: row.visible ?? prior?.visible ?? true,
1088
+ };
1089
+ if (row.sortable !== undefined) {
1090
+ column.sortable = row.sortable;
1091
+ }
1092
+ if (row.align !== undefined) {
1093
+ const align = row.align.trim();
1094
+ if (align === 'left' || align === 'center' || align === 'right') {
1095
+ column.align = align;
1096
+ }
1097
+ else {
1098
+ delete column.align;
1099
+ }
1100
+ }
1101
+ if (row.width !== undefined) {
1102
+ const width = parseWidth(row.width);
1103
+ if (width == null) {
1104
+ delete column.width;
1105
+ }
1106
+ else {
1107
+ column.width = width;
1108
+ }
1109
+ }
1110
+ if (row.widgetType !== undefined) {
1111
+ const widget = buildColumnWidget(row, row.field);
1112
+ if (widget == null) {
1113
+ delete column.widget;
1114
+ }
1115
+ else {
1116
+ column.widget = widget;
1117
+ }
1118
+ }
1119
+ return column;
1120
+ });
1121
+ }
1122
+ function resolveDefaultLayoutId(currentDefault, savedId, enabled, isDefault, layouts) {
1123
+ if (!enabled) {
1124
+ if (currentDefault && layouts.some((layout) => layout.id === currentDefault)) {
1125
+ return currentDefault;
1126
+ }
1127
+ return layouts[0]?.id ?? '';
1128
+ }
1129
+ if (isDefault || layouts.length === 1 || !currentDefault) {
1130
+ return savedId;
1131
+ }
1132
+ if (currentDefault === savedId && !isDefault) {
1133
+ return layouts.find((layout) => layout.id !== savedId)?.id ?? savedId;
1134
+ }
1135
+ if (!layouts.some((layout) => layout.id === currentDefault)) {
1136
+ return savedId;
1137
+ }
1138
+ return currentDefault;
1139
+ }
1140
+ function displayTitle(title, preset) {
1141
+ if (title == null || title === preset.title || isBlankText(title)) {
1142
+ return '';
1143
+ }
1144
+ return title;
1145
+ }
1146
+ function storedTitle(title, preset) {
1147
+ return isBlankText(title) ? preset.title : title;
1148
+ }
1149
+ function storedOptionalText(value) {
1150
+ return isBlankText(value) ? undefined : value;
1151
+ }
1152
+ function formatYFields(value) {
1153
+ return Array.isArray(value) ? value.join(', ') : value ?? '';
1154
+ }
1155
+ function parseYFields(value) {
1156
+ const parts = value.split(',').map((part) => part.trim()).filter((part) => part.length > 0);
1157
+ if (parts.length <= 1) {
1158
+ return parts[0] ?? '';
1159
+ }
1160
+ return parts;
1161
+ }
1162
+ function normalizeInputs(value) {
1163
+ return value.flatMap((row) => {
1164
+ if (row == null || typeof row !== 'object') {
1165
+ return [];
1166
+ }
1167
+ const record = row;
1168
+ return [{
1169
+ parameterKey: typeof record['parameterKey'] === 'string' ? record['parameterKey'] : '',
1170
+ bindTo: typeof record['bindTo'] === 'string' ? record['bindTo'] : '',
1171
+ }];
1172
+ });
1173
+ }
1174
+ function sameInputs(left, right) {
1175
+ return left.length === right.length && left.every((input, index) => {
1176
+ const other = right[index];
1177
+ return input.parameterKey.trim() === other?.parameterKey.trim() && input.bindTo.trim() === other?.bindTo.trim();
1178
+ });
1179
+ }
1180
+ function normalizeSummaries(value) {
1181
+ return value.flatMap((row) => {
1182
+ if (row == null || typeof row !== 'object') {
1183
+ return [];
1184
+ }
1185
+ const record = row;
1186
+ return [{
1187
+ field: typeof record['field'] === 'string' ? record['field'] : '',
1188
+ operation: typeof record['operation'] === 'string' ? record['operation'] : '',
1189
+ displayIn: typeof record['displayIn'] === 'string' ? record['displayIn'] : '',
1190
+ }];
1191
+ });
1192
+ }
1193
+ function normalizeColumns(value) {
1194
+ return value.flatMap((row) => {
1195
+ if (row == null || typeof row !== 'object') {
1196
+ return [];
1197
+ }
1198
+ const record = row;
1199
+ return [{
1200
+ field: typeof record['field'] === 'string' ? record['field'] : '',
1201
+ title: typeof record['title'] === 'string' ? record['title'] : '',
1202
+ visible: typeof record['visible'] === 'boolean' ? record['visible'] : true,
1203
+ sortable: record['sortable'] === true,
1204
+ align: typeof record['align'] === 'string' ? record['align'] : '',
1205
+ width: typeof record['width'] === 'string' || typeof record['width'] === 'number' ? String(record['width']) : '',
1206
+ widgetType: typeof record['widgetType'] === 'string' ? record['widgetType'] : '',
1207
+ widgetFormat: typeof record['widgetFormat'] === 'string' ? record['widgetFormat'] : '',
1208
+ decimals: typeof record['decimals'] === 'string' || typeof record['decimals'] === 'number' ? String(record['decimals']) : '',
1209
+ }];
1210
+ });
1211
+ }
1212
+ function isText(value) {
1213
+ if (typeof value === 'string') {
1214
+ return true;
1215
+ }
1216
+ if (value == null || typeof value !== 'object' || Array.isArray(value)) {
1217
+ return false;
1218
+ }
1219
+ return Object.values(value).every((item) => typeof item === 'string');
1220
+ }
1221
+ function isBlankText(value) {
1222
+ if (value == null) {
1223
+ return true;
1224
+ }
1225
+ if (typeof value === 'string') {
1226
+ return value.trim().length === 0;
1227
+ }
1228
+ return Object.values(value).every((item) => item.trim().length === 0);
1229
+ }
1230
+ function sameText(left, right) {
1231
+ if (isBlankText(left) && isBlankText(right)) {
1232
+ return true;
1233
+ }
1234
+ if (typeof left === 'string' || typeof right === 'string') {
1235
+ return left === right;
1236
+ }
1237
+ const keys = new Set([...Object.keys(left), ...Object.keys(right)]);
1238
+ for (const key of keys) {
1239
+ if ((left[key] ?? '').trim() !== (right[key] ?? '').trim()) {
1240
+ return false;
1241
+ }
1242
+ }
1243
+ return true;
1244
+ }
1245
+ function sameColumns(left, right) {
1246
+ const a = left.map(normalizeColumnIdentity);
1247
+ const b = right.map(normalizeColumnIdentity);
1248
+ if (a.length !== b.length) {
1249
+ return false;
1250
+ }
1251
+ return a.every((row, index) => JSON.stringify(row) === JSON.stringify(b[index]));
1252
+ }
1253
+ function normalizeColumnIdentity(row) {
1254
+ return {
1255
+ field: row.field.trim(),
1256
+ title: row.title.trim(),
1257
+ visible: row.visible !== false,
1258
+ sortable: row.sortable === true,
1259
+ align: row.align?.trim() ?? '',
1260
+ width: row.width?.trim() ?? '',
1261
+ widgetType: row.widgetType?.trim() ?? '',
1262
+ widgetFormat: row.widgetFormat?.trim() ?? '',
1263
+ decimals: row.decimals?.trim() ?? '',
1264
+ };
1265
+ }
1266
+ function sameSummaries(left, right) {
1267
+ const normalize = (rows) => rows.map((row) => ({
1268
+ field: row.field.trim(),
1269
+ operation: row.operation.trim(),
1270
+ displayIn: row.displayIn.trim(),
1271
+ }));
1272
+ return JSON.stringify(normalize(left)) === JSON.stringify(normalize(right));
1273
+ }
1274
+ function readColumn(column) {
1275
+ const widget = column.widget;
1276
+ const options = widget?.options ?? {};
1277
+ return {
1278
+ field: column.field,
1279
+ title: column.title ?? '',
1280
+ visible: column.visible !== false,
1281
+ sortable: column.sortable === true,
1282
+ align: column.align ?? '',
1283
+ width: column.width == null ? '' : String(column.width),
1284
+ widgetType: widget?.type ?? '',
1285
+ widgetFormat: typeof options['format'] === 'string' ? options['format'] : '',
1286
+ decimals: options['decimals'] == null ? '' : String(options['decimals']),
1287
+ };
1288
+ }
1289
+ function headerTitle(layout) {
1290
+ const title = layout?.header?.title;
1291
+ return typeof title === 'string' ? title : '';
1292
+ }
1293
+ function chartMapping(existing, form) {
1294
+ const mapping = {
1295
+ ...existing,
1296
+ xField: form.xField.trim(),
1297
+ yFields: parseYFields(form.yFields),
1298
+ };
1299
+ const groupBy = form.groupBy.trim();
1300
+ if (groupBy) {
1301
+ mapping.groupBy = groupBy;
1302
+ }
1303
+ else {
1304
+ delete mapping.groupBy;
1305
+ }
1306
+ return mapping;
1307
+ }
1308
+ function buildHeaderFooter(existing, title, showDate) {
1309
+ const next = { ...existing, showDate };
1310
+ const trimmed = title.trim();
1311
+ if (trimmed) {
1312
+ next.title = trimmed;
1313
+ }
1314
+ else {
1315
+ delete next.title;
1316
+ }
1317
+ const hasContent = Boolean(next.title || next.logoUrl || next.showDate || next.showParameters || next.customHtml);
1318
+ return hasContent ? next : undefined;
1319
+ }
1320
+ function buildExport(existing, form) {
1321
+ const fileNameTemplate = form.fileNameTemplate.trim();
1322
+ const sheetName = form.excelSheetName.trim();
1323
+ const touched = Boolean(fileNameTemplate ||
1324
+ sheetName ||
1325
+ form.pdfExportEnabled ||
1326
+ form.excelExportEnabled ||
1327
+ form.csvExportEnabled ||
1328
+ existing);
1329
+ if (!touched) {
1330
+ return undefined;
1331
+ }
1332
+ return {
1333
+ ...existing,
1334
+ ...(fileNameTemplate ? { fileNameTemplate } : {}),
1335
+ pdf: { ...existing?.pdf, enabled: form.pdfExportEnabled },
1336
+ excel: {
1337
+ ...existing?.excel,
1338
+ enabled: form.excelExportEnabled,
1339
+ ...(sheetName ? { sheetName } : {}),
1340
+ },
1341
+ csv: { ...existing?.csv, enabled: form.csvExportEnabled },
1342
+ };
1343
+ }
1344
+ function mergeSummaries(rows) {
1345
+ return rows.flatMap((row) => {
1346
+ const field = row.field.trim();
1347
+ const operation = row.operation.trim();
1348
+ const displayIn = row.displayIn.trim();
1349
+ if (!field || !isSummaryOperation(operation) || !isSummaryDisplay(displayIn)) {
1350
+ return [];
1351
+ }
1352
+ return [{ field, operation, displayIn }];
1353
+ });
1354
+ }
1355
+ function isSummaryOperation(value) {
1356
+ return value === 'sum' || value === 'avg' || value === 'count' || value === 'min' || value === 'max';
1357
+ }
1358
+ function isSummaryDisplay(value) {
1359
+ return value === 'groupFooter' || value === 'reportFooter';
1360
+ }
1361
+ function parseWidth(value) {
1362
+ const trimmed = value?.trim() ?? '';
1363
+ if (!trimmed) {
1364
+ return undefined;
1365
+ }
1366
+ if (trimmed === 'auto') {
1367
+ return 'auto';
1368
+ }
1369
+ const width = Number(trimmed);
1370
+ return Number.isFinite(width) ? width : undefined;
1371
+ }
1372
+ function buildColumnWidget(row, field) {
1373
+ const type = row.widgetType?.trim() ?? '';
1374
+ if (!type) {
1375
+ return undefined;
1376
+ }
1377
+ const options = {};
1378
+ const format = row.widgetFormat?.trim() ?? '';
1379
+ if (format) {
1380
+ options['format'] = format;
1381
+ }
1382
+ const decimals = row.decimals?.trim() ?? '';
1383
+ if (decimals && Number.isFinite(Number(decimals))) {
1384
+ options['decimals'] = Number(decimals);
1385
+ }
1386
+ return { type, path: field, options };
1387
+ }
1388
+ //#endregion
1389
+
1390
+ /**
1391
+ * The definition stores each view as JSON objects, not as the few switches on the page.
1392
+ * Returns only the objects that are actually present on the matching layout.
1393
+ */
1394
+ function reportLayoutJsonSections(report, preset) {
1395
+ const current = (report?.layouts ?? []).find((layout) => layoutMatchesPreset(layout, preset));
1396
+ if (!current) {
1397
+ return [];
1398
+ }
1399
+ const sections = [];
1400
+ pushSection(sections, 'layout', 'layout', current.layout);
1401
+ pushSection(sections, 'dataSource', 'data-source', current.dataSource);
1402
+ pushSection(sections, 'actions', 'actions', current.actions);
1403
+ pushSection(sections, 'export', 'export', current.export);
1404
+ return sections;
1405
+ }
1406
+ function pushSection(sections, name, labelKey, value) {
1407
+ if (!hasJsonContent(value)) {
1408
+ return;
1409
+ }
1410
+ sections.push({ name, labelKey, value });
1411
+ }
1412
+ function hasJsonContent(value) {
1413
+ if (Array.isArray(value)) {
1414
+ return value.length > 0;
1415
+ }
1416
+ if (value != null && typeof value === 'object') {
1417
+ return Object.keys(value).length > 0;
1418
+ }
1419
+ return false;
1420
+ }
1421
+ //#endregion
1422
+
1423
+ //#endregion
1424
+ //#region ---- Starter shape ----
1425
+ /** `inputs` maps report filters to fields of the query rows. It is one sample row, never stored as is. */
1426
+ const QUERY_DATA_SOURCE = { type: 'query', name: '', description: '', inputs: [{ parameterKey: '', bindTo: '' }] };
1427
+ const EXPORT_OPTIONS = {
1428
+ fileNameTemplate: '',
1429
+ pdf: { enabled: false },
1430
+ excel: { enabled: false, sheetName: '' },
1431
+ csv: { enabled: false },
1432
+ };
1433
+ /**
1434
+ * The keys a view needs, with one sample value per key so the page can choose an editor for it.
1435
+ * A list holds one sample row. The sample only gives the row its fields; it is never stored.
1436
+ */
1437
+ function reportLayoutStarterShape(preset) {
1438
+ if (preset.layoutType === 'table') {
1439
+ return {
1440
+ layout: {
1441
+ type: 'table',
1442
+ columns: [{ field: '', title: '', visible: true, sortable: false, align: 'left' }],
1443
+ options: { pagination: true, stickyHeader: true, stripedRows: true },
1444
+ },
1445
+ dataSource: { ...QUERY_DATA_SOURCE },
1446
+ export: cloneJson(EXPORT_OPTIONS),
1447
+ };
1448
+ }
1449
+ if (preset.layoutType === 'chart') {
1450
+ return {
1451
+ layout: {
1452
+ type: 'chart',
1453
+ options: {
1454
+ chartType: preset.chartType ?? 'bar',
1455
+ dataMapping: { xField: '', yFields: [''], groupBy: '', seriesField: '', labelField: '' },
1456
+ },
1457
+ },
1458
+ dataSource: { ...QUERY_DATA_SOURCE },
1459
+ export: cloneJson(EXPORT_OPTIONS),
1460
+ };
1461
+ }
1462
+ return {
1463
+ layout: {
1464
+ type: 'pdf',
1465
+ options: {
1466
+ showDownloadButton: true,
1467
+ showPrintButton: true,
1468
+ showZoomControls: true,
1469
+ showFullscreenButton: true,
1470
+ defaultZoom: 100,
1471
+ height: '',
1472
+ },
1473
+ header: { title: '', showDate: false },
1474
+ footer: { showDate: false },
1475
+ },
1476
+ dataSource: { ...QUERY_DATA_SOURCE },
1477
+ export: cloneJson(EXPORT_OPTIONS),
1478
+ };
1479
+ }
1480
+ //#endregion
1481
+ //#region ---- Starter values ----
1482
+ /**
1483
+ * Values a view that is not stored yet starts with.
1484
+ * Fixed keys (`type`, `chartType`) and switches that default to on are filled. Everything else is blank,
1485
+ * lists are empty and `false` switches stay unset, so nothing is stored until the user enters it.
1486
+ */
1487
+ function reportLayoutStarterValues(preset) {
1488
+ return blankOut(reportLayoutStarterShape(preset));
1489
+ }
1490
+ function blankOut(value) {
1491
+ if (Array.isArray(value)) {
1492
+ return [];
1493
+ }
1494
+ if (value != null && typeof value === 'object') {
1495
+ const result = {};
1496
+ for (const [key, item] of Object.entries(value)) {
1497
+ if (item === false) {
1498
+ continue;
1499
+ }
1500
+ result[key] = blankOut(item);
1501
+ }
1502
+ return result;
1503
+ }
1504
+ return value;
1505
+ }
1506
+ function cloneJson(value) {
1507
+ return JSON.parse(JSON.stringify(value));
1508
+ }
1509
+ //#endregion
1510
+
1511
+ //#endregion
1512
+ //#region ---- Server to UI ----
1513
+ /**
1514
+ * Copies the stored objects of one view for the editing page.
1515
+ * The widgets write into this copy, so the loaded report definition is never touched.
1516
+ * A view that is not stored yet starts from the keys it needs, so it can be defined from scratch.
1517
+ */
1518
+ function readReportLayoutSections(report, preset) {
1519
+ const sections = {};
1520
+ for (const section of reportLayoutJsonSections(report, preset)) {
1521
+ sections[section.name] = cloneStoredJson(section.value);
1522
+ }
1523
+ return Object.keys(sections).length > 0 ? sections : reportLayoutStarterValues(preset);
1524
+ }
1525
+ /**
1526
+ * Maps every report filter to the field of the view's query that has the same name.
1527
+ * Filters the view already maps are left as they are, so a choice made on the page always wins.
1528
+ * Returns the given sections untouched when the view has no query or nothing needs mapping.
1529
+ */
1530
+ function autoMapReportLayoutInputs(sections, parameterKeys, columns) {
1531
+ const dataSource = sections['dataSource'];
1532
+ if (!isRecord(dataSource) || reportLayoutQueryName(sections) === '') {
1533
+ return sections;
1534
+ }
1535
+ const stored = Array.isArray(dataSource['inputs']) ? dataSource['inputs'] : [];
1536
+ const mapped = new Set(stored.filter(isRecord).map((row) => row['parameterKey']));
1537
+ const available = new Set(columns);
1538
+ const added = [...new Set(parameterKeys)]
1539
+ .filter((key) => key !== '' && available.has(key) && !mapped.has(key))
1540
+ .map((key) => ({ parameterKey: key, bindTo: key }));
1541
+ if (added.length === 0) {
1542
+ return sections;
1543
+ }
1544
+ return { ...sections, dataSource: { ...dataSource, inputs: [...stored, ...added] } };
1545
+ }
1546
+ /**
1547
+ * Editors for one view: every stored property, plus the keys the view needs that are not stored yet.
1548
+ * The page and the cleaning below must use the same schema.
1549
+ */
1550
+ function reportLayoutFieldSchema(baseline, preset) {
1551
+ return inferReportLayoutFields(preset ? addMissingKeys(baseline, reportLayoutStarterShape(preset)) : baseline);
1552
+ }
1553
+ //#endregion
1554
+ //#region ---- UI to server ----
1555
+ /**
1556
+ * Turns edited section values back into the shape the server stores.
1557
+ * Only the properties the page can edit are normalised; every other stored key travels through as it was.
1558
+ * `baseline` is the section copy the page started from. It decides which properties are editable.
1559
+ */
1560
+ function cleanReportLayoutSections(baseline, edited, preset) {
1561
+ const result = cloneStoredJson(edited ?? {});
1562
+ for (const field of reportLayoutFieldSchema(baseline, preset)) {
1563
+ cleanField(result, field);
1564
+ }
1565
+ return result;
1566
+ }
1567
+ /** True when the edited sections differ from the baseline once both are normalised. */
1568
+ function reportLayoutSectionsChanged(baseline, edited, preset) {
1569
+ return !sameJson(cleanReportLayoutSections(baseline, baseline, preset), cleanReportLayoutSections(baseline, edited, preset));
1570
+ }
1571
+ /**
1572
+ * Writes the edited sections onto the layout of this preset.
1573
+ * A section is written when the view already stored it or the user entered something in it.
1574
+ * The layout `type` and chart type stay the ones the tab stands for.
1575
+ */
1576
+ function applyReportLayoutSections(layouts, preset, baseline, edited) {
1577
+ const cleaned = cleanReportLayoutSections(baseline, edited, preset);
1578
+ return layouts.map((layout) => {
1579
+ if (!layoutMatchesPreset(layout, preset)) {
1580
+ return layout;
1581
+ }
1582
+ const next = { ...layout };
1583
+ if (isRecord(cleaned['layout'])) {
1584
+ next.layout = fixedLayout(cleaned['layout'], layout, preset);
1585
+ }
1586
+ if (shouldWrite(baseline, cleaned, 'dataSource')) {
1587
+ assignOrRemove(next, 'dataSource', usableDataSource(cleaned['dataSource']));
1588
+ }
1589
+ if (shouldWrite(baseline, cleaned, 'actions')) {
1590
+ assignOrRemove(next, 'actions', cleaned['actions']);
1591
+ }
1592
+ if (shouldWrite(baseline, cleaned, 'export')) {
1593
+ assignOrRemove(next, 'export', cleaned['export']);
1594
+ }
1595
+ return next;
1596
+ });
1597
+ }
1598
+ function shouldWrite(baseline, cleaned, name) {
1599
+ return name in baseline || hasContent(cleaned[name]);
1600
+ }
1601
+ /** The tab decides the layout type and chart type, so editing the sections cannot move the view elsewhere. */
1602
+ function fixedLayout(edited, stored, preset) {
1603
+ const layout = { ...edited, type: stored.layout.type };
1604
+ if (preset.layoutType === 'chart') {
1605
+ layout['options'] = { ...(isRecord(layout['options']) ? layout['options'] : {}), chartType: preset.chartType ?? 'bar' };
1606
+ }
1607
+ return layout;
1608
+ }
1609
+ /** A query data source without a query name is not a data source yet. */
1610
+ function usableDataSource(value) {
1611
+ if (!isRecord(value)) {
1612
+ return undefined;
1613
+ }
1614
+ if (value['type'] === 'query' && typeof value['name'] !== 'string') {
1615
+ return undefined;
1616
+ }
1617
+ return value;
1618
+ }
1619
+ //#endregion
1620
+ //#region ---- Starter keys ----
1621
+ /**
1622
+ * Copy of the stored sections with the keys a view needs added where they are missing.
1623
+ * Used for editor inference only. A record whose `type` differs from the starter's is left alone.
1624
+ */
1625
+ function addMissingKeys(stored, shape) {
1626
+ const result = cloneStoredJson(stored);
1627
+ mergeShape(result, shape);
1628
+ return result;
1629
+ }
1630
+ function mergeShape(target, shape) {
1631
+ for (const [key, sample] of Object.entries(shape)) {
1632
+ const current = target[key];
1633
+ if (current == null) {
1634
+ target[key] = cloneStoredJson(sample);
1635
+ }
1636
+ else if (isRecord(current) && isRecord(sample)) {
1637
+ if (!hasOtherType(current, sample)) {
1638
+ mergeShape(current, sample);
1639
+ }
1640
+ }
1641
+ else if (Array.isArray(current) && Array.isArray(sample)) {
1642
+ mergeSampleItems(target, key, current, sample);
1643
+ }
1644
+ }
1645
+ }
1646
+ function mergeSampleItems(target, key, current, sample) {
1647
+ if (current.length === 0) {
1648
+ target[key] = cloneStoredJson(sample);
1649
+ return;
1650
+ }
1651
+ if (current.every(isRecord) && sample.every(isRecord)) {
1652
+ target[key] = [...current, ...cloneStoredJson(sample)];
1653
+ }
1654
+ }
1655
+ function hasOtherType(current, sample) {
1656
+ return typeof current['type'] === 'string' && typeof sample['type'] === 'string' && current['type'] !== sample['type'];
1657
+ }
1658
+ //#endregion
1659
+ //#region ---- Field cleaning ----
1660
+ function cleanField(container, field) {
1661
+ const value = container[field.key];
1662
+ switch (field.kind) {
1663
+ case 'group':
1664
+ cleanGroup(container, field, value);
1665
+ return;
1666
+ case 'list':
1667
+ cleanList(container, field, value);
1668
+ return;
1669
+ case 'toggle':
1670
+ assignOrDelete(container, field.key, typeof value === 'boolean' ? value : value == null ? undefined : Boolean(value));
1671
+ return;
1672
+ case 'number':
1673
+ assignOrDelete(container, field.key, toNumber(value));
1674
+ return;
1675
+ case 'tags':
1676
+ case 'column-list':
1677
+ cleanTags(container, field.key, value);
1678
+ return;
1679
+ case 'locale-text':
1680
+ cleanLocaleText(container, field.key, value);
1681
+ return;
1682
+ case 'json':
1683
+ return;
1684
+ default:
1685
+ assignOrDelete(container, field.key, toText(value));
1686
+ }
1687
+ }
1688
+ function cleanGroup(container, field, value) {
1689
+ if (!isRecord(value)) {
1690
+ delete container[field.key];
1691
+ return;
1692
+ }
1693
+ for (const child of field.fields ?? []) {
1694
+ cleanField(value, child);
1695
+ }
1696
+ if (Object.keys(value).length === 0) {
1697
+ delete container[field.key];
1698
+ }
1699
+ }
1700
+ function cleanList(container, field, value) {
1701
+ if (!Array.isArray(value)) {
1702
+ delete container[field.key];
1703
+ return;
1704
+ }
1705
+ const children = field.fields ?? [];
1706
+ const rowsHaveId = children.some((child) => child.key === 'id');
1707
+ const rows = value.filter(isRecord);
1708
+ for (const row of rows) {
1709
+ for (const child of children) {
1710
+ cleanField(row, child);
1711
+ }
1712
+ // The repeater stamps an `id` on every row it adds. Keep it only when the stored rows carry one.
1713
+ if (!rowsHaveId) {
1714
+ delete row['id'];
1715
+ }
1716
+ }
1717
+ const kept = rows.filter((row) => Object.keys(row).length > 0);
1718
+ assignOrDelete(container, field.key, kept.length > 0 ? kept : undefined);
1719
+ }
1720
+ function cleanTags(container, key, value) {
1721
+ if (!Array.isArray(value)) {
1722
+ delete container[key];
1723
+ return;
1724
+ }
1725
+ // A multi select may hand back its rows (`{ id }`). The server stores the bare values.
1726
+ const bare = value.map((tag) => (isRecord(tag) && 'id' in tag ? tag['id'] : tag));
1727
+ const tags = bare.filter((tag) => (typeof tag === 'string' ? tag.trim().length > 0 : tag != null));
1728
+ assignOrDelete(container, key, tags.length > 0 ? tags : undefined);
1729
+ }
1730
+ function cleanLocaleText(container, key, value) {
1731
+ if (isRecord(value)) {
1732
+ const entries = Object.entries(value).filter(([, text]) => typeof text === 'string' && text.trim().length > 0);
1733
+ assignOrDelete(container, key, entries.length > 0 ? Object.fromEntries(entries) : undefined);
1734
+ return;
1735
+ }
1736
+ assignOrDelete(container, key, toText(value));
1737
+ }
1738
+ //#endregion
1739
+ //#region ---- Value helpers ----
1740
+ /** A select widget may hand back its row (`{ id }`). The server stores the bare value. */
1741
+ function toText(value) {
1742
+ const raw = isRecord(value) && 'id' in value ? value['id'] : value;
1743
+ if (raw == null) {
1744
+ return undefined;
1745
+ }
1746
+ const text = typeof raw === 'string' ? raw : typeof raw === 'number' ? String(raw) : undefined;
1747
+ return text != null && text.trim().length > 0 ? text : undefined;
1748
+ }
1749
+ function toNumber(value) {
1750
+ if (typeof value === 'number') {
1751
+ return Number.isFinite(value) ? value : undefined;
1752
+ }
1753
+ if (typeof value === 'string' && value.trim().length > 0) {
1754
+ const parsed = Number(value);
1755
+ return Number.isFinite(parsed) ? parsed : undefined;
1756
+ }
1757
+ return undefined;
1758
+ }
1759
+ function assignOrDelete(container, key, value) {
1760
+ if (value === undefined) {
1761
+ delete container[key];
1762
+ return;
1763
+ }
1764
+ container[key] = value;
1765
+ }
1766
+ function assignOrRemove(layout, key, value) {
1767
+ if (hasContent(value)) {
1768
+ layout[key] = value;
1769
+ return;
1770
+ }
1771
+ delete layout[key];
1772
+ }
1773
+ function hasContent(value) {
1774
+ if (Array.isArray(value)) {
1775
+ return value.length > 0;
1776
+ }
1777
+ return isRecord(value) && Object.keys(value).length > 0;
1778
+ }
1779
+ /** Report definitions are plain JSON, so a JSON round trip is a faithful deep copy. */
1780
+ function cloneStoredJson(value) {
1781
+ return value === undefined ? value : JSON.parse(JSON.stringify(value));
1782
+ }
1783
+ /** Deep equality for stored JSON. Key order does not matter, array order does. */
1784
+ function sameJson(left, right) {
1785
+ if (Array.isArray(left) || Array.isArray(right)) {
1786
+ return (Array.isArray(left) &&
1787
+ Array.isArray(right) &&
1788
+ left.length === right.length &&
1789
+ left.every((item, index) => sameJson(item, right[index])));
1790
+ }
1791
+ if (isRecord(left) && isRecord(right)) {
1792
+ const keys = new Set([...Object.keys(left), ...Object.keys(right)]);
1793
+ return [...keys].every((key) => sameJson(left[key], right[key]));
1794
+ }
1795
+ return left === right;
1796
+ }
1797
+ function isRecord(value) {
1798
+ return value != null && typeof value === 'object' && !Array.isArray(value);
1799
+ }
1800
+ //#endregion
1801
+
1802
+ const AXP_REPORT_LAYOUT_PRESETS = [
1803
+ {
1804
+ key: 'table',
1805
+ componentKey: 'report-definition-layout-table',
1806
+ title: '@report-management:report-viewer.layouts.table.title',
1807
+ description: '@report-management:reports.entities.report.layout-editor.page-description',
1808
+ icon: 'fa-light fa-table',
1809
+ order: 10,
1810
+ layoutType: 'table',
1811
+ },
1812
+ {
1813
+ key: 'bar',
1814
+ componentKey: 'report-definition-layout-bar',
1815
+ title: '@report-management:report-viewer.layouts.bar-chart.title',
1816
+ description: '@report-management:reports.entities.report.layout-editor.page-description',
1817
+ icon: 'fa-light fa-chart-bar',
1818
+ order: 20,
1819
+ layoutType: 'chart',
1820
+ chartType: 'bar',
1821
+ },
1822
+ {
1823
+ key: 'line',
1824
+ componentKey: 'report-definition-layout-line',
1825
+ title: '@report-management:report-viewer.layouts.line-chart.title',
1826
+ description: '@report-management:reports.entities.report.layout-editor.page-description',
1827
+ icon: 'fa-light fa-chart-line',
1828
+ order: 30,
1829
+ layoutType: 'chart',
1830
+ chartType: 'line',
1831
+ },
1832
+ {
1833
+ key: 'doughnut',
1834
+ componentKey: 'report-definition-layout-doughnut',
1835
+ title: '@report-management:report-viewer.layouts.doughnut-chart.title',
1836
+ description: '@report-management:reports.entities.report.layout-editor.page-description',
1837
+ icon: 'fa-light fa-chart-pie',
1838
+ order: 40,
1839
+ layoutType: 'chart',
1840
+ chartType: 'doughnut',
1841
+ },
1842
+ {
1843
+ key: 'pie',
1844
+ componentKey: 'report-definition-layout-pie',
1845
+ title: '@report-management:report-viewer.layouts.pie-chart.title',
1846
+ description: '@report-management:reports.entities.report.layout-editor.page-description',
1847
+ icon: 'fa-light fa-chart-pie',
1848
+ order: 50,
1849
+ layoutType: 'chart',
1850
+ chartType: 'pie',
1851
+ },
1852
+ {
1853
+ key: 'pdf',
1854
+ componentKey: 'report-definition-layout-pdf',
1855
+ title: '@report-management:report-viewer.layouts.pdf.title',
1856
+ description: '@report-management:reports.entities.report.layout-editor.page-description',
1857
+ icon: 'fa-light fa-file-pdf',
1858
+ order: 60,
1859
+ layoutType: 'pdf',
1860
+ },
1861
+ ];
1862
+ function reportLayoutPresetByKey(key) {
1863
+ if (!key) {
1864
+ return undefined;
1865
+ }
1866
+ return AXP_REPORT_LAYOUT_PRESETS.find((preset) => preset.key === key);
1867
+ }
1868
+ //#endregion
1869
+
1870
+ //#region ---- Filter mapping ----
1871
+ /**
1872
+ * Applies the filter mapping of a view's data source to the conditions built from the report filters.
1873
+ * A condition on a filter that the view maps to a query field runs on that field instead.
1874
+ * Filters without a mapping keep their own name, which is the field of the query rows with the same name.
1875
+ */
1876
+ function applyReportParameterBindings(clause, inputs) {
1877
+ const targets = new Map();
1878
+ for (const input of inputs ?? []) {
1879
+ const parameterKey = typeof input?.parameterKey === 'string' ? input.parameterKey.trim() : '';
1880
+ const bindTo = typeof input?.bindTo === 'string' ? input.bindTo.trim() : '';
1881
+ if (parameterKey && bindTo && parameterKey !== bindTo) {
1882
+ targets.set(parameterKey, bindTo);
1883
+ }
1884
+ }
1885
+ return targets.size === 0 ? clause : remap(clause, targets);
1886
+ }
1887
+ function remap(clause, targets) {
1888
+ if (Array.isArray(clause.filters)) {
1889
+ return { ...clause, filters: clause.filters.map((child) => remap(child, targets)) };
1890
+ }
1891
+ const target = typeof clause.field === 'string' ? targets.get(clause.field) : undefined;
1892
+ return target ? { ...clause, field: target } : clause;
1893
+ }
1894
+ //#endregion
1895
+
1896
+ //#region ---- Imports ----
1897
+ //#endregion
1898
+
169
1899
  //#region ---- Report management runtime keys ----
170
1900
  const AXMReportManagementQueryKeys = {
171
1901
  Category: {
@@ -183,11 +1913,122 @@ const AXMReportManagementQueryKeys = {
183
1913
  };
184
1914
  //#endregion
185
1915
 
186
- //#region ----- Imports -----
187
- //#endregion
188
-
189
- //#region ----- Imports -----
190
- //#endregion
1916
+ /** Trusted dependencies for coded reports, not administrator execution policies. */
1917
+ const AXP_REPORT_QUERY_TARGETS = [
1918
+ ['HumanCapitalManagement:Reports:GetHeadcountByDepartment', 'HumanCapitalManagement.Employee', false],
1919
+ ['HumanCapitalManagement:Reports:GetLeaveUsageByType', 'HumanCapitalManagement.LeaveRequest', false],
1920
+ ['ProjectManagement:Reports:GetProjectsByStatus', 'ProjectManagement.Project', false],
1921
+ ['TenantManagement:Dashboard:ActiveUsersKpi', 'TenantManagement.TenantUser', false],
1922
+ ['HumanCapitalManagement:Dashboard:EmployeesKpi', 'HumanCapitalManagement.Employee', false],
1923
+ ['TaskManagement:Dashboard:OpenTasksKpi', 'TaskManagement.Task', false],
1924
+ ['ProjectManagement:Dashboard:ActiveProjectsKpi', 'ProjectManagement.Project', false],
1925
+ ['WorkplaceSafetyManagement:Dashboard:OpenHazardsKpi', 'WorkplaceSafetyManagement.Hazard', false],
1926
+ ['DocumentManagement:Dashboard:DocumentsKpi', 'DocumentManagement.Document', false],
1927
+ ['WorkflowManagement:Dashboard:WorkflowDefinitionsKpi', 'WorkflowManagement.WorkflowDefinition', false],
1928
+ ['SubscriptionManagement:Dashboard:SubscriptionKpi', 'SubscriptionManagement.Subscription', false],
1929
+ ['WorkplaceSafetyManagement:Dashboard:HighRisksKpi', 'WorkplaceSafetyManagement.HazardRisk', false],
1930
+ ['WorkplaceSafetyManagement:Dashboard:ActiveSafetyPlansKpi', 'WorkplaceSafetyManagement.SafetyPlan', false],
1931
+ ['WorkplaceSafetyManagement:Dashboard:Take5ChecklistsKpi', 'WorkplaceSafetyManagement.SafetyPlan', false],
1932
+ ['WorkplaceSafetyManagement:Dashboard:Take5CompletedKpi', 'WorkplaceSafetyManagement.SafetyPlan', false],
1933
+ ['AssessmentManagement:Dashboard:OverdueAssessmentsKpi', 'AssessmentManagement.AssessmentCase', true],
1934
+ ['AssessmentManagement:Dashboard:PendingAssessmentsKpi', 'AssessmentManagement.AssessmentCase', false],
1935
+ ['AssessmentManagement:Dashboard:MyAssessmentsKpi', 'AssessmentManagement.AssessmentCase', false],
1936
+ ['TaskManagement:Dashboard:OverdueTasksKpi', 'TaskManagement.Task', true],
1937
+ ['TaskManagement:Dashboard:MyOpenTasksKpi', 'TaskManagement.Task', false],
1938
+ ['LearningManagement:Dashboard:TrainingDueKpi', 'LearningManagement.Enrollment', true],
1939
+ ['PlatformManagement:Dashboard:OnlineUsersKpi', 'PlatformManagement.UserPresenceSegment', false],
1940
+ ['PlatformManagement:Dashboard:TodayLoggedInUsersKpi', 'SecurityManagement.DeviceSessions', true],
1941
+ ['WorkflowManagement:Dashboard:RunningInstancesKpi', 'WorkflowManagement.WorkflowInstance', false],
1942
+ ['WorkflowManagement:Dashboard:FaultedInstancesKpi', 'WorkflowManagement.WorkflowInstance', false],
1943
+ ['WorkflowManagement:Dashboard:AwaitingActionInstancesKpi', 'WorkflowManagement.WorkflowInstance', false],
1944
+ ];
1945
+ const KPI_CACHE_FIELDS = [
1946
+ 'title',
1947
+ 'titleBadgeText',
1948
+ 'titleBadgeTone',
1949
+ 'value',
1950
+ 'valuePrefix',
1951
+ 'valueSuffix',
1952
+ 'format',
1953
+ 'icon',
1954
+ 'iconTone',
1955
+ 'trendValue',
1956
+ 'trendLabel',
1957
+ 'trendStatus',
1958
+ 'subtitle',
1959
+ 'segments',
1960
+ 'details',
1961
+ 'targetValue',
1962
+ 'progressValue',
1963
+ 'progressPercent',
1964
+ ];
1965
+ const AXP_DASHBOARD_ADDITIONAL_KPI_TARGETS = [
1966
+ ['TenantManagement:Dashboard:TmApplicationUsersKpi', ['TenantManagement.TenantUserAppAccess']],
1967
+ ['WorkflowManagement:Dashboard:StartedTodayInstancesKpi', ['WorkflowManagement.WorkflowInstance']],
1968
+ ['WorkflowManagement:Dashboard:CompletedTodayInstancesKpi', ['WorkflowManagement.WorkflowInstance']],
1969
+ ['WorkflowManagement:Dashboard:AvgRunningAgeHoursKpi', ['WorkflowManagement.WorkflowInstance']],
1970
+ ];
1971
+ for (const [key, entity] of AXP_REPORT_QUERY_TARGETS)
1972
+ axpRegisterDataExecutionCapabilities({
1973
+ targetKind: 'Query',
1974
+ targetKey: key,
1975
+ revision: 'report-result-contract-v3',
1976
+ operations: ['read'],
1977
+ dataDependencies: key === 'PlatformManagement:Dashboard:OnlineUsersKpi' ? [entity, 'TenantManagement.TenantUser'] : [entity],
1978
+ ...(key.includes(':Dashboard:') ? { clientCache: { storageKinds: ['indexed-db'], allowedFields: KPI_CACHE_FIELDS, maxItems: 10000, maxBytes: 5 * 1024 * 1024, maxAgeMs: 5400000, allowOfflineRead: true } } : {}),
1979
+ serverCache: { supported: true, scope: 'session', maxRowsPerEntry: 10_000, maxEntryBytes: 5 * 1024 * 1024, maxAgeMs: 5_400_000 },
1980
+ });
1981
+ /** Public chart result contracts, including every entity consulted by the handler. */
1982
+ const AXP_DASHBOARD_CHART_TARGETS = [
1983
+ ['AssessmentManagement:Dashboard:AssessmentsWeekLine', ['AssessmentManagement.AssessmentSession'], 'series'],
1984
+ ['BackgroundJobManagement:Dashboard:JobsByStatusBar', ['BackgroundJobManagement.BackgroundJob'], 'items'],
1985
+ ['BackgroundJobManagement:Dashboard:JobSchedulesByStatusBar', ['BackgroundJobManagement.BackgroundJobSchedule'], 'items'],
1986
+ ['CommunicationManagement:Dashboard:DeliveryStatusDonut', ['CommunicationManagement.CommunicationDeliveries'], 'items'],
1987
+ ['HealthCore:Dashboard:HealthEventsTrendLine', ['HealthCore.HealthEvent'], 'series'],
1988
+ ['IntegrationManagement:Dashboard:IntegrationsDonut', ['IntegrationManagement.IntegrationConnection'], 'items'],
1989
+ ['LearningManagement:Dashboard:TrainingComplianceGauge', ['LearningManagement.Enrollment'], 'value'],
1990
+ ['LearningManagement:Dashboard:TrainingStatusDonut', ['LearningManagement.Enrollment'], 'items'],
1991
+ ['OrganizationManagement:Dashboard:TeamsBar', ['OrganizationManagement.Team'], 'items'],
1992
+ ['PlatformManagement:Dashboard:TodayOnlineByHourLine', ['PlatformManagement.UserPresenceSegment'], 'series'],
1993
+ ['ProjectManagement:Dashboard:ProjectsByStatusBar', ['ProjectManagement.Project'], 'items'],
1994
+ ['ProjectManagement:Dashboard:ProjectsTasksCountBar', ['ProjectManagement.Project', 'TaskManagement.Task'], 'items'],
1995
+ ['ProjectManagement:Dashboard:CustomersProjectsCountBar', ['ProjectManagement.Project', 'CustomerManagement.Customer', 'BusinessCore.Party'], 'items'],
1996
+ ['TaskManagement:Dashboard:TaskStatusDonut', ['TaskManagement.Task'], 'items'],
1997
+ ['TenantManagement:Dashboard:UsersByRoleDonut', ['TenantManagement.TenantUser', 'SecurityManagement.Role'], 'items'],
1998
+ ['WorkflowManagement:Dashboard:WorkflowsByStatusBar', ['WorkflowManagement.WorkflowDefinition'], 'items'],
1999
+ ['WorkflowManagement:Dashboard:InstancesBySubStatusDonut', ['WorkflowManagement.WorkflowInstance'], 'items'],
2000
+ ['WorkflowManagement:Dashboard:InstancesByDefinitionBar', ['WorkflowManagement.WorkflowInstance', 'WorkflowManagement.WorkflowDefinition'], 'items'],
2001
+ ['WorkflowManagement:Dashboard:InstancesThroughputLine', ['WorkflowManagement.WorkflowInstance'], 'series'],
2002
+ ['WorkflowManagement:Dashboard:InstancesByCurrentActivityBar', ['WorkflowManagement.WorkflowInstance', 'WorkflowManagement.WorkflowDefinition'], 'items'],
2003
+ ['WorkflowManagement:Dashboard:InstancesFaultHeatmap', ['WorkflowManagement.WorkflowInstance'], 'items'],
2004
+ ['WorkplaceSafetyManagement:Dashboard:HazardsByCategoryDonut', ['WorkplaceSafetyManagement.Hazard'], 'items'],
2005
+ ['WorkplaceSafetyManagement:Dashboard:RisksByRatingBar', ['WorkplaceSafetyManagement.HazardRisk'], 'items'],
2006
+ ['WorkplaceSafetyManagement:Dashboard:PlansByTypeBar', ['WorkplaceSafetyManagement.SafetyPlan'], 'items'],
2007
+ ['WorkplaceSafetyManagement:Dashboard:HazardsByStatusBar', ['WorkplaceSafetyManagement.Hazard'], 'items'],
2008
+ ['WorkplaceSafetyManagement:Dashboard:PpeCoverageDonut', ['WorkplaceSafetyManagement.Hazard', 'WorkplaceSafetyManagement.HazardPpeRule'], 'items'],
2009
+ ];
2010
+ for (const [key, dependencies, field] of AXP_DASHBOARD_CHART_TARGETS) {
2011
+ axpRegisterDataExecutionCapabilities({
2012
+ targetKind: 'Query',
2013
+ targetKey: key,
2014
+ revision: 'dashboard-chart-cache-v2',
2015
+ operations: ['read'],
2016
+ dataDependencies: [...dependencies],
2017
+ clientCache: { storageKinds: ['indexed-db'], allowedFields: [field], maxItems: 10000, maxBytes: 5 * 1024 * 1024, maxAgeMs: 86400000, allowOfflineRead: true },
2018
+ serverCache: { supported: true, scope: 'session', maxRowsPerEntry: 10000, maxEntryBytes: 5 * 1024 * 1024, maxAgeMs: 86400000 },
2019
+ });
2020
+ }
2021
+ for (const [key, dependencies] of AXP_DASHBOARD_ADDITIONAL_KPI_TARGETS) {
2022
+ axpRegisterDataExecutionCapabilities({
2023
+ targetKind: 'Query',
2024
+ targetKey: key,
2025
+ revision: 'dashboard-kpi-cache-v2',
2026
+ operations: ['read'],
2027
+ dataDependencies: [...dependencies],
2028
+ clientCache: { storageKinds: ['indexed-db'], allowedFields: KPI_CACHE_FIELDS, maxItems: 10000, maxBytes: 5 * 1024 * 1024, maxAgeMs: 86400000, allowOfflineRead: true },
2029
+ serverCache: { supported: true, scope: 'session', maxRowsPerEntry: 10000, maxEntryBytes: 5 * 1024 * 1024, maxAgeMs: 86400000 },
2030
+ });
2031
+ }
191
2032
 
192
2033
  //#region ---- Contracts barrel ----
193
2034
 
@@ -195,5 +2036,5 @@ const AXMReportManagementQueryKeys = {
195
2036
  * Generated bundle index. Do not edit.
196
2037
  */
197
2038
 
198
- export { AXMPermissionsKeys, AXMReportManagementCommandKeys, AXMReportManagementQueryKeys, AXM_RECALCULATE_QUERY_SNAPSHOTS_COMMAND_KEY, AXM_REFRESH_QUERY_SNAPSHOTS_COMMAND_KEY, AXPInsightsReportingPermissionKeys, AXPReportManagementFeatureKeys, AXPReportManagementMenuKeys, AXPReportManagementSettings, AXP_REPORT_MANAGEMENT_GENERATION_SETTING_DEFAULTS, REPORT_GENERATION_NOTIFICATION_DEFINITION_KEY, REPORT_GENERATION_OPEN_FROZEN_COMMAND, ReportManagementManifest, RootConfig, buildReportGenerationNotificationCorrelationId };
2039
+ export { AXMPermissionsKeys, AXMReportManagementCommandKeys, AXMReportManagementQueryKeys, AXPInsightsReportingPermissionKeys, AXPReportManagementFeatureKeys, AXPReportManagementMenuKeys, AXPReportManagementSettings, AXP_DASHBOARD_ADDITIONAL_KPI_TARGETS, AXP_DASHBOARD_CHART_TARGETS, AXP_REPORT_LAYOUT_PRESETS, AXP_REPORT_MANAGEMENT_GENERATION_SETTING_DEFAULTS, AXP_REPORT_QUERY_TARGETS, REPORT_GENERATION_NOTIFICATION_DEFINITION_KEY, REPORT_GENERATION_OPEN_FROZEN_COMMAND, REPORT_LAYOUT_FIELD_LABEL_KEYS, ReportManagementManifest, RootConfig, applyReportFilterForm, applyReportLayoutForm, applyReportLayoutSections, applyReportParameterBindings, autoMapReportLayoutInputs, buildReportGenerationNotificationCorrelationId, cleanReportLayoutSections, findDefaultReportTableLayout, inferReportLayoutFields, isReportLayoutColumnKind, layoutMatchesPreset, overlayReportExportTemplates, pickReportFilterForm, pickReportLayoutForm, projectReportDefaultTableExportDefinition, readReportFilterForm, readReportLayoutForm, readReportLayoutSections, reportExportSourceBinding, reportLayoutFieldFallbackLabel, reportLayoutFieldKebabKey, reportLayoutFieldSchema, reportLayoutJsonSections, reportLayoutPresetByKey, reportLayoutQueryName, reportLayoutSectionsChanged, reportLayoutStarterShape, reportLayoutStarterValues, reportLayoutStoredColumns, reportLayoutStoredParameters, reportTableInterchangeExportActions, resolveCurrentReportExportSnapshot, resolveReportExportTableLayout, sameReportFilterForm, sameReportLayoutForm, virtualReportExportKey, visibleDefaultTableColumns };
199
2040
  //# sourceMappingURL=acorex-platform-module-report-management-client-contracts.mjs.map