Skip to content

Commit 188530a

Browse files
committed
MMM-CalendarExt2 supported
1 parent 8004e83 commit 188530a

2 files changed

Lines changed: 49 additions & 8 deletions

File tree

MMM-CalendarExtTimeline.js

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Module.register("MMM-CalendarExtTimeline",{
2323
time_display_section_count: 6,
2424
time_display_section_format: "hh:mm a",
2525
calendars: [],
26+
source: "CALEXT2", // "CALEXT" or "CALEXT2"
2627
},
2728

2829
start: function() {
@@ -149,6 +150,13 @@ Module.register("MMM-CalendarExtTimeline",{
149150
if (notification == "CALEXT_SAYS_SCHEDULE") {
150151
this.updateContent(payload)
151152
}
153+
154+
if (notification == "CALEXT2_CALENDAR_MODIFIED") {
155+
var self = this
156+
setTimeout(function(){
157+
self.updateRequest2()
158+
}, 1000)
159+
}
152160
},
153161

154162
makeEvents: function(name, parentDom) {
@@ -157,9 +165,11 @@ Module.register("MMM-CalendarExtTimeline",{
157165
var totalGap = endTime.format("x") - startTime.format("x")
158166
var events = []
159167
var stack = [[]]
168+
var self = this
160169
this.events.forEach(function(e) {
161-
if (e.name) {
162-
if (e.name == name) {
170+
var eName = e.name
171+
if (eName) {
172+
if (eName == name) {
163173
var eStart = moment.unix(e.startDate / 1000)
164174
var eEnd = moment.unix(e.endDate / 1000)
165175
var isValid = false
@@ -209,6 +219,7 @@ Module.register("MMM-CalendarExtTimeline",{
209219
stack.forEach(function(s) {
210220
var line = document.createElement("div")
211221
line.className = "eventPositionLine"
222+
if (self.config.source == "CALEXT2") line.className += " CX2"
212223
s.forEach(function(e) {
213224
var eStart = moment.unix(e.startDate / 1000)
214225
var eEnd = moment.unix(e.endDate / 1000)
@@ -239,13 +250,10 @@ Module.register("MMM-CalendarExtTimeline",{
239250
if (e.fullDayEvent) {
240251
ev.className += " fulldayevent"
241252
}
242-
243253
line.appendChild(ev)
244254
})
245-
246255
parentDom.appendChild(line)
247256
})
248-
249257
return parentDom
250258
},
251259

@@ -276,5 +284,33 @@ Module.register("MMM-CalendarExtTimeline",{
276284
sessionId: moment().format('x')
277285
}
278286
this.sendNotification("CALEXT_TELL_SCHEDULE", payload)
287+
},
288+
289+
updateRequest2: function() {
290+
var payload = {
291+
filter: (e) => {
292+
var from = moment().startOf("day").format("X")
293+
var to = moment().endOf("day").format("X")
294+
if (this.names.indexOf(e.calendarName) < 0) return false
295+
if (e.startDate > to || e.endDate < from) return false
296+
return true
297+
},
298+
callback: (events) => {
299+
if (events.length > 0) {
300+
for (i = 0; i < events.length; i++) {
301+
events[i].name = events[i].calendarName
302+
events[i].startDate = events[i].startDate * 1000
303+
events[i].endDate = events[i].endDate * 1000
304+
events[i].styleName = events[i].className
305+
}
306+
var payload = {
307+
message: "SCHEDULE_FOUND",
308+
events: events
309+
}
310+
this.updateContent(payload)
311+
}
312+
}
313+
}
314+
this.sendNotification("CALEXT2_EVENT_QUERY", payload)
279315
}
280316
})

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ cd <your MagicMirror Directory>/modules
1414
git clone https://github.com/eouia/MMM-CalendarExtTimeline
1515
```
1616

17+
## Update ##
18+
**2018-12-19**
19+
- `MMM-CalendarExt2` supported.
20+
1721
## Configuration ##
1822
```javascript
1923
{
@@ -24,16 +28,17 @@ git clone https://github.com/eouia/MMM-CalendarExtTimeline
2428
refresh_interval_sec: 60, // minimum 60,
2529
table_title_format: "ddd, MMM Do",
2630
begin_hour: 0, //ignored when you set type to 'dynamic'
27-
end_hour: 6, //how many hours to show.
28-
time_display_section_count: 6,
31+
end_hour: 6, //how many hours to show.
32+
time_display_section_count: 6,
2933
time_display_section_format: "HH:mm",
3034
calendars: ["your calendar name", "another name"] //in your `MMM-CalendarExt` configuration
35+
source: "CALEXT2", // or "CALEXT"
3136
}
3237
}
3338
```
3439
### type:"static" or "dynamic"
3540
#### type:"static"
36-
This will show timeline from `begin_hour` to `end_hour` of today.
41+
This will show timeline from `begin_hour` to `end_hour` of today.
3742

3843
By example)
3944
```javascript

0 commit comments

Comments
 (0)