forked from MagicMirrorModules/MMM-GrafanaChart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMM-GrafanaChart.js
executable file
·82 lines (75 loc) · 2.63 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* 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", // this is needed, so it can be overwritten in the old-style config
url: "invalid",
height:"100%",
width:"100%",
scrolling:"no",
refreshInterval: 900
},
// Define start sequence.
start: function() {
Log.info("Starting module: " + this.name);
// if the user did not provide a URL property, try to assemble one from the older config style, that stored everything in parts
if( this.config.url === "invalid" ){
this.config.url = this.buildUrl();
}
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;
if( this.config.from ){
URL += "&from=" + this.config.from;
}
if( this.config.to ){
URL += "&to=" + this.config.to
}
if (this.config.version == "6") {
URL += "&fullscreen&kiosk";
}
return URL;
},
// Override dom generator.
getDom: function() {
if( ! this.config.url.match(/^https?:/i) ){
return document.createTextNode(this.name+" found no usable URL configured. Please check your config!");
}
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.src = this.config.url;
// this attribute is used to ensure MagicMirror doesn't throw away our updateDom(), because the DOM object is identical to the previous one
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();
}
});