Merge pull request #2214 from Alvinger/customEvents

Custom events - Use custom symbol/color based on keyword in title
This commit is contained in:
Michael Teeuw 2020-12-08 15:21:39 +01:00 committed by GitHub
commit db874a011c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 9 deletions

View File

@ -17,6 +17,8 @@ _This release is scheduled to be released on 2021-01-01._
- Chuvash translation.
- Calendar: new options "limitDays" and "coloredEvents"
- Added new option "customEvents" - use custom symbol/color based on keyword in event title
### Updated
- Weather module - forecast now show TODAY and TOMORROW instead of weekday, to make it easier to understand.

View File

@ -38,7 +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
customEvents: [], // Array of {keyword: "", symbol: "", color: ""} where Keyword is a regexp and symbol/color are to be applied for matched
tableClass: "small",
calendars: [
{
@ -181,6 +181,8 @@ Module.register("calendar", {
var currentFadeStep = 0;
var lastSeenDate = "";
var ev;
var needle;
for (var e in events) {
var event = events[e];
@ -226,6 +228,19 @@ Module.register("calendar", {
symbolWrapper.className = "symbol align-right " + symbolClass;
var symbols = this.symbolsForEvent(event);
// If symbols are displayed and custom symbol is set, replace event symbol
if (this.config.displaySymbol && this.config.customEvents.length > 0) {
for (ev in this.config.customEvents) {
if (typeof this.config.customEvents[ev].symbol !== "undefined" && this.config.customEvents[ev].symbol !== "") {
needle = new RegExp(this.config.customEvents[ev].keyword, "gi");
if (needle.test(event.title)) {
symbols[0] = this.config.customEvents[ev].symbol;
break;
}
}
}
}
for (var i = 0; i < symbols.length; i++) {
var symbol = document.createElement("span");
symbol.className = "fa fa-fw fa-" + symbols[i];
@ -256,14 +271,20 @@ 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;
if (this.config.displaySymbol) symbolWrapper.style.cssText = "color:" + this.config.coloredEvents[ev].color;
break;
// Color events if custom color is specified
if (this.config.customEvents.length > 0) {
for (ev in this.config.customEvents) {
if (typeof this.config.customEvents[ev].color !== "undefined" && this.config.customEvents[ev].color !== "") {
needle = new RegExp(this.config.customEvents[ev].keyword, "gi");
if (needle.test(event.title)) {
eventWrapper.style.cssText = "color:" + this.config.customEvents[ev].color;
titleWrapper.style.cssText = "color:" + this.config.customEvents[ev].color;
if (this.config.displaySymbol) {
symbolWrapper.style.cssText = "color:" + this.config.customEvents[ev].color;
}
break;
}
}
}
}