GUI -- Table headers can dynamically display with an icon which sorting directio…
…n the table is currently sorted as. Change-Id: I6c5e6d1c196495dc6065ae58fa6cb21001c01778
Showing
4 changed files
with
93 additions
and
32 deletions
| ... | @@ -161,6 +161,28 @@ | ... | @@ -161,6 +161,28 @@ |
| 161 | return g; | 161 | return g; |
| 162 | } | 162 | } |
| 163 | 163 | ||
| 164 | + function createSortIcon() { | ||
| 165 | + function sortAsc(div) { | ||
| 166 | + div.style('display', 'inline-block'); | ||
| 167 | + loadEmbeddedIcon(div, 'tableColSortAsc', 10); | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + function sortDesc(div) { | ||
| 171 | + div.style('display', 'inline-block'); | ||
| 172 | + loadEmbeddedIcon(div, 'tableColSortDesc', 10); | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + function sortNone(div) { | ||
| 176 | + div.remove(); | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + return { | ||
| 180 | + sortAsc: sortAsc, | ||
| 181 | + sortDesc: sortDesc, | ||
| 182 | + sortNone: sortNone | ||
| 183 | + }; | ||
| 184 | + } | ||
| 185 | + | ||
| 164 | 186 | ||
| 165 | // ========================= | 187 | // ========================= |
| 166 | // === DEFINE THE MODULE | 188 | // === DEFINE THE MODULE |
| ... | @@ -180,7 +202,8 @@ | ... | @@ -180,7 +202,8 @@ |
| 180 | loadEmbeddedIcon: loadEmbeddedIcon, | 202 | loadEmbeddedIcon: loadEmbeddedIcon, |
| 181 | addDeviceIcon: addDeviceIcon, | 203 | addDeviceIcon: addDeviceIcon, |
| 182 | addHostIcon: addHostIcon, | 204 | addHostIcon: addHostIcon, |
| 183 | - iconConfig: function () { return config; } | 205 | + iconConfig: function () { return config; }, |
| 206 | + createSortIcon: createSortIcon | ||
| 184 | }; | 207 | }; |
| 185 | }]); | 208 | }]); |
| 186 | 209 | ... | ... |
| ... | @@ -20,7 +20,7 @@ | ... | @@ -20,7 +20,7 @@ |
| 20 | (function () { | 20 | (function () { |
| 21 | 'use strict'; | 21 | 'use strict'; |
| 22 | 22 | ||
| 23 | - var $window, fs, | 23 | + var $log, $window, fs, is, |
| 24 | bottomMargin = 200; | 24 | bottomMargin = 200; |
| 25 | 25 | ||
| 26 | // Render a plain d3 table by giving it the div, a config file, and data | 26 | // Render a plain d3 table by giving it the div, a config file, and data |
| ... | @@ -101,9 +101,9 @@ | ... | @@ -101,9 +101,9 @@ |
| 101 | }); | 101 | }); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | - function fixTable(t, th, tb, height) { | 104 | + function fixTable(t, th, tb) { |
| 105 | setTableWidth(t); | 105 | setTableWidth(t); |
| 106 | - setTableHeight(th, tb, height); | 106 | + setTableHeight(th, tb); |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | angular.module('onosWidget') | 109 | angular.module('onosWidget') |
| ... | @@ -137,6 +137,7 @@ | ... | @@ -137,6 +137,7 @@ |
| 137 | 137 | ||
| 138 | scope.setTableHW = function () { | 138 | scope.setTableHW = function () { |
| 139 | scope.$on('LastElement', function (event) { | 139 | scope.$on('LastElement', function (event) { |
| 140 | + // only adjust the table once it's completely loaded | ||
| 140 | fixTable(table, thead, tbody); | 141 | fixTable(table, thead, tbody); |
| 141 | shouldResize = true; | 142 | shouldResize = true; |
| 142 | }); | 143 | }); |
| ... | @@ -153,6 +154,70 @@ | ... | @@ -153,6 +154,70 @@ |
| 153 | }); | 154 | }); |
| 154 | }; | 155 | }; |
| 155 | 156 | ||
| 157 | + }]) | ||
| 158 | + | ||
| 159 | + .directive('onosSortableHeader', ['$log', 'IconService', | ||
| 160 | + function (_$log_, _is_) { | ||
| 161 | + return function (scope, element, attrs) { | ||
| 162 | + $log = _$log_; | ||
| 163 | + is = _is_; | ||
| 164 | + var table = d3.select(element[0]), | ||
| 165 | + currCol = {}, | ||
| 166 | + prevCol = {}, | ||
| 167 | + sortIconAPI = is.createSortIcon(); | ||
| 168 | + | ||
| 169 | + // when a header is clicked, change its icon tag and get sorting | ||
| 170 | + // order to send to the server. | ||
| 171 | + table.selectAll('th').on('click', function () { | ||
| 172 | + var thElem = d3.select(this), | ||
| 173 | + div; | ||
| 174 | + | ||
| 175 | + currCol.colId = thElem.attr('colId'); | ||
| 176 | + | ||
| 177 | + if (currCol.colId === prevCol.colId) { | ||
| 178 | + (currCol.icon === 'tableColSortDesc') ? | ||
| 179 | + currCol.icon = 'tableColSortAsc' : | ||
| 180 | + currCol.icon = 'tableColSortDesc'; | ||
| 181 | + prevCol.icon = currCol.icon; | ||
| 182 | + } else { | ||
| 183 | + currCol.icon = 'tableColSortAsc'; | ||
| 184 | + prevCol.icon = 'tableColSortNone'; | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + $log.debug('currCol clicked: ' + currCol.colId + | ||
| 188 | + ', with sorting icon: ' + currCol.icon); | ||
| 189 | + $log.debug('prevCol clicked: ' + prevCol.colId + | ||
| 190 | + ', with its current sorting icon as ' + prevCol.icon); | ||
| 191 | + | ||
| 192 | + div = thElem.select('div'); | ||
| 193 | + div.remove(); | ||
| 194 | + | ||
| 195 | + div = thElem.append('div'); | ||
| 196 | + | ||
| 197 | + if (currCol.icon === 'tableColSortAsc') { | ||
| 198 | + sortIconAPI.sortAsc(div); | ||
| 199 | + } else { | ||
| 200 | + sortIconAPI.sortDesc(div); | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + if (prevCol.colId !== undefined && | ||
| 204 | + prevCol.icon === 'tableColSortNone') { | ||
| 205 | + sortIconAPI.sortNone(prevCol.elem.select('div')); | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + prevCol.colId = currCol.colId; | ||
| 209 | + prevCol.elem = thElem; | ||
| 210 | + | ||
| 211 | + }); | ||
| 212 | + | ||
| 213 | + // TODO: send the prev and currCol info to the server to use in sorting table | ||
| 214 | + | ||
| 215 | + // TODO: figure out timing of events: | ||
| 216 | + // updating the icon | ||
| 217 | + // sending the column sorting info to the server | ||
| 218 | + // refreshing the table so that the new rows will be sorted | ||
| 219 | + | ||
| 220 | + } | ||
| 156 | }]); | 221 | }]); |
| 157 | 222 | ||
| 158 | }()); | 223 | }()); | ... | ... |
| ... | @@ -4,6 +4,7 @@ | ... | @@ -4,6 +4,7 @@ |
| 4 | <table class="summary-list" | 4 | <table class="summary-list" |
| 5 | onos-fixed-header | 5 | onos-fixed-header |
| 6 | ng-style="setTableHW()" | 6 | ng-style="setTableHW()" |
| 7 | + onos-sortable-header | ||
| 7 | sort-callback="ctrl.sortCallback()"> | 8 | sort-callback="ctrl.sortCallback()"> |
| 8 | <thead> | 9 | <thead> |
| 9 | <tr> | 10 | <tr> | ... | ... |
| ... | @@ -20,9 +20,6 @@ | ... | @@ -20,9 +20,6 @@ |
| 20 | 20 | ||
| 21 | (function () { | 21 | (function () { |
| 22 | 'use strict'; | 22 | 'use strict'; |
| 23 | - var currCol = {}, | ||
| 24 | - prevCol = {}; | ||
| 25 | - | ||
| 26 | 23 | ||
| 27 | angular.module('ovDevice', []) | 24 | angular.module('ovDevice', []) |
| 28 | .controller('OvDeviceCtrl', ['$log', '$location', 'RestService', | 25 | .controller('OvDeviceCtrl', ['$log', '$location', 'RestService', |
| ... | @@ -38,31 +35,6 @@ | ... | @@ -38,31 +35,6 @@ |
| 38 | self.deviceData = data.devices; | 35 | self.deviceData = data.devices; |
| 39 | }); | 36 | }); |
| 40 | 37 | ||
| 41 | - d3.selectAll('th').on('click', function () { | ||
| 42 | - var thElem = d3.select(this); | ||
| 43 | - currCol.colId = thElem.attr('colId'); | ||
| 44 | - | ||
| 45 | - if(currCol.colId === prevCol.colId) { | ||
| 46 | - (currCol.icon === 'tableColSortDesc') ? | ||
| 47 | - currCol.icon = 'tableColSortAsc' : | ||
| 48 | - currCol.icon = 'tableColSortDesc'; | ||
| 49 | - prevCol.icon = currCol.icon; | ||
| 50 | - } else { | ||
| 51 | - currCol.icon = 'tableColSortAsc'; | ||
| 52 | - prevCol.icon = 'tableColSortNone'; | ||
| 53 | - } | ||
| 54 | - | ||
| 55 | - $log.debug('currCol clicked: ' + currCol.colId + | ||
| 56 | - ', with sorting icon: ' + currCol.icon); | ||
| 57 | - $log.debug('prevCol clicked: ' + prevCol.colId + | ||
| 58 | - ', with its current sorting icon as ' + prevCol.icon); | ||
| 59 | - | ||
| 60 | - // TODO: send the prev and currCol info to the server to use in sorting table here | ||
| 61 | - | ||
| 62 | - prevCol.colId = currCol.colId; | ||
| 63 | - | ||
| 64 | - }); | ||
| 65 | - | ||
| 66 | $log.log('OvDeviceCtrl has been created'); | 38 | $log.log('OvDeviceCtrl has been created'); |
| 67 | }]); | 39 | }]); |
| 68 | }()); | 40 | }()); | ... | ... |
-
Please register or login to post a comment