Only add parameters to the URL when changed from defaults

Currently, page state parameters like 'end', 'resolutionKey', and
'groupKey' are sync'd to the page URL on every page change
unconditionally. This results in a lot of unnecessary information that
we can assume by default until a user actually requests a different
value.

This patch modifies the current parameter sync implementation so that
it only maintains page parameters after their initial values have been
explicitly set by a user, and assumes default values otherwise. In
most cases, this should significantly shorten shared URL length.

Change-Id: Ife271444817bdfa8d19c0b69ca6039c5c7c290db
Closes-Bug: #1572766
This commit is contained in:
Tim Buckley 2016-04-20 23:00:47 -06:00
parent f6f12919af
commit 9bb57ab0b4
3 changed files with 27 additions and 19 deletions

View File

@ -162,7 +162,6 @@ function HomeController(
// ViewModel
var vm = this;
vm.loadData = loadData;
vm.groupKey = viewService.groupKey();
vm.searchProject = $location.search().searchProject || '';
vm.loaded = false;
vm.hold = 0;
@ -170,6 +169,11 @@ function HomeController(
vm.recentRuns = {};
vm.apiRoot = null;
vm.groupKey = viewService.groupKey();
if (vm.groupKey !== 'project') {
$location.search('groupKey', vm.groupKey);
}
configurePeriods();
loadData();
@ -177,6 +181,10 @@ function HomeController(
vm.groupKey = groupKey;
configurePeriods();
loadData();
// set the groupKey here instead of in the viewService, since we only need
// it to be sharable from the this page
$location.search('groupKey', groupKey).replace();
});
$scope.$on('view:resolution', function(event, resolution) {

View File

@ -48,12 +48,10 @@ function crumbMenu() {
};
$scope.$on('view:resolution', function(event, resolution) {
$location.search('resolutionKey', resolution.key).replace();
$scope.selectedResolution = resolution;
});
$scope.$on('view:groupKey', function(event, groupKey) {
$location.search('groupKey', groupKey).replace();
$scope.selectedGroupKey = groupKey;
});

View File

@ -24,19 +24,6 @@ var viewService = function($rootScope, $location) {
}
});
var regActionSuccess = $rootScope.$on('$locationChangeSuccess', function() {
$location.search('groupKey', groupKey);
$location.search('resolutionKey', resolution.key);
if (userDuration !== null) {
$location.search('duration', userDuration.toISOString());
}
if (periodEnd !== null) {
$location.search('end', periodEnd.toISOString());
}
$location.replace();
});
var periodEnd = new Date();
var periodOptions = [
moment.duration({ hours: 1 }),
@ -62,6 +49,20 @@ var viewService = function($rootScope, $location) {
periodEnd = new Date(searchEnd);
}
var searchParams = new Map();
var search = function(key, value) {
$location.search(key, value).replace();
searchParams.set(key, value);
};
var regActionSuccess = $rootScope.$on('$locationChangeSuccess', function() {
searchParams.forEach(function(value, key) {
$location.search(key, value);
});
$location.replace();
});
var selectDuration = function() {
if (userDuration) {
return userDuration;
@ -77,6 +78,7 @@ var viewService = function($rootScope, $location) {
if (arguments.length === 1) {
resolution = res;
$rootScope.$broadcast('view:resolution', res);
search('resolutionKey', resolution.key);
}
return resolution;
@ -87,7 +89,7 @@ var viewService = function($rootScope, $location) {
},
groupKey: function(key) {
if (arguments.length === 1) {
if (arguments.length === 1 && groupKey !== key) {
groupKey = key;
$rootScope.$broadcast('view:groupKey', groupKey);
}
@ -104,7 +106,7 @@ var viewService = function($rootScope, $location) {
return periodEnd;
}
$location.search('end', end.toISOString()).replace();
search('end', end.toISOString());
periodEnd = end;
$rootScope.$broadcast('view:periodEnd', end);
@ -176,7 +178,7 @@ var viewService = function($rootScope, $location) {
$rootScope.$broadcast('view:duration', duration, false);
$rootScope.$broadcast('view:period', false);
$location.search('duration', userDuration.toISOString()).replace();
search('duration', userDuration.toISOString());
return duration;
},