Skip to content

Commit

Permalink
Dashboard and Widget download fixes (#2052)
Browse files Browse the repository at this point in the history
* Dashboard widget: fix token generation xibosignage/xibo#3104
* Embedded: fix problem downloading widgets with library references xibosignage/xibo#3105
* Chore: Add GetResource to XMDS test
* Widgets that use `let` or `const` and dangling `,` xibosignage/xibo#3106
  • Loading branch information
dasgarner committed Sep 6, 2023
1 parent 0f56fd4 commit e9a63b2
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 44 deletions.
2 changes: 1 addition & 1 deletion lib/Widget/Render/WidgetHtmlRenderer.php
Expand Up @@ -347,7 +347,7 @@ public function decorateForPlayer(
} else if (Str::startsWith($match, 'mediaId') || Str::startsWith($match, 'libraryId')) {
$value = explode('=', $match);
if (array_key_exists($value[1], $storedAs)) {
$output = str_replace('[[' . $match . ']]', $storedAs[$value[1]]['storedAs'], $output);
$output = str_replace('[[' . $match . ']]', $storedAs[$value[1]], $output);
} else {
$output = str_replace('[[' . $match . ']]', '', $output);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/clock-analogue.xml
Expand Up @@ -197,7 +197,7 @@ var theme = (properties.themeId == 1) ? "light" : "dark";
$(target).addClass(theme);
]]></onInitialize>
<onVisible><![CDATA[
const updateClock = xiboIC.get(id, 'updateClock');
var updateClock = xiboIC.get(id, 'updateClock');
// Run update clock if it's defined in the template
if (typeof updateClock === 'function') {
// Start the first time
Expand Down
6 changes: 3 additions & 3 deletions modules/clock-digital.xml
Expand Up @@ -80,8 +80,8 @@ moment.locale(properties.lang || globalOptions.locale);
// Parse any Clock elements
// Use regex to out the bit between the [] brackets and use that as the format mask for moment.
let text = properties.format;
let regex = /\[.*?\]/g;
var text = properties.format;
var regex = /\[.*?\]/g;
properties.format = text.replace(regex, function (match) {
return '<span class="clock" format="' + match.replace('[', '').replace(']', '') + '"></span>';
Expand All @@ -104,7 +104,7 @@ xiboIC.set(
);
]]></onInitialize>
<onVisible><![CDATA[
const updateClock = xiboIC.get(id, 'updateClock');
var updateClock = xiboIC.get(id, 'updateClock');
// Run update clock if it's defined in the template
if (typeof updateClock === 'function') {
// Start the first time
Expand Down
2 changes: 1 addition & 1 deletion modules/forecastio.xml
Expand Up @@ -123,7 +123,7 @@ if (items.length === 0) {
moment.locale(globalOptions.locale);
// Make replacements [] with target data
const makeReplacement = (html, item) => {
var makeReplacement = (html, item) => {
// Make replacements [] with item data
return html.replace(/\[([^\]]+)\]/g, (match, key) => {
// If its [time] or [time|format] then return the time
Expand Down
2 changes: 1 addition & 1 deletion modules/templates/article-static.xml
Expand Up @@ -136,7 +136,7 @@ if (properties.copyright) {
$(target).find('#content').empty();
// Add items to container
for (let index = 0; index < items.length; index++) {
for (var index = 0; index < items.length; index++) {
$(items[index]).appendTo($(target).find('#content'));
}
Expand Down
8 changes: 4 additions & 4 deletions modules/templates/currency-elements.xml
Expand Up @@ -179,11 +179,11 @@ if (elementData !== null && elementData.hasOwnProperty('ChangeStyle')) {
</stencil>
<onTemplateRender><![CDATA[
// Width and Height of the element
const width = $(target).width();
const height = $(target).height();
var width = $(target).width();
var height = $(target).height();
const $logoContainer = $(target).find('.currency-elements-logo');
const $imageContainer = $(target).find('.img-circle');
var $logoContainer = $(target).find('.currency-elements-logo');
var $imageContainer = $(target).find('.img-circle');
// Scale image to the container
if (width > height) {
Expand Down
10 changes: 2 additions & 8 deletions modules/templates/dataset-static.xml
Expand Up @@ -458,10 +458,7 @@ for (var i = 0; i < items.length; i++) {
// Scale the layout
$('body').xiboLayoutScaler(properties);
$(target).xiboTextRender(
Object.assign(properties, globalOptions),
$(target).find('#content > *'),
);
$(target).xiboTextRender(Object.assign(properties, globalOptions), $(target).find('#content > *'));
]]></onTemplateRender>
</template>
<template>
Expand Down Expand Up @@ -2679,10 +2676,7 @@ for (var i = 0; i < items.length; i++) {
// Scale the layout
$('body').xiboLayoutScaler(properties);
$(target).xiboTextRender(
Object.assign(properties, globalOptions),
$(target).find('#content > *'),
);
$(target).xiboTextRender(Object.assign(properties, globalOptions), $(target).find('#content > *'));
]]></onTemplateRender>
<assets>
<asset id="dataset-slideshow" type="path" mimeType="image/png" cmsOnly="true" path="/modules/assets/template-thumbnails/dataset/dataset-slideshow.png" />
Expand Down
2 changes: 1 addition & 1 deletion modules/templates/event-static.xml
Expand Up @@ -114,7 +114,7 @@ if (items.length <= 0 && properties.noDataMessage && properties.noDataMessage !=
$(target).find('#content').empty();
// Add items to container
for (let index = 0; index < items.length; index++) {
for (var index = 0; index < items.length; index++) {
$(items[index]).appendTo($(target).find('#content'));
}
Expand Down
2 changes: 1 addition & 1 deletion modules/templates/forecast-elements.xml
Expand Up @@ -47,7 +47,7 @@ if (String(value).length === 0) {
}
if (properties.data && properties.data.temperatureUnit) {
const temperatureUnit = properties.data.temperatureUnit;
var temperatureUnit = properties.data.temperatureUnit;
if (String(value).includes('°' + temperatureUnit)) {
return value;
Expand Down
2 changes: 1 addition & 1 deletion modules/templates/message-static.xml
Expand Up @@ -111,7 +111,7 @@ if (items.length <= 0 && properties.noDataMessage && properties.noDataMessage !=
$(target).find('#content').empty();
// Add items to container
for (let index = 0; index < items.length; index++) {
for (var index = 0; index < items.length; index++) {
$(items[index]).appendTo($(target).find('#content'));
}
Expand Down
16 changes: 8 additions & 8 deletions modules/templates/product-elements.xml
Expand Up @@ -203,8 +203,8 @@ return value;
]]></hbs>
</stencil>
<onTemplateRender><![CDATA[
const optionSlot = Number(properties.optionSlot) - 1;
let $productContainer = null;
var optionSlot = Number(properties.optionSlot) - 1;
var $productContainer = null;
if ($(target).is('.element-content')) {
$productContainer = $(target).find('.product-elements-options-name');
Expand All @@ -218,8 +218,8 @@ if (
properties.data.productOptions.length > 0 &&
properties.data.productOptions[optionSlot]
) {
const option = properties.data.productOptions[optionSlot];
let name = option.name;
var option = properties.data.productOptions[optionSlot];
var name = option.name;
if (properties.prefix && properties.prefix !== '') {
name = properties.prefix + '' + name;
Expand Down Expand Up @@ -303,8 +303,8 @@ if (
]]></hbs>
</stencil>
<onTemplateRender><![CDATA[
const optionSlot = Number(properties.optionSlot) - 1;
let $productContainer = null;
var optionSlot = Number(properties.optionSlot) - 1;
var $productContainer = null;
if ($(target).is('.element-content')) {
$productContainer = $(target).find('.product-elements-options-value');
Expand All @@ -318,8 +318,8 @@ if (
properties.data.productOptions.length > 0 &&
properties.data.productOptions[optionSlot]
) {
const option = properties.data.productOptions[optionSlot];
let value = option.value;
var option = properties.data.productOptions[optionSlot];
var value = option.value;
if (properties.prefix && properties.prefix !== '') {
value = properties.prefix + '' + value;
Expand Down
10 changes: 5 additions & 5 deletions modules/templates/social-media-static.xml
Expand Up @@ -2683,7 +2683,7 @@ small {
</stencil>
<onTemplateRender><![CDATA[
// Set widget design width and height based on the window orientation
let orientation = 'landscape';
var orientation = 'landscape';
if($(window).width() >= $(window).height()) {
properties.widgetDesignWidth = 1920;
properties.widgetDesignHeight = 1080;
Expand All @@ -2697,21 +2697,21 @@ if($(window).width() >= $(window).height()) {
$(target).xiboLayoutScaler(properties);
// Get an array of items from the templates generated
const itemsHTML = $(target).find('.metro-cell-template').map(function(_k, el) {
var itemsHTML = $(target).find('.metro-cell-template').map(function(_k, el) {
return $(el).html();
});
// Get metro render container
const $metroRenderContainer = $(target).find('.metro-render-container');
var $metroRenderContainer = $(target).find('.metro-render-container');
// Mark container as landscape or portrait
$metroRenderContainer.removeClass('orientation-landscape orientation-portrait').
addClass('orientation-' + orientation);
// Get colours array
const colors = [];
var colors = [];
for (let i = 1; i <= 8; i++) {
for (var i = 1; i <= 8; i++) {
if (properties['color' + i] !== '') {
colors.push(properties['color' + i]);
}
Expand Down
4 changes: 2 additions & 2 deletions modules/templates/stock-elements.xml
Expand Up @@ -122,8 +122,8 @@ if (elementData !== null && elementData.hasOwnProperty('ChangeStyle')) {
]]></hbs>
</stencil>
<onTemplateRender><![CDATA[
const $arrowContainer = $(target).find('.stock-elements-icon');
const $targetContainer = $(target).is('body') ? $('body') : $(target).parent().parent();
var $arrowContainer = $(target).find('.stock-elements-icon');
var $targetContainer = $(target).is('body') ? $('body') : $(target).parent().parent();
// Inject CSS into target container if it's not added yet
if ($targetContainer.find('.sampleCSS').length == 0) {
Expand Down
11 changes: 4 additions & 7 deletions modules/text.xml
Expand Up @@ -93,7 +93,7 @@
// target: The target element to render
// properties: The properties for the widget
// -------------------------------------------
let hasClock = false;
var hasClock = false;
// Parse any Clock elements
if (properties.text && properties.text.indexOf('[Clock]') >= 0) {
Expand All @@ -118,8 +118,8 @@ if (properties.text && properties.text.indexOf('[Date|') >= 0) {
if (hasClock) {
// Use regex to out the bit between the [] brackets and use that as the format mask for moment.
let text = properties.text;
let regex = /\[.*?\]/g;
var text = properties.text;
var regex = /\[.*?\]/g;
properties.text = text.replace(regex, function (match) {
return '<span class="clock" format="' + match.replace('[', '').replace(']', '') + '"></span>';
Expand Down Expand Up @@ -151,10 +151,7 @@ $(target).find('img').xiboImageRender(properties);
// Scale the layout
$('body').xiboLayoutScaler(properties);
$(target).xiboTextRender(
Object.assign(properties, globalOptions),
$(target).find('#content > *'),
);
$(target).xiboTextRender(Object.assign(properties, globalOptions), $(target).find('#content > *'));
]]></onRender>
<onVisible><![CDATA[
// If we have a clock, create method and start it
Expand Down
21 changes: 21 additions & 0 deletions tests/XMDS.http
Expand Up @@ -71,6 +71,27 @@ Content-Type: application/xml
POST {{url}}/xmds.php?v=7
Content-Type: application/xml

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="urn:xmds" xmlns:types="urn:xmds/encodedTypes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<tns:GetResource>
<serverKey xsi:type="xsd:string">{{serverKey}}</serverKey>
<hardwareKey xsi:type="xsd:string">{{hardwareKey}}</hardwareKey>
<layoutId xsi:type="xsd:string">12</layoutId>
<regionId xsi:type="xsd:string">33</regionId>
<mediaId xsi:type="xsd:string">{{testWidgetId}}</mediaId>
</tns:GetResource>
</soap:Body>
</soap:Envelope>

###

POST {{url}}/xmds.php?v=7
Content-Type: application/xml

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="urn:xmds" xmlns:types="urn:xmds/encodedTypes"
Expand Down

0 comments on commit e9a63b2

Please sign in to comment.