Skip to content

Commit 33e76c1

Browse files
authored
Merge pull request #193 from FamousWolf/138-filter-event-text
[FEATURE] Add options to filter event text
2 parents fdc9dbf + 0851dab commit 33e76c1

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Custom Home Assistant card displaying a responsive overview of multiple days wit
7979
| `hideDaysWithoutEvents` | boolean | false | `false` \| `true` | Do not show days without events, except for today | 1.4.0 |
8080
| `hideTodayWithoutEvents` | boolean | false | `false` \| `true` | Also do not show today without events if `hideDaysWithoutEvents` is set | 1.8.0 |
8181
| `filter` | string | optional | Any regular expression | Remove events that match the regular expression | 1.7.0 |
82+
| `filterText` | string | optional | Any regular expression | Remove text from events | 1.10.0 |
8283
| `combineSimilarEvents` | boolean | false | `false` \| `true` | Combine events with the same start date/time, end date/time and title | 1.9.0 |
8384
| `showLegend` | boolean | false | `false` \| `true` | Show calendar legend | 1.7.0 |
8485

@@ -89,8 +90,9 @@ Custom Home Assistant card displaying a responsive overview of multiple days wit
8990
| `entity` | string | **Required** | `calendar.my_calendar` | Entity ID | 1.0.0 |
9091
| `name` | string | optional | Any text | Name of the calendar | 1.7.0 |
9192
| `color` | string | optional | Any CSS color | Color used for events from the calendar | 1.0.0 |
92-
| `icon` | string | optional | Any icon | Icon used for events from the calendar | 1.0.0 |
93+
| `icon` | string | optional | Any icon | Icon used for events from the calendar | 1.10.0 |
9394
| `filter` | string | optional | Any regular expression | Remove events that match the regular expression | 1.8.0 |
95+
| `filterText` | string | optional | Any regular expression | Remove text from events | 1.10.0 |
9496
| `hideInLegend` | boolean | false | `false` \| `true` | Do not show the calendar in the legend | 1.8.0 |
9597

9698
### Texts

src/card.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export class WeekPlannerCard extends LitElement {
7878
_hideDaysWithoutEvents;
7979
_hideTodayWithoutEvents;
8080
_filter;
81+
_filterText;
8182
_combineSimilarEvents;
8283
_showLegend;
8384
_actions;
@@ -170,6 +171,7 @@ export class WeekPlannerCard extends LitElement {
170171
this._hideDaysWithoutEvents = config.hideDaysWithoutEvents ?? false;
171172
this._hideTodayWithoutEvents = config.hideTodayWithoutEvents ?? false;
172173
this._filter = config.filter ?? false;
174+
this._filterText = config.filterText ?? false;
173175
this._combineSimilarEvents = config.combineSimilarEvents ?? false;
174176
this._showLegend = config.showLegend ?? false;
175177
this._actions = config.actions ?? false;
@@ -676,7 +678,7 @@ export class WeekPlannerCard extends LitElement {
676678
}
677679
} else {
678680
this._calendarEvents[eventKey] = {
679-
summary: event.summary ?? null,
681+
summary: this._filterEventSummary(event.summary ?? null, calendar),
680682
description: event.description ?? null,
681683
location: event.location ?? null,
682684
start: startDate,
@@ -697,6 +699,22 @@ export class WeekPlannerCard extends LitElement {
697699
}
698700
}
699701

702+
_filterEventSummary(summary, calendar) {
703+
if (!summary) {
704+
return '';
705+
}
706+
707+
if (calendar.filterText) {
708+
summary = summary.replace(new RegExp(calendar.filterText), '');
709+
}
710+
711+
if (this._filterText) {
712+
summary = summary.replace(new RegExp(this._filterText), '');
713+
}
714+
715+
return summary;
716+
}
717+
700718
_getEventClass(startDate, endDate, fullDay) {
701719
let classes = [];
702720
let now = DateTime.now();

src/editor.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class WeekPlannerCardEditor extends LitElement {
3636
${this.addTextField('calendars.' + index + '.color', 'Color')}
3737
${this.addTextField('calendars.' + index + '.icon', 'Icon')}
3838
${this.addTextField('calendars.' + index + '.filter', 'Filter events (regex)')}
39+
${this.addTextField('calendars.' + index + '.filterText', 'Filter event text (regex)')}
3940
${this.addBooleanField('calendars.' + index + '.hideInLegend', 'Hide in legend')}
4041
${this.addButton('Remove calendar', 'mdi:trash-can', () => {
4142
const config = Object.assign({}, this._config);
@@ -105,6 +106,7 @@ export class WeekPlannerCardEditor extends LitElement {
105106
html`
106107
${this.addBooleanField('hidePastEvents', 'Hide past events')}
107108
${this.addTextField('filter', 'Filter events (regex)')}
109+
${this.addTextField('filterText', 'Filter event text (regex)')}
108110
${this.addBooleanField('combineSimilarEvents', 'Combine similar events')}
109111
${this.addBooleanField('showLocation', 'Show location in overview')}
110112
${this.addTextField('locationLink', 'Override location link base URL')}

0 commit comments

Comments
 (0)