@disy/cadenza.js 2.10.0 → 2.12.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 (49) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -0
  3. package/apidoc/assets/highlight.css +14 -0
  4. package/apidoc/assets/navigation.js +1 -1
  5. package/apidoc/assets/search.js +1 -1
  6. package/apidoc/classes/AbortError.html +3 -3
  7. package/apidoc/classes/CadenzaClient.html +52 -29
  8. package/apidoc/classes/CadenzaError.html +5 -5
  9. package/apidoc/functions/cadenza.html +3 -3
  10. package/apidoc/index.html +27 -19
  11. package/apidoc/interfaces/CadenzaClientOptions.html +5 -5
  12. package/apidoc/interfaces/CadenzaEvent.html +4 -4
  13. package/apidoc/interfaces/Distance.html +3 -0
  14. package/apidoc/interfaces/ExternalLinkKey.html +5 -5
  15. package/apidoc/interfaces/Feature.html +12 -0
  16. package/apidoc/interfaces/FeatureCollection.html +4 -0
  17. package/apidoc/interfaces/Geometry.html +3 -3
  18. package/apidoc/interfaces/GeometryZoomTarget.html +4 -0
  19. package/apidoc/interfaces/PageSource.html +3 -3
  20. package/apidoc/modules.html +8 -2
  21. package/apidoc/types/CadenzaChangeSelectionEvent.html +2 -2
  22. package/apidoc/types/CadenzaDrillThroughEvent.html +2 -2
  23. package/apidoc/types/CadenzaEditGeometryCancelEvent.html +2 -2
  24. package/apidoc/types/CadenzaEditGeometryOkEvent.html +2 -2
  25. package/apidoc/types/CadenzaEditGeometryUpdateEvent.html +2 -2
  26. package/apidoc/types/CadenzaErrorEvent.html +2 -2
  27. package/apidoc/types/CadenzaEventByType.html +1 -1
  28. package/apidoc/types/CadenzaEventType.html +2 -2
  29. package/apidoc/types/CadenzaObjectInfoEvent.html +2 -2
  30. package/apidoc/types/CadenzaSelectObjectsCancelEvent.html +2 -2
  31. package/apidoc/types/CadenzaSelectObjectsOkEvent.html +2 -2
  32. package/apidoc/types/DataType.html +2 -2
  33. package/apidoc/types/EmbeddingTargetId.html +2 -2
  34. package/apidoc/types/Extent.html +2 -2
  35. package/apidoc/types/FilterVariables.html +2 -2
  36. package/apidoc/types/GeometryType.html +2 -2
  37. package/apidoc/types/GlobalId.html +2 -2
  38. package/apidoc/types/LengthUnit.html +1 -0
  39. package/apidoc/types/OpaqueString.html +3 -3
  40. package/apidoc/types/OperationMode.html +2 -2
  41. package/apidoc/types/TablePart.html +2 -2
  42. package/apidoc/types/UiFeature.html +2 -2
  43. package/apidoc/types/WorkbookLayerPath.html +2 -2
  44. package/apidoc/types/ZoomTarget.html +2 -0
  45. package/cadenza.d.ts +145 -28
  46. package/cadenza.js +163 -38
  47. package/package.json +1 -1
  48. package/sandbox.cjs +2 -2
  49. package/sandbox.html +102 -18
package/cadenza.js CHANGED
@@ -55,7 +55,7 @@ globalThis.cadenza = Object.assign((/** @type Parameters<cadenza> */ ...args) =>
55
55
  * The idea is to have a specific type e.g. for the {@link EmbeddingTargetId} instead of a plain `string`.
56
56
  * You don't need to _actually_ add that `__type` property. In TS code, just use a
57
57
  * [type assertion](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions)
58
- * (e.g. `cadenzaClient.show('{embeddingTargetId}' as EmbeddingTargetId)`).
58
+ * (e.g. `cadenzaClient.show('<embeddingTargetId>' as EmbeddingTargetId)`).
59
59
  */
60
60
  /**
61
61
  * @typedef {OpaqueString<'EmbeddingTargetId'>} EmbeddingTargetId - The ID of a Cadenza embedding target
@@ -74,7 +74,7 @@ globalThis.cadenza = Object.assign((/** @type Parameters<cadenza> */ ...args) =>
74
74
  *
75
75
  * You get the `repositoryName` and `externalLinkId` from the URL of the external link's page in the Cadenza management center:
76
76
  * ```
77
- * {baseUrl}/admin/repositories/{repositoryName}/external-links/{externalLinkId}?...
77
+ * <baseUrl>/admin/repositories/<repositoryName>/external-links/<externalLinkId>?...
78
78
  * ```
79
79
  *
80
80
  * @property {string} repositoryName - The name of the link's repository
@@ -96,6 +96,14 @@ globalThis.cadenza = Object.assign((/** @type Parameters<cadenza> */ ...args) =>
96
96
  * * `"workbook-design"` - The workbook designer
97
97
  * * `"workbook-view-management"` - Add/Edit/Remove workbook views (Is included in 'workbook-design'.)
98
98
  * */
99
+ /**
100
+ * @typedef Distance
101
+ * @property {number} value
102
+ * @property {LengthUnit} lengthUnit
103
+ */
104
+ /**
105
+ * @typedef {'m'|'km'} LengthUnit
106
+ */
99
107
  /**
100
108
  * @typedef Geometry - A [GeoJSON](https://geojson.org/) geometry object
101
109
  * @property {GeometryType} type - The type of the geometry
@@ -106,6 +114,13 @@ globalThis.cadenza = Object.assign((/** @type Parameters<cadenza> */ ...args) =>
106
114
  * _Note:_ The GeoJSON geometry type "GeometryCollection" is currently not supported.
107
115
  */
108
116
  /** @typedef {[number,number,number,number]} Extent - An array of numbers representing an extent: [minx, miny, maxx, maxy] */
117
+ /**
118
+ * @typedef {GeometryZoomTarget} ZoomTarget - An object describing a target to zoom to
119
+ */
120
+ /**
121
+ * @typedef GeometryZoomTarget - Instructs Cadenza to zoom to a provided {@Link Geometry}
122
+ * @property {'geometry'} type The type of the zoom target
123
+ */
109
124
  /**
110
125
  * @typedef {'csv' | 'excel' | 'json' | 'pdf' | 'png'} DataType - A data type
111
126
  *
@@ -120,11 +135,28 @@ globalThis.cadenza = Object.assign((/** @type Parameters<cadenza> */ ...args) =>
120
135
  * _Note:_ Since numbers in JavaScript are Double values ([more info on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number#number_encoding)),
121
136
  * for Long variables, the API is currently limited to the Double value range.
122
137
  */
138
+ /**
139
+ * @typedef Feature - A adapted [GeoJSON](https://geojson.org/) feature object.
140
+ * @property {any[]} objectId - The id of the feature
141
+ * @property {Geometry} geometry - The geometry
142
+ * @property {Record<string, string>} properties - The formated properties
143
+ * @property {number} [area] - The area of a `Polygon` feature
144
+ * @property {number} [length] - The area of a `LineString` feature
145
+ */
146
+ /**
147
+ * @typedef FeatureCollection - A adapted [GeoJSON](https://geojson.org/) feature collection object
148
+ * @property {Feature[]} features - The features within this collection
149
+ */
123
150
  let hasCadenzaSession = false;
124
151
  /** @type {Promise<void> | undefined} */
125
152
  let firstEmbeddingTargetShown;
126
153
  /**
127
154
  * _Notes:_
155
+ * * Most public methods are tagged with one of these modifiers:
156
+ * * `Embed`: The method embeds Cadenza in the given iframe.
157
+ * * `Post Message`: The method communicates with an embedded or parent/opener Cadenza via postMessage.
158
+ * * `Post Message Parent`: The method communicates with a parent/opener Cadenza via postMessage.
159
+ * * `Server`: The method communicates with the Cadenza server via HTTP.
128
160
  * * Most public methods can be aborted using an [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal).
129
161
  * When aborted, the result Promise is rejected with an {@link AbortError}.
130
162
  * * If there's another error, the result Promise is rejected with a {@link CadenzaError}.
@@ -222,6 +254,7 @@ export class CadenzaClient {
222
254
  * @return {Promise<void>} A `Promise` for when the iframe is loaded
223
255
  * @throws For invalid arguments
224
256
  * @fires {@link CadenzaDrillThroughEvent}
257
+ * @embed
225
258
  */
226
259
  show(source, { dataType, disabledUiFeatures, expandNavigator, filter, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, labelSet, operationMode, signal, } = {}) {
227
260
  this.#log('CadenzaClient#show', ...arguments);
@@ -246,6 +279,26 @@ export class CadenzaClient {
246
279
  });
247
280
  return this.#show(resolvePath(source), params, signal);
248
281
  }
282
+ /**
283
+ * Reload the views of a worksheet.
284
+ * @param {object} [options] - Options
285
+ * @param {boolean} [options.invalidateCaches] - When true, caches will be invalidated for objecttypes used
286
+ * in the worksheet
287
+ * @postMessage
288
+ */
289
+ reload({ invalidateCaches = false } = {}) {
290
+ this.#log('CadenzaClient#reload', ...arguments);
291
+ this.#postEvent('reload', { invalidateCaches });
292
+ }
293
+ /**
294
+ * Sends a message to parent Cadenza window to close the window containing this application
295
+ * @postMessageParent
296
+ */
297
+ closeMe() {
298
+ this.#log('CadenzaClient#closeMe');
299
+ assert(this.#iframe == null, 'Cannot send closeMe to iframe');
300
+ this.#postEvent('closeMe');
301
+ }
249
302
  /**
250
303
  * Show a workbook map view in an iframe.
251
304
  *
@@ -262,16 +315,19 @@ export class CadenzaClient {
262
315
  * @param {Extent} [options.mapExtent] - A map extent to set
263
316
  * @param {OperationMode} [options.operationMode] - The mode in which a workbook should be operated
264
317
  * @param {boolean} [options.useMapSrs] - Whether the geometry and the extent are in the map's SRS (otherwise EPSG:4326 is assumed)
318
+ * @param {ZoomTarget} [options.zoomTarget] - A target Cadenza should zoom to
265
319
  * @param {AbortSignal} [options.signal] - A signal to abort the iframe loading
266
320
  * @return {Promise<void>} A `Promise` for when the iframe is loaded
267
321
  * @throws For invalid arguments
268
322
  * @fires {@link CadenzaDrillThroughEvent}
323
+ * @embed
269
324
  */
270
- async showMap(mapView, { disabledUiFeatures, expandNavigator, filter, geometry, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, locationFinder, mapExtent, operationMode, useMapSrs, signal, } = {}) {
325
+ async showMap(mapView, { disabledUiFeatures, expandNavigator, filter, geometry, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, locationFinder, mapExtent, operationMode, useMapSrs, zoomTarget, signal, } = {}) {
271
326
  this.#log('CadenzaClient#showMap', ...arguments);
272
327
  if (geometry) {
273
328
  assertValidGeometryType(geometry.type);
274
329
  }
330
+ const zoomToGeometry = geometry && zoomTarget?.type === 'geometry';
275
331
  const params = createParams({
276
332
  disabledUiFeatures,
277
333
  expandNavigator,
@@ -279,7 +335,9 @@ export class CadenzaClient {
279
335
  hideMainHeaderAndFooter,
280
336
  hideWorkbookToolBar,
281
337
  highlightGlobalId,
282
- locationFinder,
338
+ // only use locationFinder if zoom to geometry is not set, to avoid
339
+ // zooming race condition for Cadenza versions below 10.1
340
+ locationFinder: zoomToGeometry ? undefined : locationFinder,
283
341
  mapExtent,
284
342
  operationMode,
285
343
  targetType: 'MAP',
@@ -287,13 +345,17 @@ export class CadenzaClient {
287
345
  });
288
346
  await this.#show(resolvePath(mapView), params, signal);
289
347
  if (geometry) {
290
- this.#postEvent('setGeometry', { geometry });
348
+ this.#postEvent('setGeometry', {
349
+ geometry,
350
+ zoomToGeometry,
351
+ });
291
352
  }
292
353
  }
293
354
  /**
294
355
  * Expand/collapse the navigator.
295
356
  *
296
357
  * @param {boolean} expanded - The expansion state of the navigator
358
+ * @postMessage
297
359
  */
298
360
  expandNavigator(expanded = true) {
299
361
  this.#log('CadenzaClient#expandNavigator', ...arguments);
@@ -308,6 +370,7 @@ export class CadenzaClient {
308
370
  * @template {DataType} T
309
371
  * @param {T} dataType - The requested data type. Currently, only `"png"` is supported.
310
372
  * @return {Promise<T extends 'png' ? Blob : never>}
373
+ * @postMessage
311
374
  */
312
375
  async getData(dataType) {
313
376
  this.#log('CadenzaClient#getData', ...arguments);
@@ -320,6 +383,7 @@ export class CadenzaClient {
320
383
  * @hidden
321
384
  * @param {FilterVariables} filter - The variable values
322
385
  * @return {Promise<void>} A `Promise` for when the filter variables were set.
386
+ * @postMessage
323
387
  */
324
388
  setFilter(filter) {
325
389
  this.#log('CadenzaClient#setFilter', ...arguments);
@@ -336,6 +400,7 @@ export class CadenzaClient {
336
400
  * (identified using a layer path or a print name)
337
401
  * @param {boolean} visible - The visibility state of the layer
338
402
  * @return {Promise<void>} A `Promise` for when the layer visibility was set.
403
+ * @postMessage
339
404
  */
340
405
  setLayerVisibility(layer, visible) {
341
406
  this.#log('CadenzaClient#setLayerVisibility', ...arguments);
@@ -349,8 +414,9 @@ export class CadenzaClient {
349
414
  *
350
415
  * @hidden
351
416
  * @param {WorkbookLayerPath | string} layer - The data view layer to set the selection in
352
- * @param {unknown[]} values - The IDs of the objects to select
417
+ * @param {unknown[][]} values - The IDs of the objects to select
353
418
  * @return {Promise<void>} A `Promise` for when the selection was set.
419
+ * @postMessage
354
420
  */
355
421
  setSelection(layer, values) {
356
422
  this.#log('CadenzaClient#setSelection', ...arguments);
@@ -361,8 +427,9 @@ export class CadenzaClient {
361
427
  *
362
428
  * @hidden
363
429
  * @param {WorkbookLayerPath | string} layer - The data view layer to change the selection in
364
- * @param {unknown[]} values - The IDs of the objects to select
430
+ * @param {unknown[][]} values - The IDs of the objects to select
365
431
  * @return {Promise<void>} A `Promise` for when the selection was changed.
432
+ * @postMessage
366
433
  */
367
434
  addSelection(layer, values) {
368
435
  this.#log('CadenzaClient#addSelection', ...arguments);
@@ -373,8 +440,9 @@ export class CadenzaClient {
373
440
  *
374
441
  * @hidden
375
442
  * @param {WorkbookLayerPath | string} layer - The data view layer to change the selection in
376
- * @param {unknown[]} values - The IDs of the objects to unselect
443
+ * @param {unknown[][]} values - The IDs of the objects to unselect
377
444
  * @return {Promise<void>} A `Promise` for when the selection was changed.
445
+ * @postMessage
378
446
  */
379
447
  removeSelection(layer, values) {
380
448
  this.#log('CadenzaClient#removeSelection', ...arguments);
@@ -404,6 +472,7 @@ export class CadenzaClient {
404
472
  * - {@link CadenzaEditGeometryUpdateEvent}
405
473
  * - {@link CadenzaEditGeometryOkEvent}
406
474
  * - {@link CadenzaEditGeometryCancelEvent}
475
+ * @embed
407
476
  */
408
477
  createGeometry(backgroundMapView, geometryType, { filter, locationFinder, mapExtent, minScale, useMapSrs, signal } = {}) {
409
478
  this.#log('CadenzaClient#createGeometry', ...arguments);
@@ -429,6 +498,7 @@ export class CadenzaClient {
429
498
  * @param {Extent} [options.mapExtent] - A map extent to set
430
499
  * @param {number} [options.minScale] - The minimum scale where the user should work on. A warning is shown when the map is zoomed out above the threshold.
431
500
  * @param {boolean} [options.useMapSrs] - Whether the geometry is in the map's SRS (otherwise EPSG:4326 is assumed)
501
+ * @param {ZoomTarget} [options.zoomTarget] - A target Cadenza should zoom to
432
502
  * @param {AbortSignal} [options.signal] - A signal to abort the iframe loading
433
503
  * @return {Promise<void>} A `Promise` for when the iframe is loaded
434
504
  * @throws For invalid arguments
@@ -436,21 +506,28 @@ export class CadenzaClient {
436
506
  * - {@link CadenzaEditGeometryUpdateEvent}
437
507
  * - {@link CadenzaEditGeometryOkEvent}
438
508
  * - {@link CadenzaEditGeometryCancelEvent}
509
+ * @embed
439
510
  */
440
- async editGeometry(backgroundMapView, geometry, { filter, locationFinder, mapExtent, minScale, useMapSrs, signal } = {}) {
511
+ async editGeometry(backgroundMapView, geometry, { filter, locationFinder, mapExtent, minScale, useMapSrs, zoomTarget, signal, } = {}) {
441
512
  this.#log('CadenzaClient#editGeometry', ...arguments);
442
513
  assertValidGeometryType(geometry.type);
514
+ const zoomToGeometry = geometry && zoomTarget?.type === 'geometry';
443
515
  const params = createParams({
444
516
  action: 'editGeometry',
445
517
  filter,
446
- locationFinder,
518
+ // only use locationFinder if zoom to geometry is not set, to avoid
519
+ // zooming race condition for Cadenza versions below 10.1
520
+ locationFinder: zoomToGeometry ? undefined : locationFinder,
447
521
  mapExtent,
448
522
  minScale,
449
523
  useMapSrs,
450
524
  });
451
525
  await this.#show(resolvePath(backgroundMapView), params, signal);
452
526
  if (geometry) {
453
- this.#postEvent('setGeometry', { geometry });
527
+ this.#postEvent('setGeometry', {
528
+ geometry,
529
+ zoomToGeometry,
530
+ });
454
531
  }
455
532
  }
456
533
  /**
@@ -472,6 +549,7 @@ export class CadenzaClient {
472
549
  * - {@link CadenzaObjectInfoEvent}
473
550
  * - {@link CadenzaSelectObjectsOkEvent}
474
551
  * - {@link CadenzaSelectObjectsCancelEvent}
552
+ * @embed
475
553
  */
476
554
  selectObjects(backgroundMapView, { filter, layers, locationFinder, mapExtent, useMapSrs, signal } = {}) {
477
555
  this.#log('CadenzaClient#selectObjects', ...arguments);
@@ -665,29 +743,93 @@ export class CadenzaClient {
665
743
  * Fetch data from a workbook view.
666
744
  *
667
745
  * @param {EmbeddingTargetId} source - The workbook view to fetch data from.
668
- * Currently only table and indicator views are supported.
669
746
  * @param {DataType} dataType - The data type you want to get back from the server.
670
- * Currently, `"csv"`, `"excel"` and `"json"` are supported.
747
+ * Currently, `"csv"`, `"excel"` and `"json"` are supported for table and indicator views
748
+ * and `"pdf"` for views of type "JasperReports report".
671
749
  * @param {object} [options] - Options
672
750
  * @param {FilterVariables} [options.filter] - Filter variables
673
751
  * @param {TablePart[]} [options.parts] - Table parts to export; If not specified, all parts are exported.
674
752
  * @param {AbortSignal} [options.signal] - A signal to abort the data fetching
675
753
  * @return {Promise<Response>} A `Promise` for the fetch response
676
754
  * @throws For invalid arguments
755
+ * @server
677
756
  */
678
757
  fetchData(source, dataType, { filter, parts, signal } = {}) {
679
758
  this.#log('CadenzaClient#fetchData', ...arguments);
680
- assertSupportedDataType(dataType, ['csv', 'excel', 'json']);
759
+ assertSupportedDataType(dataType, ['csv', 'excel', 'json', 'pdf']);
681
760
  const params = createParams({ dataType, filter, parts });
682
761
  return this.#fetch(resolvePath(source), params, signal);
683
762
  }
763
+ /**
764
+ * Fetch object info from a workbook map view.
765
+ *
766
+ * @param {EmbeddingTargetId} source - The workbook view to fetch object info from.
767
+ * @param {(WorkbookLayerPath | string)[]} layerPath - Layer path to identify the layer
768
+ * (identified using layer paths or print names)
769
+ * @param {unknown[][]} objectIds - The IDs of the objects to select
770
+ * @param {object} [options] - Options
771
+ * @param {FilterVariables} [options.filter] - Filter variables
772
+ * @param {AbortSignal} [options.signal] - A signal to abort the data fetching
773
+ * @param {Boolean} [options.useMapSrs] - Use the map SRS instead of WGS84
774
+ * @param {Boolean} [options.fullGeometries] - Return non-simplified geometries
775
+ * @return {Promise<FeatureCollection>} A `Promise` for the fetch response
776
+ * @throws For invalid arguments
777
+ */
778
+ fetchObjectInfo(source, layerPath, objectIds, { filter, signal, useMapSrs, fullGeometries } = {}) {
779
+ this.#log('CadenzaClient#fetchObjectInfo', ...arguments);
780
+ const params = createParams({
781
+ filter,
782
+ });
783
+ return this.#fetch(resolvePath(source) + '/objectinfo', params, signal, JSON.stringify({
784
+ objectIds,
785
+ layerPath: array(layerPath),
786
+ useMapSrs,
787
+ fullGeometries,
788
+ })).then((response) => response.json());
789
+ }
790
+ /**
791
+ * Fetch the intersection areas from a workbook map view layer in JSON format for a given area.
792
+ *
793
+ * @param {EmbeddingTargetId} source - The workbook view to fetch object info from.
794
+ * @param {(WorkbookLayerPath | string)[]} layerPath - Layer path to identify the layer
795
+ * (identified using layer paths or print names)
796
+ * @param {Geometry} geometry - The intersection geometry
797
+ * @param {object} [options] - Options
798
+ * @param {boolean} [options.useMapSrs] - The intersection geometry and the result geometries are in the map's SRS (otherwise EPSG:4326 is assumed)
799
+ * @param {Distance} [options.buffer] - Buffer size for geometry of the transition
800
+ * @param {AbortSignal} [options.signal] - A signal to abort the data fetching
801
+ * @return {Promise<FeatureCollection>} A `Promise` for the fetch response
802
+ * @server
803
+ */
804
+ fetchAreaIntersections(source, layerPath, geometry, { useMapSrs, buffer, signal } = {}) {
805
+ this.#log('CadenzaClient#areaIntersections', ...arguments);
806
+ const params = createParams({});
807
+ return this.#fetch(resolvePath(source) + '/area-intersections', params, signal, JSON.stringify({
808
+ layerPath: array(layerPath),
809
+ geometry: geometry,
810
+ useMapSrs: useMapSrs,
811
+ buffer: buffer,
812
+ })).then((response) => response.json());
813
+ }
684
814
  async #fetch(
685
815
  /** @type string */ path,
686
816
  /** @type URLSearchParams */ params,
687
- /** @type AbortSignal | undefined */ signal) {
817
+ /** @type AbortSignal | undefined */ signal,
818
+ /** @type String | undefined If body is set, the fetch will be a post.*/ body) {
688
819
  const url = this.#createUrl(path, params);
689
820
  this.#log('Fetch', url.toString());
690
- const res = await fetch(url, { signal });
821
+ const method = body ? 'POST' : undefined;
822
+ const headers = new Headers();
823
+ headers.set('X-Requested-With', 'XMLHttpRequest');
824
+ if (body) {
825
+ headers.set('Content-Type', 'application/json');
826
+ }
827
+ const res = await fetch(url, {
828
+ signal,
829
+ method,
830
+ headers,
831
+ body,
832
+ });
691
833
  if (!res.ok) {
692
834
  const errorType = {
693
835
  400: 'bad-request',
@@ -703,40 +845,23 @@ export class CadenzaClient {
703
845
  *
704
846
  * _Note:_ The file name, if not provided, is generated from the name of the workbook view and the current date.
705
847
  *
706
- * @param {EmbeddingTargetId} source - The workbook view to download data from.
707
- * Currently only table and indicator views are supported.
848
+ * @param {EmbeddingTargetId} source - The workbook view to fetch data from.
708
849
  * @param {DataType} dataType - The data type you want to get back from the server.
709
- * Currently, `"csv"`, `"excel"` and `"json"` are supported.
850
+ * Currently, `"csv"`, `"excel"` and `"json"` are supported for table and indicator views
851
+ * and `"pdf"` for views of type "JasperReports report".
710
852
  * @param {object} [options] - Options
711
853
  * @param {string} [options.fileName] - The file name to use; The file extension is appended by Cadenza.
712
854
  * @param {FilterVariables} [options.filter] - Filter variables
713
855
  * @param {TablePart[]} [options.parts] - Table parts to export; If not specified, all parts are exported.
714
856
  * @throws For invalid arguments
857
+ * @server
715
858
  */
716
859
  downloadData(source, dataType, { fileName, filter, parts } = {}) {
717
860
  this.#log('CadenzaClient#downloadData', ...arguments);
718
- assertSupportedDataType(dataType, ['csv', 'excel', 'json']);
861
+ assertSupportedDataType(dataType, ['csv', 'excel', 'json', 'pdf']);
719
862
  const params = createParams({ dataType, fileName, filter, parts });
720
863
  this.#download(resolvePath(source), params);
721
864
  }
722
- /**
723
- * Reload the views of a worksheet.
724
- * @param {object} [options] - Options
725
- * @param {boolean} [options.invalidateCaches] - When true, caches will be invalidated for objecttypes used
726
- * in the worksheet
727
- */
728
- reload({ invalidateCaches = false } = {}) {
729
- this.#log('CadenzaClient#reload', ...arguments);
730
- this.#postEvent('reload', { invalidateCaches });
731
- }
732
- /**
733
- * Sends a message to parent Cadenza window to close the window containing this application
734
- */
735
- closeMe() {
736
- this.#log('CadenzaClient#closeMe');
737
- assert(this.#iframe == null, 'Cannot send closeMe to iframe');
738
- this.#postEvent('closeMe');
739
- }
740
865
  #download(/** @type string */ path, /** @type URLSearchParams */ params) {
741
866
  const url = this.#createUrl(path, params);
742
867
  const a = document.createElement('a');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@disy/cadenza.js",
3
- "version": "2.10.0",
3
+ "version": "2.12.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": "github:DisyInformationssysteme/cadenza.js",
6
6
  "type": "module",
package/sandbox.cjs CHANGED
@@ -6,8 +6,8 @@ const DEFAULT_CADENZA_URL = 'http://localhost:8080/cadenza';
6
6
 
7
7
  const index = process.argv.indexOf(CADENZA_URL_PARAM);
8
8
  const cadenzaUrlFromArgs = index !== -1
9
- ? process.argv[index + 1]
10
- : process.argv.find(arg => arg.startsWith(CADENZA_URL_PARAM + '='))?.slice(CADENZA_URL_PARAM.length + 1);
9
+ ? process.argv[index + 1]
10
+ : process.argv.find(arg => arg.startsWith(CADENZA_URL_PARAM + '='))?.slice(CADENZA_URL_PARAM.length + 1);
11
11
  const cadenzaUrl = new URL(cadenzaUrlFromArgs || process.env.CADENZA_URL || DEFAULT_CADENZA_URL);
12
12
 
13
13
  execSync(`npx --yes http-server -a localhost -c-1 -d false --proxy ${cadenzaUrl.origin} --proxy-options.headers.Origin ${cadenzaUrl.origin} -o /sandbox.html${cadenzaUrl.pathname !== '/' ? `?contextPath=${cadenzaUrl.pathname}` : ''}`, { stdio: 'inherit' });
package/sandbox.html CHANGED
@@ -161,9 +161,9 @@
161
161
  },
162
162
  setFilter: data => cadenzaClient.setFilter(parseFilterVariables(data.filter)),
163
163
  setLayerVisibility: data => cadenzaClient.setLayerVisibility(JSON.parse(data.layer), data.visibility === 'on'),
164
- setSelection: data => cadenzaClient.setSelection(JSON.parse(data.layer), JSON.parse(data.values)),
165
- addSelection: data => cadenzaClient.addSelection(JSON.parse(data.layer), JSON.parse(data.values)),
166
- removeSelection: data => cadenzaClient.removeSelection(JSON.parse(data.layer), JSON.parse(data.values)),
164
+ setSelection: data => cadenzaClient.setSelection(JSON.parse(data.layer), JSON.parse(data.objectIds)),
165
+ addSelection: data => cadenzaClient.addSelection(JSON.parse(data.layer), JSON.parse(data.objectIds)),
166
+ removeSelection: data => cadenzaClient.removeSelection(JSON.parse(data.layer), JSON.parse(data.objectIds)),
167
167
  createGeometry: data => cadenzaClient.createGeometry(data.embeddingTargetId, data.geometryType, getOptions(data)),
168
168
  editGeometry: ({ geometry, ...data }) => cadenzaClient.editGeometry(data.embeddingTargetId, JSON.parse(geometry), getOptions(data)),
169
169
  selectObjects: data => cadenzaClient.selectObjects(data.embeddingTargetId, getOptions(data)),
@@ -171,6 +171,16 @@
171
171
  console.log('Inspect the fetchData() request in the devtools.');
172
172
  cadenzaClient.fetchData(data.embeddingTargetId, data.dataType, getOptions(data));
173
173
  },
174
+ fetchObjectInfo: data => {
175
+ console.log('Inspect the fetchObjectInfo() request in the devtools.');
176
+ cadenzaClient.fetchObjectInfo(data.embeddingTargetId, JSON.parse(data.layer), JSON.parse(data.objectIds), getOptions(data))
177
+ .then(console.log);
178
+ },
179
+ fetchAreaIntersections: data => {
180
+ console.log('Inspect the fetchAreaIntersections() request in the devtools.');
181
+ cadenzaClient.fetchAreaIntersections(data.embeddingTargetId, JSON.parse(data.layer), JSON.parse(data.geometry), getOptions(data))
182
+ .then(console.log);
183
+ },
174
184
  downloadData: data => cadenzaClient.downloadData(data.embeddingTargetId, data.dataType, getOptions(data))
175
185
  };
176
186
 
@@ -216,7 +226,11 @@
216
226
  parts,
217
227
  layers,
218
228
  simplifiedOperationMode,
219
- useMapSrs
229
+ useMapSrs,
230
+ fullGeometries,
231
+ zoomToGeometry,
232
+ distance,
233
+ lengthUnit
220
234
  }) {
221
235
  return {
222
236
  disabledUiFeatures: disabledUiFeatures && disabledUiFeatures.split(','),
@@ -235,7 +249,10 @@
235
249
  parts: parts && parts.split(','),
236
250
  ...(simplifiedOperationMode === 'on' && { operationMode: 'simplified' }),
237
251
  layers: layers ? JSON.parse(layers) : undefined,
238
- useMapSrs: useMapSrs === 'on'
252
+ useMapSrs: useMapSrs === 'on',
253
+ fullGeometries: fullGeometries === 'on',
254
+ zoomTarget: zoomToGeometry === 'on' ? { type: 'geometry' } : undefined,
255
+ buffer: distance ? { value: Number(distance), lengthUnit: lengthUnit ? lengthUnit : 'm' } : undefined
239
256
  };
240
257
  }
241
258
 
@@ -284,6 +301,8 @@
284
301
  <optgroup label="Without Iframe">
285
302
  <option value="downloadData">Download data</option>
286
303
  <option value="fetchData">Fetch data</option>
304
+ <option value="fetchObjectInfo">Fetch Object Info</option>
305
+ <option value="fetchAreaIntersections">Fetch Area Intersections</option>
287
306
  </optgroup>
288
307
  </select>
289
308
  </div>
@@ -389,6 +408,7 @@
389
408
  <option>csv</option>
390
409
  <option>excel</option>
391
410
  <option>json</option>
411
+ <option>pdf</option>
392
412
  </select>
393
413
  </div>
394
414
  <div>
@@ -441,7 +461,7 @@
441
461
  </div>
442
462
  </template>
443
463
 
444
- <template data-action="showMap" data-common="map,showWorkbook,filter,show">
464
+ <template data-action="showMap" data-common="zoomTo,map,showWorkbook,filter,show">
445
465
  <div>
446
466
  <label for="embeddingTargetId">Embedding target ID of the map view *</label>
447
467
  <input name="embeddingTargetId" id="embeddingTargetId" required>
@@ -476,7 +496,7 @@
476
496
  </div>
477
497
  </template>
478
498
 
479
- <template data-action="editGeometry" data-common="map,filter">
499
+ <template data-action="editGeometry" data-common="zoomTo,map,filter">
480
500
  <div>
481
501
  <label for="embeddingTargetId">Embedding target ID of the map view *</label>
482
502
  <input name="embeddingTargetId" id="embeddingTargetId" required>
@@ -501,8 +521,8 @@
501
521
  <input name="layers" id="layers">
502
522
  <small>
503
523
  <p>
504
- A JSON value like <code>["{layerPrintName}",...]</code> or
505
- <code>[["{layerGroupPrintName}","{layerPrintName}"],...]</code>
524
+ A JSON value like <code>["&lt;layerPrintName&gt;",...]</code> or
525
+ <code>[["&lt;layerGroupPrintName&gt;","&lt;layerPrintName&gt;"],...]</code>
506
526
  </p>
507
527
  </small>
508
528
  </div>
@@ -517,9 +537,9 @@
517
537
  </div>
518
538
  </template>
519
539
 
520
- <template data-action="setSelection" data-common="layer,layer-selection"></template>
521
- <template data-action="addSelection" data-common="layer,layer-selection"></template>
522
- <template data-action="removeSelection" data-common="layer,layer-selection"></template>
540
+ <template data-action="setSelection" data-common="layer,object-ids"></template>
541
+ <template data-action="addSelection" data-common="layer,object-ids"></template>
542
+ <template data-action="removeSelection" data-common="layer,object-ids"></template>
523
543
 
524
544
  <template data-action="reload">
525
545
  <div>
@@ -531,12 +551,12 @@
531
551
  </template>
532
552
  <template data-action="closeMe">No Parameters needed.</template>
533
553
 
534
- <template id="common-layer-selection">
554
+ <template id="common-object-ids">
535
555
  <div>
536
- <label for="values">List of Object IDs *</label>
537
- <textarea name="values" id="values" rows="5" required></textarea>
556
+ <label for="objectids">List of object ID value lists *</label>
557
+ <textarea name="objectIds" id="objectids" rows="5" required></textarea>
538
558
  <small>
539
- <p>A JSON value like <code>["object1","object2"]</code></p>
559
+ <p>A JSON value like <code>[["&lt;object1-id&gt;"],["&lt;object2-id&gt;"]]</code></p>
540
560
  </small>
541
561
  </div>
542
562
  </template>
@@ -547,13 +567,22 @@
547
567
  <input name="layer" id="layer" required>
548
568
  <small>
549
569
  <p>
550
- A JSON value like <code>"{layerPrintName}"</code> or
551
- <code>["{layerGroupPrintName}","{layerPrintName}"]</code>
570
+ A JSON value like <code>"&lt;layerPrintName&gt;"</code> or
571
+ <code>["&lt;layerGroupPrintName&gt;","&lt;layerPrintName&gt;"]</code>
552
572
  </p>
553
573
  </small>
554
574
  </div>
555
575
  </template>
556
576
 
577
+ <template id="common-zoomTo">
578
+ <div>
579
+ <label>
580
+ <input type="checkbox" name="zoomToGeometry">
581
+ Zoom to geometry
582
+ </label>
583
+ </div>
584
+ </template>
585
+
557
586
  <template data-action="downloadData" data-common="data,filter">
558
587
  <div>
559
588
  <label for="embeddingTargetId">Embedding target ID *</label>
@@ -572,6 +601,61 @@
572
601
  </div>
573
602
  </template>
574
603
 
604
+ <template data-action="fetchObjectInfo" data-common="layer,object-ids,filter">
605
+ <div>
606
+ <label for="embeddingTargetId">Embedding target ID *</label>
607
+ <input name="embeddingTargetId" id="embeddingTargetId" required>
608
+ </div>
609
+ <div>
610
+ <label>
611
+ <input type="checkbox" name="useMapSrs">
612
+ Use map SRS
613
+ </label>
614
+ </div>
615
+ <div>
616
+ <label>
617
+ <input type="checkbox" name="fullGeometries">
618
+ Return the non-simplified geometries
619
+ </label>
620
+ </div>
621
+ </template>
622
+
623
+ <template data-action="fetchAreaIntersections" data-common="layer">
624
+ <div>
625
+ <label for="embeddingTargetId">Embedding target ID *</label>
626
+ <input name="embeddingTargetId" id="embeddingTargetId" required>
627
+ </div>
628
+ <div>
629
+ <label for="geometry">Intersection Geometry (GeoJSON) *</label>
630
+ <textarea name="geometry" id="geometry" rows="5" required></textarea>
631
+ <small>
632
+ <p>
633
+ The geometry must result in an area in combination with the buffer specification.
634
+ </p>
635
+ </small>
636
+ </div>
637
+ <div>
638
+ <label>
639
+ <input type="checkbox" name="useMapSrs">
640
+ Use map SRS
641
+ </label>
642
+ </div>
643
+ <div>
644
+ <label for="distance">Buffer size</label>
645
+ <input name="distance" id="distance" type="number" min="0">
646
+ <label for="lengthUnit">Length unit</label>
647
+ <select name="lengthUnit" id="lengthUnit">
648
+ <option>m</option>
649
+ <option>km</option>
650
+ </select>
651
+ <small>
652
+ <p>
653
+ A positive buffer size is needed for point or line intersection geometries.
654
+ </p>
655
+ </small>
656
+ </div>
657
+ </template>
658
+
575
659
  <template data-action="getData">
576
660
  <div>
577
661
  <label for="dataType">Data type</label>