Chromium Code Reviews| Index: gm/rebaseline_server/static/loader.js |
| =================================================================== |
| --- gm/rebaseline_server/static/loader.js (revision 12480) |
| +++ gm/rebaseline_server/static/loader.js (working copy) |
| @@ -42,8 +42,8 @@ |
| 'Loader.Controller', |
| function($scope, $http, $filter, $location) { |
| $scope.windowTitle = "Loading GM Results..."; |
| - var resultsToLoad = $location.search().resultsToLoad; |
| - $scope.loadingMessage = "Loading results of type '" + resultsToLoad + |
| + $scope.resultsToLoad = $location.search().resultsToLoad; |
| + $scope.loadingMessage = "Loading results of type '" + $scope.resultsToLoad + |
| "', please wait..."; |
| /** |
| @@ -51,7 +51,7 @@ |
| * Once the dictionary is loaded, unhide the page elements so they can |
| * render the data. |
| */ |
| - $http.get("/results/" + resultsToLoad).success( |
| + $http.get("/results/" + $scope.resultsToLoad).success( |
| function(data, status, header, config) { |
| $scope.loadingMessage = "Processing data, please wait..."; |
| @@ -110,6 +110,9 @@ |
| $scope.categoryValueMatch.builder = ""; |
| $scope.categoryValueMatch.test = ""; |
| + // If any defaults were overridden in the URL, get them now. |
| + $scope.parseURL(); |
| + |
| $scope.updateResults(); |
| $scope.loadingMessage = ""; |
| $scope.windowTitle = "Current GM Results"; |
| @@ -117,7 +120,7 @@ |
| ).error( |
| function(data, status, header, config) { |
| $scope.loadingMessage = "Failed to load results of type '" |
| - + resultsToLoad + "'"; |
| + + $scope.resultsToLoad + "'"; |
| $scope.windowTitle = "Failed to Load GM Results"; |
| } |
| ); |
| @@ -211,6 +214,70 @@ |
| // |
| + // Read/write parameters within the URL. |
| + // |
| + |
| + // Simple variables within $scope |
| + simpleUrlParams = ['resultsToLoad', 'displayLimitPending', |
| + 'imageSizePending', 'sortColumn']; |
| + // Elements within the associative array $scope.categoryValueMatch |
| + categoryUrlParams = ['builder', 'test']; |
| + // Sets, each of which has 0 or more values. |
| + setUrlParams = ['hiddenResultTypes', 'hiddenConfigs']; |
| + |
| + /** |
| + * Updates the URL, so that current filter results can be bookmarked. |
| + */ |
| + $scope.updateURL = function() { |
| + var nameValuePairs = {}; |
| + for (var i = simpleUrlParams.length - 1; i >= 0; i--) { |
| + var name = simpleUrlParams[i]; |
| + nameValuePairs[name] = $scope[name]; |
| + } |
| + for (var i = categoryUrlParams.length - 1; i >= 0; i--) { |
| + var name = categoryUrlParams[i]; |
| + nameValuePairs[name] = $scope.categoryValueMatch[name]; |
| + } |
| + for (var i = setUrlParams.length - 1; i >= 0; i--) { |
| + var name = setUrlParams[i]; |
| + nameValuePairs[name] = Object.keys($scope[name]).join(','); |
| + } |
| + $location.search(nameValuePairs); |
| + } |
| + |
| + /** |
| + * Reads parameter settings from the URL. |
| + * Any which are not found within the URL will keep their current value. |
| + */ |
| + $scope.parseURL = function() { |
| + var nameValuePairs = $location.search(); |
| + for (var i = simpleUrlParams.length - 1; i >= 0; i--) { |
| + var name = simpleUrlParams[i]; |
| + var value = nameValuePairs[name]; |
| + if (value) { |
| + $scope[name] = value; |
| + } |
| + } |
| + for (var i = categoryUrlParams.length - 1; i >= 0; i--) { |
| + var name = categoryUrlParams[i]; |
| + var value = nameValuePairs[name]; |
| + if (value) { |
| + $scope.categoryValueMatch[name] = value; |
| + } |
| + } |
| + for (var i = setUrlParams.length - 1; i >= 0; i--) { |
| + var name = setUrlParams[i]; |
| + var value = nameValuePairs[name]; |
|
epoger
2013/12/04 19:49:22
The loop setup is annoyingly copy-pasted for the 3
jcgregorio
2013/12/05 15:05:09
How about a dictionary that maps query parameter n
epoger
2013/12/05 17:08:49
Hmm, interesting idea! I played with it for a whi
|
| + if (value) { |
| + var valueArray = value.split(','); |
| + $scope[name] = {}; |
| + $scope.toggleValuesInSet(valueArray, $scope[name]); |
| + } |
| + } |
| + } |
| + |
| + |
| + // |
| // updateResults() and friends. |
| // |
| @@ -232,7 +299,8 @@ |
| } |
| /** |
| - * Update the displayed results, based on filters/settings. |
| + * Update the displayed results, based on filters/settings, |
| + * and call updateURL() so that the new filter results can be bookmarked. |
| */ |
| $scope.updateResults = function() { |
| $scope.displayLimit = $scope.displayLimitPending; |
| @@ -275,6 +343,7 @@ |
| } |
| $scope.imageSize = $scope.imageSizePending; |
| $scope.setUpdatesPending(false); |
| + $scope.updateURL(); |
| } |
| /** |