فهرست منبع

feat(data source observerable): started work on handling data source observerable

Torkel Ödegaard 9 سال پیش
والد
کامیت
a738945a88
1فایلهای تغییر یافته به همراه21 افزوده شده و 0 حذف شده
  1. 21 0
      public/app/features/panel/metrics_panel_ctrl.ts

+ 21 - 0
public/app/features/panel/metrics_panel_ctrl.ts

@@ -26,6 +26,7 @@ class MetricsPanelCtrl extends PanelCtrl {
   timeInfo: any;
   timeInfo: any;
   skipDataOnInit: boolean;
   skipDataOnInit: boolean;
   datasources: any[];
   datasources: any[];
+  dataSubscription: any;
 
 
   constructor($scope, $injector) {
   constructor($scope, $injector) {
     super($scope, $injector);
     super($scope, $injector);
@@ -182,6 +183,12 @@ class MetricsPanelCtrl extends PanelCtrl {
       return datasource.query(metricsQuery).then(results => {
       return datasource.query(metricsQuery).then(results => {
         this.setTimeQueryEnd();
         this.setTimeQueryEnd();
 
 
+        // check for if data source returns observable
+        if (results && results.subscribe) {
+          this.handleObservable(results);
+          return {data: []};
+        }
+
         if (this.dashboard.snapshot) {
         if (this.dashboard.snapshot) {
           this.panel.snapshotData = results;
           this.panel.snapshotData = results;
         }
         }
@@ -193,6 +200,20 @@ class MetricsPanelCtrl extends PanelCtrl {
     }
     }
   }
   }
 
 
+  handleObservable(observable) {
+    this.dataSubscription = observable.subscribe({
+      next: (data) => {
+        console.log('panel: observer got data');
+      },
+      error: (error) => {
+        console.log('panel: observer got error');
+      },
+      complete: () => {
+        console.log('panel: observer got complete');
+      }
+    });
+  }
+
   setDatasource(datasource) {
   setDatasource(datasource) {
     // switching to mixed
     // switching to mixed
     if (datasource.meta.mixed) {
     if (datasource.meta.mixed) {