Skip to content

Commit

Permalink
CADENZA-33335 [Workbook Embedding] Extend folder in navigator
Browse files Browse the repository at this point in the history
* add highlightGlobalId to CadenzaClient#show and #showMap methods
  • Loading branch information
adrian.nistor committed Oct 3, 2023
1 parent ab35f5a commit 7fe3a33
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `CadenzaClient#fetchData`
- `CadenzaClient#downloadData`
- optional `highlightGlobalId` parameter to `options` parameter of `CadenzaClient#show` and `CadenzaClient#showMap`

## 1.0.0 - 2023-09-07

Expand Down
18 changes: 14 additions & 4 deletions sandbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,21 @@

const cadenzaClient = cadenza(location.origin + '/trunk', { iframe: 'iframe', debug: true });
const actionHandlers = {
show ({ embeddingTargetId, hideMainHeaderAndFooter, hideWorkbookToolBar, jasperReportAsPdf }) {
show ({ embeddingTargetId, hideMainHeaderAndFooter, hideWorkbookToolBar, jasperReportAsPdf, highlightGlobalId }) {
cadenzaClient.show(embeddingTargetId, {
hideMainHeaderAndFooter: (hideMainHeaderAndFooter === 'on'),
hideWorkbookToolBar: (hideWorkbookToolBar === 'on'),
...(jasperReportAsPdf === 'on' && { mediaType: 'application/pdf' })
highlightGlobalId,
...(jasperReportAsPdf === 'on' && { mediaType: 'application/pdf' }),
});
},
showMap ({ embeddingTargetId, useMapSrs, geometry, mapExtent, locationFinder }) {
showMap ({ embeddingTargetId, useMapSrs, geometry, mapExtent, locationFinder, highlightGlobalId }) {
cadenzaClient.showMap(embeddingTargetId, {
useMapSrs: useMapSrs === 'on',
geometry: geometry && JSON.parse(geometry),
mapExtent: mapExtent && mapExtent.split(','),
locationFinder
locationFinder,
highlightGlobalId
});
},
createGeometry ({ embeddingTargetId, geometryType, useMapSrs, minScale, mapExtent, locationFinder }) {
Expand Down Expand Up @@ -182,6 +184,10 @@
Hide workbook toolbar
</label>
</div>
<div>
<label for="highlightGlobalId">Highlighted folder ID</label>
<input name="highlightGlobalId" id="highlightGlobalId">
</div>
</template>

<template data-action="showMap">
Expand Down Expand Up @@ -211,6 +217,10 @@
<label for="locationFinder">Location finder search query</label>
<input name="locationFinder" id="locationFinder">
</div>
<div>
<label for="highlightGlobalId">Highlighted folder ID</label>
<input name="highlightGlobalId" id="highlightGlobalId">
</div>
</template>

<template data-action="createGeometry">
Expand Down
18 changes: 17 additions & 1 deletion src/cadenza.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ globalThis.cadenza = Object.assign(

/** @typedef {string} EmbeddingTargetId - The ID of an embedding target */

/** @typedef {string} FolderId - The ID of a navigator folder */

/**
* @typedef ExternalLinkKey - A tuple qualifying a Cadenza external link
* @property {string} repositoryName - The name of the link's repository
Expand Down Expand Up @@ -164,13 +166,20 @@ export class CadenzaClient {
* @param {boolean} [options.hideWorkbookToolBar] - Whether to hide the workbook toolbar.
* @param {string} [options.mediaType] - Set to "application/pdf" for Jasper Report views
* to show the PDF directly, without any Cadenza headers or footers.
* @param {FolderId} [options.highlightGlobalId] - The id of the folder to expand in the navigator.
* @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
*/
show(
source,
{ hideMainHeaderAndFooter, hideWorkbookToolBar, signal, mediaType } = {},
{
hideMainHeaderAndFooter,
hideWorkbookToolBar,
signal,
mediaType,
highlightGlobalId,
} = {},
) {
this.#log('CadenzaClient#show', source);
if (mediaType) {
Expand All @@ -179,6 +188,7 @@ export class CadenzaClient {
const params = createParams({
hideMainHeaderAndFooter,
hideWorkbookToolBar,
highlightGlobalId,
webApplication: this.#webApplication,
mediaType,
});
Expand All @@ -196,6 +206,7 @@ export class CadenzaClient {
* @param {string} [options.locationFinder] - A search query for the location finder
* @param {Extent} [options.mapExtent] - A map extent to set
* @param {boolean} [options.useMapSrs] - Whether the geometry and the extent are in the map's SRS (otherwise EPSG:4326 is assumed)
* @param {FolderId} [options.highlightGlobalId] - The id of the folder to expand in the navigator.
* @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 workbook view source or geometry type
Expand All @@ -209,6 +220,7 @@ export class CadenzaClient {
locationFinder,
mapExtent,
useMapSrs,
highlightGlobalId,
signal,
} = {},
) {
Expand All @@ -222,6 +234,7 @@ export class CadenzaClient {
locationFinder,
mapExtent,
useMapSrs,
highlightGlobalId,
webApplication: this.#webApplication,
});
return this.#show(resolvePath(mapView), { params, signal }).then(() =>
Expand Down Expand Up @@ -665,6 +678,7 @@ function assertSupportedMediaType(type, supportedTypes) {
* @param {string} [params.mediaType]
* @param {number} [params.minScale]
* @param {boolean} [params.useMapSrs]
* @param {FolderId} [params.highlightGlobalId]
* @param {ExternalLinkKey} [params.webApplication]
* @return {URLSearchParams}
*/
Expand All @@ -679,6 +693,7 @@ function createParams({
mediaType,
minScale,
useMapSrs,
highlightGlobalId,
webApplication,
}) {
if (geometryType) {
Expand All @@ -695,6 +710,7 @@ function createParams({
...(mediaType && { mediaType }),
...(minScale && { minScale: String(minScale) }),
...(useMapSrs && { useMapSrs: 'true' }),
...(highlightGlobalId && { highlightGlobalId }),
...(webApplication && {
webApplicationLink: webApplication.externalLinkId,
webApplicationLinkRepository: webApplication.repositoryName,
Expand Down
3 changes: 2 additions & 1 deletion src/cadenza.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ describe('Given a Cadenza JS client instance', () => {
cadenza(BASE_URL, { iframe }).show(EMBEDDING_TARGET_ID, {
hideMainHeaderAndFooter: true,
hideWorkbookToolBar: true,
highlightGlobalId: 'ROOT.MyFolder',
});
expect(cad.iframe!.src).toBe(
`${BASE_URL}/w/${EMBEDDING_TARGET_ID}?hideMainHeaderAndFooter=true&hideWorkbookToolBar=true`,
`${BASE_URL}/w/${EMBEDDING_TARGET_ID}?hideMainHeaderAndFooter=true&hideWorkbookToolBar=true&highlightGlobalId=ROOT.MyFolder`,
);
});

Expand Down

0 comments on commit 7fe3a33

Please sign in to comment.