Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!-- | |
| 2 Copyright 2016 The LUCI Authors. All rights reserved. | |
| 3 Use of this source code is governed under the Apache License, Version 2.0 | |
| 4 that can be found in the LICENSE file. | |
| 5 | |
| 6 This in an HTML Import-able file that contains the definition | |
| 7 of the following elements: | |
| 8 | |
| 9 <sort-toggle> | |
| 10 | |
| 11 Sort-toggle is a small ui widget that can be tapped to change the way | |
| 12 something is sorted. | |
| 13 | |
| 14 Properties: | |
| 15 name: String, the name of the thing being sorted. To be used in the | |
| 16 fired event. | |
| 17 sort: Number, the direction of the sorting. 1, 0, -1 for | |
|
stephana
2016/07/29 14:09:31
IMO, should be a string with either values: 'asc',
kjlubick
2016/07/29 19:13:25
Done.
| |
| 18 ascending/nothing/descending. | |
| 19 | |
| 20 Methods: | |
| 21 None. | |
| 22 | |
| 23 Events: | |
| 24 sort_change: when a user has tapped this element. The details includes | |
| 25 name and sort. | |
| 26 --> | |
| 27 | |
| 28 <link rel="import" href="/res/imp/bower_components/iron-icons/iron-icons.html"> | |
| 29 | |
| 30 <dom-module id="sort-toggle"> | |
| 31 <template> | |
| 32 <style> | |
| 33 :host { | |
| 34 display: inline-block; | |
| 35 position: relative; | |
| 36 min-width: 20px; | |
| 37 min-height: 16px; | |
| 38 vertical-align: middle; | |
| 39 } | |
| 40 iron-icon { | |
| 41 position: absolute; | |
| 42 left: 0; | |
| 43 cursor: pointer; | |
| 44 } | |
| 45 .hidden { | |
| 46 visibility: hidden; | |
| 47 } | |
| 48 </style> | |
| 49 | |
| 50 <span on-click="toggle"> | |
| 51 <iron-icon | |
| 52 style="top:0" | |
| 53 class$="[[_hidden(sort,'1')]]" | |
| 54 icon="icons:arrow-drop-down"> | |
| 55 </iron-icon> | |
| 56 <iron-icon | |
| 57 style="bottom:0" | |
| 58 class$="[[_hidden(sort,'-1')]]" | |
| 59 icon="icons:arrow-drop-up"> | |
| 60 </iron-icon> | |
| 61 </span> | |
| 62 | |
| 63 </template> | |
| 64 <script> | |
| 65 Polymer({ | |
| 66 is: "sort-toggle", | |
| 67 properties: { | |
| 68 name: { | |
| 69 type: String, | |
| 70 observer: "_resetSort", | |
| 71 }, | |
| 72 sort: { | |
| 73 type: Number, | |
| 74 value: 0, | |
| 75 notify: true, | |
| 76 }, | |
| 77 }, | |
| 78 toggle: function() { | |
|
stephana
2016/07/29 14:09:31
Nit: spaces between methods.
kjlubick
2016/07/29 19:13:25
Done.
| |
| 79 if (this.sort === -1) { | |
| 80 this.set("sort", 0); | |
| 81 } else if (this.sort === 1) { | |
| 82 this.set("sort", -1); | |
| 83 } else { | |
| 84 this.set("sort", 1); | |
| 85 } | |
| 86 this.fire("sort_change", {sort: this.sort, name: this.name}); | |
| 87 }, | |
| 88 _hidden: function(num, compare) { | |
| 89 // double equals intentionally used here because compare is a string | |
| 90 // and num is an int. | |
| 91 if (num == compare) { | |
| 92 return "hidden"; | |
| 93 } | |
| 94 return ""; | |
| 95 }, | |
| 96 _resetSort: function(newV, old) { | |
| 97 // Because of how Polymer inserts and moves elements around, we need to | |
| 98 // reset the sort value if the name changes so the ascending sort by | |
| 99 // "os" doesn't become the ascending sort by "gpu" if a column gets | |
| 100 // added before "os", for example. | |
| 101 this.set("sort", 0); | |
| 102 this.fire("sort_change", {sort: 0, name: newV}); | |
| 103 }, | |
| 104 }); | |
| 105 </script> | |
| 106 </dom-module> | |
| OLD | NEW |