forked from MagicMirrorModules/MMM-GrafanaChart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-GrafanaChart.js
executable file
·66 lines (61 loc) · 1.86 KB
/
MMM-GrafanaChart.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
/* MMM-GrafanaChart
* This MagicMirror² module allows you to display a chart generated by grafana.
*
* By SvenSommer https://github.com/SvenSommer
* MIT Licensed.
*/
Module.register("MMM-GrafanaChart", {
// Default module config.
defaults: {
protocol: "http",
height:"100%",
width:"100%",
scrolling:"no",
refreshInterval: 900
},
// Define start sequence.
start: function() {
Log.info("Starting module: " + this.name);
this.scheduleUpdate();
},
buildUrl: function() {
var URL = "";
URL += this.config.protocol + "://";
URL += this.config.host + ":" + this.config.port;
if (this.config.version == "6") {
URL += "/d-solo/" + this.config.id;
} else{
URL += "/dashboard-solo/db";
}
URL += "/" + this.config.dashboardname;
URL += "?orgId=" + this.config.orgId;
URL += "&panelId=" + this.config.panelId;
URL += "&from=" + this.config.from;
URL += "&to=" + this.config.to
if (this.config.version == "6") {
URL += "&fullscreen&kiosk";
}
return URL;
},
// Override dom generator.
getDom: function() {
var iframe = document.createElement("IFRAME");
iframe.style = "border:0"
iframe.width = this.config.width;
iframe.height = this.config.height;
iframe.scrolling = this.config.scrolling;
iframe.setAttribute("timestamp", new Date().getTime());
return iframe;
},
scheduleUpdate: function() {
var self = this;
setTimeout(function() {
self.updateFrame();
}, this.config.refreshInterval*1000);
},
updateFrame: function() {
Log.info("attempting to update dom for iFrameReload");
this.updateDom(1000);
this.scheduleUpdate();
}
});