-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMMM-NextCloud-Tasks.js
executable file
·134 lines (116 loc) · 3.04 KB
/
MMM-NextCloud-Tasks.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
/* global Module */
/* Magic Mirror
* Module: MMM-NextCloud-Tasks
*
* By Jan Ryklikas
* MIT Licensed.
*/
Module.register("MMM-NextCloud-Tasks", {
defaults: {
updateInterval: 60000,
hideCompletedTasks: true
},
requiresVersion: "2.1.0", // Required version of MagicMirror
toDoList: null,
error: null,
start: function () {
var self = this;
//Flag for check if module is loaded
self.loaded = false;
if(self.verifyConfig(self.config)) {
// Schedule update timer.
self.getData();
setInterval(function() {
self.getData();
self.updateDom();
}, self.config.updateInterval);
} else {
Log.info("config invalid");
self.error = "config invalid";
self.updateDom();
}
},
/*
* getData
* function example return data and show it in the module wrapper
* get a URL request
*
*/
getData: function () {
this.sendSocketNotification(
"MMM-NextCloud-Tasks-UPDATE",
{
id: this.identifier,
config: this.config
}
);
},
getDom: function () {
let self = this;
// create element wrapper for show into the module
let wrapper = document.createElement("div");
wrapper.className = "MMM-NextCloud-Tasks-wrapper";
if (self.toDoList) {
wrapper.appendChild(self.renderList(self.toDoList));
self.error = null;
} else {
wrapper.innerHTML= "<div>Loading...</div>";
}
if (self.error) {
wrapper.innerHTML= "<div>" + self.error + "</div>";
}
return wrapper;
},
renderList: function (children) {
let self = this;
let checked = "<span class=\"fa fa-fw fa-check-square\"></span>"
let unchecked = "<span class=\"fa fa-fw fa-square\"></span>"
let ul = document.createElement("ul");
for (const element of children) {
self.config
if (element.status !== "COMPLETED" || self.config.hideCompletedTasks === false) {
icon = (element.status === "COMPLETED" ? checked : unchecked );
let li = document.createElement("li");
li.innerHTML = icon + " " + element.summary;
if (typeof element.children !== "undefined") {
let childList = self.renderList(element.children);
li.appendChild(childList);
}
ul.appendChild(li);
}
}
return ul;
},
getStyles: function () {
return [
"MMM-NextCloud-Tasks.css",
];
},
socketNotificationReceived: function (notification, payload) {
if(notification === "MMM-NextCloud-Tasks-Helper-TODOS#" + this.identifier) {
this.toDoList = payload;
this.updateDom();
}
if(notification === "MMM-NextCloud-Tasks-Helper-LOG#" + this.identifier) {
Log.log("LOG: ", payload);
}
if(notification === "MMM-NextCloud-Tasks-Helper-ERROR#" + this.identifier) {
Log.error("ERROR: ", payload);
this.error = payload + "<br>";
this.updateDom();
}
},
verifyConfig: function (config) {
if(
typeof config.listUrl === "undefined" ||
typeof config.webDavAuth === "undefined" ||
typeof config.webDavAuth.username === "undefined" ||
typeof config.webDavAuth.password === "undefined"
) {
this.error = "Config variable missing";
Log.error("Config variable missing");
return false;
}
return true;
}
});