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 3 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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ const cadenza = window.cadenza.noConflict();

<small>API: [CadenzaClient#show](./classes/CadenzaClient.html#show)</small>

Show an embedding target in an iframe and hide Cadenza's main header and footer as well as the workbook toolbar:
Show an embedding target in an iframe and hide Cadenza's main header and footer as well as the workbook toolbar. Additionally, enable simplified operation mode and disable the designer.

```javascript
cadenzaClient.show('{embeddingTargetId}', {
hideMainHeaderAndFooter: true,
hideWorkbookToolBar: true,
operationMode: 'simplified',
disabledUiFeatures: ['workbook-design']
});
```

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
35 changes: 35 additions & 0 deletions src/cadenza.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ 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 {'normal'|'simplified'} OperationMode - The mode in which a workbook should be operated */
/**
* @typedef {'workbook-design'|'workbook-view-management'} UiFeature - The name of a Cadenza UI feature
*
* _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 +173,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 {OperationMode} [options.operationMode] - The mode in which a workbook should be operated
* @param {UiFeature[]} [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 +186,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 +625,16 @@ function validGeometryType(/** @type string */ value) {
].includes(value);
}

function assertValidUiFeatures(/** @type UiFeature[] */ 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 +668,8 @@ function assertSupportedMediaType(
* @param {string} [params.mediaType]
* @param {number} [params.minScale]
* @param {boolean} [params.useMapSrs]
* @param {OperationMode} [params.operationMode]
* @param {UiFeature[]} [params.disabledUiFeatures]
* @param {ExternalLinkKey} [params.webApplication]
* @return {URLSearchParams}
*/
Expand All @@ -657,6 +686,8 @@ function createParams({
minScale,
useMapSrs,
webApplication,
operationMode,
disabledUiFeatures,
}) {
if (geometryType) {
assertValidGeometryType(geometryType);
Expand All @@ -677,6 +708,10 @@ function createParams({
webApplicationLink: webApplication.externalLinkId,
webApplicationLinkRepository: webApplication.repositoryName,
}),
...(operationMode && { operationMode }),
...(disabledUiFeatures && {
disabledUiFeatures: disabledUiFeatures.join(),
}),
});
}

Expand Down