Commit 27e486d6 by Patrick O'Carroll Committed by Carl Bergquist

converted 3 .js files to .ts (#9958)

* converted files from .js to .ts
parent ca940c2a
define([
'angular',
'lodash',
],
function (angular, _) {
'use strict';
import angular from 'angular';
import _ from 'lodash';
var module = angular.module('grafana.controllers');
export class CloudWatchQueryParameter {
module.directive('cloudwatchQueryParameter', function() {
constructor() {
return {
templateUrl: 'public/app/plugins/datasource/cloudwatch/partials/query.parameter.html',
controller: 'CloudWatchQueryParameterCtrl',
......@@ -18,9 +14,12 @@ function (angular, _) {
onChange: "&",
}
};
});
}
}
module.controller('CloudWatchQueryParameterCtrl', function($scope, templateSrv, uiSegmentSrv, datasourceSrv, $q) {
export class CloudWatchQueryParameterCtrl {
constructor($scope, templateSrv, uiSegmentSrv, datasourceSrv, $q) {
$scope.init = function() {
var target = $scope.target;
......@@ -120,8 +119,7 @@ function (angular, _) {
if (segment.value === $scope.removeDimSegment.value) {
$scope.dimSegments.splice(index, 3);
}
else if (segment.type === 'plus-button') {
} else if (segment.type === 'plus-button') {
$scope.dimSegments.push(uiSegmentSrv.newOperator('='));
$scope.dimSegments.push(uiSegmentSrv.newFake('select dimension value', 'value', 'query-segment-value'));
segment.type = 'key';
......@@ -195,7 +193,8 @@ function (angular, _) {
};
$scope.init();
}
}
});
});
angular.module('grafana.controllers').directive('cloudwatchQueryParameter', CloudWatchQueryParameter);
angular.module('grafana.controllers').controller('CloudWatchQueryParameterCtrl', CloudWatchQueryParameterCtrl);
define([
'lodash'
],
function (_) {
'use strict';
import _ from "lodash";
function PrometheusMetricFindQuery(datasource, query, timeSrv) {
export default class PrometheusMetricFindQuery {
datasource: any;
query: any;
range: any;
constructor(datasource, query, timeSrv) {
this.datasource = datasource;
this.query = query;
this.range = timeSrv.timeRange();
}
PrometheusMetricFindQuery.prototype.process = function() {
process() {
var label_values_regex = /^label_values\((?:(.+),\s*)?([a-zA-Z_][a-zA-Z0-9_]+)\)$/;
var metric_names_regex = /^metrics\((.+)\)$/;
var query_result_regex = /^query_result\((.+)\)$/;
......@@ -18,7 +19,10 @@ function (_) {
var label_values_query = this.query.match(label_values_regex);
if (label_values_query) {
if (label_values_query[1]) {
return this.labelValuesQuery(label_values_query[2], label_values_query[1]);
return this.labelValuesQuery(
label_values_query[2],
label_values_query[1]
);
} else {
return this.labelValuesQuery(label_values_query[2], null);
}
......@@ -36,29 +40,32 @@ function (_) {
// if query contains full metric name, return metric name and label list
return this.metricNameAndLabelsQuery(this.query);
};
}
PrometheusMetricFindQuery.prototype.labelValuesQuery = function(label, metric) {
labelValuesQuery(label, metric) {
var url;
if (!metric) {
// return label values globally
url = '/api/v1/label/' + label + '/values';
url = "/api/v1/label/" + label + "/values";
return this.datasource._request('GET', url).then(function(result) {
return this.datasource._request("GET", url).then(function(result) {
return _.map(result.data.data, function(value) {
return {text: value};
return { text: value };
});
});
} else {
var start = this.datasource.getPrometheusTime(this.range.from, false);
var end = this.datasource.getPrometheusTime(this.range.to, true);
url = '/api/v1/series?match[]=' + encodeURIComponent(metric)
+ '&start=' + start
+ '&end=' + end;
return this.datasource._request('GET', url)
.then(function(result) {
url =
"/api/v1/series?match[]=" +
encodeURIComponent(metric) +
"&start=" +
start +
"&end=" +
end;
return this.datasource._request("GET", url).then(function(result) {
var _labels = _.map(result.data.data, function(metric) {
return metric[label];
});
......@@ -71,58 +78,64 @@ function (_) {
});
});
}
};
}
PrometheusMetricFindQuery.prototype.metricNameQuery = function(metricFilterPattern) {
var url = '/api/v1/label/__name__/values';
metricNameQuery(metricFilterPattern) {
var url = "/api/v1/label/__name__/values";
return this.datasource._request('GET', url)
.then(function(result) {
return this.datasource._request("GET", url).then(function(result) {
return _.chain(result.data.data)
.filter(function(metricName) {
var r = new RegExp(metricFilterPattern);
return r.test(metricName);
})
.map(function(matchedMetricName) {
return {
text: matchedMetricName,
expandable: true
};
})
.value();
.filter(function(metricName) {
var r = new RegExp(metricFilterPattern);
return r.test(metricName);
})
.map(function(matchedMetricName) {
return {
text: matchedMetricName,
expandable: true
};
})
.value();
});
};
}
PrometheusMetricFindQuery.prototype.queryResultQuery = function(query) {
queryResultQuery(query) {
var end = this.datasource.getPrometheusTime(this.range.to, true);
return this.datasource.performInstantQuery({ expr: query }, end)
.then(function(result) {
return _.map(result.data.data.result, function(metricData) {
var text = metricData.metric.__name__ || '';
delete metricData.metric.__name__;
text += '{' +
_.map(metricData.metric, function(v, k) { return k + '="' + v + '"'; }).join(',') +
'}';
text += ' ' + metricData.value[1] + ' ' + metricData.value[0] * 1000;
return this.datasource
.performInstantQuery({ expr: query }, end)
.then(function(result) {
return _.map(result.data.data.result, function(metricData) {
var text = metricData.metric.__name__ || "";
delete metricData.metric.__name__;
text +=
"{" +
_.map(metricData.metric, function(v, k) {
return k + '="' + v + '"';
}).join(",") +
"}";
text += " " + metricData.value[1] + " " + metricData.value[0] * 1000;
return {
text: text,
expandable: true
};
return {
text: text,
expandable: true
};
});
});
});
};
}
PrometheusMetricFindQuery.prototype.metricNameAndLabelsQuery = function(query) {
metricNameAndLabelsQuery(query) {
var start = this.datasource.getPrometheusTime(this.range.from, false);
var end = this.datasource.getPrometheusTime(this.range.to, true);
var url = '/api/v1/series?match[]=' + encodeURIComponent(query)
+ '&start=' + start
+ '&end=' + end;
var url =
"/api/v1/series?match[]=" +
encodeURIComponent(query) +
"&start=" +
start +
"&end=" +
end;
var self = this;
return this.datasource._request('GET', url)
.then(function(result) {
return this.datasource._request("GET", url).then(function(result) {
return _.map(result.data.data, function(metric) {
return {
text: self.datasource.getOriginalMetricName(metric),
......@@ -130,7 +143,5 @@ function (_) {
};
});
});
};
return PrometheusMetricFindQuery;
});
}
}
define([
'angular',
'jquery',
'lodash',
], function(angular, jquery, _) {
'use strict';
import _ from 'lodash';
import angular from 'angular';
var module = angular.module('grafana.controllers');
export class SeriesOverridesCtrl {
module.controller('SeriesOverridesCtrl', function($scope, $element, popoverSrv) {
/** @ngInject */
constructor($scope, $element, popoverSrv) {
$scope.overrideMenu = [];
$scope.currentOverrides = [];
$scope.override = $scope.override || {};
$scope.addOverrideOption = function(name, propertyName, values) {
var option = {};
option.text = name;
option.propertyName = propertyName;
option.index = $scope.overrideMenu.length;
option.values = values;
option.submenu = _.map(values, function(value) {
return { text: String(value), value: value };
});
var option = {
text: name,
propertyName: propertyName,
index: $scope.overrideMenu.lenght,
values: values,
submenu: _.map(values, function(value) {
return { text: String(value), value: value };
})
};
$scope.overrideMenu.push(option);
};
......@@ -97,22 +94,24 @@ define([
$scope.addOverrideOption('Bars', 'bars', [true, false]);
$scope.addOverrideOption('Lines', 'lines', [true, false]);
$scope.addOverrideOption('Line fill', 'fill', [0,1,2,3,4,5,6,7,8,9,10]);
$scope.addOverrideOption('Line width', 'linewidth', [0,1,2,3,4,5,6,7,8,9,10]);
$scope.addOverrideOption('Line fill', 'fill', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
$scope.addOverrideOption('Line width', 'linewidth', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
$scope.addOverrideOption('Null point mode', 'nullPointMode', ['connected', 'null', 'null as zero']);
$scope.addOverrideOption('Fill below to', 'fillBelowTo', $scope.getSeriesNames());
$scope.addOverrideOption('Staircase line', 'steppedLine', [true, false]);
$scope.addOverrideOption('Dashes', 'dashes', [true, false]);
$scope.addOverrideOption('Dash Length', 'dashLength', [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]);
$scope.addOverrideOption('Dash Space', 'spaceLength', [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]);
$scope.addOverrideOption('Dash Length', 'dashLength', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]);
$scope.addOverrideOption('Dash Space', 'spaceLength', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]);
$scope.addOverrideOption('Points', 'points', [true, false]);
$scope.addOverrideOption('Points Radius', 'pointradius', [1,2,3,4,5]);
$scope.addOverrideOption('Points Radius', 'pointradius', [1, 2, 3, 4, 5]);
$scope.addOverrideOption('Stack', 'stack', [true, false, 'A', 'B', 'C', 'D']);
$scope.addOverrideOption('Color', 'color', ['change']);
$scope.addOverrideOption('Y-axis', 'yaxis', [1, 2]);
$scope.addOverrideOption('Z-index', 'zindex', [-3,-2,-1,0,1,2,3]);
$scope.addOverrideOption('Z-index', 'zindex', [-3, -2, -1, 0, 1, 2, 3]);
$scope.addOverrideOption('Transform', 'transform', ['negative-Y']);
$scope.addOverrideOption('Legend', 'legend', [true, false]);
$scope.updateCurrentOverrides();
});
});
}
}
angular.module('grafana.controllers').controller('SeriesOverridesCtrl', SeriesOverridesCtrl);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment