Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CADENZA-36890 Add the object info to cadenza.js and sandbox.html #36

Merged
merged 17 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
- `CadenzaClient#fetchObjectInfo`
JensLuebke marked this conversation as resolved.
Show resolved Hide resolved

## 2.11.0 - 2024-07-12
### Added
- Support for `dataType=pdf` in `CadenzaClient#downloadData` and `CadenzaClient#fetchData`
- `CadenzaClient#fetchObjectInfo`
JensLuebke marked this conversation as resolved.
Show resolved Hide resolved

### Fixed
- Make Cadenza return an error instead of showing an error page.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@disy/cadenza.js",
"version": "2.10.0",
"version": "2.11.0",
"license": "Apache-2.0",
"repository": "github:DisyInformationssysteme/cadenza.js",
"type": "module",
Expand Down
60 changes: 44 additions & 16 deletions sandbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,21 @@
},
setFilter: data => cadenzaClient.setFilter(parseFilterVariables(data.filter)),
setLayerVisibility: data => cadenzaClient.setLayerVisibility(JSON.parse(data.layer), data.visibility === 'on'),
setSelection: data => cadenzaClient.setSelection(JSON.parse(data.layer), JSON.parse(data.values)),
addSelection: data => cadenzaClient.addSelection(JSON.parse(data.layer), JSON.parse(data.values)),
removeSelection: data => cadenzaClient.removeSelection(JSON.parse(data.layer), JSON.parse(data.values)),
setSelection: data => cadenzaClient.setSelection(JSON.parse(data.layer), JSON.parse(data.objectIds)),
addSelection: data => cadenzaClient.addSelection(JSON.parse(data.layer), JSON.parse(data.objectIds)),
removeSelection: data => cadenzaClient.removeSelection(JSON.parse(data.layer), JSON.parse(data.objectIds)),
createGeometry: data => cadenzaClient.createGeometry(data.embeddingTargetId, data.geometryType, getOptions(data)),
editGeometry: ({ geometry, ...data }) => cadenzaClient.editGeometry(data.embeddingTargetId, JSON.parse(geometry), getOptions(data)),
selectObjects: data => cadenzaClient.selectObjects(data.embeddingTargetId, getOptions(data)),
fetchData: data => {
console.log('Inspect the fetchData() request in the devtools.');
cadenzaClient.fetchData(data.embeddingTargetId, data.dataType, getOptions(data));
},
fetchObjectInfo: data => {
console.log('Inspect the fetchObjectInfo() request in the devtools.');
cadenzaClient.fetchObjectInfo(data.embeddingTargetId, JSON.parse(data.layer), JSON.parse(data.objectIds), getOptions(data))
.then(oi => console.log(oi));
},
downloadData: data => cadenzaClient.downloadData(data.embeddingTargetId, data.dataType, getOptions(data))
};

Expand Down Expand Up @@ -216,7 +221,8 @@
parts,
layers,
simplifiedOperationMode,
useMapSrs
useMapSrs,
fullGeometries
}) {
return {
disabledUiFeatures: disabledUiFeatures && disabledUiFeatures.split(','),
Expand All @@ -235,7 +241,8 @@
parts: parts && parts.split(','),
...(simplifiedOperationMode === 'on' && { operationMode: 'simplified' }),
layers: layers ? JSON.parse(layers) : undefined,
useMapSrs: useMapSrs === 'on'
useMapSrs: useMapSrs === 'on',
fullGeometries: fullGeometries === 'on'
};
}

Expand Down Expand Up @@ -284,6 +291,7 @@
<optgroup label="Without Iframe">
<option value="downloadData">Download data</option>
<option value="fetchData">Fetch data</option>
<option value="fetchObjectInfo">Fetch Object Info</option>
</optgroup>
</select>
</div>
Expand Down Expand Up @@ -389,6 +397,7 @@
<option>csv</option>
<option>excel</option>
<option>json</option>
<option>pdf</option>
</select>
</div>
<div>
Expand Down Expand Up @@ -501,8 +510,8 @@
<input name="layers" id="layers">
<small>
<p>
A JSON value like <code>["{layerPrintName}",...]</code> or
<code>[["{layerGroupPrintName}","{layerPrintName}"],...]</code>
A JSON value like <code>["&lt;layerPrintName&gt;",...]</code> or
<code>[["&lt;layerGroupPrintName&gt;","&lt;layerPrintName&gt;"],...]</code>
</p>
</small>
</div>
Expand All @@ -517,9 +526,9 @@
</div>
</template>

<template data-action="setSelection" data-common="layer,layer-selection"></template>
<template data-action="addSelection" data-common="layer,layer-selection"></template>
<template data-action="removeSelection" data-common="layer,layer-selection"></template>
<template data-action="setSelection" data-common="layer,object-ids"></template>
<template data-action="addSelection" data-common="layer,object-ids"></template>
<template data-action="removeSelection" data-common="layer,object-ids"></template>

<template data-action="reload">
<div>
Expand All @@ -531,12 +540,12 @@
</template>
<template data-action="closeMe">No Parameters needed.</template>

<template id="common-layer-selection">
<template id="common-object-ids">
<div>
<label for="values">List of Object IDs *</label>
<textarea name="values" id="values" rows="5" required></textarea>
<label for="objectids">List of object ID value lists *</label>
<textarea name="objectIds" id="objectids" rows="5" required></textarea>
<small>
<p>A JSON value like <code>["object1","object2"]</code></p>
<p>A JSON value like <code>[["&lt;object1-id&gt;"],["&lt;object2-id&gt;"]]</code></p>
</small>
</div>
</template>
Expand All @@ -547,8 +556,8 @@
<input name="layer" id="layer" required>
<small>
<p>
A JSON value like <code>"{layerPrintName}"</code> or
<code>["{layerGroupPrintName}","{layerPrintName}"]</code>
A JSON value like <code>"&lt;layerPrintName&gt;"</code> or
<code>["&lt;layerGroupPrintName&gt;","&lt;layerPrintName&gt;"]</code>
</p>
</small>
</div>
Expand All @@ -572,6 +581,25 @@
</div>
</template>

<template data-action="fetchObjectInfo" data-common="layer,object-ids,filter">
<div>
<label for="embeddingTargetId">Embedding target ID *</label>
<input name="embeddingTargetId" id="embeddingTargetId" required>
</div>
<div>
<label>
<input type="checkbox" name="useMapSrs">
Use map SRS
</label>
</div>
<div>
<label>
<input type="checkbox" name="fullGeometries">
Return the non-simplified geometries
</label>
</div>
</template>

<template data-action="getData">
<div>
<label for="dataType">Data type</label>
Expand Down
77 changes: 61 additions & 16 deletions src/cadenza.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ globalThis.cadenza = Object.assign(
* The idea is to have a specific type e.g. for the {@link EmbeddingTargetId} instead of a plain `string`.
* You don't need to _actually_ add that `__type` property. In TS code, just use a
* [type assertion](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions)
* (e.g. `cadenzaClient.show('{embeddingTargetId}' as EmbeddingTargetId)`).
* (e.g. `cadenzaClient.show('<embeddingTargetId>' as EmbeddingTargetId)`).
*/

/**
Expand All @@ -83,7 +83,7 @@ globalThis.cadenza = Object.assign(
*
* You get the `repositoryName` and `externalLinkId` from the URL of the external link's page in the Cadenza management center:
* ```
* {baseUrl}/admin/repositories/{repositoryName}/external-links/{externalLinkId}?...
* <baseUrl>/admin/repositories/<repositoryName>/external-links/<externalLinkId>?...
* ```
*
* @property {string} repositoryName - The name of the link's repository
Expand Down Expand Up @@ -133,6 +133,18 @@ globalThis.cadenza = Object.assign(
* _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)),
* for Long variables, the API is currently limited to the Double value range.
*/
/**
* @typedef Feature - A [GeoJSON](https://geojson.org/) feature object
* @property {any[]} id - The id of the feature
JensLuebke marked this conversation as resolved.
Show resolved Hide resolved
* @property {Geometry} geometry - The geometry
* @property {Record<string, string>} properties - The properties
JensLuebke marked this conversation as resolved.
Show resolved Hide resolved
* @property {Number | undefined} area - The area of the polygon
* @property {Number | undefined} length - The length of the line
JensLuebke marked this conversation as resolved.
Show resolved Hide resolved
*/
/**
* @typedef FeatureCollection - A [GeoJSON](https://geojson.org/) feature collection object
* @property {Feature[]} features - The type of the geometry
JensLuebke marked this conversation as resolved.
Show resolved Hide resolved
*/

let hasCadenzaSession = false;

Expand Down Expand Up @@ -457,7 +469,7 @@ export class CadenzaClient {
*
* @hidden
* @param {WorkbookLayerPath | string} layer - The data view layer to set the selection in
* @param {unknown[]} values - The IDs of the objects to select
* @param {unknown[][]} values - The IDs of the objects to select
* @return {Promise<void>} A `Promise` for when the selection was set.
* @postMessage
*/
Expand All @@ -471,7 +483,7 @@ export class CadenzaClient {
*
* @hidden
* @param {WorkbookLayerPath | string} layer - The data view layer to change the selection in
* @param {unknown[]} values - The IDs of the objects to select
* @param {unknown[][]} values - The IDs of the objects to select
* @return {Promise<void>} A `Promise` for when the selection was changed.
* @postMessage
*/
Expand All @@ -485,7 +497,7 @@ export class CadenzaClient {
*
* @hidden
* @param {WorkbookLayerPath | string} layer - The data view layer to change the selection in
* @param {unknown[]} values - The IDs of the objects to unselect
* @param {unknown[][]} values - The IDs of the objects to unselect
* @return {Promise<void>} A `Promise` for when the selection was changed.
* @postMessage
*/
Expand Down Expand Up @@ -826,9 +838,9 @@ export class CadenzaClient {
* Fetch data from a workbook view.
*
* @param {EmbeddingTargetId} source - The workbook view to fetch data from.
* Currently only table and indicator views are supported.
* @param {DataType} dataType - The data type you want to get back from the server.
* Currently, `"csv"`, `"excel"` and `"json"` are supported.
* Currently, `"csv"`, `"excel"` and `"json"` are supported for table and indicator views
* and `"pdf"` for views of type "JasperReports report".
* @param {object} [options] - Options
* @param {FilterVariables} [options.filter] - Filter variables
* @param {TablePart[]} [options.parts] - Table parts to export; If not specified, all parts are exported.
Expand All @@ -839,24 +851,57 @@ export class CadenzaClient {
*/
fetchData(source, dataType, { filter, parts, signal } = {}) {
this.#log('CadenzaClient#fetchData', ...arguments);
assertSupportedDataType(dataType, ['csv', 'excel', 'json']);
assertSupportedDataType(dataType, ['csv', 'excel', 'json', 'pdf']);
const params = createParams({ dataType, filter, parts });
return this.#fetch(resolvePath(source), params, signal);
}

/**
* Fetch object info from a workbook map view.
*
* @param {EmbeddingTargetId} source - The workbook view to fetch object info from.
* @param {(WorkbookLayerPath | string)[]} [layerPath] - Layer path to identify the layer
* (identified using layer paths or print names)
* @param {unknown[][]} objectIds - The IDs of the objects to select
* @param {object} [options] - Options
* @param {FilterVariables} [options.filter] - Filter variables
* @param {AbortSignal} [options.signal] - A signal to abort the data fetching
* @param {Boolean} [options.useMapSrs] - Use the map SRS instead of WGS84
* @param {Boolean} [options.fullGeometries] - Return non-simplified geometries
* @return {Promise<FeatureCollection>} A `Promise` for the fetch response
* @throws For invalid arguments
*/
fetchObjectInfo(source, layerPath, objectIds, { filter, signal, useMapSrs, fullGeometries } = {}) {
this.#log('CadenzaClient#fetchObjectInfo', ...arguments);
const params = createParams({
filter});
return this.#fetch(
resolvePath(source) + "/objectinfo" ,
JensLuebke marked this conversation as resolved.
Show resolved Hide resolved
params,
signal,
JSON.stringify({ objectIds, layerPath: array(layerPath), useMapSrs, fullGeometries}))
.then(response => response.json());
}

async #fetch(
/** @type string */ path,
/** @type URLSearchParams */ params,
/** @type AbortSignal | undefined */ signal,
/** @type String | undefined If body is set, the fetch will be a post.*/ body,
) {
const url = this.#createUrl(path, params);
this.#log('Fetch', url.toString());
const method = body ? "POST" : undefined;
const headers = new Headers();
headers.set('X-Requested-With', 'XMLHttpRequest');
if (body) {
headers.set('Content-Type', "application/json");
JensLuebke marked this conversation as resolved.
Show resolved Hide resolved
}
const res = await fetch(url, {
signal,
headers: {
// Make Cadenza return an error instead of showing an error page.
'X-Requested-With': 'XMLHttpRequest',
},
method,
headers,
body,
});
if (!res.ok) {
const errorType =
Expand All @@ -875,10 +920,10 @@ export class CadenzaClient {
*
* _Note:_ The file name, if not provided, is generated from the name of the workbook view and the current date.
*
* @param {EmbeddingTargetId} source - The workbook view to download data from.
* Currently only table and indicator views are supported.
* @param {EmbeddingTargetId} source - The workbook view to fetch data from.
* @param {DataType} dataType - The data type you want to get back from the server.
* Currently, `"csv"`, `"excel"` and `"json"` are supported.
* Currently, `"csv"`, `"excel"` and `"json"` are supported for table and indicator views
* and `"pdf"` for views of type "JasperReports report".
* @param {object} [options] - Options
* @param {string} [options.fileName] - The file name to use; The file extension is appended by Cadenza.
* @param {FilterVariables} [options.filter] - Filter variables
Expand All @@ -888,7 +933,7 @@ export class CadenzaClient {
*/
downloadData(source, dataType, { fileName, filter, parts } = {}) {
this.#log('CadenzaClient#downloadData', ...arguments);
assertSupportedDataType(dataType, ['csv', 'excel', 'json']);
assertSupportedDataType(dataType, ['csv', 'excel', 'json', 'pdf']);
const params = createParams({ dataType, fileName, filter, parts });
this.#download(resolvePath(source), params);
}
Expand Down
Loading