Skip to content

Commit e77ea9a

Browse files
committed
Initial commit for MMM-NextEvent, based on Boaz Arad's excellent MMM-CountDown.
No issue #
1 parent eea1962 commit e77ea9a

11 files changed

+157
-87
lines changed

MMM-CountDown.css

-10
This file was deleted.

MMM-CountDown.js

-62
This file was deleted.

MMM-NextEvent.css

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
*
3+
* MMM-NextEvent
4+
*
5+
*
6+
* MIT Licensed.
7+
*
8+
* Custom here your css module
9+
*
10+
*/
11+
12+
.green {
13+
color: #0f0;
14+
}
15+
16+
.yellow {
17+
color: #ff0;
18+
}
19+
20+
.red {
21+
color: #f00;
22+
}

MMM-NextEvent.js

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
Module.register("MMM-NextEvent",{
2+
// Default module config.
3+
defaults: {
4+
event: "Next event",
5+
date: "3000-01-01",
6+
showHours: true,
7+
showMinutes: true,
8+
showSeconds: true,
9+
customInterval: 1000,
10+
daysLabel: 'd',
11+
hoursLabel: 'h',
12+
minutesLabel: 'm',
13+
secondsLabel: 's',
14+
},
15+
16+
// set update interval
17+
start: function() {
18+
var self = this;
19+
self.getEvents();
20+
setInterval(function() {
21+
self.getEvents();
22+
self.updateDom(); // no speed defined, so it updates instantly.
23+
}, this.config.customInterval);
24+
},
25+
26+
updateDate: function(events) {
27+
//console.log(events)
28+
events.sort((a, b) => a.startDate.localeCompare(b.startDate))
29+
if (typeof events[0] !== 'undefined') {
30+
this.config.event = events[0].title;
31+
this.config.date = events[0].startDateJ;
32+
} else {
33+
this.config.event = "Next event"
34+
this.config.date = "0000-00-00"
35+
}
36+
this.updateDom(); // no speed defined, so it updates instantly.
37+
},
38+
39+
getEvents: function() {
40+
var now = moment().format("X")
41+
var endOfDay = moment().endOf('day').format("X")
42+
var filterFn = (event) => {
43+
// Do not consider all-day events. Only consider events that start in the future in the next few days.
44+
if ((event.isFullday !== true) && (event.startDate > now) && (event.startDate < endOfDay)) return true
45+
}
46+
var callbackFn = (events) => {
47+
this.updateDate(events)
48+
}
49+
this.sendNotification("CALEXT2_EVENT_QUERY", {filter:filterFn, callback:callbackFn})
50+
},
51+
52+
getStyles: function() {
53+
return ["MMM-NextEvent.css"]
54+
},
55+
56+
// Update function
57+
getDom: function() {
58+
var wrapper = document.createElement("div");
59+
60+
var timeWrapper = document.createElement("div");
61+
var textWrapper = document.createElement("div");
62+
63+
textWrapper.className = "align-left week dimmed medium";
64+
timeWrapper.className = "time bright xlarge light";
65+
textWrapper.innerHTML=this.config.event;
66+
67+
var today = new Date(Date.now());
68+
var target = new Date(this.config.date);
69+
var timeDiff = target - today;
70+
71+
// Set days, hours, minutes and seconds
72+
var diffDays = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
73+
var diffHours = Math.floor((timeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
74+
var diffMinutes = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60));
75+
var diffSeconds = Math.floor((timeDiff % (1000 * 60)) / 1000);
76+
77+
// Build the output
78+
var hrs = '';
79+
var mins = '';
80+
var secs = '';
81+
var days = '';
82+
if (diffDays > 0) {
83+
days = diffDays + this.config.daysLabel;
84+
}
85+
86+
if(this.config.showHours == true) hrs = diffHours + this.config.hoursLabel;
87+
if(this.config.showMinutes == true) mins = diffMinutes + this.config.minutesLabel;
88+
if(this.config.showSeconds == true) secs = diffSeconds + this.config.secondsLabel;
89+
90+
if ((this.config.showMinutes == true) && (mins.length < 2)) { mins = "0" + mins; }
91+
if ((this.config.showSeconds == true) && (secs.length < 2)) { secs = "0" + secs; }
92+
93+
if (this.config.date === "0000-00-00") {
94+
timeWrapper.innerHTML = "Not today!";
95+
timeWrapper.className = "time xlarge light green";
96+
} else if (this.config.date !== "3000-01-01") {
97+
timeWrapper.innerHTML = days + hrs + mins + secs;
98+
}
99+
if ((diffHours == 0) && (diffMinutes <= 5)) {
100+
timeWrapper.className = "time xlarge light red";
101+
} else if ((diffHours == 0) && (diffMinutes <= 10)) {
102+
timeWrapper.className = "time xlarge light yellow";
103+
}
104+
105+
wrapper.appendChild(textWrapper);
106+
wrapper.appendChild(timeWrapper);
107+
108+
return wrapper;
109+
}
110+
});

README.md

+21-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
1-
# MMM-CountDown
2-
![Screenshot](https://github.com/boazarad/MMM-CountDown/raw/master/screenshots/screenshot.png)
1+
# MMM-NextEvent
32

4-
This is a module for the [MagicMirror²](https://github.com/MichMich/MagicMirror/) which can count down the days to a date/event.
3+
## Screenshot
4+
![Screenshot](https://github.com/cure/MMM-NextEvent/raw/main/screenshots/screenshot1.png)
5+
![Screenshot](https://github.com/cure/MMM-NextEvent/raw/main/screenshots/screenshot2.png)
6+
![Screenshot](https://github.com/cure/MMM-NextEvent/raw/main/screenshots/screenshot3.png)
7+
![Screenshot](https://github.com/cure/MMM-NextEvent/raw/main/screenshots/screenshot4.png)
58

6-
I've never written anything with Node.js before, so hopefully this isn't a total mess, if it is - feel free to lend a hand :)
9+
## Description
710

8-
## Using the module
11+
This is a module for [MagicMirror²](https://github.com/MichMich/MagicMirror/) which counts down to the next calendar event today. It is a slightly modified version of Boaz Arad's [MMM-CountDown](https://github.com/boazarad/MMM-CountDown), who did the hard work, thank you!
12+
13+
This module requests an event list from [MMM-CalExt2](https://github.com/MMM-CalendarExt2/MMM-CalendarExt2) for the current date, and displays a countdown in hours and minutes to the next event. If there is no event later today, it displays a happy 'Not today!' message.
14+
15+
## Installation
16+
17+
```
18+
cd ~/MagicMirror/modules
19+
git clone --depth=1 https://github.com/cure/MMM-NextEvent
20+
```
21+
## Configuration
922

1023
To use this module, add the following configuration block to the modules array in the `config/config.js` file:
1124

1225
```js
1326
var config = {
1427
modules: [
1528
{
16-
module: 'MMM-CountDown',
29+
module: 'MMM-NextEvent',
1730
config: {
1831
// See configuration options
1932
}
@@ -22,13 +35,12 @@ var config = {
2235
}
2336
```
2437

25-
## Configuration options
38+
### Configuration options
2639

2740
| Option | Description |
2841
| ---------------- | --------------------------------------------------------------------------------------------------------------------- |
2942
| `position` | *Required* Where do you want to place the counter (use standard magicmirror positions) |
30-
| `event` | *Required* Name of event to count down to (displayed above counter) |
31-
| `date` | *Required* Date to count down to (YYYY-MM-DD HH:MM:SS) |
43+
| `event` | Name of the title displayed above counter when there is no next event. Default is 'Next event' |
3244
| `showHours` | Decide whether or not to display the hours. Default is true |
3345
| `showMinutes` | Decide whether or not to display the minutes. Default is true |
3446
| `showSeconds` | Decide whether or not to display the seconds. Default is true |
@@ -37,5 +49,3 @@ var config = {
3749
| `hoursLabel` | Choose how you wish to display your Hours label. Default is h |
3850
| `minutesLabel` | Choose how you wish to display your Minutes label. Default is m |
3951
| `secondsLabel` | Choose how you wish to display your Seconds label. Default is m |
40-
41-
If either of the above are missing, the module will count down to the New Millenium (3000-01-01)

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"name": "MMM-CountDown",
2+
"name": "MMM-NextEvent",
33
"version": "1.0.0",
4-
"description": "Count down to a specific event",
5-
"main": "MMM-CountDown.js",
6-
"author": "Boaz Arad",
4+
"description": "Count down to the next calendar event of the day",
5+
"main": "MMM-NextEvent.js",
6+
"author": "Ward Vandewege",
77
"license": "MIT",
88
"devDependencies": {
99
"grunt": "latest",

screenshots/screenshot.png

-7.71 KB
Binary file not shown.

screenshots/screenshot1.png

8.61 KB
Loading

screenshots/screenshot2.png

10.5 KB
Loading

screenshots/screenshot3.png

9.18 KB
Loading

screenshots/screenshot4.png

9.81 KB
Loading

0 commit comments

Comments
 (0)