blob: 8b5374a323320018e259d886f1280655842b16a9 [file] [log] [blame]
epoger@google.comf9d134d2013-09-27 15:02:44 +00001/*
2 * Loader:
epoger@google.comafaad3d2013-09-30 15:06:25 +00003 * Reads GM result reports written out by results.py, and imports
4 * them into $scope.categories and $scope.testData .
epoger@google.comf9d134d2013-09-27 15:02:44 +00005 */
6var Loader = angular.module(
7 'Loader',
8 []
9);
epoger@google.com5f2bb002013-10-02 18:57:48 +000010
11// TODO(epoger): Combine ALL of our filtering operations (including
12// truncation) into this one filter, so that runs most efficiently?
13// (We would have to make sure truncation still took place after
14// sorting, though.)
15Loader.filter(
16 'removeHiddenItems',
17 function() {
18 return function(unfilteredItems, hiddenResultTypes, hiddenConfigs) {
19 var filteredItems = [];
20 for (var i = 0; i < unfilteredItems.length; i++) {
21 var item = unfilteredItems[i];
22 if ((hiddenResultTypes.indexOf(item.resultType) < 0) &&
23 (hiddenConfigs.indexOf(item.config) < 0)) {
24 filteredItems.push(item);
25 }
26 }
27 return filteredItems;
28 };
29 }
30);
31
epoger@google.comf9d134d2013-09-27 15:02:44 +000032Loader.controller(
33 'Loader.Controller',
epoger@google.com5f2bb002013-10-02 18:57:48 +000034 function($scope, $http, $filter) {
epoger@google.comf9d134d2013-09-27 15:02:44 +000035 $http.get("/results/all").then(
36 function(response) {
epoger@google.comafaad3d2013-09-30 15:06:25 +000037 $scope.categories = response.data.categories;
38 $scope.testData = response.data.testData;
epoger@google.comf9d134d2013-09-27 15:02:44 +000039 $scope.sortColumn = 'test';
epoger@google.com5f2bb002013-10-02 18:57:48 +000040
41 $scope.hiddenResultTypes = [
42 'failure-ignored', 'no-comparison', 'succeeded'];
43 $scope.hiddenConfigs = [];
44
45 $scope.updateResults();
epoger@google.comf9d134d2013-09-27 15:02:44 +000046 }
47 );
epoger@google.com5f2bb002013-10-02 18:57:48 +000048
49 $scope.isHiddenResultType = function(thisResultType) {
50 return ($scope.hiddenResultTypes.indexOf(thisResultType) >= 0);
51 }
52 $scope.toggleHiddenResultType = function(thisResultType) {
53 var i = $scope.hiddenResultTypes.indexOf(thisResultType);
54 if (i >= 0) {
55 $scope.hiddenResultTypes.splice(i, 1);
56 } else {
57 $scope.hiddenResultTypes.push(thisResultType);
58 }
59 $scope.areUpdatesPending = true;
60 }
61
62 // TODO(epoger): Rather than maintaining these as hard-coded
63 // variants of isHiddenResultType and toggleHiddenResultType, we
64 // should create general-purpose functions that can work with ANY
65 // category.
66 // But for now, I wanted to see this working. :-)
67 $scope.isHiddenConfig = function(thisConfig) {
68 return ($scope.hiddenConfigs.indexOf(thisConfig) >= 0);
69 }
70 $scope.toggleHiddenConfig = function(thisConfig) {
71 var i = $scope.hiddenConfigs.indexOf(thisConfig);
72 if (i >= 0) {
73 $scope.hiddenConfigs.splice(i, 1);
74 } else {
75 $scope.hiddenConfigs.push(thisConfig);
76 }
77 $scope.areUpdatesPending = true;
78 }
79
80 $scope.updateResults = function() {
81 $scope.displayLimit = $scope.displayLimitPending;
82 // TODO(epoger): Every time we apply a filter, AngularJS creates
83 // another copy of the array. Is there a way we can filter out
84 // the items as they are displayed, rather than storing multiple
85 // array copies? (For better performance.)
86 $scope.filteredTestData =
87 $filter("orderBy")(
88 $filter("removeHiddenItems")(
89 $scope.testData,
90 $scope.hiddenResultTypes,
91 $scope.hiddenConfigs
92 ),
93 $scope.sortColumn);
94 $scope.limitedTestData = $filter("limitTo")(
95 $scope.filteredTestData, $scope.displayLimit);
96 $scope.imageSize = $scope.imageSizePending;
97 $scope.areUpdatesPending = false;
98 }
99
100 $scope.sortResultsBy = function(sortColumn) {
101 $scope.sortColumn = sortColumn;
102 $scope.updateResults();
103 }
epoger@google.comf9d134d2013-09-27 15:02:44 +0000104 }
105);