Skip to content

Commit

Permalink
3.3.9 issues (xibosignage#2173)
Browse files Browse the repository at this point in the history
* Library Upload : Protect against empty default resize limit CMS setting. xibosignage/xibo#3159
* Playlists : Fix various issues causing the displayOrder on dynamic Playlist to be incorrect. xibosignage/xibo#3163
  • Loading branch information
PeterMis authored Oct 19, 2023
1 parent 6a86718 commit 5b12855
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
31 changes: 26 additions & 5 deletions lib/Entity/Playlist.php
Original file line number Diff line number Diff line change
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 @@ -458,10 +458,9 @@ public function assignWidget($widget, $displayOrder = null)
// This widget is >= the display order and therefore needs to be moved down one position.
$existingWidget->displayOrder = $existingWidget->displayOrder + 1;
}

// Set the incoming widget to the requested display order.
$widget->displayOrder = $displayOrder;
}
// Set the incoming widget to the requested display order.
$widget->displayOrder = $displayOrder;
} else {
// Take the next available one
$widget->displayOrder = count($this->widgets) + 1;
Expand Down Expand Up @@ -579,7 +578,8 @@ public function load($loadOptions = [])
'loadPermissions' => true,
'loadWidgets' => true,
'loadTags' => true,
'loadActions' => true
'loadActions' => true,
'checkDisplayOrder' => false,
], $loadOptions);

$this->getLog()->debug('Load Playlist with ' . json_encode($options));
Expand All @@ -601,6 +601,27 @@ public function load($loadOptions = [])
$widget->load($options['loadActions']);
$this->widgets[] = $widget;
}

// for dynamic sync task
// make sure we have correct displayOrder on all existing Widgets here.
if ($this->isDynamic === 1 && $options['checkDisplayOrder']) {
// Sort the widgets by their display order
usort($this->widgets, function ($a, $b) {
/**
* @var Widget $a
* @var Widget $b
*/
return $a->displayOrder - $b->displayOrder;
});

$i = 0;
foreach ($this->widgets as $widget) {
/* @var Widget $widget */
$i++;
// Assert the displayOrder
$widget->displayOrder = $i;
}
}
}

$this->hash = $this->hash();
Expand Down
19 changes: 12 additions & 7 deletions lib/XTR/DynamicPlaylistSyncTask.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
/**
* Copyright (C) 2020 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 @@ -108,7 +108,7 @@ public function run()
foreach ($this->playlistFactory->query(null, ['isDynamic' => 1]) as $playlist) {
try {
// We want to detect any differences in what should be assigned to this Playlist.
$playlist->load();
$playlist->load(['checkDisplayOrder' => true]);

$this->log->debug('Assessing Playlist: ' . $playlist->name);

Expand All @@ -128,6 +128,7 @@ public function run()
// Query for media which would be assigned to this Playlist and see if there are any differences
$media = [];
$mediaIds = [];
$displayOrder = [];
foreach ($this->mediaFactory->query(null, [
'name' => $playlist->filterMediaName,
'logicalOperatorName' => $playlist->filterMediaNameLogicalOperator,
Expand All @@ -137,9 +138,11 @@ public function run()
'userCheckUserId' => $playlist->getOwnerId(),
'start' => 0,
'length' => $playlist->maxNumberOfItems
]) as $item) {
]) as $index => $item) {
$media[$item->mediaId] = $item;
$mediaIds[] = $item->mediaId;
// store the expected display order
$displayOrder[$item->mediaId] = $index + 1;
}

// Work out if the set of widgets is different or not.
Expand Down Expand Up @@ -230,7 +233,8 @@ public function run()
break;
}
$assignmentMade = true;
$this->createAndAssign($playlist, $item, $count);
// make sure we pass the expected displayOrder for the new item we are about to add.
$this->createAndAssign($playlist, $item, $displayOrder[$item->mediaId]);
}
}

Expand Down Expand Up @@ -296,7 +300,8 @@ private function createAndAssign($playlist, $media, $displayOrder)
$module->widget->calculatedDuration = $mediaDuration;

// Assign the widget to the playlist
$playlist->assignWidget($widget);
// making sure we pass the displayOrder here, otherwise it would be added to the end of the array.
$playlist->assignWidget($widget, $displayOrder);
}
}
}
4 changes: 4 additions & 0 deletions ui/src/core/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ function openUploadForm(options) {
uploadTemplate = Handlebars.compile($("#" + options.templateId).html());
}

if (typeof maxImagePixelSize === undefined || maxImagePixelSize === '') {
maxImagePixelSize = 0;
}

// Handle bars and open a dialog
var dialog = bootbox.dialog({
message: uploadTemplate(options.templateOptions),
Expand Down
2 changes: 1 addition & 1 deletion views/include-file-upload.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

{# Max image resize size from settings #}
<script type="text/javascript">
const maxImagePixelSize = {{ settings.DEFAULT_RESIZE_LIMIT }};
let maxImagePixelSize = "{{ settings.DEFAULT_RESIZE_LIMIT }}";
</script>

{# Handlebars Templates #}
Expand Down

0 comments on commit 5b12855

Please sign in to comment.