-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-Radarr.js
81 lines (65 loc) · 2.41 KB
/
MMM-Radarr.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
Module.register("MMM-Radarr", {
defaults: {
apiKey: "",
baseUrl: "http://localhost:8989",
upcomingLimit: 5,
historyLimit: 5,
updateInterval: 1 * 60 * 1000, // 1 minutes
},
start: function() {
this.upcoming = [];
this.history = [];
this.sendSocketNotification("START_RADARR", this.config);
},
getStyles: function() {
return ["MMM-Radarr.css"];
},
getDom: function() {
const wrapper = document.createElement("div");
wrapper.className = "radarr-wrapper";
if (this.config.upcomingLimit > 0) {
const upcomingSection = this.createSection("Upcoming Movies", this.upcoming, this.config.upcomingLimit);
wrapper.appendChild(upcomingSection);
}
if (this.config.historyLimit > 0) {
const historySection = this.createSection("Recently Downloaded", this.history, this.config.historyLimit);
wrapper.appendChild(historySection);
}
return wrapper;
},
createSection: function(title, data, limit) {
const section = document.createElement("div");
section.className = "radarr-section";
const header = document.createElement("h2");
header.textContent = title;
section.appendChild(header);
const list = document.createElement("ul");
// Create a Set to store unique entries
const uniqueEntries = new Set();
data.forEach(item => {
let entryText;
if (title === "Upcoming Movies") {
entryText = `${item.title}`;
} else {
entryText = `${item.movie.title} (${item.movie.year})`;
}
if (!uniqueEntries.has(entryText) && uniqueEntries.size < limit) {
uniqueEntries.add(entryText);
const listItem = document.createElement("li");
listItem.textContent = entryText;
list.appendChild(listItem);
}
});
section.appendChild(list);
return section;
},
socketNotificationReceived: function(notification, payload) {
if (notification === "RADARR_UPCOMING") {
this.upcoming = payload;
this.updateDom();
} else if (notification === "RADARR_HISTORY") {
this.history = payload;
this.updateDom();
}
},
});