|
|
@@ -5,62 +5,64 @@ import _ from 'lodash';
|
|
|
import moment from 'moment';
|
|
|
|
|
|
import * as dateMath from 'app/core/utils/datemath';
|
|
|
+import {QueryEditorCtrl} from 'app/features/panel/panel';
|
|
|
|
|
|
-function PrometheusQueryCtrl($scope, templateSrv) {
|
|
|
- $scope.panelCtrl = $scope.ctrl;
|
|
|
- $scope.panel = $scope.panelCtrl.panel;
|
|
|
+/** @ngInject */
|
|
|
+class PrometheusQueryCtrl extends QueryEditorCtrl {
|
|
|
+ static templateUrl = 'public/app/plugins/datasource/prometheus/partials/query.editor.html';
|
|
|
+ metric: any;
|
|
|
+ resolutions: any;
|
|
|
+ oldTarget: any;
|
|
|
|
|
|
- $scope.init = function() {
|
|
|
- var target = $scope.target;
|
|
|
+ constructor($scope, $injector, private templateSrv) {
|
|
|
+ super($scope, $injector);
|
|
|
|
|
|
+ var target = this.target;
|
|
|
target.expr = target.expr || '';
|
|
|
target.intervalFactor = target.intervalFactor || 2;
|
|
|
|
|
|
- $scope.metric = '';
|
|
|
- $scope.resolutions = _.map([1,2,3,4,5,10], function(f) {
|
|
|
+ this.metric = '';
|
|
|
+ this.resolutions = _.map([1,2,3,4,5,10], function(f) {
|
|
|
return {factor: f, label: '1/' + f};
|
|
|
});
|
|
|
|
|
|
- $scope.$on('typeahead-updated', function() {
|
|
|
- $scope.$apply($scope.inputMetric);
|
|
|
- $scope.refreshMetricData();
|
|
|
+ $scope.$on('typeahead-updated', () => {
|
|
|
+ $scope.$apply(this.inputMetric);
|
|
|
+ this.refreshMetricData();
|
|
|
});
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- $scope.refreshMetricData = function() {
|
|
|
- if (!_.isEqual($scope.oldTarget, $scope.target)) {
|
|
|
- $scope.oldTarget = angular.copy($scope.target);
|
|
|
- $scope.paneCtrl.refresh();
|
|
|
+ refreshMetricData() {
|
|
|
+ if (!_.isEqual(this.oldTarget, this.target)) {
|
|
|
+ this.oldTarget = angular.copy(this.target);
|
|
|
+ this.panelCtrl.refresh();
|
|
|
}
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- $scope.inputMetric = function() {
|
|
|
- $scope.target.expr += $scope.target.metric;
|
|
|
- $scope.metric = '';
|
|
|
- };
|
|
|
+ inputMetric() {
|
|
|
+ this.target.expr += this.target.metric;
|
|
|
+ this.metric = '';
|
|
|
+ }
|
|
|
|
|
|
- $scope.suggestMetrics = function(query, callback) {
|
|
|
- $scope.datasource
|
|
|
- .performSuggestQuery(query)
|
|
|
- .then(callback);
|
|
|
- };
|
|
|
+ suggestMetrics(query, callback) {
|
|
|
+ this.datasource.performSuggestQuery(query).then(callback);
|
|
|
+ }
|
|
|
|
|
|
- $scope.linkToPrometheus = function() {
|
|
|
- var range = Math.ceil(($scope.range.to.valueOf() - $scope.range.from.valueOf()) / 1000);
|
|
|
- var endTime = $scope.range.to.utc().format('YYYY-MM-DD HH:mm');
|
|
|
+ linkToPrometheus() {
|
|
|
+ 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');
|
|
|
var expr = {
|
|
|
- expr: templateSrv.replace($scope.target.expr, $scope.panel.scopedVars),
|
|
|
- range_input: range + 's',
|
|
|
+ expr: this.templateSrv.replace(this.target.expr, this.panelCtrl.panel.scopedVars),
|
|
|
+ range_input: rangeDiff + 's',
|
|
|
end_input: endTime,
|
|
|
step_input: '',
|
|
|
- stacked: $scope.panel.stack,
|
|
|
+ stacked: this.panelCtrl.panel.stack,
|
|
|
tab: 0
|
|
|
};
|
|
|
var hash = encodeURIComponent(JSON.stringify([expr]));
|
|
|
- return $scope.datasource.directUrl + '/graph#' + hash;
|
|
|
+ return this.datasource.directUrl + '/graph#' + hash;
|
|
|
};
|
|
|
-
|
|
|
- $scope.init();
|
|
|
}
|
|
|
|
|
|
export {PrometheusQueryCtrl};
|