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
4 found in the LICENSE file.
7 <link rel="import" href="ct-commit-list.html">
10 function CTFailureGroup(key, data, category) {
13 this._annotation = CTFailureGroup._mergeAnnotations(data.getAnnotations());
14 this._originalCategory = category || 'default';
15 this._computeProperties();
18 CTFailureGroup.prototype.snoozeUntil = function(time) {
19 return this._annotate({
24 CTFailureGroup.prototype.unsnooze = function() {
25 return this._annotate({
26 snoozeTime: undefined,
30 CTFailureGroup.prototype.setBug = function(bug) {
31 if (/^[0-9]+$/.test(bug))
32 bug = 'https://crbug.com/' + bug;
33 return this._annotate({
38 CTFailureGroup.prototype.clearBug = function(bug) {
39 return this._annotate({
44 CTFailureGroup.prototype._failedOnce = function() {
45 return this.data.failedOnce && this.data.failedOnce();
48 CTFailureGroup.prototype._computeProperties = function() {
49 this.isSnoozed = Date.now() < this._annotation.snoozeTime;
51 this.category = 'snoozed';
53 if (this._failedOnce()) {
54 this.category = 'failedOnce';
56 this.category = this._originalCategory;
58 // FIXME: crbug.com/400397 Split Tree closers into their own list.
61 this.bug = this._annotation.bug;
62 // FIXME: Bug labels would be simpler to implement as a filter in the UI.
64 this.bugLabel = 'Bug ' + /([0-9]{3,})/.exec(this.bug)[0];
66 this.bugLabel = undefined;
69 CTFailureGroup._mergeAnnotations = function(failureAnnotations) {
70 // FIXME: This should be a union of all bugs.
71 var bug = failureAnnotations.map('bug').compact().first();
73 // The group is only snoozed if all the failures specify a snooze-time, and only
74 // until the first has elapsed.
75 var snoozeTimes = failureAnnotations.map('snoozeTime').compact();
76 var snoozeTime = snoozeTimes.length < failureAnnotations.length ? undefined : snoozeTimes.min();
82 if (snoozeTime != null) {
83 annotation.snoozeTime = snoozeTime;
88 CTFailureGroup.prototype._annotate = function(newAnnotation) {
89 var failureAnnotations = [];
90 // FIXME: Post the new annotation to frontend rather than storing locally.
91 return CTFailureGroup.fetchAnnotations().then(function(annotations) {
92 this.data.failureKeys().forEach(function(failureKey) {
93 var annotation = annotations[failureKey] || {};
95 Object.keys(newAnnotation, function(key, value) {
96 if (value === undefined) {
97 delete annotation[key];
99 annotation[key] = value;
103 if (Object.size(annotation) == 0) {
104 delete annotations[failureKey];
106 annotations[failureKey] = annotation;
107 failureAnnotations.push(annotation);
111 localStorage.CTFailureGroupAnnotations = JSON.stringify(annotations);
112 this._annotation = CTFailureGroup._mergeAnnotations(failureAnnotations);
113 this._computeProperties();
117 CTFailureGroup.fetchAnnotations = function() {
118 // FIXME: Fetch annotations from frontend.
119 var stored = localStorage.CTFailureGroupAnnotations;
120 var annotations = stored ? JSON.parse(stored) : {};
121 return Promise.resolve(annotations);