| OLD | NEW |
| (Empty) | |
| 1 <!-- The <commits-panel-sk> custom element declaration. |
| 2 |
| 3 An element to display information on one or more commits. |
| 4 |
| 5 Attributes: |
| 6 mailbox - The sk.Mailbox name to listen for the data to populate |
| 7 the element. The mailbox data needs to be a serialized slice |
| 8 of []*types.Commit. |
| 9 |
| 10 Events: |
| 11 None. |
| 12 |
| 13 Methods: |
| 14 None. |
| 15 |
| 16 |
| 17 --> |
| 18 <polymer-element name="commits-panel-sk"> |
| 19 <template> |
| 20 <table> |
| 21 <template repeat="{{c in commitinfo}}"> |
| 22 <tr> |
| 23 <td>{{c.author}}</td> |
| 24 <td>{{c.commit_time | humanize}}</td> |
| 25 <td><a href="https://skia.googlesource.com/skia/+/{{c.hash}}">{{c.hash
| trunc}}</a></td> |
| 26 <td>{{c.message}}</td> |
| 27 </tr> |
| 28 </template> |
| 29 </table> |
| 30 </template> |
| 31 <script> |
| 32 Polymer({ |
| 33 publish: { |
| 34 mailbox: { |
| 35 value: "", |
| 36 reflect: true, |
| 37 }, |
| 38 }, |
| 39 |
| 40 ready: function() { |
| 41 sk.Mailbox.subscribe(this.mailbox, function(info) { |
| 42 this.commitinfo = info; |
| 43 this.populateCommitMessage(); |
| 44 }.bind(this)); |
| 45 }, |
| 46 |
| 47 populateCommitMessage: function() { |
| 48 if (this.commitinfo && this.commitinfo.length && this.commitinfo[0].mess
age == undefined) { |
| 49 var lastHash = this.commitinfo[0].hash; |
| 50 var url = "https://skia.googlesource.com/skia/+log/" + lastHash + "~"
+ this.commitinfo.length + ".." + lastHash + "?format=json"; |
| 51 sk.get(url).then(this.removeSecurityHeader).then(JSON.parse).then(func
tion(json) { |
| 52 var len = this.commitinfo.length; |
| 53 for (var i=0; i<json.log.length; i++) { |
| 54 this.commitinfo[i].message = json.log[i].message.slice(0, 60); |
| 55 } |
| 56 }.bind(this)); |
| 57 } |
| 58 }, |
| 59 |
| 60 // removeSecurityHeader strips the first 4 chars from the input. Needed |
| 61 // since googlesource.com prefixes all JSON responses with )]}' as an |
| 62 // XSS defense. |
| 63 removeSecurityHeader: function(s) { |
| 64 return s.slice(4, s.length); |
| 65 }, |
| 66 |
| 67 humanize: function(s) { |
| 68 return sk.human.diffDate(s*1000); |
| 69 }, |
| 70 |
| 71 trunc: function(s) { |
| 72 return s.slice(0, 7); |
| 73 } |
| 74 |
| 75 }); |
| 76 </script> |
| 77 </polymer-element> |
| OLD | NEW |