mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
Merge pull request #1304 from kjb085/kb/calendar-regex
Add regex filtering to calendar module
This commit is contained in:
commit
d47cfe9504
@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- Added option to calendar module that colors only the symbol instead of the whole line
|
- Added option to calendar module that colors only the symbol instead of the whole line
|
||||||
- Added option for new display format in the calendar module with date headers with times/events below.
|
- Added option for new display format in the calendar module with date headers with times/events below.
|
||||||
- Ability to fetch compliments from a remote server
|
- Ability to fetch compliments from a remote server
|
||||||
|
- Add regex filtering to calendar module
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Upgrade to Electron 2.0.0.
|
- Upgrade to Electron 2.0.0.
|
||||||
|
@ -48,7 +48,7 @@ The following properties can be configured:
|
|||||||
| `broadcastEvents` | If this property is set to true, the calendar will broadcast all the events to all other modules with the notification message: `CALENDAR_EVENTS`. The event objects are stored in an array and contain the following fields: `title`, `startDate`, `endDate`, `fullDayEvent`, `location` and `geo`. <br><br> **Possible values:** `true`, `false` <br><br> **Default value:** `true`
|
| `broadcastEvents` | If this property is set to true, the calendar will broadcast all the events to all other modules with the notification message: `CALENDAR_EVENTS`. The event objects are stored in an array and contain the following fields: `title`, `startDate`, `endDate`, `fullDayEvent`, `location` and `geo`. <br><br> **Possible values:** `true`, `false` <br><br> **Default value:** `true`
|
||||||
| `hidePrivate` | Hides private calendar events. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
|
| `hidePrivate` | Hides private calendar events. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
|
||||||
| `hideOngoing` | Hides calendar events that have already started. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
|
| `hideOngoing` | Hides calendar events that have already started. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
|
||||||
| `excludedEvents` | An array of words / phrases from event titles that will be excluded from being shown. <br><br>Additionally advanced filter objects can be passed in. Below is the configuration for the advance filtering object.<br>**Required**<br>`filterBy` - string used to determine if filter is applied.<br>**Optional**<br>`until` - Time before an event to display it Ex: [`'3 days'`, `'2 months'`, `'1 week'`]<br>`caseSensitive` - By default, excludedEvents are case insensitive, set this to true to enforce case sensitivity<br><br> **Example:** `['Birthday', 'Hide This Event', {filterBy: 'Payment', until: '6 days', caseSensitive: true}]` <br> **Default value:** `[]`
|
| `excludedEvents` | An array of words / phrases from event titles that will be excluded from being shown. <br><br>Additionally advanced filter objects can be passed in. Below is the configuration for the advance filtering object.<br>**Required**<br>`filterBy` - string used to determine if filter is applied.<br>**Optional**<br>`until` - Time before an event to display it Ex: [`'3 days'`, `'2 months'`, `'1 week'`]<br>`caseSensitive` - By default, excludedEvents are case insensitive, set this to true to enforce case sensitivity<br>`regex` - set to `true` if filterBy is a regex. For those not familiar with regex it is used for pattern matching, please see [here](https://regexr.com/) for more info.<br><br> **Example:** `['Birthday', 'Hide This Event', {filterBy: 'Payment', until: '6 days', caseSensitive: true}, {filterBy: '^[0-9]{1,}.*', regex: true}]` <br> **Default value:** `[]`
|
||||||
|
|
||||||
### Calendar configuration
|
### Calendar configuration
|
||||||
|
|
||||||
|
@ -119,19 +119,29 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
|||||||
for (var f in excludedEvents) {
|
for (var f in excludedEvents) {
|
||||||
var filter = excludedEvents[f],
|
var filter = excludedEvents[f],
|
||||||
testTitle = title.toLowerCase(),
|
testTitle = title.toLowerCase(),
|
||||||
until = null;
|
until = null,
|
||||||
|
useRegex = false,
|
||||||
|
regexFlags = "g";
|
||||||
|
|
||||||
if (filter instanceof Object) {
|
if (filter instanceof Object) {
|
||||||
if (typeof filter.until !== "undefined") {
|
if (typeof filter.until !== "undefined") {
|
||||||
until = filter.until;
|
until = filter.until;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof filter.regex !== "undefined") {
|
||||||
|
useRegex = filter.regex;
|
||||||
|
}
|
||||||
|
|
||||||
// If additional advanced filtering is added in, this section
|
// If additional advanced filtering is added in, this section
|
||||||
// must remain last as we overwrite the filter object with the
|
// must remain last as we overwrite the filter object with the
|
||||||
// filterBy string
|
// filterBy string
|
||||||
if (filter.caseSensitive) {
|
if (filter.caseSensitive) {
|
||||||
filter = filter.filterBy;
|
filter = filter.filterBy;
|
||||||
testTitle = title;
|
testTitle = title;
|
||||||
|
} else if (useRegex) {
|
||||||
|
filter = filter.filterBy;
|
||||||
|
testTitle = title;
|
||||||
|
regexFlags += "i";
|
||||||
} else {
|
} else {
|
||||||
filter = filter.filterBy.toLowerCase();
|
filter = filter.filterBy.toLowerCase();
|
||||||
}
|
}
|
||||||
@ -139,7 +149,7 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
|||||||
filter = filter.toLowerCase();
|
filter = filter.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (testTitle.includes(filter)) {
|
if (testTitleByFilter(testTitle, filter, useRegex, regexFlags)) {
|
||||||
if (until) {
|
if (until) {
|
||||||
dateFilter = until;
|
dateFilter = until;
|
||||||
} else {
|
} else {
|
||||||
@ -294,6 +304,22 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var testTitleByFilter = function (title, filter, useRegex, regexFlags) {
|
||||||
|
if (useRegex) {
|
||||||
|
// Assume if leading slash, there is also trailing slash
|
||||||
|
if (filter[0] === "/") {
|
||||||
|
// Strip leading and trailing slashes
|
||||||
|
filter = filter.substr(1).slice(0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
filter = new RegExp(filter, regexFlags);
|
||||||
|
|
||||||
|
return filter.test(title);
|
||||||
|
} else {
|
||||||
|
return title.includes(filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* public methods */
|
/* public methods */
|
||||||
|
|
||||||
/* startFetch()
|
/* startFetch()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user