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

This commit is contained in:
Torkel Ödegaard
2016-03-16 14:19:30 +01:00
parent b273cd1339
commit a738945a88

View File

@@ -26,6 +26,7 @@ class MetricsPanelCtrl extends PanelCtrl {
timeInfo: any;
skipDataOnInit: boolean;
datasources: any[];
dataSubscription: any;
constructor($scope, $injector) {
super($scope, $injector);
@@ -182,6 +183,12 @@ class MetricsPanelCtrl extends PanelCtrl {
return datasource.query(metricsQuery).then(results => {
this.setTimeQueryEnd();
// check for if data source returns observable
if (results && results.subscribe) {
this.handleObservable(results);
return {data: []};
}
if (this.dashboard.snapshot) {
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) {
// switching to mixed
if (datasource.meta.mixed) {