OLD | NEW |
---|---|
(Empty) | |
1 /* | |
epoger
2013/07/26 21:43:02
To check it out in action, go to https://x20web.co
| |
2 * JsonDataModule: | |
3 * Reads an actual-results.json file, and imports its data into $scope. | |
4 */ | |
5 var JsonDataModule = angular.module( | |
6 'JsonDataModule', | |
7 [], | |
8 function($httpProvider) { | |
9 /* Override transformResponse so that the numeric checksums are interprete d as | |
10 * strings instead, since Javascript cannot handle 64-bit integers. */ | |
11 $httpProvider.defaults.transformResponse = function(data, headersGetter) { | |
12 return JSON.parse(data.replace(/\s(\d+)\s/g, " \"$1\" ")); | |
13 } | |
14 } | |
15 ); | |
16 JsonDataModule.controller( | |
17 'JsonDataModule.Controller', | |
18 function($scope, $http) { | |
19 /* When the changePlatformPath function is called, download actual-results .json | |
20 * from the desired platform directory. | |
21 * | |
22 * When the JSON is received, return it in several forms that are needed b y | |
23 * the frontend: | |
24 * 1. rawJsonData | |
Zach Reizner
2013/07/29 18:40:34
rawJsonData is not used in the front end.
epoger
2013/07/29 22:38:39
Correct. rawJsonData had been used by the fronten
| |
25 * 2. actualResults (an array broken down by result type) | |
26 * 3. expectedResultsByImageName (a dictionary) | |
27 */ | |
28 $scope.changePlatformPath = function() { | |
29 $http.get($scope.platformPath + "/actual-results.json").success( | |
30 function(response) { | |
31 | |
32 // Return rawJsonData | |
33 $scope.rawJsonData = response; | |
34 | |
35 // Assemble and return actualResults | |
36 var actualResults = []; | |
37 angular.forEach(response['actual-results'], function(resultsOfThis Type, resultType) { | |
38 var resultCollection = []; | |
39 angular.forEach(resultsOfThisType, function(hashTypeAndValue, im ageName) { | |
40 var hashType = hashTypeAndValue[0]; | |
41 var hashValue = hashTypeAndValue[1]; | |
42 var testName = imageName.replace(/_[^_]+\.png/, ""); | |
43 var url = "http://chromium-skia-gm.commondatastorage.googleapi s.com/gm/" | |
44 + hashType + "/" + testName + "/" + hashValue + ".png"; | |
45 var thisResult = new Object(); | |
Zach Reizner
2013/07/29 18:40:34
Creating objects like this is clearer and more Jav
epoger
2013/07/29 22:38:39
Cool, thanks for the tip! Done.
| |
46 thisResult['imageName'] = imageName; | |
47 thisResult['testName'] = testName; | |
Zach Reizner
2013/07/29 18:40:34
testName is not used in the front end. Neither is
epoger
2013/07/29 22:38:39
hashValue *is* used, but the others aren't... remo
| |
48 thisResult['hashType'] = hashType; | |
49 thisResult['hashValue'] = hashValue; | |
50 thisResult['url'] = url; | |
51 resultCollection.push(thisResult); | |
52 }); | |
53 var resultTypeAndCollection = new Object(); | |
54 resultTypeAndCollection['resultType'] = resultType; | |
55 resultTypeAndCollection['resultsOfThisType'] = resultCollection; | |
56 actualResults.push(resultTypeAndCollection); | |
57 }); | |
58 $scope.actualResults = actualResults; | |
59 | |
60 // Assemble and return expectedResultsByImageName | |
61 var expectedResultsByImageName = response['expected-results']; | |
62 angular.forEach(expectedResultsByImageName, function(resultsForThi sImageName, imageName) { | |
63 var allowedDigests = resultsForThisImageName['allowed-digests']; | |
64 if (allowedDigests != null) { | |
65 var hashType = allowedDigests[0][0]; | |
66 var hashValue = allowedDigests[0][1]; | |
67 var testName = imageName.replace(/_[^_]+\.png/, ""); | |
68 var url = "http://chromium-skia-gm.commondatastorage.googleapi s.com/gm/" | |
69 + hashType + "/" + testName + "/" + hashValue + ".png"; | |
70 expectedResultsByImageName[imageName]['hashValue'] = hashValue ; | |
71 expectedResultsByImageName[imageName]['url'] = url; | |
72 } | |
73 }); | |
74 $scope.expectedResultsByImageName = expectedResultsByImageName; | |
75 | |
76 } | |
77 ); | |
78 }; | |
79 } | |
80 ); | |
OLD | NEW |