Bri Prebilic Cole | 384e8dc | 2015-04-13 15:51:14 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Bri Prebilic Cole | 384e8dc | 2015-04-13 15:51:14 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | ONOS GUI -- Cluster View Module |
| 19 | */ |
| 20 | |
| 21 | (function () { |
| 22 | 'use strict'; |
| 23 | |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 24 | // injected references |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 25 | var $log, $scope, fs, mast, ps, is, wss; |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 26 | |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 27 | // internal state |
| 28 | var detailsPanel, |
| 29 | pStartY, |
| 30 | pHeight, |
| 31 | top, |
| 32 | topTable, |
| 33 | bottom, |
| 34 | iconDiv, |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 35 | wSize; |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 36 | |
| 37 | |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 38 | // constants |
| 39 | var topPdg = 28, |
| 40 | ctnrPdg = 24, |
| 41 | scrollSize = 17, |
| 42 | portsTblPdg = 50, |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 43 | pName = 'cluster-details-panel', |
| 44 | detailsReq = 'clusterDetailsRequest', |
| 45 | detailsResp = 'clusterDetailsResponse', |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 46 | propOrder = [ |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 47 | 'id', 'ip', |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 48 | ], |
Viswanath KSP | 116f0c1 | 2016-11-21 00:02:51 +0530 | [diff] [blame] | 49 | deviceCols = [ |
| 50 | 'id', 'type', 'chassisid', 'mfr', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 51 | 'hw', 'sw', 'protocol', 'serial', |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 52 | ]; |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 53 | |
Simon Hunt | 083e6fb | 2017-06-16 16:51:41 -0700 | [diff] [blame] | 54 | // deferred fetching of user-visible strings, so that lion context is set |
| 55 | function getLionProps() { |
| 56 | var l = $scope.lion; |
| 57 | return [ |
| 58 | l('node_id'), |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 59 | l('ip_address'), |
Simon Hunt | 083e6fb | 2017-06-16 16:51:41 -0700 | [diff] [blame] | 60 | ]; |
| 61 | } |
| 62 | |
| 63 | function getLionDeviceCols() { |
| 64 | var l = $scope.lion; |
| 65 | return [ |
| 66 | l('uri'), |
| 67 | l('type'), |
| 68 | l('chassis_id'), |
| 69 | l('vendor'), |
| 70 | l('hw_version'), |
| 71 | l('sw_version'), |
| 72 | l('protocol'), |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 73 | l('serial_number'), |
Simon Hunt | 083e6fb | 2017-06-16 16:51:41 -0700 | [diff] [blame] | 74 | ]; |
| 75 | } |
| 76 | |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 77 | function closePanel() { |
| 78 | if (detailsPanel.isVisible()) { |
| 79 | $scope.selId = null; |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 80 | detailsPanel.hide(); |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 81 | return true; |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 82 | } |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 83 | return false; |
| 84 | } |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 85 | |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 86 | function addCloseBtn(div) { |
| 87 | is.loadEmbeddedIcon(div, 'close', 20); |
| 88 | div.on('click', closePanel); |
| 89 | } |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 90 | |
Viswanath KSP | 8601627 | 2016-10-27 09:49:46 +0530 | [diff] [blame] | 91 | function handleEscape() { |
| 92 | return closePanel(); |
| 93 | } |
| 94 | |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 95 | function setUpPanel() { |
Simon Hunt | 083e6fb | 2017-06-16 16:51:41 -0700 | [diff] [blame] | 96 | var container, closeBtn; |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 97 | detailsPanel.empty(); |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 98 | |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 99 | container = detailsPanel.append('div').classed('container', true); |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 100 | |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 101 | top = container.append('div').classed('top', true); |
| 102 | closeBtn = top.append('div').classed('close-btn', true); |
| 103 | addCloseBtn(closeBtn); |
| 104 | iconDiv = top.append('div').classed('dev-icon', true); |
| 105 | top.append('h2'); |
| 106 | topTable = top.append('div').classed('top-content', true) |
| 107 | .append('table'); |
| 108 | top.append('hr'); |
| 109 | |
Viswanath KSP | 116f0c1 | 2016-11-21 00:02:51 +0530 | [diff] [blame] | 110 | bottom = container.append('div').classed('bottom', true); |
Simon Hunt | 239f09e | 2017-05-18 13:10:09 -0700 | [diff] [blame] | 111 | bottom.append('h2').classed('devices-title', true).text('Devices'); |
Viswanath KSP | 116f0c1 | 2016-11-21 00:02:51 +0530 | [diff] [blame] | 112 | bottom.append('table'); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 113 | // TODO: add more details |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Simon Hunt | 083e6fb | 2017-06-16 16:51:41 -0700 | [diff] [blame] | 116 | function addProp(tbody, label, value) { |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 117 | var tr = tbody.append('tr'); |
| 118 | |
| 119 | function addCell(cls, txt) { |
Simon Hunt | 239f09e | 2017-05-18 13:10:09 -0700 | [diff] [blame] | 120 | tr.append('td').attr('class', cls).text(txt); |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 121 | } |
Simon Hunt | 083e6fb | 2017-06-16 16:51:41 -0700 | [diff] [blame] | 122 | addCell('label', label + ' :'); |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 123 | addCell('value', value); |
| 124 | } |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 125 | |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 126 | function populateTop(details) { |
Simon Hunt | 083e6fb | 2017-06-16 16:51:41 -0700 | [diff] [blame] | 127 | var propLabels = getLionProps(); |
| 128 | |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 129 | is.loadEmbeddedIcon(iconDiv, 'node', 40); |
Simon Hunt | 239f09e | 2017-05-18 13:10:09 -0700 | [diff] [blame] | 130 | top.select('h2').text(details.id); |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 131 | |
| 132 | var tbody = topTable.append('tbody'); |
| 133 | |
| 134 | propOrder.forEach(function (prop, i) { |
Simon Hunt | 083e6fb | 2017-06-16 16:51:41 -0700 | [diff] [blame] | 135 | addProp(tbody, propLabels[i], details[prop]); |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 136 | }); |
| 137 | } |
| 138 | |
Viswanath KSP | 116f0c1 | 2016-11-21 00:02:51 +0530 | [diff] [blame] | 139 | function addDeviceRow(tbody, device) { |
| 140 | var tr = tbody.append('tr'); |
| 141 | |
| 142 | deviceCols.forEach(function (col) { |
Simon Hunt | 239f09e | 2017-05-18 13:10:09 -0700 | [diff] [blame] | 143 | tr.append('td').text(device[col]); |
Viswanath KSP | 116f0c1 | 2016-11-21 00:02:51 +0530 | [diff] [blame] | 144 | }); |
| 145 | } |
| 146 | |
| 147 | function populateBottom(devices) { |
| 148 | var table = bottom.select('table'), |
| 149 | theader = table.append('thead').append('tr'), |
| 150 | tbody = table.append('tbody'), |
| 151 | tbWidth, tbHeight; |
| 152 | |
Simon Hunt | 083e6fb | 2017-06-16 16:51:41 -0700 | [diff] [blame] | 153 | getLionDeviceCols().forEach(function (col) { |
Simon Hunt | 239f09e | 2017-05-18 13:10:09 -0700 | [diff] [blame] | 154 | theader.append('th').text(col); |
Viswanath KSP | 116f0c1 | 2016-11-21 00:02:51 +0530 | [diff] [blame] | 155 | }); |
| 156 | devices.forEach(function (device) { |
| 157 | addDeviceRow(tbody, device); |
| 158 | }); |
| 159 | |
| 160 | tbWidth = fs.noPxStyle(tbody, 'width') + scrollSize; |
| 161 | tbHeight = pHeight |
| 162 | - (fs.noPxStyle(detailsPanel.el() |
| 163 | .select('.top'), 'height') |
| 164 | + fs.noPxStyle(detailsPanel.el() |
| 165 | .select('.devices-title'), 'height') |
| 166 | + portsTblPdg); |
| 167 | |
| 168 | table.style({ |
| 169 | height: tbHeight + 'px', |
| 170 | width: tbWidth + 'px', |
| 171 | overflow: 'auto', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 172 | display: 'block', |
Viswanath KSP | 116f0c1 | 2016-11-21 00:02:51 +0530 | [diff] [blame] | 173 | }); |
| 174 | |
| 175 | detailsPanel.width(tbWidth + ctnrPdg); |
| 176 | } |
| 177 | |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 178 | function createDetailsPane() { |
| 179 | detailsPanel = ps.createPanel(pName, { |
| 180 | width: wSize.width, |
| 181 | margin: 0, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 182 | hideMargin: 0, |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 183 | }); |
| 184 | detailsPanel.el().style({ |
| 185 | position: 'absolute', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 186 | top: pStartY + 'px', |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 187 | }); |
| 188 | $scope.hidePanel = function () { detailsPanel.hide(); }; |
| 189 | detailsPanel.hide(); |
| 190 | } |
| 191 | |
| 192 | function populateDetails(details) { |
| 193 | setUpPanel(); |
Viswanath KSP | 116f0c1 | 2016-11-21 00:02:51 +0530 | [diff] [blame] | 194 | |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 195 | populateTop(details); |
Viswanath KSP | 116f0c1 | 2016-11-21 00:02:51 +0530 | [diff] [blame] | 196 | populateBottom(details.devices); |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 197 | detailsPanel.height(pHeight); |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | function respDetailsCb(data) { |
| 201 | $scope.panelData = data.details; |
| 202 | $scope.$apply(); |
| 203 | } |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 204 | |
| 205 | |
Bri Prebilic Cole | 384e8dc | 2015-04-13 15:51:14 -0700 | [diff] [blame] | 206 | angular.module('ovCluster', []) |
| 207 | .controller('OvClusterCtrl', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 208 | ['$log', '$scope', 'FnService', 'MastService', |
| 209 | 'PanelService', 'IconService', 'WebSocketService', |
Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [diff] [blame] | 210 | 'LionService', 'TableBuilderService', |
Bri Prebilic Cole | 384e8dc | 2015-04-13 15:51:14 -0700 | [diff] [blame] | 211 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 212 | function (_$log_, _$scope_, _fs_, _mast_, _ps_, _is_, _wss_, lion, tbs) { |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 213 | var handlers = {}; |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 214 | |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 215 | $log = _$log_; |
| 216 | $scope = _$scope_; |
| 217 | fs = _fs_; |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 218 | mast = _mast_; |
| 219 | ps = _ps_; |
Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [diff] [blame] | 220 | is = _is_; |
| 221 | wss = _wss_; |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 222 | |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame] | 223 | $scope.lion = lion.bundle('core.view.Cluster'); |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 224 | $scope.panelData = {}; |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 225 | |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 226 | tbs.buildTable({ |
| 227 | scope: $scope, |
| 228 | selCb: selCb, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 229 | tag: 'cluster', |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 230 | }); |
| 231 | |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 232 | // details panel handlers |
| 233 | handlers[detailsResp] = respDetailsCb; |
| 234 | wss.bindHandlers(handlers); |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 235 | |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 236 | function selCb($event, row) { |
| 237 | if ($scope.selId) { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 238 | wss.sendEvent(detailsReq, { id: row.id }); |
Simon Hunt | 6b5a941 | 2016-10-26 19:32:04 -0700 | [diff] [blame] | 239 | } else { |
| 240 | $scope.hidePanel(); |
| 241 | } |
| 242 | $log.debug('Got a click on:', row); |
| 243 | } |
| 244 | |
| 245 | $scope.$on('$destroy', function () { |
| 246 | wss.unbindHandlers(handlers); |
| 247 | }); |
| 248 | |
| 249 | $log.log('OvClusterCtrl has been created'); |
| 250 | }]) |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 251 | |
Simon Hunt | a271e0a | 2016-10-26 10:59:14 -0700 | [diff] [blame] | 252 | .directive('clusterDetailsPanel', |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 253 | ['$rootScope', '$window', '$timeout', 'KeyService', |
| 254 | function ($rootScope, $window, $timeout, ks) { |
| 255 | return function (scope) { |
Simon Hunt | 083e6fb | 2017-06-16 16:51:41 -0700 | [diff] [blame] | 256 | var unbindWatch, |
| 257 | lion = scope.lion; |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 258 | |
| 259 | function heightCalc() { |
| 260 | pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height') |
| 261 | + mast.mastHeight() + topPdg; |
| 262 | wSize = fs.windowSize(pStartY); |
| 263 | pHeight = wSize.height; |
| 264 | } |
| 265 | |
| 266 | function initPanel() { |
| 267 | heightCalc(); |
| 268 | createDetailsPane(); |
| 269 | } |
| 270 | |
| 271 | // Safari has a bug where it renders the fixed-layout table wrong |
| 272 | // if you ask for the window's size too early |
| 273 | if (scope.onos.browser === 'safari') { |
| 274 | $timeout(initPanel); |
| 275 | } else { |
| 276 | initPanel(); |
| 277 | } |
Viswanath KSP | 8601627 | 2016-10-27 09:49:46 +0530 | [diff] [blame] | 278 | // create key bindings to handle panel |
| 279 | ks.keyBindings({ |
Simon Hunt | 17b4bcb | 2017-06-21 18:46:34 -0700 | [diff] [blame] | 280 | esc: [handleEscape, lion('qh_hint_close_detail')], |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 281 | _helpFormat: ['esc'], |
Viswanath KSP | 8601627 | 2016-10-27 09:49:46 +0530 | [diff] [blame] | 282 | }); |
| 283 | ks.gestureNotes([ |
Simon Hunt | 17b4bcb | 2017-06-21 18:46:34 -0700 | [diff] [blame] | 284 | [lion('click'), lion('qh_hint_click')], |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 285 | [lion('scroll_down'), lion('qh_hint_scroll_down')], |
Viswanath KSP | 8601627 | 2016-10-27 09:49:46 +0530 | [diff] [blame] | 286 | ]); |
Simon Hunt | a271e0a | 2016-10-26 10:59:14 -0700 | [diff] [blame] | 287 | // if the panelData changes |
| 288 | scope.$watch('panelData', function () { |
| 289 | if (!fs.isEmptyObject(scope.panelData)) { |
| 290 | populateDetails(scope.panelData); |
| 291 | detailsPanel.show(); |
| 292 | } |
| 293 | }); |
| 294 | |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 295 | // if the window size changes |
| 296 | unbindWatch = $rootScope.$watchCollection( |
| 297 | function () { |
| 298 | return { |
| 299 | h: $window.innerHeight, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 300 | w: $window.innerWidth, |
Viswanath KSP | 9fcf970 | 2016-10-23 17:13:29 +0530 | [diff] [blame] | 301 | }; |
| 302 | }, function () { |
| 303 | if (!fs.isEmptyObject(scope.panelData)) { |
| 304 | heightCalc(); |
| 305 | populateDetails(scope.panelData); |
| 306 | } |
| 307 | } |
| 308 | ); |
| 309 | |
| 310 | scope.$on('$destroy', function () { |
| 311 | unbindWatch(); |
| 312 | ps.destroyPanel(pName); |
| 313 | }); |
| 314 | }; |
| 315 | }]); |
Bri Prebilic Cole | 384e8dc | 2015-04-13 15:51:14 -0700 | [diff] [blame] | 316 | }()); |