Skip to content

Commit

Permalink
Calendar widget issues with triggers and number of items (#2792)
Browse files Browse the repository at this point in the history
* Widget: calendar not sending trigger events
 fixes to xibosignage/xibo#3509

* Widget: calendar number of items to be handled by onDataLoad.
 fixes to xibosignage/xibo#3515
  • Loading branch information
dasgarner authored Nov 6, 2024
1 parent 277c981 commit bafd9fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
29 changes: 19 additions & 10 deletions modules/calendar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@
// meta: Metadata
// properties: The properties for the widget
// Track whether there is an event currently ongoing
window.ongoingEvent = false;
// Process events
var now = moment();
for(var idx = 0; idx < items.length; idx++) {
Expand All @@ -194,9 +198,7 @@ for(var idx = 0; idx < items.length; idx++) {
var endDate = moment(item.endDate);
// Check if there is an event ongoing and change it if the variable isn't set or is false
if ((typeof ongoingEvent != 'undefined' || !window.ongoingEvent) && startDate.isBefore(now) && endDate.isAfter(now)) {
window.ongoingEvent = true;
}
window.ongoingEvent = window.ongoingEvent || (startDate.isBefore(now) && endDate.isAfter(now));
if (endDate.isAfter(now)) {
if (moment(items[idx].startDate).isBefore(now)) {
Expand All @@ -206,7 +208,7 @@ for(var idx = 0; idx < items.length; idx++) {
}
}
if(endDate.isBefore(now)) {
if (endDate.isBefore(now)) {
items[idx].pastEvent = true;
} else {
items[idx].pastEvent = false;
Expand All @@ -226,20 +228,27 @@ for(var idx = 0; idx < items.length; idx++) {
}
}
return {dataItems: items};
// If we have numItems, send only that number
var numItems = properties.numItems && properties.numItems < items.length
? properties.numItems
: items.length;
return {dataItems: items.slice(0, numItems)};
]]></onDataLoad>
<onRender>
<![CDATA[
// Module renderer options
// id: The id of the widget
// target: The target element to render
// properties: The properties for the <widget></widget>
if(typeof ongoingEvent != 'undefined' && ongoingEvent && properties.currentEventTrigger) {
// If there is an event now, send the Current Event trigger ( if exists )
xiboIC.trigger(properties.currentEventTrigger);
} else if(properties.noEventTrigger) {
// Event triggers
if (properties.currentEventTrigger && window.ongoingEvent) {
// If there is an event now, send the Current Event trigger (if exists)
xiboIC.trigger(properties.currentEventTrigger, {targetId: 0});
} else if (properties.noEventTrigger) {
// If there is no event now, send the No Event trigger
xiboIC.trigger(properties.noEventTrigger);
xiboIC.trigger(properties.noEventTrigger, {targetId: 0});
}
]]></onRender>
<sampleData><![CDATA[
Expand Down
10 changes: 2 additions & 8 deletions modules/templates/event-static.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
~ Copyright (C) 2023 Xibo Signage Ltd
~ Copyright (C) 2024 Xibo Signage Ltd
~
~ Xibo - Digital Signage - https://xibosignage.com
~
Expand Down Expand Up @@ -112,13 +112,7 @@ if (items.length <= 0 && properties.noDataMessage && properties.noDataMessage !=
$(target).find('#content').empty();
// Add items to container
// If we have numItems, send only that number
var numItems =
properties.numItems && properties.numItems < items.length ?
properties.numItems :
items.length;
for (var index = 0; index < numItems; index++) {
for (var index = 0; index < items.length; index++) {
var $newItem = $('<div>').addClass('event').html(items[index]).appendTo('body');
$(target).find('#content').append($newItem);
}
Expand Down

0 comments on commit bafd9fd

Please sign in to comment.