Add eventClass for customEvents in calendar (#3193)

Hello,
This pull request allows you to add a class to the tr of the event
sought in customEvents. You must enter the class with the "eventClass"
option.

---------

Co-authored-by: TeddyStarinvest <teddy.payet@starinvest.com>
This commit is contained in:
Teddy 2023-09-20 22:04:41 +02:00 committed by GitHub
parent 8b1c279c07
commit a67a0b677c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 6 deletions

View File

@ -20,6 +20,7 @@ _This release is scheduled to be released on 2023-10-01._
- Added AnimateIn and animateOut in module config definition - Added AnimateIn and animateOut in module config definition
- Apply AnimateIn rules on the first start - Apply AnimateIn rules on the first start
- Added automatic client page reload when server was restarted by setting `reloadAfterServerRestart: true` in `config.js`, per default `false` (#3105) - Added automatic client page reload when server was restarted by setting `reloadAfterServerRestart: true` in `config.js`, per default `false` (#3105)
- Added eventClass option for customEvents on the default calendar
### Removed ### Removed

View File

@ -42,7 +42,7 @@ Module.register("calendar", {
hideDuplicates: true, hideDuplicates: true,
showTimeToday: false, showTimeToday: false,
colored: false, colored: false,
customEvents: [], // Array of {keyword: "", symbol: "", color: ""} where Keyword is a regexp and symbol/color are to be applied for matched customEvents: [], // Array of {keyword: "", symbol: "", color: "", eventClass: ""} where Keyword is a regexp and symbol/color/eventClass are to be applied for matched
tableClass: "small", tableClass: "small",
calendars: [ calendars: [
{ {
@ -321,12 +321,12 @@ Module.register("calendar", {
} }
} }
// Color events if custom color is specified // Color events if custom color or eventClass are specified
if (this.config.customEvents.length > 0) { if (this.config.customEvents.length > 0) {
for (let ev in this.config.customEvents) { for (let ev in this.config.customEvents) {
if (typeof this.config.customEvents[ev].color !== "undefined" && this.config.customEvents[ev].color !== "") {
let needle = new RegExp(this.config.customEvents[ev].keyword, "gi"); let needle = new RegExp(this.config.customEvents[ev].keyword, "gi");
if (needle.test(event.title)) { if (needle.test(event.title)) {
if (typeof this.config.customEvents[ev].color !== "undefined" && this.config.customEvents[ev].color !== "") {
// Respect parameter ColoredSymbolOnly also for custom events // Respect parameter ColoredSymbolOnly also for custom events
if (this.config.coloredText) { if (this.config.coloredText) {
eventWrapper.style.cssText = `color:${this.config.customEvents[ev].color}`; eventWrapper.style.cssText = `color:${this.config.customEvents[ev].color}`;
@ -337,6 +337,9 @@ Module.register("calendar", {
} }
break; break;
} }
if (typeof this.config.customEvents[ev].eventClass !== "undefined" && this.config.customEvents[ev].eventClass !== "") {
eventWrapper.className += ` ${this.config.customEvents[ev].eventClass}`;
}
} }
} }
} }

View File

@ -11,7 +11,7 @@ let config = {
module: "calendar", module: "calendar",
position: "bottom_bar", position: "bottom_bar",
config: { config: {
customEvents: [{ keyword: "CustomEvent", symbol: "dice" }], customEvents: [{ keyword: "CustomEvent", symbol: "dice", eventClass: "undo" }],
calendars: [ calendars: [
{ {
maximumEntries: 5, maximumEntries: 5,

View File

@ -60,6 +60,10 @@ describe("Calendar module", () => {
await testElementLength(".calendar .event .fa-dice", 1); await testElementLength(".calendar .event .fa-dice", 1);
}); });
it("should show a customEvent calendar eventClass in one event", async () => {
await testElementLength(".calendar .event.undo", 1);
});
it("should show two custom icons for repeating events", async () => { it("should show two custom icons for repeating events", async () => {
await testElementLength(".calendar .event .fa-undo", 2); await testElementLength(".calendar .event .fa-undo", 2);
}); });