Skip to content

Commit

Permalink
de-duplicate sandbox code
Browse files Browse the repository at this point in the history
  • Loading branch information
jkissel committed Nov 17, 2023
1 parent 13f5b6d commit 7612816
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 153 deletions.
257 changes: 105 additions & 152 deletions sandbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
label {
font-weight: 600;
}
select, input:is(:not([type]), [type=text], [type=number]), textarea {
select, input:is(:not([type]), [type=text], [type=number]), textarea, hr {
display: block;
width: 100%
}
Expand All @@ -57,6 +57,12 @@
const action = actionSelect.value;
const settingsTemplate = document.querySelector(`[data-action=${action}]`);
settingsContainer.append(settingsTemplate.content.cloneNode(true));
const commonSettingsTemplate = document.getElementById(`common-${settingsTemplate.dataset.common}`);
if (commonSettingsTemplate) {
settingsContainer.append(
document.createElement('hr'),
commonSettingsTemplate.content.cloneNode(true));
}

const data = localStorage.getItem(`cadenzajs-sandbox-${action}`);
if (data) {
Expand All @@ -72,64 +78,17 @@
?? location.pathname.slice(0, location.pathname.indexOf('/sandbox'));
const cadenzaClient = cadenza(location.origin + contextPath, { iframe: 'iframe', debug: true });
const actionHandlers = {
show ({ embeddingTargetId, expandNavigator, hideMainHeaderAndFooter, hideWorkbookToolBar, jasperReportAsPdf, highlightGlobalId, operationMode, disabledUiFeatures }) {
cadenzaClient.show(embeddingTargetId, {
expandNavigator: (expandNavigator === 'on'),
hideMainHeaderAndFooter: (hideMainHeaderAndFooter === 'on'),
hideWorkbookToolBar: (hideWorkbookToolBar === 'on'),
highlightGlobalId,
...(jasperReportAsPdf === 'on' && { mediaType: 'application/pdf' }),
...(operationMode === 'on' && { operationMode: 'normal' }),
disabledUiFeatures: disabledUiFeatures && disabledUiFeatures.split(',')
});
},
showPage ({ page, expandNavigator, highlightGlobalId, labelSet }) {
cadenzaClient.show({ page: page }, {
expandNavigator: (expandNavigator === 'on'),
highlightGlobalId,
labelSet
});
},
expandNavigator ({ expandNavigator }) {
cadenzaClient.expandNavigator(expandNavigator === 'on');
},
showMap ({ embeddingTargetId, useMapSrs, geometry, mapExtent, locationFinder, highlightGlobalId }) {
cadenzaClient.showMap(embeddingTargetId, {
useMapSrs: useMapSrs === 'on',
geometry: geometry && JSON.parse(geometry),
mapExtent: mapExtent && mapExtent.split(','),
locationFinder,
highlightGlobalId
});
},
createGeometry ({ embeddingTargetId, geometryType, useMapSrs, minScale, mapExtent, locationFinder }) {
cadenzaClient.createGeometry(embeddingTargetId, geometryType, {
useMapSrs: useMapSrs === 'on',
minScale,
mapExtent: mapExtent && mapExtent.split(','),
locationFinder
});
},
editGeometry ({ embeddingTargetId, geometry, useMapSrs, minScale, mapExtent, locationFinder }) {
cadenzaClient.editGeometry(embeddingTargetId, JSON.parse(geometry), {
useMapSrs: useMapSrs === 'on',
minScale,
mapExtent: mapExtent && mapExtent.split(','),
locationFinder
});
},
fetchData ({ embeddingTargetId, mediaType, parts }) {
show: data => cadenzaClient.show(data.embeddingTargetId, getOptions(data)),
showPage: data => cadenzaClient.show({ page: data.page }, getOptions(data)),
expandNavigator: data => cadenzaClient.expandNavigator(getOptions(data)),
showMap: data => cadenzaClient.showMap(data.embeddingTargetId, getOptions(data)),
createGeometry: data => cadenzaClient.createGeometry(data.embeddingTargetId, data.geometryType, getOptions(data)),
editGeometry: data => cadenzaClient.editGeometry(data.embeddingTargetId, JSON.parse(data.geometry), getOptions(data)),
fetchData: data => {
console.log('Inspect the fetchData() request in the devtools.');
cadenzaClient.fetchData(embeddingTargetId, mediaType, {
parts: parts && parts.split(',')
});
cadenzaClient.fetchData(data.embeddingTargetId, data.mediaType, getOptions(data));
},
downloadData ({ embeddingTargetId, mediaType, fileName, parts }) {
cadenzaClient.downloadData(embeddingTargetId, mediaType, {
fileName,
parts: parts && parts.split(',')
});
}
downloadData: data => cadenzaClient.downloadData(data.embeddingTargetId, data.mediaType, getOptions(data))
};

const form = document.getElementById('form');
Expand All @@ -155,6 +114,40 @@
}
}
}

function getOptions ({
disabledUiFeatures,
expandNavigator,
geometry,
hideMainHeaderAndFooter,
hideWorkbookToolBar,
highlightGlobalId,
jasperReportAsPdf,
labelSet,
locationFinder,
mapExtent,
minScale,
parts,
simplifiedOperationMode,
useMapSrs
}) {
return {
disabledUiFeatures: disabledUiFeatures && disabledUiFeatures.split(','),
expandNavigator: (expandNavigator === 'on'),
geometry: geometry && JSON.parse(geometry),
hideMainHeaderAndFooter: (hideMainHeaderAndFooter === 'on'),
hideWorkbookToolBar: (hideWorkbookToolBar === 'on'),
highlightGlobalId,
...(jasperReportAsPdf === 'on' && { mediaType: 'application/pdf' }),
labelSet,
locationFinder,
mapExtent: mapExtent && mapExtent.split(','),
minScale,
parts: parts && parts.split(','),
...(simplifiedOperationMode === 'on' && { operationMode: 'simplified' }),
useMapSrs: useMapSrs === 'on'
};
}
</script>
</head>
<body>
Expand Down Expand Up @@ -186,17 +179,7 @@
<iframe id="iframe"></iframe>
</main>

<template data-action="show">
<div>
<label for="embeddingTargetId">Embedding target ID *</label>
<input name="embeddingTargetId" id="embeddingTargetId" required>
</div>
<div>
<label>
<input type="checkbox" name="jasperReportAsPdf" id="jasperReportAsPdf"/>
Show Jasper Report as PDF
</label>
</div>
<template id="common-show">
<div>
<label>
<input type="checkbox" name="expandNavigator">
Expand All @@ -217,8 +200,8 @@
</div>
<div>
<label>
<input type="checkbox" name="operationMode">
Enable simplified operation mode
<input type="checkbox" name="simplifiedOperationMode">
Simplified operation mode
</label>
</div>
<div>
Expand All @@ -231,7 +214,53 @@
</div>
</template>

<template data-action="showPage">
<template id="common-map">
<div>
<label>
<input type="checkbox" name="useMapSrs">
Use map SRS
</label>
</div>
<div>
<label for="mapExtent">Map extent coordinates</label>
<input name="mapExtent" id="mapExtent" placeholder="minX,minY,maxX,maxY">
</div>
<div>
<label for="locationFinder">Location finder search query</label>
<input name="locationFinder" id="locationFinder">
</div>
</template>

<template id="common-data">
<div>
<label for="mediaType">Media type *</label>
<select name="mediaType" id="mediaType" required>
<option>text/csv</option>
<option>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</option>
<option>application/json</option>
<option>application/pdf</option>
</select>
</div>
<div>
<label for="parts">Parts</label>
<input name="parts" id="parts" placeholder="columns,values,totals">
</div>
</template>

<template data-action="show" data-common="show">
<div>
<label for="embeddingTargetId">Embedding target ID *</label>
<input name="embeddingTargetId" id="embeddingTargetId" required>
</div>
<div>
<label>
<input type="checkbox" name="jasperReportAsPdf" id="jasperReportAsPdf"/>
Show Jasper Report as PDF
</label>
</div>
</template>

<template data-action="showPage" data-common="show">
<div>
<label for="page">Page *</label>
<select name="page" id="page" required>
Expand All @@ -245,10 +274,6 @@
Expand navigator tree
</label>
</div>
<div>
<label for="highlightGlobalId">Highlighted Global ID</label>
<input name="highlightGlobalId" id="highlightGlobalId">
</div>
<div>
<label for="labelSet">Label Set</label>
<input name="labelSet" id="labelSet">
Expand All @@ -264,46 +289,22 @@
</div>
</template>

<template data-action="showMap">
<template data-action="showMap" data-common="show">
<div>
<label for="embeddingTargetId">Embedding target ID of the map view *</label>
<input name="embeddingTargetId" id="embeddingTargetId" required>
</div>
<div>
<label>
<input type="checkbox" name="useMapSrs">
Use map SRS
</label>
</div>
<div>
<label for="geometry">Geometry (GeoJSON)</label>
<textarea name="geometry" id="geometry" rows="5"></textarea>
</div>
<div>
<label for="mapExtent">Map extent coordinates</label>
<input name="mapExtent" id="mapExtent" placeholder="minX,minY,maxX,maxY">
</div>
<div>
<label for="locationFinder">Location finder search query</label>
<input name="locationFinder" id="locationFinder">
</div>
<div>
<label for="highlightGlobalId">Highlighted Global ID</label>
<input name="highlightGlobalId" id="highlightGlobalId">
</div>
</template>

<template data-action="createGeometry">
<template data-action="createGeometry" data-common="map">
<div>
<label for="embeddingTargetId">Embedding target ID of the map view *</label>
<input name="embeddingTargetId" id="embeddingTargetId" required>
</div>
<div>
<label>
<input type="checkbox" name="useMapSrs">
Use map SRS
</label>
</div>
<div>
<label for="geometryType">Geometry type</label>
<select name="geometryType" id="geometryType">
Expand All @@ -319,27 +320,13 @@
<label for="minScale">Minimum Scale</label>
<input type="number" name="minScale" id="minScale">
</div>
<div>
<label for="mapExtent">Map extent coordinates</label>
<input name="mapExtent" id="mapExtent" placeholder="minX,minY,maxX,maxY">
</div>
<div>
<label for="locationFinder">Location finder search query</label>
<input name="locationFinder" id="locationFinder">
</div>
</template>

<template data-action="editGeometry">
<template data-action="editGeometry" data-common="map">
<div>
<label for="embeddingTargetId">Embedding target ID of the map view *</label>
<input name="embeddingTargetId" id="embeddingTargetId" required>
</div>
<div>
<label>
<input type="checkbox" name="useMapSrs">
Use map SRS
</label>
</div>
<div>
<label for="geometry">Geometry (GeoJSON) *</label>
<textarea name="geometry" id="geometry" rows="5" required></textarea>
Expand All @@ -348,58 +335,24 @@
<label for="minScale">Minimum Scale</label>
<input type="number" name="minScale" id="minScale">
</div>
<div>
<label for="mapExtent">Map extent coordinates</label>
<input name="mapExtent" id="mapExtent" placeholder="minX,minY,maxX,maxY">
</div>
<div>
<label for="locationFinder">Location finder search query</label>
<input name="locationFinder" id="locationFinder">
</div>
</template>

<template data-action="downloadData">
<template data-action="downloadData" data-common="data">
<div>
<label for="embeddingTargetId">Embedding target ID *</label>
<input name="embeddingTargetId" id="embeddingTargetId" required>
</div>
<div>
<label for="parts">Parts</label>
<input name="parts" id="parts" placeholder="columns,values,totals">
</div>
<div>
<label for="mediaType">Media type *</label>
<select name="mediaType" id="mediaType" required>
<option>text/csv</option>
<option>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</option>
<option>application/json</option>
<option>application/pdf</option>
</select>
</div>
<div>
<label for="fileName">Filename</label>
<input name="fileName" id="fileName">
</div>
</template>

<template data-action="fetchData">
<template data-action="fetchData" data-common="data">
<div>
<label for="embeddingTargetId">Embedding target ID *</label>
<input name="embeddingTargetId" id="embeddingTargetId" required>
</div>
<div>
<label for="parts">Parts</label>
<input name="parts" id="parts" placeholder="columns,values,totals">
</div>
<div>
<label for="mediaType">Media type *</label>
<select name="mediaType" id="mediaType" required>
<option>text/csv</option>
<option>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</option>
<option>application/json</option>
<option>application/pdf</option>
</select>
</div>
</template>

</body>
Expand Down
2 changes: 1 addition & 1 deletion src/cadenza.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ function createParams({
...(mapExtent && { mapExtent: mapExtent.join() }),
...(mediaType && { mediaType }),
...(minScale && { minScale: String(minScale) }),
...(operationMode && { operationMode }),
...(operationMode !== 'normal' && { operationMode }),
...(parts && { parts: parts.join() }),
...(useMapSrs && { useMapSrs: 'true' }),
...(webApplication && {
Expand Down

0 comments on commit 7612816

Please sign in to comment.