Chromium Code Reviews| Index: Tools/GardeningServer/model/ct-failure-group.html |
| diff --git a/Tools/GardeningServer/model/ct-failure-group.html b/Tools/GardeningServer/model/ct-failure-group.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e814bb0290ba0bcf5131063665d3b002baacf621 |
| --- /dev/null |
| +++ b/Tools/GardeningServer/model/ct-failure-group.html |
| @@ -0,0 +1,64 @@ |
| +<!-- |
| +Copyright 2014 The Chromium Authors. All rights reserved. |
| +Use of this source code is governed by a BSD-style license that can be |
| +found in the LICENSE file. |
| +--> |
| + |
| +<script> |
| +function CTFailureGroup(key, failures, annotation) { |
| + this.key = key; |
| + this.failures = failures; |
| + this.annotation = annotation || {}; |
| + this._computeProperties(); |
| +} |
| + |
| +CTFailureGroup.prototype.snoozeUntil = function(time) { |
| + return this._annotate({ |
| + snoozeTime: time, |
| + }); |
| +}; |
| + |
| +CTFailureGroup.prototype.unsnooze = function() { |
| + return this._annotate({ |
| + snoozeTime: undefined, |
| + }); |
| +}; |
| + |
| +CTFailureGroup.prototype._computeProperties = function() { |
| + this.isSnoozed = Date.now() < this.annotation.snoozeTime; |
| +}; |
| + |
| +CTFailureGroup.prototype._annotate = function(newAnnotation) { |
| + // FIXME: Post the new annotation to frontend rather than storing locally. |
| + return CTFailureGroup.fetchAnnotations().then(function(annotations) { |
| + var annotation = annotations[this.key] || {}; |
| + |
| + Object.keys(newAnnotation).forEach(function(key) { |
|
ojan
2014/08/07 00:09:57
Nit: The sugarjs Object.keys takes a callback func
dstockwell
2014/08/11 01:20:42
Done.
|
| + var value = newAnnotation[key]; |
| + if (typeof value == 'undefined') { |
|
ojan
2014/08/07 00:09:58
Nit: I'd just do:
if (value === undefined)
...
e
dstockwell
2014/08/11 01:20:42
Done.
|
| + delete annotation[key]; |
| + } else { |
| + annotation[key] = value; |
| + } |
| + }); |
| + |
| + if (Object.keys(annotation).length == 0) { |
|
ojan
2014/08/07 00:09:57
sugarjs has Object.size. So this can just be
if (O
dstockwell
2014/08/11 01:20:42
Done.
|
| + delete annotations[this.key]; |
| + } else { |
| + annotations[this.key] = annotation; |
| + } |
| + |
| + localStorage.CTFailureGroupAnnotations = JSON.stringify(annotations); |
| + |
| + this.annotation = annotation; |
| + this._computeProperties(); |
| + }.bind(this)); |
| +}; |
| + |
| +CTFailureGroup.fetchAnnotations = function() { |
| + // FIXME: Fetch annotations from frontend. |
| + var stored = localStorage.CTFailureGroupAnnotations; |
| + var annotations = stored ? JSON.parse(stored) : {}; |
| + return Promise.resolve(annotations); |
| +}; |
| +</script> |