Sfoglia il codice sorgente

If earlier dashboard refresh was supressed, force a new one on page becoming visible (#8076)

Simen Bekkhus 8 anni fa
parent
commit
21ae987bcd
1 ha cambiato i file con 11 aggiunte e 0 eliminazioni
  1. 11 0
      public/app/features/dashboard/time_srv.ts

+ 11 - 0
public/app/features/dashboard/time_srv.ts

@@ -15,6 +15,7 @@ class TimeSrv {
   oldRefresh: boolean;
   oldRefresh: boolean;
   dashboard: any;
   dashboard: any;
   timeAtLoad: any;
   timeAtLoad: any;
+  private autoRefreshBlocked: boolean;
 
 
   /** @ngInject **/
   /** @ngInject **/
   constructor(private $rootScope, private $timeout, private $location, private timer, private contextSrv) {
   constructor(private $rootScope, private $timeout, private $location, private timer, private contextSrv) {
@@ -23,6 +24,14 @@ class TimeSrv {
 
 
     $rootScope.$on('zoom-out', this.zoomOut.bind(this));
     $rootScope.$on('zoom-out', this.zoomOut.bind(this));
     $rootScope.$on('$routeUpdate', this.routeUpdated.bind(this));
     $rootScope.$on('$routeUpdate', this.routeUpdated.bind(this));
+
+    document.addEventListener('visibilitychange', () => {
+      if (this.autoRefreshBlocked && document.visibilityState === 'visible') {
+        this.autoRefreshBlocked = false;
+
+        this.refreshDashboard();
+      }
+    });
   }
   }
 
 
   init(dashboard) {
   init(dashboard) {
@@ -137,6 +146,8 @@ class TimeSrv {
       this.startNextRefreshTimer(afterMs);
       this.startNextRefreshTimer(afterMs);
       if (this.contextSrv.isGrafanaVisible()) {
       if (this.contextSrv.isGrafanaVisible()) {
         this.refreshDashboard();
         this.refreshDashboard();
+      } else {
+        this.autoRefreshBlocked = true;
       }
       }
     }, afterMs));
     }, afterMs));
   }
   }