added URL hash option always_update to remember the state of the refreshing; fixes #423, fixes #1120
Costa Tsaousis (ktsaou) committed
Oct 15, 2016 at 19:46 UTC
b0ffc3acb9852a608c5893040ae67d90e8d47cd3
1 file changed
+74
-55
web/index.html
+74
-55
@@ -407,6 +407,7 @@
407
hash: '#',
408
theme: null,
409
help: null,
410
+ update_always: false,
411
pan_and_zoom: false,
412
after: 0,
413
before: 0,
@@ -418,75 +419,80 @@
419
alarm_unique_id: 0,
420
alarm_id: 0,
421
alarm_event_id: 0,
422
+
423
hasProperty: function(property) {
424
// console.log('checking property ' + property + ' of type ' + typeof(this[property]));
425
return typeof this[property] !== 'undefined';
424
- }
425
- };
426
-
427
- function netdataPanAndZoomCallback(status, after, before) {
428
- urlOptions.pan_and_zoom = status;
429
- urlOptions.after = after;
430
- urlOptions.before = before;
431
- netdataHashUpdate();
432
- }
426
+ },
427
434
- function netdataHashUpdate() {
435
- history.replaceState(null, '', netdataHash());
436
- }
428
+ genHash: function() {
429
+ var hash = urlOptions.hash;
430
438
- function netdataHash() {
439
- var hash = urlOptions.hash;
431
+ if(urlOptions.pan_and_zoom === true) {
432
+ hash += ';after=' + urlOptions.after.toString() +
433
+ ';before=' + urlOptions.before.toString();
434
+ }
435
441
- if(urlOptions.pan_and_zoom === true) {
442
- hash += ';after=' + urlOptions.after.toString() +
443
- ';before=' + urlOptions.before.toString();
444
- }
436
+ if(urlOptions.theme !== null)
437
+ hash += ';theme=' + urlOptions.theme.toString();
438
446
- if(urlOptions.theme !== null)
447
- hash += ';theme=' + urlOptions.theme.toString();
439
+ if(urlOptions.help !== null)
440
+ hash += ';help=' + urlOptions.help.toString();
441
449
- if(urlOptions.help !== null)
450
- hash += ';help=' + urlOptions.help.toString();
442
+ if(urlOptions.update_always === true)
443
+ hash += ';update_always=true';
444
452
- return hash;
453
- }
445
+ return hash;
446
+ },
447
455
- function netdataHashParse() {
456
- var variables = document.location.hash.split(';');
457
- var len = variables.length;
458
- while(len--) {
459
- if(len !== 0) {
460
- var p = variables[len].split('=');
461
- if(urlOptions.hasProperty(p[0]) && typeof p[1] !== 'undefined')
462
- urlOptions[p[0]] = decodeURIComponent(p[1]);
448
+ parseHash: function() {
449
+ var variables = document.location.hash.split(';');
450
+ var len = variables.length;
451
+ while(len--) {
452
+ if(len !== 0) {
453
+ var p = variables[len].split('=');
454
+ if(urlOptions.hasProperty(p[0]) && typeof p[1] !== 'undefined')
455
+ urlOptions[p[0]] = decodeURIComponent(p[1]);
456
+ }
457
+ else {
458
+ if(variables[len].length > 0)
459
+ urlOptions.hash = variables[len];
460
+ }
461
}
464
- else {
465
- if(variables[len].length > 0)
466
- urlOptions.hash = variables[len];
462
+
463
+ var booleans = [ 'nowelcome', 'show_alarms', 'pan_and_zoom', 'update_always' ];
464
+ len = booleans.length;
465
+ while(len--) {
466
+ if(urlOptions[booleans[len]] === 'true' || urlOptions[booleans[len]] === true || urlOptions[booleans[len]] === '1' || urlOptions[booleans[len]] === 1)
467
+ urlOptions[booleans[len]] = true;
468
+ else
469
+ urlOptions[booleans[len]] = false;
470
}
468
- }
471
470
- var booleans = [ 'nowelcome', 'show_alarms', 'pan_and_zoom' ];
471
- len = booleans.length;
472
- while(len--) {
473
- if(urlOptions[booleans[len]] === 'true' || urlOptions[booleans[len]] === true || urlOptions[booleans[len]] === '1' || urlOptions[booleans[len]] === 1)
474
- urlOptions[booleans[len]] = true;
472
+ if(urlOptions.before > 0 && urlOptions.after > 0) {
473
+ urlOptions.pan_and_zoom = true;
474
+ urlOptions.nowelcome = true;
475
+ }
476
else
476
- urlOptions[booleans[len]] = false;
477
- }
477
+ urlOptions.pan_and_zoom = false;
478
+
479
+ // console.log(urlOptions);
480
+ },
481
+
482
+ hashUpdate: function() {
483
+ history.replaceState(null, '', urlOptions.genHash());
484
+ },
485
479
- if(urlOptions.before > 0 && urlOptions.after > 0) {
480
- urlOptions.pan_and_zoom = true;
481
- urlOptions.nowelcome = true;
486
+ netdataPanAndZoomCallback: function(status, after, before) {
487
+ urlOptions.pan_and_zoom = status;
488
+ urlOptions.after = after;
489
+ urlOptions.before = before;
490
+ urlOptions.hashUpdate();
491
}
483
- else
484
- urlOptions.pan_and_zoom = false;
492
486
- // console.log(urlOptions);
487
- }
493
+ };
494
489
- netdataHashParse();
495
+ urlOptions.parseHash();
496
497
// --------------------------------------------------------------------
498
// check options that should be processed before loading netdata.js
@@ -660,7 +666,7 @@
666
if(url.indexOf('#') !== -1)
667
url = url.substring(0, url.indexOf('#'));
668
663
- var hash = netdataHash();
669
+ var hash = urlOptions.genHash();
670
671
// console.log('netdataURL: ' + url + hash);
672
@@ -2278,7 +2284,7 @@
2284
// ------------------------------------------------------------------------
2285
2286
// callback for us to track PanAndZoom operations
2281
- NETDATA.globalPanAndZoom.callback = netdataPanAndZoomCallback;
2287
+ NETDATA.globalPanAndZoom.callback = urlOptions.netdataPanAndZoomCallback;
2288
2289
// let it run (update the charts)
2290
NETDATA.unpause();
@@ -2323,7 +2329,7 @@
2329
if(typeof hash === 'string' && hash.substring(0, 1) === '#' && urlOptions.hash.startsWith(hash + '_submenu_') === false) {
2330
urlOptions.hash = hash;
2331
//console.log(urlOptions.hash);
2326
- netdataHashUpdate();
2332
+ urlOptions.hashUpdate();
2333
}
2334
//else console.log('hash: not accepting ' + hash);
2335
//}
@@ -2380,11 +2386,18 @@
2386
$('#concurrent_refreshes').change(function() { NETDATA.setOption('concurrent_refreshes', $(this).prop('checked')); });
2387
$('#sync_selection').change(function() { NETDATA.setOption('sync_selection', $(this).prop('checked')); });
2388
$('#sync_pan_and_zoom').change(function() { NETDATA.setOption('sync_pan_and_zoom', $(this).prop('checked')); });
2383
- $('#stop_updates_when_focus_is_lost').change(function() { NETDATA.setOption('stop_updates_when_focus_is_lost', $(this).prop('checked')); });
2389
+ $('#stop_updates_when_focus_is_lost').change(function() {
2390
+ urlOptions.update_always = !$(this).prop('checked');
2391
+ urlOptions.hashUpdate();
2392
+
2393
+ NETDATA.setOption('stop_updates_when_focus_is_lost', !urlOptions.update_always);
2394
+ });
2395
$('#smooth_plot').change(function() { NETDATA.setOption('smooth_plot', $(this).prop('checked')); });
2396
$('#pan_and_zoom_data_padding').change(function() { NETDATA.setOption('pan_and_zoom_data_padding', $(this).prop('checked')); });
2397
$('#show_help').change(function() {
2398
urlOptions.help = $(this).prop('checked');
2399
+ urlOptions.hashUpdate();
2400
+
2401
NETDATA.setOption('show_help', urlOptions.help);
2402
netdataReload();
2403
});
@@ -2393,6 +2406,8 @@
2406
// it reloads the page
2407
$('#netdata_theme_control').change(function() {
2408
urlOptions.theme = $(this).prop('checked')?'slate':'white';
2409
+ urlOptions.hashUpdate();
2410
+
2411
if(setTheme(urlOptions.theme))
2412
netdataReload();
2413
});
@@ -2475,6 +2490,10 @@
2490
if(isdemo()) {
2491
document.getElementById('masthead').style.display = 'block';
2492
}
2493
+ else {
2494
+ if(urlOptions.update_always === true)
2495
+ NETDATA.setOption('stop_updates_when_focus_is_lost', !urlOptions.update_always);
2496
+ }
2497
}
2498
2499
// our entry point