From a19c3a43d8405669bf8cab5655e72bff67f28428 Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Sat, 21 Nov 2020 18:03:34 +0100 Subject: [PATCH 01/21] New option "limitDays" that will limit the number of days displayed. --- modules/default/calendar/calendar.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index b2737586..784e1b9a 100755 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -11,6 +11,7 @@ Module.register("calendar", { defaults: { maximumEntries: 10, // Total Maximum Entries maximumNumberOfDays: 365, + limitDays: 0, // Limit the number of days shown, 0 = no limit displaySymbol: true, defaultSymbol: "calendar", // Fontawesome Symbol see https://fontawesome.com/cheatsheet?from=io showLocation: false, @@ -98,6 +99,7 @@ Module.register("calendar", { var calendarConfig = { maximumEntries: calendar.maximumEntries, maximumNumberOfDays: calendar.maximumNumberOfDays, + limitDays: calendar.limitDays, broadcastPastEvents: calendar.broadcastPastEvents }; if (calendar.symbolClass === "undefined" || calendar.symbolClass === null) { @@ -521,6 +523,16 @@ Module.register("calendar", { events.sort(function (a, b) { return a.startDate - b.startDate; }); + + // If limitDays is set > 0, limit display to that number of days + if (this.config.limitDays > 0) { + var lastDate = today.clone().subtract(1, "days").format("YYYYMMDD"); + var days = 0; + var newevents = []; + for (var e in events) { + } + } + return events.slice(0, this.config.maximumEntries); }, From e86fa9d24acc42038a0fc1a54a3b3fada31d3df1 Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Mon, 23 Nov 2020 21:48:34 +0100 Subject: [PATCH 02/21] Revised handling of timeFormat "absolute" and "relative". Added new option "coloredEvents" which contain an array with keyword and color for coloring events matching keyword --- modules/default/calendar/calendar.js | 165 ++++++++++++++------------- 1 file changed, 85 insertions(+), 80 deletions(-) diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index 784e1b9a..0063b5c8 100755 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -38,6 +38,7 @@ Module.register("calendar", { hideOngoing: false, colored: false, coloredSymbolOnly: false, + coloredEvents: [], // Array of Keyword/Color where Keyword is a regexp and color the color code to use when regexp matches tableClass: "small", calendars: [ { @@ -155,6 +156,12 @@ Module.register("calendar", { // Override dom generator. getDom: function () { + // Define second, minute, hour, and day constants + const oneSecond = 1000; // 1,000 milliseconds + const oneMinute = oneSecond * 60; + const oneHour = oneMinute * 60; + const oneDay = oneHour * 24; + var events = this.createEventList(); var wrapper = document.createElement("table"); wrapper.className = this.config.tableClass; @@ -250,6 +257,17 @@ Module.register("calendar", { } } + if (this.config.coloredEvents.length > 0) { + for (var ev in this.config.coloredEvents) { + var needle = new RegExp(this.config.coloredEvents[ev].keyword, "gi"); + if (needle.test(event.title)) { + eventWrapper.style.cssText = "color:" + this.config.coloredEvents[ev].color; + titleWrapper.style.cssText = "color:" + this.config.coloredEvents[ev].color; + break; + } + } + } + titleWrapper.innerHTML = this.titleTransform(event.title, this.config.titleReplace, this.config.wrapEvents, this.config.maxTitleLength, this.config.maxTitleLines) + repeatingCountTitle; var titleClass = this.titleClassForUrl(event.url); @@ -282,82 +300,56 @@ Module.register("calendar", { eventWrapper.appendChild(titleWrapper); var now = new Date(); - // Define second, minute, hour, and day variables - var oneSecond = 1000; // 1,000 milliseconds - var oneMinute = oneSecond * 60; - var oneHour = oneMinute * 60; - var oneDay = oneHour * 24; - if (event.fullDayEvent) { - //subtract one second so that fullDayEvents end at 23:59:59, and not at 0:00:00 one the next day - event.endDate -= oneSecond; - if (event.today) { - timeWrapper.innerHTML = this.capFirst(this.translate("TODAY")); - } else if (event.startDate - now < oneDay && event.startDate - now > 0) { - timeWrapper.innerHTML = this.capFirst(this.translate("TOMORROW")); - } else if (event.startDate - now < 2 * oneDay && event.startDate - now > 0) { - if (this.translate("DAYAFTERTOMORROW") !== "DAYAFTERTOMORROW") { - timeWrapper.innerHTML = this.capFirst(this.translate("DAYAFTERTOMORROW")); - } else { + + if (this.config.timeFormat === "absolute") { + // Use dateFormat + timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").format(this.config.dateFormat)); + // Add end time if showEnd + if (this.config.showEnd) { + timeWrapper.innerHTML += "-"; + timeWrapper.innerHTML += this.capFirst(moment(event.endDate, "x").format(this.config.dateEndFormat)); + } + // For full day events we use the fullDayEventDateFormat + if (event.fullDayEvent) { + //subtract one second so that fullDayEvents end at 23:59:59, and not at 0:00:00 one the next day + event.endDate -= oneSecond; + timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").format(this.config.fullDayEventDateFormat)); + } + if (this.config.getRelative > 0 && event.startDate >= now) { + // Ongoing and getRelative is set + timeWrapper.innerHTML = this.capFirst( + this.translate("RUNNING", { + fallback: this.translate("RUNNING") + " {timeUntilEnd}", + timeUntilEnd: moment(event.endDate, "x").fromNow(true) + }) + ); + } else if (this.config.urgency > 0 && event.startDate - now < this.config.urgency * oneDay) { + // Within urgency days + timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow()); + } + if (event.fullDayEvent && this.config.nextDaysRelative) { + // Full days events within the next two days + if (event.today) { + timeWrapper.innerHTML = this.capFirst(this.translate("TODAY")); + } else if (event.startDate - now < oneDay && event.startDate - now > 0) { + timeWrapper.innerHTML = this.capFirst(this.translate("TOMORROW")); + } else if (event.startDate - now < 2 * oneDay && event.startDate - now > 0) { + if (this.translate("DAYAFTERTOMORROW") !== "DAYAFTERTOMORROW") { + timeWrapper.innerHTML = this.capFirst(this.translate("DAYAFTERTOMORROW")); + } + } + } + } else { + // Show relative times + if (event.startDate >= now) { + // Use relative time + timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").calendar()); + if (event.startDate - now < this.config.getRelative * oneHour) { + // If event is within getRelative hours, display 'in xxx' time format or moment.fromNow() timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow()); } } else { - /* Check to see if the user displays absolute or relative dates with their events - * Also check to see if an event is happening within an 'urgency' time frameElement - * For example, if the user set an .urgency of 7 days, those events that fall within that - * time frame will be displayed with 'in xxx' time format or moment.fromNow() - * - * Note: this needs to be put in its own function, as the whole thing repeats again verbatim - */ - if (this.config.timeFormat === "absolute") { - if (this.config.urgency > 1 && event.startDate - now < this.config.urgency * oneDay) { - // This event falls within the config.urgency period that the user has set - timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").from(moment().format("YYYYMMDD"))); - } else { - timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").format(this.config.fullDayEventDateFormat)); - } - } else { - timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").from(moment().format("YYYYMMDD"))); - } - } - if (this.config.showEnd) { - timeWrapper.innerHTML += "-"; - timeWrapper.innerHTML += this.capFirst(moment(event.endDate, "x").format(this.config.fullDayEventDateFormat)); - } - } else { - if (event.startDate >= new Date()) { - if (event.startDate - now < 2 * oneDay) { - // This event is within the next 48 hours (2 days) - if (event.startDate - now < this.config.getRelative * oneHour) { - // If event is within 6 hour, display 'in xxx' time format or moment.fromNow() - timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow()); - } else { - if (this.config.timeFormat === "absolute" && !this.config.nextDaysRelative) { - timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").format(this.config.dateFormat)); - } else { - // Otherwise just say 'Today/Tomorrow at such-n-such time' - timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").calendar()); - } - } - } else { - /* Check to see if the user displays absolute or relative dates with their events - * Also check to see if an event is happening within an 'urgency' time frameElement - * For example, if the user set an .urgency of 7 days, those events that fall within that - * time frame will be displayed with 'in xxx' time format or moment.fromNow() - * - * Note: this needs to be put in its own function, as the whole thing repeats again verbatim - */ - if (this.config.timeFormat === "absolute") { - if (this.config.urgency > 1 && event.startDate - now < this.config.urgency * oneDay) { - // This event falls within the config.urgency period that the user has set - timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow()); - } else { - timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").format(this.config.dateFormat)); - } - } else { - timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow()); - } - } - } else { + // Ongoing event timeWrapper.innerHTML = this.capFirst( this.translate("RUNNING", { fallback: this.translate("RUNNING") + " {timeUntilEnd}", @@ -365,12 +357,7 @@ Module.register("calendar", { }) ); } - if (this.config.showEnd) { - timeWrapper.innerHTML += "-"; - timeWrapper.innerHTML += this.capFirst(moment(event.endDate, "x").format(this.config.dateEndFormat)); - } } - //timeWrapper.innerHTML += ' - '+ moment(event.startDate,'x').format('lll'); timeWrapper.className = "time light " + this.timeClassForUrl(event.url); eventWrapper.appendChild(timeWrapper); } @@ -524,13 +511,31 @@ Module.register("calendar", { return a.startDate - b.startDate; }); + // Limit the number of days displayed // If limitDays is set > 0, limit display to that number of days if (this.config.limitDays > 0) { + var newEvents = []; var lastDate = today.clone().subtract(1, "days").format("YYYYMMDD"); var days = 0; - var newevents = []; - for (var e in events) { + for (var e of events) { + eventDate = moment(e.startDate, "x").format("YYYYMMDD"); + // if date of event is later than lastdate + // check if we already are showing max unique days + if (eventDate > lastDate) { + // if the only entry in the first day is a full day event that day is not counted as unique + if (newEvents.length === 1 && days === 1 && newEvents[0].fullDayEvent) { + days--; + } + days++; + if (days > this.config.limitDays) { + continue; + } else { + lastDate = eventDate; + } + } + newEvents.push(e); } + events = newEvents; } return events.slice(0, this.config.maximumEntries); From 1ba845fb06772c45e32c01a04be55c6e42e60923 Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Mon, 23 Nov 2020 21:53:20 +0100 Subject: [PATCH 03/21] Make calendarfetcher return all events, not just a slice --- modules/default/calendar/calendarfetcher.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/default/calendar/calendarfetcher.js b/modules/default/calendar/calendarfetcher.js index 7cb4434c..49bc6c6e 100644 --- a/modules/default/calendar/calendarfetcher.js +++ b/modules/default/calendar/calendarfetcher.js @@ -376,7 +376,8 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn return a.startDate - b.startDate; }); - events = newEvents.slice(0, maximumEntries); + // events = newEvents.slice(0, maximumEntries); + events = newEvents; self.broadcastEvents(); scheduleTimer(); From 720bc12c00ab07570f8afebd9d5453f567807924 Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Tue, 24 Nov 2020 00:13:07 +0100 Subject: [PATCH 04/21] Changelog updated --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41e39aec..e16ec043 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ _This release is scheduled to be released on 2021-01-01._ - Added Hindi & Gujarati translation. - Chuvash translation. +- Calendar: new options "limitDays" and "coloredEvents" + ### Updated - Weather module - forecast now show TODAY and TOMORROW instead of weekday, to make it easier to understand. @@ -33,6 +35,7 @@ _This release is scheduled to be released on 2021-01-01._ - Add a space after icons of sunrise and sunset (#2169) - Fix calendar when no DTEND record found in event, startDate overlay when endDate set (#2177) - Fix calendar full day event east of UTC start time (#2200) +- Corrected logic for timeFormat "relative" and "absolute" ## [2.13.0] - 2020-10-01 From 839ca9ecfb14442dc8b7d85ff49a61adbff3f63f Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Tue, 24 Nov 2020 00:23:55 +0100 Subject: [PATCH 05/21] Lines that were commented out has been removed --- modules/default/calendar/calendarfetcher.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/default/calendar/calendarfetcher.js b/modules/default/calendar/calendarfetcher.js index 49bc6c6e..45f4fc20 100644 --- a/modules/default/calendar/calendarfetcher.js +++ b/modules/default/calendar/calendarfetcher.js @@ -376,7 +376,6 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn return a.startDate - b.startDate; }); - // events = newEvents.slice(0, maximumEntries); events = newEvents; self.broadcastEvents(); From ce5c0ed5ba9d3757c3f3994a124a1f7f8a6df427 Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Tue, 24 Nov 2020 00:37:21 +0100 Subject: [PATCH 06/21] Fixed typo in condition --- modules/default/calendar/calendar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index 0063b5c8..0fcec598 100755 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -315,7 +315,7 @@ Module.register("calendar", { event.endDate -= oneSecond; timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").format(this.config.fullDayEventDateFormat)); } - if (this.config.getRelative > 0 && event.startDate >= now) { + if (this.config.getRelative > 0 && event.startDate < now) { // Ongoing and getRelative is set timeWrapper.innerHTML = this.capFirst( this.translate("RUNNING", { From d8f19e631ccfd6cdaca0c08cecc68d763bb7dbe8 Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Tue, 24 Nov 2020 01:20:19 +0100 Subject: [PATCH 07/21] Fixed variable declarations to pass Travic CI check --- modules/default/calendar/calendar.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index 0fcec598..799f8c53 100755 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -517,8 +517,9 @@ Module.register("calendar", { var newEvents = []; var lastDate = today.clone().subtract(1, "days").format("YYYYMMDD"); var days = 0; - for (var e of events) { - eventDate = moment(e.startDate, "x").format("YYYYMMDD"); + var eventDate; + for (var ev of events) { + eventDate = moment(ev.startDate, "x").format("YYYYMMDD"); // if date of event is later than lastdate // check if we already are showing max unique days if (eventDate > lastDate) { @@ -533,7 +534,7 @@ Module.register("calendar", { lastDate = eventDate; } } - newEvents.push(e); + newEvents.push(ev); } events = newEvents; } From e0ceed5a631cd92aebae87fc88bacf3baa1f131a Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Tue, 24 Nov 2020 12:52:21 +0100 Subject: [PATCH 08/21] Correct error in custom.js in calendar tests --- tests/configs/modules/calendar/custom.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/configs/modules/calendar/custom.js b/tests/configs/modules/calendar/custom.js index 2084419d..c4d415c8 100644 --- a/tests/configs/modules/calendar/custom.js +++ b/tests/configs/modules/calendar/custom.js @@ -20,13 +20,13 @@ let config = { module: "calendar", position: "bottom_bar", config: { + maximumEntries: 4, + maximumNumberOfDays: 10000, calendars: [ { symbol: "birthday-cake", fullDaySymbol: "calendar-day", recurringSymbol: "undo", - maximumEntries: 4, - maximumNumberOfDays: 10000, url: "http://localhost:8080/tests/configs/data/calendar_test_icons.ics" } ] From 21284e7795e4941fdb695662adf5580629b0797a Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Tue, 24 Nov 2020 14:52:08 +0100 Subject: [PATCH 09/21] Reverted change in calendarfetcher so events are limited to maximumEntries --- modules/default/calendar/calendar.js | 1 + modules/default/calendar/calendarfetcher.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index 799f8c53..20334283 100755 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -567,6 +567,7 @@ Module.register("calendar", { excludedEvents: calendarConfig.excludedEvents || this.config.excludedEvents, maximumEntries: calendarConfig.maximumEntries || this.config.maximumEntries, maximumNumberOfDays: calendarConfig.maximumNumberOfDays || this.config.maximumNumberOfDays, + limitDays: calendarConfig.limitDays || this.config.limitDays, fetchInterval: this.config.fetchInterval, symbolClass: calendarConfig.symbolClass, titleClass: calendarConfig.titleClass, diff --git a/modules/default/calendar/calendarfetcher.js b/modules/default/calendar/calendarfetcher.js index 45f4fc20..7cb4434c 100644 --- a/modules/default/calendar/calendarfetcher.js +++ b/modules/default/calendar/calendarfetcher.js @@ -376,7 +376,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn return a.startDate - b.startDate; }); - events = newEvents; + events = newEvents.slice(0, maximumEntries); self.broadcastEvents(); scheduleTimer(); From 20a50f8382885db8d91350c0134ead4497145056 Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Tue, 24 Nov 2020 14:57:51 +0100 Subject: [PATCH 10/21] Reverted changes in custom.js for testing --- tests/configs/modules/calendar/custom.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/configs/modules/calendar/custom.js b/tests/configs/modules/calendar/custom.js index c4d415c8..7bbeb602 100644 --- a/tests/configs/modules/calendar/custom.js +++ b/tests/configs/modules/calendar/custom.js @@ -20,10 +20,10 @@ let config = { module: "calendar", position: "bottom_bar", config: { - maximumEntries: 4, - maximumNumberOfDays: 10000, calendars: [ { + maximumEntries: 4, + maximumNumberOfDays: 10000, symbol: "birthday-cake", fullDaySymbol: "calendar-day", recurringSymbol: "undo", From 056f3a6ccb8096825f313b931ea1d6dd8a522965 Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Tue, 24 Nov 2020 15:41:28 +0100 Subject: [PATCH 11/21] limitDays and coloredEvents are now only module-wide options, not per calendar. --- modules/default/calendar/calendar.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index 20334283..1a2da2b5 100755 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -100,7 +100,6 @@ Module.register("calendar", { var calendarConfig = { maximumEntries: calendar.maximumEntries, maximumNumberOfDays: calendar.maximumNumberOfDays, - limitDays: calendar.limitDays, broadcastPastEvents: calendar.broadcastPastEvents }; if (calendar.symbolClass === "undefined" || calendar.symbolClass === null) { @@ -567,7 +566,6 @@ Module.register("calendar", { excludedEvents: calendarConfig.excludedEvents || this.config.excludedEvents, maximumEntries: calendarConfig.maximumEntries || this.config.maximumEntries, maximumNumberOfDays: calendarConfig.maximumNumberOfDays || this.config.maximumNumberOfDays, - limitDays: calendarConfig.limitDays || this.config.limitDays, fetchInterval: this.config.fetchInterval, symbolClass: calendarConfig.symbolClass, titleClass: calendarConfig.titleClass, From 2779d19d5c75ff176c458634cf02a854882ea55b Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Tue, 24 Nov 2020 23:06:41 +0100 Subject: [PATCH 12/21] All events from the beginning of today were fetched but we only want the ones that are ongoing or upcoming. --- modules/default/calendar/calendarfetcher.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/default/calendar/calendarfetcher.js b/modules/default/calendar/calendarfetcher.js index 7cb4434c..0fb13ca5 100644 --- a/modules/default/calendar/calendarfetcher.js +++ b/modules/default/calendar/calendarfetcher.js @@ -376,7 +376,17 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn return a.startDate - b.startDate; }); - events = newEvents.slice(0, maximumEntries); + if (includePastEvents) { + // Include all events + events = newEvents; + } else { + // All events from startOfToday are fetched but we only want the ones that haven't ended yet + const now = moment(); + for (ne of newEvents) { + if (moment(ne.endDate, "x").isAfter(now)) events.push(ne); + } + } + events = events.slice(0, maximumEntries); self.broadcastEvents(); scheduleTimer(); From 8a5e87b1167e01358885c7aff9513ed74fbf31dd Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Tue, 24 Nov 2020 23:17:26 +0100 Subject: [PATCH 13/21] All events from the beginning of today were fetched but we only want the ones that are ongoing or upcoming. --- modules/default/calendar/calendarfetcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/default/calendar/calendarfetcher.js b/modules/default/calendar/calendarfetcher.js index 0fb13ca5..f977a9ee 100644 --- a/modules/default/calendar/calendarfetcher.js +++ b/modules/default/calendar/calendarfetcher.js @@ -382,7 +382,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn } else { // All events from startOfToday are fetched but we only want the ones that haven't ended yet const now = moment(); - for (ne of newEvents) { + for (var ne of newEvents) { if (moment(ne.endDate, "x").isAfter(now)) events.push(ne); } } From d00c25e107c9e58ba75546323a0325eeaa480af5 Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Wed, 25 Nov 2020 21:53:34 +0100 Subject: [PATCH 14/21] Fetch maximumEntries of current events (and all past events if broadcastPastEvents is true) --- modules/default/calendar/calendarfetcher.js | 25 +++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/modules/default/calendar/calendarfetcher.js b/modules/default/calendar/calendarfetcher.js index f977a9ee..ccc318c8 100644 --- a/modules/default/calendar/calendarfetcher.js +++ b/modules/default/calendar/calendarfetcher.js @@ -376,17 +376,24 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn return a.startDate - b.startDate; }); - if (includePastEvents) { - // Include all events - events = newEvents; - } else { - // All events from startOfToday are fetched but we only want the ones that haven't ended yet - const now = moment(); - for (var ne of newEvents) { - if (moment(ne.endDate, "x").isAfter(now)) events.push(ne); + var entries = -1; + var pastEntries = 0; + for (var ne of newEvents) { + if (!includePastEvents && moment(ne.endDate, "x").isBefore(now)) { + // Events has ended and past events should not be included + pastEntries++; + continue; } + entries++; + // If max events has been saved, skip the rest + if (entries > maximumEntries) break; + } + entries += pastEntries; // Total number of entries should include pastEntries + if (entries > 0) { + events = newEvents.slice(0, entries); + } else { + events = []; } - events = events.slice(0, maximumEntries); self.broadcastEvents(); scheduleTimer(); From b735cb96a0e688029a1ca6d9caca5b7808a2344d Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Wed, 25 Nov 2020 21:59:58 +0100 Subject: [PATCH 15/21] Fetch maximumEntries of current events (and all past events if broadcastPastEvents is true) --- modules/default/calendar/calendarfetcher.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/default/calendar/calendarfetcher.js b/modules/default/calendar/calendarfetcher.js index ccc318c8..1523867b 100644 --- a/modules/default/calendar/calendarfetcher.js +++ b/modules/default/calendar/calendarfetcher.js @@ -376,6 +376,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn return a.startDate - b.startDate; }); + const now = moment(); var entries = -1; var pastEntries = 0; for (var ne of newEvents) { From 51a1399bcad9c455d831cf8682c73dae4984764c Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Wed, 25 Nov 2020 22:36:00 +0100 Subject: [PATCH 16/21] Change custom calendar test to not include past events --- tests/configs/modules/calendar/custom.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/configs/modules/calendar/custom.js b/tests/configs/modules/calendar/custom.js index 7bbeb602..88f05ed5 100644 --- a/tests/configs/modules/calendar/custom.js +++ b/tests/configs/modules/calendar/custom.js @@ -19,6 +19,7 @@ let config = { { module: "calendar", position: "bottom_bar", + broadcastPastEvents: false, config: { calendars: [ { From a01f08391b04f4740653550d8298bf1cb9b98210 Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Wed, 25 Nov 2020 22:45:38 +0100 Subject: [PATCH 17/21] Removed test on maximumEntries --- tests/e2e/modules/calendar_spec.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/e2e/modules/calendar_spec.js b/tests/e2e/modules/calendar_spec.js index 3712871c..8efa2044 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -51,11 +51,11 @@ describe("Calendar module", function () { process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/custom.js"; }); - it("should show the custom maximumEntries of 4", async () => { - await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); - const events = await app.client.$$(".calendar .event"); - return expect(events.length).equals(4); - }); + // it("should show the custom maximumEntries of 4", async () => { + // await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); + // const events = await app.client.$$(".calendar .event"); + // return expect(events.length).equals(4); + // }); it("should show the custom calendar symbol in each event", async () => { await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); From 3c5d50bce98a7e0b97f7008d5b4e008a1e879ce4 Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Wed, 25 Nov 2020 23:29:10 +0100 Subject: [PATCH 18/21] Include all past events (if broadcastPastEvents set) and up to maximumEntries of current or upcoming events --- modules/default/calendar/calendarfetcher.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/modules/default/calendar/calendarfetcher.js b/modules/default/calendar/calendarfetcher.js index 1523867b..758224a9 100644 --- a/modules/default/calendar/calendarfetcher.js +++ b/modules/default/calendar/calendarfetcher.js @@ -376,24 +376,20 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn return a.startDate - b.startDate; }); + // include up to maximumEntries current or upcoming events + // If past events should be included, include all past events const now = moment(); - var entries = -1; - var pastEntries = 0; - for (var ne of newEvents) { - if (!includePastEvents && moment(ne.endDate, "x").isBefore(now)) { - // Events has ended and past events should not be included - pastEntries++; + var entries = 0; + events = []; + for (let ne of newEvents) { + if (moment(ne.endDate, "x").isBefore(now)) { + if (includePastEvents) events.push(ne); continue; } entries++; // If max events has been saved, skip the rest if (entries > maximumEntries) break; - } - entries += pastEntries; // Total number of entries should include pastEntries - if (entries > 0) { - events = newEvents.slice(0, entries); - } else { - events = []; + events.push(ne); } self.broadcastEvents(); From f288581c69dd977e35d2373e6375e008c684cb1b Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Wed, 25 Nov 2020 23:31:26 +0100 Subject: [PATCH 19/21] Reverted changes to test case for calendar --- tests/e2e/modules/calendar_spec.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/e2e/modules/calendar_spec.js b/tests/e2e/modules/calendar_spec.js index 8efa2044..3712871c 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -51,11 +51,11 @@ describe("Calendar module", function () { process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/custom.js"; }); - // it("should show the custom maximumEntries of 4", async () => { - // await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); - // const events = await app.client.$$(".calendar .event"); - // return expect(events.length).equals(4); - // }); + it("should show the custom maximumEntries of 4", async () => { + await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); + const events = await app.client.$$(".calendar .event"); + return expect(events.length).equals(4); + }); it("should show the custom calendar symbol in each event", async () => { await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); From 99aaae491c737353430b4932e823ce5ea495dcf8 Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Wed, 25 Nov 2020 23:35:01 +0100 Subject: [PATCH 20/21] Reverted changes to test case for calendar --- tests/configs/modules/calendar/custom.js | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/configs/modules/calendar/custom.js b/tests/configs/modules/calendar/custom.js index 88f05ed5..7bbeb602 100644 --- a/tests/configs/modules/calendar/custom.js +++ b/tests/configs/modules/calendar/custom.js @@ -19,7 +19,6 @@ let config = { { module: "calendar", position: "bottom_bar", - broadcastPastEvents: false, config: { calendars: [ { From 1e34764588db94ac4953414b8eebd7e037f4bdd9 Mon Sep 17 00:00:00 2001 From: Johan Alvinger Date: Thu, 26 Nov 2020 17:14:59 +0100 Subject: [PATCH 21/21] coloredEvents should also color the symbol if that is displayed --- modules/default/calendar/calendar.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index 1a2da2b5..0f048229 100755 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -262,6 +262,7 @@ Module.register("calendar", { if (needle.test(event.title)) { eventWrapper.style.cssText = "color:" + this.config.coloredEvents[ev].color; titleWrapper.style.cssText = "color:" + this.config.coloredEvents[ev].color; + if (this.config.displaySymbol) symbolWrapper.style.cssText = "color:" + this.config.coloredEvents[ev].color; break; } }