Browse Source

Dashboard Snapshot sharing: singlestat panel now works, #1623

Torkel Ödegaard 10 years ago
parent
commit
41820ccb05

+ 7 - 1
src/app/features/panel/panelHelper.js

@@ -70,7 +70,13 @@ function (angular, _, kbn, $) {
         cacheTimeout: scope.panel.cacheTimeout
         cacheTimeout: scope.panel.cacheTimeout
       };
       };
 
 
-      return datasource.query(metricsQuery);
+      return datasource.query(metricsQuery).then(function(results) {
+        if (scope.dashboard.snapshot) {
+          scope.panel.snapshotData = results;
+        }
+
+        return results;
+      });
     };
     };
 
 
   });
   });

+ 7 - 0
src/app/features/panel/panelSrv.js

@@ -93,6 +93,13 @@ function (angular, _, config) {
       $scope.get_data = function() {
       $scope.get_data = function() {
         if ($scope.otherPanelInFullscreenMode()) { return; }
         if ($scope.otherPanelInFullscreenMode()) { return; }
 
 
+        if ($scope.panel.snapshotData) {
+          if ($scope.loadSnapshot) {
+            $scope.loadSnapshot($scope.panel.snapshotData);
+          }
+          return;
+        }
+
         delete $scope.panelMeta.error;
         delete $scope.panelMeta.error;
         $scope.panelMeta.loading = true;
         $scope.panelMeta.loading = true;
 
 

+ 6 - 9
src/app/panels/graph/module.js

@@ -130,12 +130,6 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) {
     $scope.refreshData = function(datasource) {
     $scope.refreshData = function(datasource) {
       panelHelper.updateTimeRange($scope);
       panelHelper.updateTimeRange($scope);
 
 
-      if ($scope.panel.snapshotData) {
-        $scope.annotationsPromise = $q.when([]);
-        $scope.dataHandler($scope.panel.snapshotData);
-        return;
-      }
-
       $scope.annotationsPromise = annotationsSrv.getAnnotations($scope.rangeUnparsed, $scope.dashboard);
       $scope.annotationsPromise = annotationsSrv.getAnnotations($scope.rangeUnparsed, $scope.dashboard);
 
 
       return panelHelper.issueMetricQuery($scope, datasource)
       return panelHelper.issueMetricQuery($scope, datasource)
@@ -146,10 +140,13 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) {
         });
         });
     };
     };
 
 
+    $scope.loadSnapshot = function(snapshotData) {
+      panelHelper.updateTimeRange($scope);
+      $scope.annotationsPromise = $q.when([]);
+      $scope.dataHandler(snapshotData);
+    };
+
     $scope.dataHandler = function(results) {
     $scope.dataHandler = function(results) {
-      if ($scope.dashboard.snapshot) {
-        $scope.panel.snapshotData = results;
-      }
       // png renderer returns just a url
       // png renderer returns just a url
       if (_.isString(results)) {
       if (_.isString(results)) {
         $scope.render(results);
         $scope.render(results);

+ 5 - 0
src/app/panels/singlestat/module.js

@@ -87,6 +87,11 @@ function (angular, app, _, TimeSeries, kbn, PanelMeta) {
         });
         });
     };
     };
 
 
+    $scope.loadSnapshot = function(snapshotData) {
+      panelHelper.updateTimeRange($scope);
+      $scope.dataHandler(snapshotData);
+    };
+
     $scope.dataHandler = function(results) {
     $scope.dataHandler = function(results) {
       $scope.series = _.map(results.data, $scope.seriesHandler);
       $scope.series = _.map(results.data, $scope.seriesHandler);
       $scope.render();
       $scope.render();