This repository was archived by the owner on Dec 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-Sonarr.js
135 lines (108 loc) · 3.36 KB
/
MMM-Sonarr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
* Created by max on 4/21/17.
*/
Module.register("MMM-Sonarr", {
defaults: {
apiBase: "",
apiKey: "",
fade: true,
updateInterval: 5 * 50 * 1000,
initialLoadDelay: 0,
maximumEntries: 5,
calendar: {
num: 1,
type: "month" // days|months|years
},
history: {
sortKey: "date", // date|series.title
sortDir: "desc"
}
},
getStyles: function () {
return ["MMM-Sonarr.css"];
},
getScripts: function () {
return ["moment.js"];
},
start: function () {
Log.info("Starting module: " + this.name);
this.loaded = false;
this.sendSocketNotification("CONFIG", this.config);
},
socketNotificationReceived: function (notification, payload) {
Log.log(this.name + " received notification");
if(notification === "RECORDS") {
this.records = payload;
this.loaded = true;
this.updateDom();
}
},
getDom: function () {
let wrapper = document.createElement("div");
if(!this.loaded) {
wrapper.innerHTML = "Fetching records...";
wrapper.className = "dimmed light small";
return wrapper;
}
let calendarTable = document.createElement("table");
let calendarHeader = document.createElement("header");
calendarTable.className = "small calendar";
calendarHeader.innerHTML = "Upcoming";
let historyTable = document.createElement("table");
let historyHeader = document.createElement("header");
historyTable.className = "small history";
historyHeader.innerHTML = "History";
for(let r in this.records.calendar) {
if(r >= this.config.maximumEntries) {break;}
let record = this.records.calendar[r];
let row = document.createElement("tr");
calendarTable.appendChild(row);
let airTimeCell = document.createElement("td");
airTimeCell.className = "airtime";
airTimeCell.innerHTML = record.airdate;
row.appendChild(airTimeCell);
let seriesTitleCell = document.createElement("td");
seriesTitleCell.className = "seriestitle";
seriesTitleCell.innerHTML = record.seriesTitle;
row.appendChild(seriesTitleCell);
let episodeTitleCell = document.createElement("td");
episodeTitleCell.className = "episodetitle";
episodeTitleCell.innerHTML = record.episodeTitle;
row.appendChild(episodeTitleCell);
}
for(let r in this.records.history) {
if(r >= this.config.maximumEntries) {break;}
let record = this.records.history[r];
let row = document.createElement("tr");
historyTable.appendChild(row);
let airTimeCell = document.createElement("td");
airTimeCell.className = "airtime";
airTimeCell.innerHTML = record.airDate;
row.appendChild(airTimeCell);
let seriesTitleCell = document.createElement("td");
seriesTitleCell.className = "seriestitle";
seriesTitleCell.innerHTML = record.seriesTitle;
row.appendChild(seriesTitleCell);
let episodeTitleCell = document.createElement("td");
episodeTitleCell.className = "episodetitle";
episodeTitleCell.innerHTML = record.episodeTitle;
row.appendChild(episodeTitleCell);
}
wrapper.appendChild(calendarHeader);
wrapper.appendChild(calendarTable);
wrapper.appendChild(historyHeader);
wrapper.appendChild(historyTable);
return wrapper;
},
scheduleUpdate: function (delay) {
let next = this.config.updateInterval;
if (typeof delay !== "undefined" && delay >= 0) {
next = delay;
}
let self = this;
clearTimeout(this.updateTimer);
this.updateTimer = setTimeout(function() {
self.updateDom();
}, next);
}
});