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