Skip to content

Commit

Permalink
allow selection of relative history
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Jan 10, 2018
1 parent 040e075 commit d45ebad
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@
</div>

<div class="kbn-timepicker-actions kuiVerticalRhythm">
<select
ng-if="history.length > 0"
ng-change="selectHistory(selectedIndex)"
ng-model="selectedIndex"
class="kuiSelect fullWidth"
>
<option value="" disabled selected hidden>Select previous absolute time</option>
<option
ng-repeat="time in history"
value="{{$index}}"
>
{{time.from}} to {{time.to}}
</option>
</select>
<span
class="kbn-timepicker-action-item kbn-timepicker-error"
ng-show="checkRelative()"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import template from './kbn_timepicker_relative_panel.html';
import { uiModules } from 'ui/modules';
import { timeHistory } from 'ui/timefilter/time_history';
import { TIME_MODES } from 'ui/timepicker/modes';

const module = uiModules.get('ui/timepicker');

Expand All @@ -14,10 +16,20 @@ module.directive('kbnTimepickerRelativePanel', function () {
relative: '=',
relativeOptions: '=',
setRelativeToNow: '&',
setRelative: '&',
units: '='
},
template,
controller: function () {
controller: function ($scope) {
$scope.history = timeHistory.getTimeHistory(TIME_MODES.RELATIVE);
$scope.selectHistory = function (selectedIndex) {
if ($scope.history[selectedIndex]) {
$scope.setRelative({
from: $scope.history[selectedIndex].from,
to: $scope.history[selectedIndex].to
});
}
};
}
};
});
1 change: 1 addition & 0 deletions src/ui/public/timepicker/timepicker.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ <h2 class="kuiLocalDropdownTitle kbn-timepicker-title__text">
relative="relative"
relative-options="relativeOptions"
set-relative-to-now="setRelativeToNow(key)"
set-relative="setRelative(from, to)"
units="units"
role="tabpanel"
aria-labelledby="timepickerRelative"
Expand Down
10 changes: 7 additions & 3 deletions src/ui/public/timepicker/timepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ module.directive('kbnTimepicker', function (timeUnits, refreshIntervals) {
case TIME_MODES.QUICK:
break;
case TIME_MODES.RELATIVE:
$scope.relative = parseRelativeParts($scope.from, $scope.to);
$scope.formatRelative('from');
$scope.formatRelative('to');
$scope.setRelative($scope.from, $scope.to);
break;
case TIME_MODES.ABSOLUTE:
$scope.absolute.from = dateMath.parse($scope.from || moment().subtract(15, 'minutes'));
Expand All @@ -157,6 +155,12 @@ module.directive('kbnTimepicker', function (timeUnits, refreshIntervals) {
$scope.formatRelative(key);
};

$scope.setRelative = function (from, to) {
$scope.relative = parseRelativeParts(from, to);
$scope.formatRelative('from');
$scope.formatRelative('to');
};

$scope.checkRelative = function () {
if ($scope.relative.from.count != null && $scope.relative.to.count != null) {
const from = dateMath.parse(getRelativeString('from'));
Expand Down

0 comments on commit d45ebad

Please sign in to comment.