Explorar o código

Merge branch 'snapshot_annotation' of https://github.com/mtanda/grafana into mtanda-snapshot_annotation

Torkel Ödegaard %!s(int64=10) %!d(string=hai) anos
pai
achega
66f7a2be15

+ 11 - 0
public/app/features/annotations/annotationsSrv.js

@@ -38,10 +38,19 @@ define([
       var rangeRaw = timeSrv.timeRange(false);
 
       var promises  = _.map(annotations, function(annotation) {
+        if (annotation.snapshotData) {
+          self.receiveAnnotationResults(annotation.snapshotData);
+          return;
+        }
         return datasourceSrv.get(annotation.datasource).then(function(datasource) {
           var query = {range: range, rangeRaw: rangeRaw, annotation: annotation};
           return datasource.annotationQuery(query)
             .then(self.receiveAnnotationResults)
+            .then(function(results) {
+              if (dashboard.snapshot) {
+                annotation.snapshotData = angular.copy(results);
+              }
+            })
             .then(null, errorHandler);
         }, this);
       });
@@ -58,6 +67,8 @@ define([
       for (var i = 0; i < results.length; i++) {
         self.addAnnotation(results[i]);
       }
+
+      return results;
     };
 
     this.addAnnotation = function(options) {

+ 15 - 2
public/app/features/dashboard/shareSnapshotCtrl.js

@@ -101,8 +101,18 @@ function (angular, _) {
         panel.links = [];
         panel.datasource = null;
       });
-      // remove annotations
-      dash.annotations.list = [];
+      // remove annotation queries
+      dash.annotations.list = _.chain(dash.annotations.list)
+      .filter(function(annotation) {
+        return annotation.enable;
+      })
+      .map(function(annotation) {
+        return {
+          name: annotation.name,
+          enable: annotation.enable,
+          snapshotData: annotation.snapshotData
+        };
+      }).value();
       // remove template queries
       _.each(dash.templating.list, function(variable) {
         variable.query = "";
@@ -122,6 +132,9 @@ function (angular, _) {
       $scope.dashboard.forEachPanel(function(panel) {
         delete panel.snapshotData;
       });
+      _.each($scope.dashboard.annotations.list, function(annotation) {
+        delete annotation.snapshotData;
+      });
     };
 
     $scope.deleteSnapshot = function() {

+ 2 - 2
public/app/plugins/panels/graph/module.js

@@ -21,7 +21,7 @@ function (angular, _, moment, kbn, TimeSeries, PanelMeta) {
     };
   });
 
-  module.controller('GraphCtrl', function($scope, $rootScope, panelSrv, annotationsSrv, panelHelper, $q) {
+  module.controller('GraphCtrl', function($scope, $rootScope, panelSrv, annotationsSrv, panelHelper) {
 
     $scope.panelMeta = new PanelMeta({
       panelName: 'Graph',
@@ -144,7 +144,7 @@ function (angular, _, moment, kbn, TimeSeries, PanelMeta) {
 
     $scope.loadSnapshot = function(snapshotData) {
       panelHelper.updateTimeRange($scope);
-      $scope.annotationsPromise = $q.when([]);
+      $scope.annotationsPromise = annotationsSrv.getAnnotations($scope.dashboard);
       $scope.dataHandler(snapshotData);
     };