Skip to content

Commit

Permalink
Misc fixes 4 (#1993)
Browse files Browse the repository at this point in the history
* Stocks: reverse conversion property shouldn't be there.
* Countdown: const/var not supported on older players. xibosignageltd/xibo-private#414
* Notification: preview should always refresh the cache (so we don't see others notifications). Add modifiedDt event. xibosignageltd/xibo-private#405
  • Loading branch information
dasgarner authored Aug 18, 2023
1 parent fde0f22 commit 8757569
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 42 deletions.
60 changes: 60 additions & 0 deletions lib/Event/NotificationModifiedDtRequestEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/*
* Copyright (C) 2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Xibo\Event;

use Carbon\Carbon;

/**
* Request for the latest released notification.
*/
class NotificationModifiedDtRequestEvent extends Event
{
public static $NAME = 'notification.modifiedDt.request.event';

/** @var int displayId */
private $displayId;

/** @var Carbon */
private $modifiedDt;

public function __construct(int $displayId)
{
$this->displayId = $displayId;
}

public function getDisplayId(): int
{
return $this->displayId;
}

public function setModifiedDt(Carbon $modifiedDt): NotificationModifiedDtRequestEvent
{
$this->modifiedDt = $modifiedDt;
return $this;
}

public function getModifiedDt(): ?Carbon
{
return $this->modifiedDt;
}
}
29 changes: 28 additions & 1 deletion lib/Listener/NotificationDataProviderListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
use Carbon\Carbon;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Xibo\Entity\User;
use Xibo\Event\NotificationCacheKeyRequestEvent;
use Xibo\Event\NotificationDataRequestEvent;
use Xibo\Event\NotificationModifiedDtRequestEvent;
use Xibo\Factory\NotificationFactory;
use Xibo\Service\ConfigServiceInterface;
use Xibo\Widget\Provider\DataProviderInterface;
Expand Down Expand Up @@ -62,6 +64,7 @@ public function __construct(
public function registerWithDispatcher(EventDispatcherInterface $dispatcher): NotificationDataProviderListener
{
$dispatcher->addListener(NotificationDataRequestEvent::$NAME, [$this, 'onDataRequest']);
$dispatcher->addListener(NotificationModifiedDtRequestEvent::$NAME, [$this, 'onModifiedDtRequest']);
return $this;
}

Expand All @@ -70,7 +73,7 @@ public function onDataRequest(NotificationDataRequestEvent $event)
$this->getData($event->getDataProvider());
}

private function getData(DataProviderInterface $dataProvider)
public function getData(DataProviderInterface $dataProvider)
{
$age = $dataProvider->getProperty('age', 0);

Expand Down Expand Up @@ -101,4 +104,28 @@ private function getData(DataProviderInterface $dataProvider)

$dataProvider->setIsHandled();
}

public function onModifiedDtRequest(NotificationModifiedDtRequestEvent $event)
{
$this->getLogger()->debug('onModifiedDtRequest');

// Get the latest notification according to the filter provided.
$displayId = $event->getDisplayId();

// If we're a user, we should always refresh
if ($displayId === 0) {
$event->setModifiedDt(Carbon::maxValue());
return;
}

$notifications = $this->notificationFactory->query(['releaseDt DESC'], [
'onlyReleased' => 1,
'displayId' => $displayId,
'length' => 1,
]);

if (count($notifications) > 0) {
$event->setModifiedDt(Carbon::createFromTimestamp($notifications[0]->releaseDt));
}
}
}
5 changes: 4 additions & 1 deletion lib/Widget/NotificationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use Carbon\Carbon;
use Xibo\Event\NotificationDataRequestEvent;
use Xibo\Event\NotificationModifiedDtRequestEvent;
use Xibo\Widget\Provider\DataProviderInterface;
use Xibo\Widget\Provider\DurationProviderNumItemsTrait;
use Xibo\Widget\Provider\WidgetProviderInterface;
Expand Down Expand Up @@ -51,6 +52,8 @@ public function getDataCacheKey(DataProviderInterface $dataProvider): ?string

public function getDataModifiedDt(DataProviderInterface $dataProvider): ?Carbon
{
return null;
$event = new NotificationModifiedDtRequestEvent($dataProvider->getDisplayId());
$this->getDispatcher()->dispatch($event, NotificationModifiedDtRequestEvent::$NAME);
return $event->getModifiedDt();
}
}
14 changes: 7 additions & 7 deletions modules/countdown-clock.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,17 @@ body {
</stencil>
<onRender><![CDATA[
// Make replacements on render for all templates
const $countdownContainer = $('.countdown-container', target);
var $countdownContainer = $('.countdown-container', target);
// Get countdown container html
let countdownHTML = $countdownContainer.html();
var countdownHTML = $countdownContainer.html();
// Make replacements
let text = countdownHTML;
let regex = /\[.*?\]/g;
var text = countdownHTML;
var regex = /\[.*?\]/g;
countdownHTML = text.replace(regex, function (match) {
let replacement = '';
let matchParsed = match.replace('[', '').replace(']', '');
var replacement = '';
var matchParsed = match.replace('[', '').replace(']', '');
// Replace tags
switch (matchParsed) {
Expand Down Expand Up @@ -262,7 +262,7 @@ $countdownContainer.html(countdownHTML);
$(target).xiboLayoutScaler(properties);
// Render the countdown
const $contentContainer = $(target).find('#content');
var $contentContainer = $(target).find('#content');
$contentContainer.xiboCountdownRender(
properties,
$contentContainer.html(),
Expand Down
14 changes: 7 additions & 7 deletions modules/countdown-custom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,20 @@
</stencil>
<onRender><![CDATA[
// Make replacements on render for all templates
const $countdownContainer = $('.countdown-container', target);
var $countdownContainer = $('.countdown-container', target);
// Get countdown container html
let countdownHTML = $countdownContainer.html();
var countdownHTML = $countdownContainer.html();
// Move countdown container to content
$countdownContainer.appendTo($('#content'));
// Make replacements
let text = countdownHTML;
let regex = /\[.*?\]/g;
var text = countdownHTML;
var regex = /\[.*?\]/g;
countdownHTML = text.replace(regex, function (match) {
let replacement = '';
let matchParsed = match.replace('[', '').replace(']', '');
var replacement = '';
var matchParsed = match.replace('[', '').replace(']', '');
// Replace tags
switch (matchParsed) {
Expand Down Expand Up @@ -233,7 +233,7 @@ $countdownContainer.html(countdownHTML);
$(target).xiboLayoutScaler(properties);
// Render the countdown
const $contentContainer = $(target).find('#content');
var $contentContainer = $(target).find('#content');
$contentContainer.xiboCountdownRender(
properties,
$contentContainer.html(),
Expand Down
14 changes: 7 additions & 7 deletions modules/countdown-days.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,17 @@ body {
</stencil>
<onRender><![CDATA[
// Make replacements on render for all templates
const $countdownContainer = $('.countdown-container', target);
var $countdownContainer = $('.countdown-container', target);
// Get countdown container html
let countdownHTML = $countdownContainer.html();
var countdownHTML = $countdownContainer.html();
// Make replacements
let text = countdownHTML;
let regex = /\[.*?\]/g;
var text = countdownHTML;
var regex = /\[.*?\]/g;
countdownHTML = text.replace(regex, function (match) {
let replacement = '';
let matchParsed = match.replace('[', '').replace(']', '');
var replacement = '';
var matchParsed = match.replace('[', '').replace(']', '');
// Replace tags
switch (matchParsed) {
Expand Down Expand Up @@ -272,7 +272,7 @@ $countdownContainer.html(countdownHTML);
$(target).xiboLayoutScaler(properties);
// Render the countdown
const $contentContainer = $(target).find('#content');
var $contentContainer = $(target).find('#content');
$contentContainer.xiboCountdownRender(
properties,
$contentContainer.html(),
Expand Down
14 changes: 7 additions & 7 deletions modules/countdown-table.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,17 @@ tr.main-header td {
</stencil>
<onRender><![CDATA[
// Make replacements on render for all templates
const $countdownContainer = $('.countdown-container', target);
var $countdownContainer = $('.countdown-container', target);
// Get countdown container html
let countdownHTML = $countdownContainer.html();
var countdownHTML = $countdownContainer.html();
// Make replacements
let text = countdownHTML;
let regex = /\[.*?\]/g;
var text = countdownHTML;
var regex = /\[.*?\]/g;
countdownHTML = text.replace(regex, function (match) {
let replacement = '';
let matchParsed = match.replace('[', '').replace(']', '');
var replacement = '';
var matchParsed = match.replace('[', '').replace(']', '');
// Replace tags
switch (matchParsed) {
Expand Down Expand Up @@ -278,7 +278,7 @@ $countdownContainer.html(countdownHTML);
$(target).xiboLayoutScaler(properties);
// Render the countdown
const $contentContainer = $(target).find('#content');
var $contentContainer = $(target).find('#content');
$contentContainer.xiboCountdownRender(
properties,
$contentContainer.html(),
Expand Down
14 changes: 7 additions & 7 deletions modules/countdown-text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,17 @@ body {
</stencil>
<onRender><![CDATA[
// Make replacements on render for all templates
const $countdownContainer = $('.countdown-container', target);
var $countdownContainer = $('.countdown-container', target);
// Get countdown container html
let countdownHTML = $countdownContainer.html();
var countdownHTML = $countdownContainer.html();
// Make replacements
let text = countdownHTML;
let regex = /\[.*?\]/g;
var text = countdownHTML;
var regex = /\[.*?\]/g;
countdownHTML = text.replace(regex, function (match) {
let replacement = '';
let matchParsed = match.replace('[', '').replace(']', '');
var replacement = '';
var matchParsed = match.replace('[', '').replace(']', '');
// Replace tags
switch (matchParsed) {
Expand Down Expand Up @@ -233,7 +233,7 @@ $countdownContainer.html(countdownHTML);
$(target).xiboLayoutScaler(properties);
// Render the countdown
const $contentContainer = $(target).find('#content');
var $contentContainer = $(target).find('#content');
$contentContainer.xiboCountdownRender(
properties,
$contentContainer.html(),
Expand Down
5 changes: 0 additions & 5 deletions modules/stocks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@
</test>
</rule>
</property>
<property id="reverseConversion" type="checkbox">
<title>Reverse conversion?</title>
<helpText>Tick if you would like your base currency to be used as the comparison currency for each currency you've entered. For example base/compare becomes compare/base - USD/GBP becomes GBP/USD.</helpText>
<default>0</default>
</property>
<property id="dateFormat" type="text" variant="dateFormat">
<title>Date Format</title>
<helpText>The format to apply to all dates returned by the Widget.</helpText>
Expand Down

0 comments on commit 8757569

Please sign in to comment.