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

Introduce support for new parameters #9

Merged
merged 5 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ cadenzaClient.show('{embeddingTargetId}', {
});
```

#### Show an Embedding Target in Simplified Operation Mode

Workbook embedding targets can be shown with simplified operation mode enabled by setting the "operationMode" option to "simplified".

```javascript
cadenzaClient.show('{embeddingTargetId}', {
operationMode: 'simplified'
});
```

#### Show an Embedding Target with Disabled Features

Embedding targets can be shown with certain UI features disabled. To disable the designer, add "workbook-design" to the "disabledUiFeatures" option. To disable editing of workbook layout and design, add "workbook-view-management".

```javascript
cadenzaClient.show('{embeddingTargetId}', {
disabledUiFeatures: ['workbook-design', 'workbook-view-management']
});
```

jkissel marked this conversation as resolved.
Show resolved Hide resolved
### Abort (Iframe) Loading

Cadenza JS uses the [AbortController Web API](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) for aborting requests. This is supported by most of the public methods.
Expand Down
14 changes: 13 additions & 1 deletion sandbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@

const cadenzaClient = cadenza(location.origin + '/trunk', { iframe: 'iframe', debug: true });
const actionHandlers = {
show ({ embeddingTargetId, hideMainHeaderAndFooter, hideWorkbookToolBar, jasperReportAsPdf, highlightGlobalId }) {
show ({ embeddingTargetId, hideMainHeaderAndFooter, hideWorkbookToolBar, jasperReportAsPdf, highlightGlobalId, operationMode, disabledUiFeatures }) {
cadenzaClient.show(embeddingTargetId, {
hideMainHeaderAndFooter: (hideMainHeaderAndFooter === 'on'),
hideWorkbookToolBar: (hideWorkbookToolBar === 'on'),
highlightGlobalId,
...(jasperReportAsPdf === 'on' && { mediaType: 'application/pdf' }),
operationMode: operationMode === 'on' ? 'simplified' : 'normal',
disabledUiFeatures: disabledUiFeatures && disabledUiFeatures.split(',')
});
},
showMap ({ embeddingTargetId, useMapSrs, geometry, mapExtent, locationFinder, highlightGlobalId }) {
Expand Down Expand Up @@ -189,10 +191,20 @@
Hide workbook toolbar
</label>
</div>
<div>
<label>
<input type="checkbox" name="operationMode">
Enable simplified operation mode
</label>
</div>
<div>
<label for="highlightGlobalId">Highlighted Global ID</label>
<input name="highlightGlobalId" id="highlightGlobalId">
</div>
<div>
<label for="disabledUiFeatures">Disabled UI features</label>
<input name="disabledUiFeatures" id="disabledUiFeatures" placeholder="feature1,feature2...">
</div>
</template>

<template data-action="showMap">
Expand Down
34 changes: 34 additions & 0 deletions src/cadenza.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ globalThis.cadenza = Object.assign(
* _Note:_ The GeoJSON geometry type "GeometryCollection" is currently not supported.
*/
/** @typedef {[number,number,number,number]} Extent - An array of numbers representing an extent: [minx, miny, maxx, maxy] */
/**
* @typedef {[string]} DisabledUiFeatures - An array of strings representing Cadenza UI features to disable
*
* _Note:_ Supported features are:
* * 'workbook-design' - Disable the designer
* * 'workbook-view-management' - Disable workbook layout/design editing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add the hint from the sprint review? "Is included in 'workbook-design'."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added :)

* */
jkissel marked this conversation as resolved.
Show resolved Hide resolved

/**
* _Notes:_
Expand Down Expand Up @@ -165,6 +172,8 @@ export class CadenzaClient {
* @param {GlobalId} [options.highlightGlobalId] - The ID of an item to highlight / expand in the navigator
* @param {string} [options.mediaType] - Set to 'application/pdf' for views of type "JasperReports report"
* to show the report PDF directly, without any Cadenza headers or footers.
* @param {string} [options.operationMode] - Whether to enable simplified operation mode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proposal: Use a type for the operation mode, too.

/** @typedef {'normal' | 'simplified'} WorkbookOperationMode - The mode in which a workbook should be operated */

Copy link
Contributor Author

@klinakerdisy klinakerdisy Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

* @param {DisabledUiFeatures} [options.disabledUiFeatures] - Cadenza UI features to disable
* @param {AbortSignal} [options.signal] - A signal to abort the iframe loading
* @return {Promise<void>} A Promise for when the iframe is loaded
* @throws For an invalid source
Expand All @@ -176,17 +185,24 @@ export class CadenzaClient {
hideWorkbookToolBar,
highlightGlobalId,
mediaType,
operationMode,
disabledUiFeatures,
signal,
} = {},
) {
this.#log('CadenzaClient#show', source);
if (mediaType) {
assertSupportedMediaType(mediaType, [MediaType.PDF]);
}
if (disabledUiFeatures) {
assertValidUiFeatures(disabledUiFeatures);
}
const params = createParams({
hideMainHeaderAndFooter,
hideWorkbookToolBar,
highlightGlobalId,
operationMode,
disabledUiFeatures,
mediaType,
webApplication: this.#webApplication,
});
Expand Down Expand Up @@ -608,6 +624,16 @@ function validGeometryType(/** @type string */ value) {
].includes(value);
}

function assertValidUiFeatures(/** @type DisabledUiFeatures */ features) {
features.forEach((feature) =>
assert(validUiFeatures(feature), 'Invalid UI feature'),
);
}

function validUiFeatures(/** @type string */ value) {
return ['workbook-design', 'workbook-view-management'].includes(value);
}

/**
* @typedef {string} MediaType - A media type
*
Expand Down Expand Up @@ -641,6 +667,8 @@ function assertSupportedMediaType(
* @param {string} [params.mediaType]
* @param {number} [params.minScale]
* @param {boolean} [params.useMapSrs]
* @param {string} [params.operationMode]
* @param {DisabledUiFeatures} [params.disabledUiFeatures]
* @param {ExternalLinkKey} [params.webApplication]
* @return {URLSearchParams}
*/
Expand All @@ -657,6 +685,8 @@ function createParams({
minScale,
useMapSrs,
webApplication,
operationMode,
disabledUiFeatures,
}) {
if (geometryType) {
assertValidGeometryType(geometryType);
Expand All @@ -677,6 +707,10 @@ function createParams({
webApplicationLink: webApplication.externalLinkId,
webApplicationLinkRepository: webApplication.repositoryName,
}),
...(operationMode && { operationMode }),
...(disabledUiFeatures && {
disabledUiFeatures: disabledUiFeatures.join(),
}),
});
}

Expand Down