feat(plugins): more work on plugin editors,prometheus query editor is working

This commit is contained in:
Torkel Ödegaard
2016-02-02 10:19:15 +01:00
parent eaaf9246b7
commit efdd4a6682
6 changed files with 43 additions and 129 deletions

View File

@@ -13,6 +13,8 @@ class PrometheusQueryCtrl extends QueryEditorCtrl {
metric: any;
resolutions: any;
oldTarget: any;
suggestMetrics: any;
linkToPrometheus: any;
constructor($scope, $injector, private templateSrv) {
super($scope, $injector);
@@ -27,28 +29,33 @@ class PrometheusQueryCtrl extends QueryEditorCtrl {
});
$scope.$on('typeahead-updated', () => {
$scope.$apply(this.inputMetric);
this.refreshMetricData();
this.$scope.$apply(() => {
this.target.expr += this.target.metric;
this.metric = '';
this.refreshMetricData();
});
});
// called from typeahead so need this
// here in order to ensure this ref
this.suggestMetrics = (query, callback) => {
console.log(this);
this.datasource.performSuggestQuery(query).then(callback);
};
this.updateLink();
}
refreshMetricData() {
if (!_.isEqual(this.oldTarget, this.target)) {
this.oldTarget = angular.copy(this.target);
this.panelCtrl.refresh();
this.updateLink();
}
}
inputMetric() {
this.target.expr += this.target.metric;
this.metric = '';
}
suggestMetrics(query, callback) {
this.datasource.performSuggestQuery(query).then(callback);
}
linkToPrometheus() {
updateLink() {
var range = this.panelCtrl.range;
var rangeDiff = Math.ceil((range.to.valueOf() - range.from.valueOf()) / 1000);
var endTime = range.to.utc().format('YYYY-MM-DD HH:mm');
@@ -61,8 +68,8 @@ class PrometheusQueryCtrl extends QueryEditorCtrl {
tab: 0
};
var hash = encodeURIComponent(JSON.stringify([expr]));
return this.datasource.directUrl + '/graph#' + hash;
};
this.linkToPrometheus = this.datasource.directUrl + '/graph#' + hash;
}
}
export {PrometheusQueryCtrl};