diff --git a/lib/Entity/Playlist.php b/lib/Entity/Playlist.php index 8ae2464c5b..da360b2726 100644 --- a/lib/Entity/Playlist.php +++ b/lib/Entity/Playlist.php @@ -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. * @@ -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; @@ -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)); @@ -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(); diff --git a/lib/XTR/DynamicPlaylistSyncTask.php b/lib/XTR/DynamicPlaylistSyncTask.php index 446c6e9a6d..29a4a53784 100644 --- a/lib/XTR/DynamicPlaylistSyncTask.php +++ b/lib/XTR/DynamicPlaylistSyncTask.php @@ -1,8 +1,8 @@ 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); @@ -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, @@ -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. @@ -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]); } } @@ -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); } } } diff --git a/ui/src/core/file-upload.js b/ui/src/core/file-upload.js index a576dde45b..e6b43cc9d4 100644 --- a/ui/src/core/file-upload.js +++ b/ui/src/core/file-upload.js @@ -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), diff --git a/views/include-file-upload.twig b/views/include-file-upload.twig index 42bd390323..f004dd73f7 100644 --- a/views/include-file-upload.twig +++ b/views/include-file-upload.twig @@ -17,7 +17,7 @@ {# Max image resize size from settings #} {# Handlebars Templates #}