Skip to content

Commit

Permalink
[FEATURE] Add options to filter event text
Browse files Browse the repository at this point in the history
Resolves: #138
  • Loading branch information
Rudy committed Nov 20, 2024
1 parent fdc9dbf commit 0851dab
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Custom Home Assistant card displaying a responsive overview of multiple days wit
| `hideDaysWithoutEvents` | boolean | false | `false` \| `true` | Do not show days without events, except for today | 1.4.0 |
| `hideTodayWithoutEvents` | boolean | false | `false` \| `true` | Also do not show today without events if `hideDaysWithoutEvents` is set | 1.8.0 |
| `filter` | string | optional | Any regular expression | Remove events that match the regular expression | 1.7.0 |
| `filterText` | string | optional | Any regular expression | Remove text from events | 1.10.0 |
| `combineSimilarEvents` | boolean | false | `false` \| `true` | Combine events with the same start date/time, end date/time and title | 1.9.0 |
| `showLegend` | boolean | false | `false` \| `true` | Show calendar legend | 1.7.0 |

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

### Texts
Expand Down
20 changes: 19 additions & 1 deletion src/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class WeekPlannerCard extends LitElement {
_hideDaysWithoutEvents;
_hideTodayWithoutEvents;
_filter;
_filterText;
_combineSimilarEvents;
_showLegend;
_actions;
Expand Down Expand Up @@ -170,6 +171,7 @@ export class WeekPlannerCard extends LitElement {
this._hideDaysWithoutEvents = config.hideDaysWithoutEvents ?? false;
this._hideTodayWithoutEvents = config.hideTodayWithoutEvents ?? false;
this._filter = config.filter ?? false;
this._filterText = config.filterText ?? false;
this._combineSimilarEvents = config.combineSimilarEvents ?? false;
this._showLegend = config.showLegend ?? false;
this._actions = config.actions ?? false;
Expand Down Expand Up @@ -676,7 +678,7 @@ export class WeekPlannerCard extends LitElement {
}
} else {
this._calendarEvents[eventKey] = {
summary: event.summary ?? null,
summary: this._filterEventSummary(event.summary ?? null, calendar),
description: event.description ?? null,
location: event.location ?? null,
start: startDate,
Expand All @@ -697,6 +699,22 @@ export class WeekPlannerCard extends LitElement {
}
}

_filterEventSummary(summary, calendar) {
if (!summary) {
return '';
}

if (calendar.filterText) {
summary = summary.replace(new RegExp(calendar.filterText), '');
}

if (this._filterText) {
summary = summary.replace(new RegExp(this._filterText), '');
}

return summary;
}

_getEventClass(startDate, endDate, fullDay) {
let classes = [];
let now = DateTime.now();
Expand Down
2 changes: 2 additions & 0 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class WeekPlannerCardEditor extends LitElement {
${this.addTextField('calendars.' + index + '.color', 'Color')}
${this.addTextField('calendars.' + index + '.icon', 'Icon')}
${this.addTextField('calendars.' + index + '.filter', 'Filter events (regex)')}
${this.addTextField('calendars.' + index + '.filterText', 'Filter event text (regex)')}
${this.addBooleanField('calendars.' + index + '.hideInLegend', 'Hide in legend')}
${this.addButton('Remove calendar', 'mdi:trash-can', () => {
const config = Object.assign({}, this._config);
Expand Down Expand Up @@ -105,6 +106,7 @@ export class WeekPlannerCardEditor extends LitElement {
html`
${this.addBooleanField('hidePastEvents', 'Hide past events')}
${this.addTextField('filter', 'Filter events (regex)')}
${this.addTextField('filterText', 'Filter event text (regex)')}
${this.addBooleanField('combineSimilarEvents', 'Combine similar events')}
${this.addBooleanField('showLocation', 'Show location in overview')}
${this.addTextField('locationLink', 'Override location link base URL')}
Expand Down

0 comments on commit 0851dab

Please sign in to comment.