Skip to content

Commit

Permalink
Misc issues 4.0.6 (#2263)
Browse files Browse the repository at this point in the history
* Layout: improve thumbnails for Canvas regions. Ensure thumbnail is taken on publish. xibosignage/xibo#3248
* Menu board: always format fractional digits xibosignageltd/xibo-private#542
* Bump to 4.0.6
* User: fix null homepage error xibosignage/xibo#3264
* XMDS: fault should trim too long reason xibosignage/xibo#3230
* Ad Campaign: impressions target type too long xibosignage/xibo#3235
  • Loading branch information
dasgarner committed Dec 8, 2023
1 parent 035eb95 commit f7eaddb
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 39 deletions.
4 changes: 2 additions & 2 deletions lib/Controller/Campaign.php
Expand Up @@ -527,7 +527,7 @@ public function addForm(Request $request, Response $response)
* @SWG\Parameter(
* name="targetType",
* in="formData",
* description="For ad campaigns, how do we measure the target? plays|budget",
* description="For ad campaigns, how do we measure the target? plays|budget|imp",
* type="string",
* required=false
* ),
Expand Down Expand Up @@ -774,7 +774,7 @@ public function editForm(Request $request, Response $response, $id)
* @SWG\Parameter(
* name="targetType",
* in="formData",
* description="For ad campaigns, how do we measure the target? plays|budget",
* description="For ad campaigns, how do we measure the target? plays|budget|imp",
* type="string",
* required=false
* ),
Expand Down
9 changes: 8 additions & 1 deletion lib/Controller/Layout.php
Expand Up @@ -1941,7 +1941,7 @@ function editBackgroundForm(Request $request, Response $response, $id)
if (!$this->getUser()->checkEditable($layout)) {
throw new AccessDeniedException();
}

// Edits always happen on Drafts, get the draft Layout using the Parent Layout ID
if ($layout->schemaVersion < 2) {
$resolution = $this->resolutionFactory->getByDesignerDimensions($layout->width, $layout->height);
Expand Down Expand Up @@ -3055,9 +3055,16 @@ public function addThumbnail(Request $request, Response $response, $id): Respons
$image = Img::canvas($layout->width, $layout->height, $layout->backgroundColor);
}

$countRegions = count($layout->regions);

// Draw some regions on it.
foreach ($layout->regions as $region) {
try {
// We don't do this for the canvas region.
if ($countRegions > 1 && $region->type === 'canvas') {
continue;
}

// Get widgets in this region
$playlist = $region->getPlaylist()->setModuleFactory($this->moduleFactory);
$widgets = $playlist->expandWidgets();
Expand Down
6 changes: 3 additions & 3 deletions lib/Entity/Campaign.php
Expand Up @@ -126,7 +126,7 @@ class Campaign implements \JsonSerializable
public $listPlayOrder;

/**
* @SWG\Property(description="For an ad campaign, what's the target type, plays|budget")
* @SWG\Property(description="For an ad campaign, what's the target type, plays|budget|imp")
* @var string
*/
public $targetType;
Expand Down Expand Up @@ -397,7 +397,7 @@ public function getProgress(?Carbon $testDate = null): CampaignProgress

if ($this->targetType === 'budget') {
$progress->progressTarget = ($this->spend / $this->target) * 100;
} else if ($this->targetType === 'impressions') {
} else if ($this->targetType === 'imp') {
$progress->progressTarget = ($this->impressions / $this->target) * 100;
} else {
$progress->progressTarget = ($this->plays / $this->target) * 100;
Expand Down Expand Up @@ -485,7 +485,7 @@ public function validate()
}

if ($this->type === 'ad') {
if (!in_array($this->targetType, ['plays', 'budget', 'impressions'])) {
if (!in_array($this->targetType, ['plays', 'budget', 'imp'])) {
throw new InvalidArgumentException(__('Invalid target type'), 'targetType');
}

Expand Down
10 changes: 7 additions & 3 deletions lib/Factory/UserGroupFactory.php
Expand Up @@ -884,12 +884,16 @@ public function getFeatures()
}

/**
* @param string $homepage The home page id
* @return array|mixed
* @param string|null $homepage The home page id
* @return \Xibo\Entity\Homepage
* @throws \Xibo\Support\Exception\NotFoundException
*/
public function getHomepageByName(string $homepage)
public function getHomepageByName(?string $homepage): Homepage
{
if (empty($homepage)) {
throw new NotFoundException(__('Homepage has not been set'));
}

$homepages = $this->getHomepages();

if (!array_key_exists($homepage, $homepages)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Helper/Environment.php
Expand Up @@ -30,7 +30,7 @@
*/
class Environment
{
public static $WEBSITE_VERSION_NAME = '4.0.5';
public static $WEBSITE_VERSION_NAME = '4.0.6';
public static $XMDS_VERSION = '7';
public static $XLF_VERSION = 4;
public static $VERSION_REQUIRED = '8.1.0';
Expand Down
4 changes: 2 additions & 2 deletions lib/XTR/CampaignSchedulerTask.php
Expand Up @@ -2,7 +2,7 @@
/*
* Copyright (C) 2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
* Xibo - Digital Signage - https://xibosignage.com
*
* This file is part of Xibo.
*
Expand Down Expand Up @@ -232,7 +232,7 @@ public function run()
// cost/impressions/displays are sums.
if ($campaign->targetType === 'budget') {
$playsNeededPerLayout = $targetNeededPerLayout / $costPerPlay;
} else if ($campaign->targetType === 'impressions') {
} else if ($campaign->targetType === 'imp') {
$playsNeededPerLayout = $targetNeededPerLayout / $impressionsPerPlay;
} else {
$playsNeededPerLayout = $targetNeededPerLayout / $countDisplays;
Expand Down
13 changes: 9 additions & 4 deletions lib/Xmds/Soap6.php
@@ -1,8 +1,8 @@
<?php
/**
* Copyright (C) 2021 Xibo Signage Ltd
/*
* Copyright (C) 2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
* Xibo - Digital Signage - https://xibosignage.com
*
* This file is part of Xibo.
*
Expand Down Expand Up @@ -50,7 +50,7 @@ public function reportFaults(string $serverKey, string $hardwareKey, string $fau
'serverKey' => $serverKey,
'hardwareKey' => $hardwareKey
]);

// Sanitize
$serverKey = $sanitizer->getString('serverKey');
$hardwareKey = $sanitizer->getString('hardwareKey');
Expand Down Expand Up @@ -90,6 +90,11 @@ public function reportFaults(string $serverKey, string $hardwareKey, string $fau
$mediaId = $sanitizedFaultAlert->getInt('mediaId');
$widgetId = $sanitizedFaultAlert->getInt('widgetId');

// Trim the reason if it is too long
if (strlen($reason) >= 255) {
$reason = substr($reason, 0, 255);
}

try {
$dbh = $this->getStore()->getConnection();

Expand Down
2 changes: 2 additions & 0 deletions modules/templates/product-elements.xml
Expand Up @@ -97,6 +97,8 @@ var options = {};
if (properties.currencyCode && properties.currencyCode !== '') {
options.style = 'currency';
options.currency = properties.currencyCode;
} else {
options.minimumFractionDigits = 2;
}
value = new Intl.NumberFormat(undefined, options).format(value);
Expand Down
19 changes: 19 additions & 0 deletions tests/XMDS.http
Expand Up @@ -128,6 +128,25 @@ 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:ReportFaults>
<serverKey xsi:type="xsd:string">{{serverKey}}</serverKey>
<hardwareKey xsi:type="xsd:string">{{hardwareKey}}</hardwareKey>
<fault xsi:type="xsd:string">[{"code":5000, "reason": "Too long: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}]</fault>
</tns:ReportFaults>
</soap:Body>
</soap:Envelope>

###

# Get the fileID from the Required Files response.
GET {{url}}/xmds.php?file=12.xlf&displayId=1&type=L&itemId=12&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230502T000000Z&X-Amz-Expires=1683048895&X-Amz-SignedHeaders=host&X-Amz-Signature=7c876be170afb29d194e7b035be6969198c22a32c22e163e2696754bb1163f5d

Expand Down
11 changes: 7 additions & 4 deletions ui/src/layout-editor/layout.js
Expand Up @@ -451,10 +451,13 @@ Layout.prototype.publish = function() {

toastr.success(res.message);

// Redirect to the new published layout ( read only mode )
window.location.href =
urlsForApi.layout.designer.url.replace(
':id', res.data.layoutId) + '?vM=1';
// Update the thumbnail
lD.uploadThumbnail().finally(() => {
// Redirect to the new published layout ( read only mode )
window.location.href =
urlsForApi.layout.designer.url.replace(
':id', res.data.layoutId) + '?vM=1';
});
} else {
lD.common.hideLoadingScreen();

Expand Down
38 changes: 23 additions & 15 deletions ui/src/layout-editor/main.js
Expand Up @@ -914,8 +914,7 @@ lD.showPublishScreen = function() {
"#publishNow",
"",
".publish-date-control"
);
lD.uploadThumbnail($("#layoutPublishForm #publishPreview"));`,
);`,
'lD.layout.publish();',
);
};
Expand Down Expand Up @@ -4169,6 +4168,7 @@ lD.importFromProvider = function(items) {
/**
* Take and upload a thumbnail
* @param {object} targetToAttach DOM object to attach the thumbnail to
* @return {Promise}
*/
lD.uploadThumbnail = function(targetToAttach) {
if ($(targetToAttach).length > 0) {
Expand All @@ -4179,19 +4179,27 @@ lD.uploadThumbnail = function(targetToAttach) {
);
$(targetToAttach).removeClass('d-none');
}
const linkToAPI = urlsForApi.layout.addThumbnail;
const requestPath = linkToAPI.url.replace(':id', lD.layout.layoutId);
$.ajax({
url: requestPath,
type: 'POST',
success: function() {
// Attach to target
if ($(targetToAttach).length > 0) {
$(targetToAttach).find('.thumb-preview')
.replaceWith($('<img style="max-width: 150px; max-height: 100%;">')
.attr('src', requestPath));
}
},

return new Promise(function(resolve, reject) {
const linkToAPI = urlsForApi.layout.addThumbnail;
const requestPath = linkToAPI.url.replace(':id', lD.layout.layoutId);
$.ajax({
url: requestPath,
type: 'POST',
success: function() {
// Attach to target
if ($(targetToAttach).length > 0) {
$(targetToAttach).find('.thumb-preview')
.replaceWith($('<img style="max-width: 150px; max-height: 100%;">')
.attr('src', requestPath));
}

resolve();
},
fail: function() {
reject();
},
});
});
};

Expand Down
2 changes: 1 addition & 1 deletion views/campaign-builder.twig
Expand Up @@ -88,7 +88,7 @@
{% set options = [
{ id: "plays", name: "Plays"|trans },
{ id: "budget", name: "Budget"|trans },
{ id: "impressions", name: "Impressions"|trans },
{ id: "imp", name: "Impressions"|trans },
] %}
{{ forms.dropdown("targetType", "single", title, campaign.targetType, options, "id", "name", helpText, "campaign-type-ad") }}

Expand Down
2 changes: 1 addition & 1 deletion views/campaign-form-add.twig
Expand Up @@ -109,7 +109,7 @@
{% set options = [
{ id: "plays", name: "Plays"|trans },
{ id: "budget", name: "Budget"|trans },
{ id: "impressions", name: "Impressions"|trans },
{ id: "imp", name: "Impressions"|trans },
] %}
{{ forms.dropdown("targetType", "single", title, "both", options, "id", "name", helpText, "campaign-type-ad") }}

Expand Down
2 changes: 2 additions & 0 deletions views/campaign-page.twig
Expand Up @@ -260,6 +260,8 @@
return '{{ "Plays"|trans }}';
} else if (data === 'budget') {
return '{{ "Budget"|trans }}';
} else if (data === 'imp') {
return '{{ "Impressions"|trans }}';
}
return data;
},
Expand Down
10 changes: 8 additions & 2 deletions views/menuboard-product-page.twig
Expand Up @@ -111,8 +111,14 @@
responsivePriority: 2
},
{
"data": "price",
responsivePriority: 2
data: 'price',
responsivePriority: 2,
render: function (data, type) {
if (type !== 'display' || data === null || data === '') {
return data;
}
return new Intl.NumberFormat(undefined, {minimumFractionDigits: 2}).format(data);
},
},
{
responsivePriority: 3,
Expand Down

0 comments on commit f7eaddb

Please sign in to comment.