Commit 1060eeb1 by Torkel Ödegaard

feat(dashboard): include org id query parameter in dashboard url, #1613

parent f923edc4
......@@ -27,25 +27,8 @@ export class SubmenuCtrl {
return this.templateValuesSrv.getValuesForTag(variable, tagKey);
}
updateUrlParamsWithCurrentVariables() {
// update url
var params = this.$location.search();
// remove variable params
_.each(params, function(value, key) {
if (key.indexOf('var-') === 0) {
delete params[key];
}
});
// add new values
this.templateSrv.fillVariableValuesForUrl(params);
// update url
this.$location.search(params);
}
variableUpdated(variable) {
this.templateValuesSrv.variableUpdated(variable).then(() => {
this.updateUrlParamsWithCurrentVariables();
this.dynamicDashboardSrv.update(this.dashboard);
this.$rootScope.$emit('template-variable-value-updated');
this.$rootScope.$broadcast('refresh');
......
......@@ -10,7 +10,7 @@ define([
var module = angular.module('grafana.services');
module.service('timeSrv', function($rootScope, $timeout, $routeParams, timer, $location) {
module.service('timeSrv', function($rootScope, $timeout, $routeParams, timer) {
var self = this;
this.init = function(dashboard) {
......@@ -108,13 +108,6 @@ define([
this.old_refresh = null;
}
// update url params
var urlParams = $location.search();
var urlRange = this.timeRangeForUrl();
urlParams.from = urlRange.from;
urlParams.to = urlRange.to;
$location.search(urlParams);
$rootScope.appEvent('time-range-changed', this.time);
$timeout(this.refreshDashboard, 0);
};
......
......@@ -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)) {
......@@ -44,6 +57,22 @@ function (angular, _, $) {
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());
}
this.syncState();
};
......
......@@ -5,8 +5,20 @@ define([
describe('when updating view state', function() {
var viewState, location;
var timeSrv = {};
var templateSrv = {};
var contextSrv = {
user: {
orgId: 19
}
};
beforeEach(module('grafana.services'));
beforeEach(module(function($provide) {
$provide.value('timeSrv', timeSrv);
$provide.value('templateSrv', templateSrv);
$provide.value('contextSrv', contextSrv);
}));
beforeEach(inject(function(dashboardViewStateSrv, $location, $rootScope) {
$rootScope.onAppEvent = function() {};
......@@ -17,9 +29,9 @@ define([
describe('to fullscreen true and edit true', function() {
it('should update querystring and view state', function() {
var updateState = { fullscreen: true, edit: true, panelId: 1 };
var updateState = {fullscreen: true, edit: true, panelId: 1};
viewState.update(updateState);
expect(location.search()).to.eql(updateState);
expect(location.search()).to.eql({fullscreen: true, edit: true, panelId: 1, org: 19});
expect(viewState.dashboard.meta.fullscreen).to.be(true);
expect(viewState.state.fullscreen).to.be(true);
});
......@@ -29,7 +41,7 @@ define([
it('should remove params from query string', function() {
viewState.update({fullscreen: true, panelId: 1, edit: true});
viewState.update({fullscreen: false});
expect(location.search()).to.eql({});
expect(location.search()).to.eql({org: 19});
expect(viewState.dashboard.meta.fullscreen).to.be(false);
expect(viewState.state.fullscreen).to.be(null);
});
......
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