Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar widget issues with triggers and number of items #2792

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 - 1))};
]]></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