Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Loader: | 2 * Loader: |
| 3 * Reads GM result reports written out by results.py, and imports | 3 * Reads GM result reports written out by results.py, and imports |
| 4 * them into $scope.categories and $scope.testData . | 4 * them into $scope.categories and $scope.testData . |
| 5 */ | 5 */ |
| 6 var Loader = angular.module( | 6 var Loader = angular.module( |
| 7 'Loader', | 7 'Loader', |
| 8 [] | 8 [] |
| 9 ); | 9 ); |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 return filteredItems; | 35 return filteredItems; |
| 36 }; | 36 }; |
| 37 } | 37 } |
| 38 ); | 38 ); |
| 39 | 39 |
| 40 | 40 |
| 41 Loader.controller( | 41 Loader.controller( |
| 42 'Loader.Controller', | 42 'Loader.Controller', |
| 43 function($scope, $http, $filter, $location) { | 43 function($scope, $http, $filter, $location) { |
| 44 $scope.windowTitle = "Loading GM Results..."; | 44 $scope.windowTitle = "Loading GM Results..."; |
| 45 var resultsToLoad = $location.search().resultsToLoad; | 45 $scope.resultsToLoad = $location.search().resultsToLoad; |
| 46 $scope.loadingMessage = "Loading results of type '" + resultsToLoad + | 46 $scope.loadingMessage = "Loading results of type '" + $scope.resultsToLoad + |
| 47 "', please wait..."; | 47 "', please wait..."; |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * On initial page load, load a full dictionary of results. | 50 * On initial page load, load a full dictionary of results. |
| 51 * Once the dictionary is loaded, unhide the page elements so they can | 51 * Once the dictionary is loaded, unhide the page elements so they can |
| 52 * render the data. | 52 * render the data. |
| 53 */ | 53 */ |
| 54 $http.get("/results/" + resultsToLoad).success( | 54 $http.get("/results/" + $scope.resultsToLoad).success( |
| 55 function(data, status, header, config) { | 55 function(data, status, header, config) { |
| 56 $scope.loadingMessage = "Processing data, please wait..."; | 56 $scope.loadingMessage = "Processing data, please wait..."; |
| 57 | 57 |
| 58 $scope.header = data.header; | 58 $scope.header = data.header; |
| 59 $scope.categories = data.categories; | 59 $scope.categories = data.categories; |
| 60 $scope.testData = data.testData; | 60 $scope.testData = data.testData; |
| 61 $scope.sortColumn = 'weightedDiffMeasure'; | 61 $scope.sortColumn = 'weightedDiffMeasure'; |
| 62 $scope.showTodos = false; | 62 $scope.showTodos = false; |
| 63 | 63 |
| 64 $scope.showSubmitAdvancedSettings = false; | 64 $scope.showSubmitAdvancedSettings = false; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 }; | 103 }; |
| 104 $scope.allResultTypes = Object.keys(data.categories['resultType']); | 104 $scope.allResultTypes = Object.keys(data.categories['resultType']); |
| 105 $scope.hiddenConfigs = {}; | 105 $scope.hiddenConfigs = {}; |
| 106 $scope.allConfigs = Object.keys(data.categories['config']); | 106 $scope.allConfigs = Object.keys(data.categories['config']); |
| 107 | 107 |
| 108 // Associative array of partial string matches per category. | 108 // Associative array of partial string matches per category. |
| 109 $scope.categoryValueMatch = {}; | 109 $scope.categoryValueMatch = {}; |
| 110 $scope.categoryValueMatch.builder = ""; | 110 $scope.categoryValueMatch.builder = ""; |
| 111 $scope.categoryValueMatch.test = ""; | 111 $scope.categoryValueMatch.test = ""; |
| 112 | 112 |
| 113 // If any defaults were overridden in the URL, get them now. | |
| 114 $scope.parseURL(); | |
| 115 | |
| 113 $scope.updateResults(); | 116 $scope.updateResults(); |
| 114 $scope.loadingMessage = ""; | 117 $scope.loadingMessage = ""; |
| 115 $scope.windowTitle = "Current GM Results"; | 118 $scope.windowTitle = "Current GM Results"; |
| 116 } | 119 } |
| 117 ).error( | 120 ).error( |
| 118 function(data, status, header, config) { | 121 function(data, status, header, config) { |
| 119 $scope.loadingMessage = "Failed to load results of type '" | 122 $scope.loadingMessage = "Failed to load results of type '" |
| 120 + resultsToLoad + "'"; | 123 + $scope.resultsToLoad + "'"; |
| 121 $scope.windowTitle = "Failed to Load GM Results"; | 124 $scope.windowTitle = "Failed to Load GM Results"; |
| 122 } | 125 } |
| 123 ); | 126 ); |
| 124 | 127 |
| 125 | 128 |
| 126 // | 129 // |
| 127 // Select/Clear/Toggle all tests. | 130 // Select/Clear/Toggle all tests. |
| 128 // | 131 // |
| 129 | 132 |
| 130 /** | 133 /** |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 for (var i = 0; i < numItems; i++) { | 207 for (var i = 0; i < numItems; i++) { |
| 205 itemIndex = itemIndices[i]; | 208 itemIndex = itemIndices[i]; |
| 206 $scope.numResultsPerTab[$scope.testData[itemIndex].tab]--; | 209 $scope.numResultsPerTab[$scope.testData[itemIndex].tab]--; |
| 207 $scope.testData[itemIndex].tab = newTab; | 210 $scope.testData[itemIndex].tab = newTab; |
| 208 } | 211 } |
| 209 $scope.numResultsPerTab[newTab] += numItems; | 212 $scope.numResultsPerTab[newTab] += numItems; |
| 210 } | 213 } |
| 211 | 214 |
| 212 | 215 |
| 213 // | 216 // |
| 217 // Read/write parameters within the URL. | |
| 218 // | |
| 219 | |
| 220 // Simple variables within $scope | |
| 221 simpleUrlParams = ['resultsToLoad', 'displayLimitPending', | |
| 222 'imageSizePending', 'sortColumn']; | |
| 223 // Elements within the associative array $scope.categoryValueMatch | |
| 224 categoryUrlParams = ['builder', 'test']; | |
| 225 // Sets, each of which has 0 or more values. | |
| 226 setUrlParams = ['hiddenResultTypes', 'hiddenConfigs']; | |
| 227 | |
| 228 /** | |
| 229 * Updates the URL, so that current filter results can be bookmarked. | |
| 230 */ | |
| 231 $scope.updateURL = function() { | |
| 232 var nameValuePairs = {}; | |
| 233 for (var i = simpleUrlParams.length - 1; i >= 0; i--) { | |
| 234 var name = simpleUrlParams[i]; | |
| 235 nameValuePairs[name] = $scope[name]; | |
| 236 } | |
| 237 for (var i = categoryUrlParams.length - 1; i >= 0; i--) { | |
| 238 var name = categoryUrlParams[i]; | |
| 239 nameValuePairs[name] = $scope.categoryValueMatch[name]; | |
| 240 } | |
| 241 for (var i = setUrlParams.length - 1; i >= 0; i--) { | |
| 242 var name = setUrlParams[i]; | |
| 243 nameValuePairs[name] = Object.keys($scope[name]).join(','); | |
| 244 } | |
| 245 $location.search(nameValuePairs); | |
| 246 } | |
| 247 | |
| 248 /** | |
| 249 * Reads parameter settings from the URL. | |
| 250 * Any which are not found within the URL will keep their current value. | |
| 251 */ | |
| 252 $scope.parseURL = function() { | |
| 253 var nameValuePairs = $location.search(); | |
| 254 for (var i = simpleUrlParams.length - 1; i >= 0; i--) { | |
| 255 var name = simpleUrlParams[i]; | |
| 256 var value = nameValuePairs[name]; | |
| 257 if (value) { | |
| 258 $scope[name] = value; | |
| 259 } | |
| 260 } | |
| 261 for (var i = categoryUrlParams.length - 1; i >= 0; i--) { | |
| 262 var name = categoryUrlParams[i]; | |
| 263 var value = nameValuePairs[name]; | |
| 264 if (value) { | |
| 265 $scope.categoryValueMatch[name] = value; | |
| 266 } | |
| 267 } | |
| 268 for (var i = setUrlParams.length - 1; i >= 0; i--) { | |
| 269 var name = setUrlParams[i]; | |
| 270 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
| |
| 271 if (value) { | |
| 272 var valueArray = value.split(','); | |
| 273 $scope[name] = {}; | |
| 274 $scope.toggleValuesInSet(valueArray, $scope[name]); | |
| 275 } | |
| 276 } | |
| 277 } | |
| 278 | |
| 279 | |
| 280 // | |
| 214 // updateResults() and friends. | 281 // updateResults() and friends. |
| 215 // | 282 // |
| 216 | 283 |
| 217 /** | 284 /** |
| 218 * Set $scope.areUpdatesPending (to enable/disable the Update Results | 285 * Set $scope.areUpdatesPending (to enable/disable the Update Results |
| 219 * button). | 286 * button). |
| 220 * | 287 * |
| 221 * TODO(epoger): We could reduce the amount of code by just setting the | 288 * TODO(epoger): We could reduce the amount of code by just setting the |
| 222 * variable directly (from, e.g., a button's ng-click handler). But when | 289 * variable directly (from, e.g., a button's ng-click handler). But when |
| 223 * I tried that, the HTML elements depending on the variable did not get | 290 * I tried that, the HTML elements depending on the variable did not get |
| 224 * updated. | 291 * updated. |
| 225 * It turns out that this is due to variable scoping within an ng-repeat | 292 * It turns out that this is due to variable scoping within an ng-repeat |
| 226 * element; see http://stackoverflow.com/questions/15388344/behavior-of-assi gnment-expression-invoked-by-ng-click-within-ng-repeat | 293 * element; see http://stackoverflow.com/questions/15388344/behavior-of-assi gnment-expression-invoked-by-ng-click-within-ng-repeat |
| 227 * | 294 * |
| 228 * @param val boolean value to set $scope.areUpdatesPending to | 295 * @param val boolean value to set $scope.areUpdatesPending to |
| 229 */ | 296 */ |
| 230 $scope.setUpdatesPending = function(val) { | 297 $scope.setUpdatesPending = function(val) { |
| 231 $scope.areUpdatesPending = val; | 298 $scope.areUpdatesPending = val; |
| 232 } | 299 } |
| 233 | 300 |
| 234 /** | 301 /** |
| 235 * Update the displayed results, based on filters/settings. | 302 * Update the displayed results, based on filters/settings, |
| 303 * and call updateURL() so that the new filter results can be bookmarked. | |
| 236 */ | 304 */ |
| 237 $scope.updateResults = function() { | 305 $scope.updateResults = function() { |
| 238 $scope.displayLimit = $scope.displayLimitPending; | 306 $scope.displayLimit = $scope.displayLimitPending; |
| 239 // TODO(epoger): Every time we apply a filter, AngularJS creates | 307 // TODO(epoger): Every time we apply a filter, AngularJS creates |
| 240 // another copy of the array. Is there a way we can filter out | 308 // another copy of the array. Is there a way we can filter out |
| 241 // the items as they are displayed, rather than storing multiple | 309 // the items as they are displayed, rather than storing multiple |
| 242 // array copies? (For better performance.) | 310 // array copies? (For better performance.) |
| 243 | 311 |
| 244 if ($scope.viewingTab == $scope.defaultTab) { | 312 if ($scope.viewingTab == $scope.defaultTab) { |
| 245 | 313 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 268 $filter("filter")( | 336 $filter("filter")( |
| 269 $scope.testData, | 337 $scope.testData, |
| 270 {tab: $scope.viewingTab}, | 338 {tab: $scope.viewingTab}, |
| 271 true | 339 true |
| 272 ), | 340 ), |
| 273 $scope.sortColumn); | 341 $scope.sortColumn); |
| 274 $scope.limitedTestData = $scope.filteredTestData; | 342 $scope.limitedTestData = $scope.filteredTestData; |
| 275 } | 343 } |
| 276 $scope.imageSize = $scope.imageSizePending; | 344 $scope.imageSize = $scope.imageSizePending; |
| 277 $scope.setUpdatesPending(false); | 345 $scope.setUpdatesPending(false); |
| 346 $scope.updateURL(); | |
| 278 } | 347 } |
| 279 | 348 |
| 280 /** | 349 /** |
| 281 * Re-sort the displayed results. | 350 * Re-sort the displayed results. |
| 282 * | 351 * |
| 283 * @param sortColumn (string): name of the column to sort on | 352 * @param sortColumn (string): name of the column to sort on |
| 284 */ | 353 */ |
| 285 $scope.sortResultsBy = function(sortColumn) { | 354 $scope.sortResultsBy = function(sortColumn) { |
| 286 $scope.sortColumn = sortColumn; | 355 $scope.sortColumn = sortColumn; |
| 287 $scope.updateResults(); | 356 $scope.updateResults(); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 * | 577 * |
| 509 * @param secondsPastEpoch (numeric): seconds past epoch in UTC | 578 * @param secondsPastEpoch (numeric): seconds past epoch in UTC |
| 510 */ | 579 */ |
| 511 $scope.localTimeString = function(secondsPastEpoch) { | 580 $scope.localTimeString = function(secondsPastEpoch) { |
| 512 var d = new Date(secondsPastEpoch * 1000); | 581 var d = new Date(secondsPastEpoch * 1000); |
| 513 return d.toString(); | 582 return d.toString(); |
| 514 } | 583 } |
| 515 | 584 |
| 516 } | 585 } |
| 517 ); | 586 ); |
| OLD | NEW |