Commit 2d2800e7 by Torkel Ödegaard

fix: url did not update correctly when closing settings view by using ESC key, fixes #8869

parent cff1c370
...@@ -25,7 +25,6 @@ function ($, angular, coreModule) { ...@@ -25,7 +25,6 @@ function ($, angular, coreModule) {
function hideEditorPane(hideToShowOtherView) { function hideEditorPane(hideToShowOtherView) {
if (editorScope) { if (editorScope) {
editorScope.dismiss(hideToShowOtherView); editorScope.dismiss(hideToShowOtherView);
scope.appEvent('dash-editor-hidden');
} }
} }
...@@ -61,7 +60,15 @@ function ($, angular, coreModule) { ...@@ -61,7 +60,15 @@ function ($, angular, coreModule) {
var urlParams = $location.search(); var urlParams = $location.search();
if (options.editview === urlParams.editview) { if (options.editview === urlParams.editview) {
delete urlParams.editview; delete urlParams.editview;
// even though we always are in apply phase here
// some angular bug is causing location search updates to
// not happen always so this is a hack fix or that
setTimeout(function() {
$rootScope.$apply(function() {
$location.search(urlParams); $location.search(urlParams);
});
});
} }
} }
}; };
......
...@@ -129,10 +129,13 @@ class TimeSrv { ...@@ -129,10 +129,13 @@ class TimeSrv {
} }
// update url // update url
if (interval) {
var params = this.$location.search(); var params = this.$location.search();
if (interval) {
params.refresh = interval; params.refresh = interval;
this.$location.search(params); this.$location.search(params);
} else if (params.refresh) {
delete params.refresh;
this.$location.search(params);
} }
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<label class="small">From:</label> <label class="small">From:</label>
<div class="gf-form-inline"> <div class="gf-form-inline">
<div class="gf-form max-width-28"> <div class="gf-form max-width-28">
<input type="text" class="gf-form-input input-large" ng-model="ctrl.timeRaw.from" input-datetime> <input type="text" class="gf-form-input input-large" ng-model="ctrl.editTimeRaw.from" input-datetime>
</div> </div>
<div class="gf-form"> <div class="gf-form">
<button class="btn gf-form-btn btn-primary" type="button" ng-click="openFromPicker=!openFromPicker"> <button class="btn gf-form-btn btn-primary" type="button" ng-click="openFromPicker=!openFromPicker">
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<label class="small">To:</label> <label class="small">To:</label>
<div class="gf-form-inline"> <div class="gf-form-inline">
<div class="gf-form max-width-28"> <div class="gf-form max-width-28">
<input type="text" class="gf-form-input input-large" ng-model="ctrl.timeRaw.to" input-datetime> <input type="text" class="gf-form-input input-large" ng-model="ctrl.editTimeRaw.to" input-datetime>
</div> </div>
<div class="gf-form"> <div class="gf-form">
<button class="btn gf-form-btn btn-primary" type="button" ng-click="openToPicker=!openToPicker"> <button class="btn gf-form-btn btn-primary" type="button" ng-click="openToPicker=!openToPicker">
......
...@@ -18,11 +18,11 @@ export class TimePickerCtrl { ...@@ -18,11 +18,11 @@ export class TimePickerCtrl {
panel: any; panel: any;
absolute: any; absolute: any;
timeRaw: any; timeRaw: any;
editTimeRaw: any;
tooltip: string; tooltip: string;
rangeString: string; rangeString: string;
timeOptions: any; timeOptions: any;
refresh: any; refresh: any;
isOpen: boolean;
isUtc: boolean; isUtc: boolean;
firstDayOfWeek: number; firstDayOfWeek: number;
...@@ -32,18 +32,18 @@ export class TimePickerCtrl { ...@@ -32,18 +32,18 @@ export class TimePickerCtrl {
$rootScope.onAppEvent('shift-time-forward', () => this.move(1), $scope); $rootScope.onAppEvent('shift-time-forward', () => this.move(1), $scope);
$rootScope.onAppEvent('shift-time-backward', () => this.move(-1), $scope); $rootScope.onAppEvent('shift-time-backward', () => this.move(-1), $scope);
$rootScope.onAppEvent('refresh', () => this.init(), $scope); $rootScope.onAppEvent('refresh', this.onRefresh.bind(this), $scope);
$rootScope.onAppEvent('dash-editor-hidden', () => this.isOpen = false, $scope);
this.init();
}
init() { // init options
this.panel = this.dashboard.timepicker; this.panel = this.dashboard.timepicker;
_.defaults(this.panel, TimePickerCtrl.defaults); _.defaults(this.panel, TimePickerCtrl.defaults);
this.firstDayOfWeek = moment.localeData().firstDayOfWeek(); this.firstDayOfWeek = moment.localeData().firstDayOfWeek();
// init time stuff
this.onRefresh();
}
onRefresh() {
var time = angular.copy(this.timeSrv.timeRange()); var time = angular.copy(this.timeSrv.timeRange());
var timeRaw = angular.copy(time.raw); var timeRaw = angular.copy(time.raw);
...@@ -65,13 +65,8 @@ export class TimePickerCtrl { ...@@ -65,13 +65,8 @@ export class TimePickerCtrl {
this.absolute = {fromJs: time.from.toDate(), toJs: time.to.toDate()}; this.absolute = {fromJs: time.from.toDate(), toJs: time.to.toDate()};
this.tooltip = this.dashboard.formatDate(time.from) + ' <br>to<br>'; this.tooltip = this.dashboard.formatDate(time.from) + ' <br>to<br>';
this.tooltip += this.dashboard.formatDate(time.to); this.tooltip += this.dashboard.formatDate(time.to);
// do not update time raw when dropdown is open
// as auto refresh will reset the from/to input fields
if (!this.isOpen) {
this.timeRaw = timeRaw; this.timeRaw = timeRaw;
} }
}
zoom(factor) { zoom(factor) {
this.$rootScope.appEvent('zoom-out', 2); this.$rootScope.appEvent('zoom-out', 2);
...@@ -101,8 +96,8 @@ export class TimePickerCtrl { ...@@ -101,8 +96,8 @@ export class TimePickerCtrl {
} }
openDropdown() { openDropdown() {
this.init(); this.onRefresh();
this.isOpen = true; this.editTimeRaw = this.timeRaw;
this.timeOptions = rangeUtil.getRelativeTimesList(this.panel, this.rangeString); this.timeOptions = rangeUtil.getRelativeTimesList(this.panel, this.rangeString);
this.refresh = { this.refresh = {
value: this.dashboard.refresh, value: this.dashboard.refresh,
...@@ -125,16 +120,16 @@ export class TimePickerCtrl { ...@@ -125,16 +120,16 @@ export class TimePickerCtrl {
this.timeSrv.setAutoRefresh(this.refresh.value); this.timeSrv.setAutoRefresh(this.refresh.value);
} }
this.timeSrv.setTime(this.timeRaw); this.timeSrv.setTime(this.editTimeRaw);
this.$rootScope.appEvent('hide-dash-editor'); this.$rootScope.appEvent('hide-dash-editor');
} }
absoluteFromChanged() { absoluteFromChanged() {
this.timeRaw.from = this.getAbsoluteMomentForTimezone(this.absolute.fromJs); this.editTimeRaw.from = this.getAbsoluteMomentForTimezone(this.absolute.fromJs);
} }
absoluteToChanged() { absoluteToChanged() {
this.timeRaw.to = this.getAbsoluteMomentForTimezone(this.absolute.toJs); this.editTimeRaw.to = this.getAbsoluteMomentForTimezone(this.absolute.toJs);
} }
getAbsoluteMomentForTimezone(jsDate) { getAbsoluteMomentForTimezone(jsDate) {
......
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