OLD | NEW |
1 <!-- | 1 <!-- |
2 Copyright 2014 The Chromium Authors. All rights reserved. | 2 Copyright 2014 The Chromium Authors. All rights reserved. |
3 Use of this source code is governed by a BSD-style license that can be | 3 Use of this source code is governed by a BSD-style license that can be |
4 found in the LICENSE file. | 4 found in the LICENSE file. |
5 --> | 5 --> |
6 | 6 |
7 <link rel="import" href="ct-commit-list.html"> | 7 <link rel="import" href="ct-commit-list.html"> |
8 | 8 |
9 <script> | 9 <script> |
10 function CTFailureGroup(failures, commitList) { | 10 function CTFailureGroup(data) { |
11 this.failures = failures; | 11 this.data = data; |
12 this.commitList = commitList; | 12 this._annotation = CTFailureGroup._mergeAnnotations(data.getAnnotations()); |
13 this._annotation = CTFailureGroup._mergeAnnotations(failures.map(function(fail
ure) { | |
14 return failure.annotations(); | |
15 }).flatten()); | |
16 this._computeProperties(); | 13 this._computeProperties(); |
17 } | 14 } |
18 | 15 |
| 16 CTFailureGroup.prototype.dataToExamine = function() { |
| 17 return this.data.dataToExamine(); |
| 18 } |
| 19 |
19 CTFailureGroup.prototype.snoozeUntil = function(time) { | 20 CTFailureGroup.prototype.snoozeUntil = function(time) { |
20 return this._annotate({ | 21 return this._annotate({ |
21 snoozeTime: time, | 22 snoozeTime: time, |
22 }); | 23 }); |
23 }; | 24 }; |
24 | 25 |
25 CTFailureGroup.prototype.unsnooze = function() { | 26 CTFailureGroup.prototype.unsnooze = function() { |
26 return this._annotate({ | 27 return this._annotate({ |
27 snoozeTime: undefined, | 28 snoozeTime: undefined, |
28 }); | 29 }); |
(...skipping 23 matching lines...) Expand all Loading... |
52 } | 53 } |
53 | 54 |
54 this.bug = this._annotation.bug; | 55 this.bug = this._annotation.bug; |
55 // FIXME: Bug labels would be simpler to implement as a filter in the UI. | 56 // FIXME: Bug labels would be simpler to implement as a filter in the UI. |
56 if (this.bug != null) | 57 if (this.bug != null) |
57 this.bugLabel = 'Bug ' + /([0-9]{3,})/.exec(this.bug)[0]; | 58 this.bugLabel = 'Bug ' + /([0-9]{3,})/.exec(this.bug)[0]; |
58 else | 59 else |
59 this.bugLabel = undefined; | 60 this.bugLabel = undefined; |
60 }; | 61 }; |
61 | 62 |
62 CTFailureGroup.prototype.failureKeys = function() { | |
63 return this.failures.map(function(failure) { | |
64 return failure.keys(); | |
65 }).flatten(); | |
66 }; | |
67 | |
68 CTFailureGroup._mergeAnnotations = function(failureAnnotations) { | 63 CTFailureGroup._mergeAnnotations = function(failureAnnotations) { |
69 // FIXME: This should be a union of all bugs. | 64 // FIXME: This should be a union of all bugs. |
70 var bug = failureAnnotations.map('bug').compact().first(); | 65 var bug = failureAnnotations.map('bug').compact().first(); |
71 | 66 |
72 // The group is only snoozed if all the failures specify a snooze-time, and on
ly | 67 // The group is only snoozed if all the failures specify a snooze-time, and on
ly |
73 // until the first has elapsed. | 68 // until the first has elapsed. |
74 var snoozeTimes = failureAnnotations.map('snoozeTime').compact(); | 69 var snoozeTimes = failureAnnotations.map('snoozeTime').compact(); |
75 var snoozeTime = snoozeTimes.length < failureAnnotations.length ? undefined :
snoozeTimes.min(); | 70 var snoozeTime = snoozeTimes.length < failureAnnotations.length ? undefined :
snoozeTimes.min(); |
76 | 71 |
77 var annotation = {}; | 72 var annotation = {}; |
78 if (bug != null) { | 73 if (bug != null) { |
79 annotation.bug = bug; | 74 annotation.bug = bug; |
80 } | 75 } |
81 if (snoozeTime != null) { | 76 if (snoozeTime != null) { |
82 annotation.snoozeTime = snoozeTime; | 77 annotation.snoozeTime = snoozeTime; |
83 } | 78 } |
84 return annotation; | 79 return annotation; |
85 }; | 80 }; |
86 | 81 |
87 CTFailureGroup.prototype._annotate = function(newAnnotation) { | 82 CTFailureGroup.prototype._annotate = function(newAnnotation) { |
88 var failureAnnotations = []; | 83 var failureAnnotations = []; |
89 // FIXME: Post the new annotation to frontend rather than storing locally. | 84 // FIXME: Post the new annotation to frontend rather than storing locally. |
90 return CTFailureGroup.fetchAnnotations().then(function(annotations) { | 85 return CTFailureGroup.fetchAnnotations().then(function(annotations) { |
91 this.failureKeys().forEach(function(failureKey) { | 86 this.data.failureKeys().forEach(function(failureKey) { |
92 var annotation = annotations[failureKey] || {}; | 87 var annotation = annotations[failureKey] || {}; |
93 | 88 |
94 Object.keys(newAnnotation, function(key, value) { | 89 Object.keys(newAnnotation, function(key, value) { |
95 if (value === undefined) { | 90 if (value === undefined) { |
96 delete annotation[key]; | 91 delete annotation[key]; |
97 } else { | 92 } else { |
98 annotation[key] = value; | 93 annotation[key] = value; |
99 } | 94 } |
100 }); | 95 }); |
101 | 96 |
(...skipping 11 matching lines...) Expand all Loading... |
113 }.bind(this)); | 108 }.bind(this)); |
114 }; | 109 }; |
115 | 110 |
116 CTFailureGroup.fetchAnnotations = function() { | 111 CTFailureGroup.fetchAnnotations = function() { |
117 // FIXME: Fetch annotations from frontend. | 112 // FIXME: Fetch annotations from frontend. |
118 var stored = localStorage.CTFailureGroupAnnotations; | 113 var stored = localStorage.CTFailureGroupAnnotations; |
119 var annotations = stored ? JSON.parse(stored) : {}; | 114 var annotations = stored ? JSON.parse(stored) : {}; |
120 return Promise.resolve(annotations); | 115 return Promise.resolve(annotations); |
121 }; | 116 }; |
122 </script> | 117 </script> |
OLD | NEW |