mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(relative time override): You can now use the new relative time option in panel time override, closes #2575
This commit is contained in:
parent
6d3b36d61b
commit
292db86c9e
@ -163,6 +163,20 @@ function($, _, moment) {
|
|||||||
return info.sec * info.count;
|
return info.sec * info.count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
kbn.getRelativeTimeInfo = function(str) {
|
||||||
|
var info = {value: str};
|
||||||
|
if (str === 'today') {
|
||||||
|
info.text = 'Today';
|
||||||
|
info.from = 'today';
|
||||||
|
info.to = 'now';
|
||||||
|
} else {
|
||||||
|
info.text = 'Last ' + str;
|
||||||
|
info.from = 'now-'+str;
|
||||||
|
info.to = 'now';
|
||||||
|
}
|
||||||
|
return info;
|
||||||
|
};
|
||||||
|
|
||||||
/* This is a simplified version of elasticsearch's date parser */
|
/* This is a simplified version of elasticsearch's date parser */
|
||||||
kbn.parseDate = function(text) {
|
kbn.parseDate = function(text) {
|
||||||
if(_.isDate(text)) {
|
if(_.isDate(text)) {
|
||||||
@ -205,7 +219,7 @@ function($, _, moment) {
|
|||||||
return kbn.parseDateMath(mathString, time);
|
return kbn.parseDateMath(mathString, time);
|
||||||
};
|
};
|
||||||
|
|
||||||
kbn._timespanRegex = /^\d+[h,m,M,w,s,H,d]$/;
|
kbn._timespanRegex = /^(\d+[h,m,M,w,s,H,d])|today$/;
|
||||||
kbn.isValidTimeSpan = function(str) {
|
kbn.isValidTimeSpan = function(str) {
|
||||||
return kbn._timespanRegex.test(str);
|
return kbn._timespanRegex.test(str);
|
||||||
};
|
};
|
||||||
|
@ -69,8 +69,10 @@ function (angular, _, kbn, $) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_.isString(scope.rangeUnparsed.from)) {
|
if (_.isString(scope.rangeUnparsed.from)) {
|
||||||
scope.panelMeta.timeInfo = "last " + scope.panel.timeFrom;
|
var timeInfo = kbn.getRelativeTimeInfo(scope.panel.timeFrom)
|
||||||
scope.rangeUnparsed.from = 'now-' + scope.panel.timeFrom;
|
scope.panelMeta.timeInfo = timeInfo.text;
|
||||||
|
scope.rangeUnparsed.from = timeInfo.from;
|
||||||
|
scope.rangeUnparsed.to = timeInfo.to;
|
||||||
scope.range.from = kbn.parseDate(scope.rangeUnparsed.from);
|
scope.range.from = kbn.parseDate(scope.rangeUnparsed.from);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,17 +74,7 @@ function (angular, app, _, moment, kbn) {
|
|||||||
|
|
||||||
$scope.loadTimeOptions = function() {
|
$scope.loadTimeOptions = function() {
|
||||||
$scope.time_options = _.map($scope.panel.time_options, function(str) {
|
$scope.time_options = _.map($scope.panel.time_options, function(str) {
|
||||||
var option = {value: str};
|
return kbn.getRelativeTimeInfo(str);
|
||||||
if (str === 'today') {
|
|
||||||
option.text = 'Today';
|
|
||||||
option.from = 'today';
|
|
||||||
option.to = 'now';
|
|
||||||
} else {
|
|
||||||
option.text = 'Last ' + str;
|
|
||||||
option.from = 'now-'+str;
|
|
||||||
option.to = 'now';
|
|
||||||
}
|
|
||||||
return option;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.refreshMenuLeftSide = $scope.time.rangeString.length < 10;
|
$scope.refreshMenuLeftSide = $scope.time.rangeString.length < 10;
|
||||||
|
Loading…
Reference in New Issue
Block a user