From c194b76712ff0f5e5984de05398fa70c9838c529 Mon Sep 17 00:00:00 2001 From: lott Date: Thu, 16 Nov 2023 18:12:08 +0100 Subject: [PATCH] add filter option to show() and showMap() --- CHANGELOG.md | 2 ++ README.md | 7 +++++-- sandbox.html | 22 ++++++++++++++++++++-- src/cadenza.js | 35 ++++++++++++++++++++++++++++++++--- 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a34c3114..39fb8ec6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ 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 +- `filter` option for `CadenzaClient#show` and `CadenzaClient#showMap` ## 1.6.0 - 2023-11-17 ### Changed diff --git a/README.md b/README.md index a4306447..4c03edce 100644 --- a/README.md +++ b/README.md @@ -71,14 +71,17 @@ const cadenza = window.cadenza.noConflict(); API: [CadenzaClient#show](./classes/CadenzaClient.html#show) -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. +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, disable the designer and set the filter variable "var1" to "foo". ```javascript cadenzaClient.show('{embeddingTargetId}', { hideMainHeaderAndFooter: true, hideWorkbookToolBar: true, operationMode: 'simplified', - disabledUiFeatures: ['workbook-design'] + disabledUiFeatures: ['workbook-design'], + filter: { + var1: 'foo' + } }); ``` diff --git a/sandbox.html b/sandbox.html index 5dc430d1..7395140e 100644 --- a/sandbox.html +++ b/sandbox.html @@ -129,7 +129,8 @@ minScale, parts, simplifiedOperationMode, - useMapSrs + useMapSrs, + filter }) { return { disabledUiFeatures: disabledUiFeatures && disabledUiFeatures.split(','), @@ -145,9 +146,22 @@ minScale, parts: parts && parts.split(','), ...(simplifiedOperationMode === 'on' && { operationMode: 'simplified' }), - useMapSrs: useMapSrs === 'on' + useMapSrs: useMapSrs === 'on', + filter: filter && parseFilterVariables(filter) }; } + + function parseFilterVariables (filterString) { + return JSON.parse(filterString, (_, value) => { + if (value === '{{currentDate}}') { // convenience for current date + return new Date(); + } + if (value.match?.(/....-..-..T..:..:..\....Z/)) { + return new Date(value); + } + return value; + }); + } @@ -212,6 +226,10 @@ +
+ + +