|
|
@@ -8,7 +8,7 @@ function (angular, _, $) {
|
|
|
|
|
|
var module = angular.module('grafana.services');
|
|
|
|
|
|
- module.factory('dashboardViewStateSrv', function($location, $timeout) {
|
|
|
+ module.factory('dashboardViewStateSrv', function($location, $timeout, templateSrv, contextSrv, timeSrv) {
|
|
|
|
|
|
// represents the transient view state
|
|
|
// like fullscreen panel & edit
|
|
|
@@ -25,6 +25,19 @@ function (angular, _, $) {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ // update url on time range change
|
|
|
+ $scope.onAppEvent('time-range-changed', function() {
|
|
|
+ var urlParams = $location.search();
|
|
|
+ var urlRange = timeSrv.timeRangeForUrl();
|
|
|
+ urlParams.from = urlRange.from;
|
|
|
+ urlParams.to = urlRange.to;
|
|
|
+ $location.search(urlParams);
|
|
|
+ });
|
|
|
+
|
|
|
+ $scope.onAppEvent('template-variable-value-updated', function() {
|
|
|
+ self.updateUrlParamsWithCurrentVariables();
|
|
|
+ });
|
|
|
+
|
|
|
$scope.onAppEvent('$routeUpdate', function() {
|
|
|
var urlState = self.getQueryStringState();
|
|
|
if (self.needsSync(urlState)) {
|
|
|
@@ -40,10 +53,26 @@ function (angular, _, $) {
|
|
|
self.registerPanel(payload.scope);
|
|
|
});
|
|
|
|
|
|
- this.update(this.getQueryStringState(), true);
|
|
|
+ this.update(this.getQueryStringState());
|
|
|
this.expandRowForPanel();
|
|
|
}
|
|
|
|
|
|
+ DashboardViewState.prototype.updateUrlParamsWithCurrentVariables = function() {
|
|
|
+ // update url
|
|
|
+ var params = $location.search();
|
|
|
+ // remove variable params
|
|
|
+ _.each(params, function(value, key) {
|
|
|
+ if (key.indexOf('var-') === 0) {
|
|
|
+ delete params[key];
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // add new values
|
|
|
+ templateSrv.fillVariableValuesForUrl(params);
|
|
|
+ // update url
|
|
|
+ $location.search(params);
|
|
|
+ };
|
|
|
+
|
|
|
DashboardViewState.prototype.expandRowForPanel = function() {
|
|
|
if (!this.state.panelId) { return; }
|
|
|
|
|
|
@@ -63,6 +92,7 @@ function (angular, _, $) {
|
|
|
state.fullscreen = state.fullscreen ? true : null;
|
|
|
state.edit = (state.edit === "true" || state.edit === true) || null;
|
|
|
state.editview = state.editview || null;
|
|
|
+ state.org = contextSrv.user.orgId;
|
|
|
return state;
|
|
|
};
|
|
|
|
|
|
@@ -70,10 +100,11 @@ function (angular, _, $) {
|
|
|
var urlState = _.clone(this.state);
|
|
|
urlState.fullscreen = this.state.fullscreen ? true : null;
|
|
|
urlState.edit = this.state.edit ? true : null;
|
|
|
+ urlState.org = contextSrv.user.orgId;
|
|
|
return urlState;
|
|
|
};
|
|
|
|
|
|
- DashboardViewState.prototype.update = function(state, skipUrlSync) {
|
|
|
+ DashboardViewState.prototype.update = function(state) {
|
|
|
_.extend(this.state, state);
|
|
|
this.dashboard.meta.fullscreen = this.state.fullscreen;
|
|
|
|
|
|
@@ -83,10 +114,7 @@ function (angular, _, $) {
|
|
|
this.state.edit = null;
|
|
|
}
|
|
|
|
|
|
- if (!skipUrlSync) {
|
|
|
- $location.search(this.serializeToUrl());
|
|
|
- }
|
|
|
-
|
|
|
+ $location.search(this.serializeToUrl());
|
|
|
this.syncState();
|
|
|
};
|
|
|
|