@@ -18,21 +18,16 @@ var REST_URL = "/rest/items/";
18
18
var SMARTHOME_GRAFANA_DEFAULTS = {
19
19
// library
20
20
debug : "false" ,
21
- render : "false" ,
22
21
refresh : "0" ,
23
22
// ESH sitemap
24
23
sitemap : "default" ,
25
24
// Grafana URL
26
25
urlPrefix : "//" + auth_type + "grafana." + domain ,
27
26
panelPath : "/d-solo/" ,
28
- renderPanelPath : "/render/d-solo/" ,
29
27
// Grafana panel parameters
30
28
from : "now-1d" ,
31
29
to : "now" ,
32
- theme : "dark" ,
33
- // Grafana render panel parameters
34
- width : "auto" ,
35
- height : "auto"
30
+ theme : "dark"
36
31
} ;
37
32
38
33
function resolveParam ( params , name )
@@ -206,14 +201,10 @@ function GrafanaPanel(params)
206
201
let frame = resolveParam ( params , "frame" ) ;
207
202
let urlPrefix = resolveParam ( params , "urlPrefix" ) ;
208
203
let panelPath = resolveParam ( params , "panelPath" ) ;
209
- let renderPanelPath = resolveParam ( params , "renderPanelPath" ) ;
210
204
let libVars = {
211
205
debug : {
212
206
value : resolveParam ( params , "debug" )
213
207
} ,
214
- render : {
215
- value : resolveParam ( params , "render" )
216
- } ,
217
208
refresh : {
218
209
value : resolveParam ( params , "refresh" )
219
210
}
@@ -237,28 +228,18 @@ function GrafanaPanel(params)
237
228
theme : {
238
229
key : "theme" ,
239
230
value : resolveParam ( params , "theme" )
240
- } ,
241
- width : {
242
- key : "width" ,
243
- value : resolveParam ( params , "width" )
244
- } ,
245
- height : {
246
- key : "height" ,
247
- value : resolveParam ( params , "height" )
248
231
}
249
232
} ;
250
233
251
234
function updateFrameSourceURL ( )
252
235
{
253
236
var debug = libVars . debug . value ;
254
- var render = libVars . render . value ;
255
237
var refresh = libVars . refresh . value ;
256
238
257
239
var iframe = document . getElementById ( frame ) ;
258
- var idocument = iframe . contentWindow . document ;
259
240
260
241
var url = urlPrefix ;
261
- url += render === "true" ? renderPanelPath : panelPath ;
242
+ url += panelPath ;
262
243
url += urlVars . dashboard . value ;
263
244
264
245
var firstParameter = true ;
@@ -267,63 +248,20 @@ function GrafanaPanel(params)
267
248
var key = urlVars [ uvKey ] . key ;
268
249
var value = urlVars [ uvKey ] . value ;
269
250
270
- if ( key === "width" )
271
- {
272
- value = render === "false" ? undefined : ( value === "auto" ? idocument . body . clientWidth : value ) ;
273
- }
274
- else if ( key === "height" )
275
- {
276
- value = render === "false" ? undefined : ( value === "auto" ? idocument . body . clientHeight : value ) ;
277
- }
278
-
279
251
if ( key !== undefined && value !== undefined )
280
252
{
281
253
url += ( firstParameter ? "?" : "&" ) + key + "=" + value ;
282
254
firstParameter = false ;
283
255
}
284
256
}
285
257
286
- if ( render === "true" )
287
- {
288
- // append cache busting parameter
289
- url += "&cacheBuster=" + Date . now ( ) ;
290
- }
291
- // update frame content
292
- if ( debug === "true" )
293
- {
294
- idocument . open ( ) ;
295
- idocument . write ( "<a href=\"" + url + "\">" + url + "</a>" ) ;
296
- idocument . close ( ) ;
297
- }
298
- else if ( render === "true" )
299
- {
300
- var htmlUrl = url . replace ( renderPanelPath , panelPath ) ;
301
- idocument . open ( ) ;
302
- idocument . write ( "<style>body{margin:0px}p{margin:0px}</style>" ) ;
303
- idocument . write ( "<p style=\"text-align:center;\"><a href=\"" + htmlUrl + "\"><img src=\"" + url + "\"></a></p>" ) ;
304
- idocument . close ( ) ;
305
- }
306
- else if ( document . getElementById ( frame ) . src !== url )
258
+ if ( document . getElementById ( frame ) . src !== url )
307
259
{
308
260
// replace the URL so changes are not added to the browser history
309
261
iframe . contentWindow . location . replace ( url ) ;
310
262
}
311
-
312
- if ( render === "true" && refresh > 0 )
313
- {
314
- refreshTimerId = setTimeout ( updateFrameSourceURL , refresh ) ;
315
- }
316
263
}
317
264
318
- function updateFrameOnResize ( )
319
- {
320
- clearTimeout ( resizeTimerId ) ;
321
- if ( libVars . render . value === "true" && ( urlVars . width . value === "auto" || urlVars . height . value === "auto" ) )
322
- {
323
- resizeTimerId = setTimeout ( updateFrameSourceURL , 500 ) ;
324
- }
325
- }
326
-
327
265
function updateVars ( vars )
328
266
{
329
267
for ( let [ key , value ] of Object . entries ( vars ) )
@@ -337,11 +275,6 @@ function GrafanaPanel(params)
337
275
{
338
276
if ( params ) updateVars ( params ) ;
339
277
updateFrameSourceURL ( ) ;
340
- if ( ! initialized && libVars . render . value === "true" && ( urlVars . width . value === "auto" || urlVars . height . value === "auto" ) )
341
- {
342
- initialized = true ;
343
- window . addEventListener ( "resize" , updateFrameOnResize ) ;
344
- }
345
278
} ,
346
279
}
347
280
}
@@ -456,14 +389,10 @@ function GrafanaBuilder(panelConfigs)
456
389
frame . id = "panel-" + uniqueId + "-frame" ;
457
390
frame . className = "panel-frame" ;
458
391
frame . scrolling = "no" ;
459
- frame . onload = function ( )
392
+ frame . addEventListener ( "load" , function ( )
460
393
{
461
- var cssLink = this . contentWindow . document . createElement ( "link" ) ;
462
- cssLink . href = "//" + auth_type + "openhab." + domain + "/static/shared/grafana/css/grafana.css" ;
463
- cssLink . rel = "stylesheet" ;
464
- cssLink . type = "text/css" ;
465
- this . contentWindow . document . head . appendChild ( cssLink ) ;
466
- } ;
394
+ this . contentWindow . postMessage ( { type : "css" , src : "//" + auth_type + "openhab." + domain + "/static/shared/grafana/css/grafana.css" } , "*" ) ;
395
+ } ) ;
467
396
div . appendChild ( frame ) ;
468
397
469
398
params [ "frame" ] = frame . id ;
0 commit comments