forked from grafana/influxdb-08-datasource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_ctrl.js
108 lines (88 loc) · 2.93 KB
/
query_ctrl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
define([
'angular',
'app/plugins/sdk'
],
function (angular, sdk) {
'use strict';
var seriesList = null;
var InfluxQueryCtrl08 = (function(_super) {
var self;
function InfluxQueryCtrl08($scope, $injector, $timeout) {
_super.call(this, $scope, $injector)
this.timeout = $timeout;
this.scope = $scope;
var target = this.target;
target.function = target.function || 'mean';
target.column = target.column || 'value';
// backward compatible correction of schema
if (target.condition_value) {
target.condition = target.condition_key + ' ' + target.condition_op + ' ' + target.condition_value;
delete target.condition_key;
delete target.condition_op;
delete target.condition_value;
}
if (target.groupby_field_add === false) {
target.groupby_field = '';
delete target.groupby_field_add;
}
this.functions = [
'count', 'mean', 'sum', 'min',
'max', 'mode', 'distinct', 'median',
'derivative', 'stddev', 'first', 'last',
'difference'
];
this.operators = ['=', '=~', '>', '<', '!~', '<>'];
this.oldSeries = target.series;
//this.$on('typeahead-updated', function() {
// self.timeout(self.panelCtrl.refresh);
//});
self = this;
};
InfluxQueryCtrl08.prototype = Object.create(_super.prototype);
InfluxQueryCtrl08.prototype.constructor = InfluxQueryCtrl08;
InfluxQueryCtrl08.templateUrl = 'public/plugins/grafana-influxdb-08-datasource/partials/query.editor.html';
InfluxQueryCtrl08.prototype.toggleEditorMode = function () {
this.target.rawQuery = !this.target.rawQuery;
};
// Cannot use typeahead and ng-change on blur at the same time
InfluxQueryCtrl08.prototype.seriesBlur = function() {
if (this.oldSeries !== this.target.series) {
this.oldSeries = this.target.series;
this.columnList = null;
this.panelCtrl.refresh();
}
};
InfluxQueryCtrl08.prototype.changeFunction = function(func) {
this.target.function = func;
this.panelCtrl.refresh();
};
// called outside of digest
InfluxQueryCtrl08.prototype.listColumns = function(query, callback) {
if (!self.columnList) {
self.scope.$apply(function() {
self.datasource.listColumns(self.target.series).then(function(columns) {
self.columnList = columns;
callback(columns);
});
});
}
else {
return self.columnList;
}
};
InfluxQueryCtrl08.prototype.listSeries = function(query, callback) {
if (query !== '') {
seriesList = [];
this.datasource.listSeries(query).then(function(series) {
seriesList = series;
callback(seriesList);
});
}
else {
return seriesList;
}
};
return InfluxQueryCtrl08;
})(sdk.QueryCtrl);
return InfluxQueryCtrl08;
});