Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!-- | |
| 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. | |
| 5 --> | |
| 6 | |
| 7 <script> | |
| 8 function CTFailureGroup(key, failures, annotation) { | |
| 9 this.key = key; | |
| 10 this.failures = failures; | |
| 11 this.annotation = annotation || {}; | |
| 12 this._computeProperties(); | |
| 13 } | |
| 14 | |
| 15 CTFailureGroup.prototype.snoozeUntil = function(time) { | |
| 16 return this._annotate({ | |
| 17 snoozeTime: time, | |
| 18 }); | |
| 19 }; | |
| 20 | |
| 21 CTFailureGroup.prototype.unsnooze = function() { | |
| 22 return this._annotate({ | |
| 23 snoozeTime: undefined, | |
| 24 }); | |
| 25 }; | |
| 26 | |
| 27 CTFailureGroup.prototype._computeProperties = function() { | |
| 28 this.isSnoozed = Date.now() < this.annotation.snoozeTime; | |
| 29 }; | |
| 30 | |
| 31 CTFailureGroup.prototype._annotate = function(newAnnotation) { | |
| 32 // FIXME: Post the new annotation to frontend rather than storing locally. | |
| 33 return CTFailureGroup.fetchAnnotations().then(function(annotations) { | |
| 34 var annotation = annotations[this.key] || {}; | |
| 35 | |
| 36 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.
| |
| 37 var value = newAnnotation[key]; | |
| 38 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.
| |
| 39 delete annotation[key]; | |
| 40 } else { | |
| 41 annotation[key] = value; | |
| 42 } | |
| 43 }); | |
| 44 | |
| 45 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.
| |
| 46 delete annotations[this.key]; | |
| 47 } else { | |
| 48 annotations[this.key] = annotation; | |
| 49 } | |
| 50 | |
| 51 localStorage.CTFailureGroupAnnotations = JSON.stringify(annotations); | |
| 52 | |
| 53 this.annotation = annotation; | |
| 54 this._computeProperties(); | |
| 55 }.bind(this)); | |
| 56 }; | |
| 57 | |
| 58 CTFailureGroup.fetchAnnotations = function() { | |
| 59 // FIXME: Fetch annotations from frontend. | |
| 60 var stored = localStorage.CTFailureGroupAnnotations; | |
| 61 var annotations = stored ? JSON.parse(stored) : {}; | |
| 62 return Promise.resolve(annotations); | |
| 63 }; | |
| 64 </script> | |
| OLD | NEW |