Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | /* |
Bri Prebilic Cole | aa0f088 | 2015-02-04 15:27:55 -0800 | [diff] [blame] | 18 | ONOS GUI -- Device View Module |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | (function () { |
| 22 | 'use strict'; |
| 23 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 24 | // injected refs |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 25 | var $log, $scope, fs, mast, ps, wss, is, bns, ns, ttip; |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 26 | |
| 27 | // internal state |
Bri Prebilic Cole | e568ead | 2015-05-01 09:51:28 -0700 | [diff] [blame] | 28 | var detailsPanel, |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 29 | pStartY, pHeight, |
| 30 | top, bottom, iconDiv, |
| 31 | wSize, selRow; |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 32 | |
| 33 | // constants |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 34 | var topPdg = 13, |
| 35 | ctnrPdg = 24, |
Bri Prebilic Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 36 | scrollSize = 17, |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 37 | portsTblPdg = 50, |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 38 | flowPath = 'flow', |
Bri Prebilic Cole | ac829e4 | 2015-05-05 13:42:06 -0700 | [diff] [blame] | 39 | portPath = 'port', |
Bri Prebilic Cole | 5c60d6e | 2015-05-12 09:11:03 -0700 | [diff] [blame] | 40 | groupPath = 'group', |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 41 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 42 | pName = 'device-details-panel', |
Bri Prebilic Cole | ac829e4 | 2015-05-05 13:42:06 -0700 | [diff] [blame] | 43 | bName = 'dev-dets-p', |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 44 | detailsReq = 'deviceDetailsRequest', |
| 45 | detailsResp = 'deviceDetailsResponse', |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 46 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 47 | propOrder = [ |
| 48 | 'type', 'masterid', 'chassisid', |
| 49 | 'mfr', 'hw', 'sw', 'protocol', 'serial' |
| 50 | ], |
| 51 | friendlyProps = [ |
| 52 | 'Type', 'Master ID', 'Chassis ID', |
| 53 | 'Vendor', 'H/W Version', 'S/W Version', 'Protocol', 'Serial #' |
| 54 | ], |
| 55 | portCols = [ |
Thomas Vachuska | b52a014 | 2015-04-21 17:48:15 -0700 | [diff] [blame] | 56 | 'enabled', 'id', 'speed', 'type', 'elinks_dest', 'name' |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 57 | ], |
| 58 | friendlyPortCols = [ |
Thomas Vachuska | b52a014 | 2015-04-21 17:48:15 -0700 | [diff] [blame] | 59 | 'Enabled', 'ID', 'Speed', 'Type', 'Egress Links', 'Name' |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 60 | ]; |
| 61 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 62 | function addCloseBtn(div) { |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 63 | is.loadEmbeddedIcon(div, 'plus', 30); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 64 | div.select('g').attr('transform', 'translate(25, 0) rotate(45)'); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 65 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 66 | div.on('click', function () { |
| 67 | detailsPanel.hide(); |
| 68 | selRow.removeClass('selected'); |
| 69 | }); |
| 70 | } |
| 71 | |
| 72 | function setUpPanel() { |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 73 | var container, closeBtn, tblDiv; |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 74 | detailsPanel.empty(); |
| 75 | |
| 76 | container = detailsPanel.append('div').classed('container', true); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 77 | |
| 78 | top = container.append('div').classed('top', true); |
| 79 | closeBtn = top.append('div').classed('close-btn', true); |
| 80 | addCloseBtn(closeBtn); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 81 | iconDiv = top.append('div').classed('dev-icon', true); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 82 | top.append('h2'); |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 83 | |
| 84 | tblDiv = top.append('div').classed('top-tables', true); |
| 85 | tblDiv.append('div').classed('left', true).append('table'); |
| 86 | tblDiv.append('div').classed('right', true).append('table'); |
| 87 | |
| 88 | top.append('div').classed('actionBtns', true); |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 89 | top.append('hr'); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 90 | |
| 91 | bottom = container.append('div').classed('bottom', true); |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 92 | bottom.append('h2').classed('ports-title', true).html('Ports'); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 93 | bottom.append('table'); |
| 94 | } |
| 95 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 96 | function addProp(tbody, index, value) { |
| 97 | var tr = tbody.append('tr'); |
| 98 | |
| 99 | function addCell(cls, txt) { |
| 100 | tr.append('td').attr('class', cls).html(txt); |
| 101 | } |
| 102 | addCell('label', friendlyProps[index] + ' :'); |
| 103 | addCell('value', value); |
| 104 | } |
| 105 | |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 106 | function populateTop(tblDiv, btnsDiv, details) { |
| 107 | var leftTbl = tblDiv.select('.left') |
| 108 | .select('table') |
| 109 | .append('tbody'), |
| 110 | rightTbl = tblDiv.select('.right') |
| 111 | .select('table') |
| 112 | .append('tbody'); |
| 113 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 114 | is.loadEmbeddedIcon(iconDiv, details._iconid_type, 40); |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 115 | top.select('h2').html(details.id); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 116 | |
| 117 | propOrder.forEach(function (prop, i) { |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 118 | // properties are split into two tables |
| 119 | addProp(i < 3 ? leftTbl : rightTbl, i, details[prop]); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 120 | }); |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 121 | |
Bri Prebilic Cole | ac829e4 | 2015-05-05 13:42:06 -0700 | [diff] [blame] | 122 | bns.button( |
| 123 | btnsDiv, |
| 124 | bName + '-flows', |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 125 | 'flowTable', |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 126 | function () { |
| 127 | ns.navTo(flowPath, { devId: details.id }); |
| 128 | }, |
Bri Prebilic Cole | ac829e4 | 2015-05-05 13:42:06 -0700 | [diff] [blame] | 129 | 'Show flow view for this device' |
| 130 | ); |
| 131 | bns.button( |
| 132 | btnsDiv, |
| 133 | bName + '-ports', |
Bri Prebilic Cole | 9467a23 | 2015-05-06 16:59:05 -0700 | [diff] [blame] | 134 | 'portTable', |
Bri Prebilic Cole | ac829e4 | 2015-05-05 13:42:06 -0700 | [diff] [blame] | 135 | function () { |
| 136 | ns.navTo(portPath, { devId: details.id }); |
| 137 | }, |
| 138 | 'Show port view for this device' |
| 139 | ); |
Bri Prebilic Cole | 5c60d6e | 2015-05-12 09:11:03 -0700 | [diff] [blame] | 140 | bns.button( |
| 141 | btnsDiv, |
| 142 | bName + '-groups', |
| 143 | 'groupTable', |
| 144 | function () { |
| 145 | ns.navTo(groupPath, { devId: details.id }); |
| 146 | }, |
| 147 | 'Show group view for this device' |
| 148 | ); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 151 | function addPortRow(tbody, port) { |
| 152 | var tr = tbody.append('tr'); |
| 153 | |
| 154 | portCols.forEach(function (col) { |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 155 | tr.append('td').html(port[col]); |
| 156 | }); |
| 157 | } |
| 158 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 159 | function populateBottom(table, ports) { |
| 160 | var theader = table.append('thead').append('tr'), |
| 161 | tbody = table.append('tbody'), |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 162 | tbWidth, tbHeight; |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 163 | |
| 164 | friendlyPortCols.forEach(function (col) { |
| 165 | theader.append('th').html(col); |
| 166 | }); |
| 167 | ports.forEach(function (port) { |
| 168 | addPortRow(tbody, port); |
| 169 | }); |
| 170 | |
| 171 | tbWidth = fs.noPxStyle(tbody, 'width') + scrollSize; |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 172 | tbHeight = pHeight |
| 173 | - (fs.noPxStyle(detailsPanel.el() |
| 174 | .select('.top'), 'height') |
| 175 | + fs.noPxStyle(detailsPanel.el() |
| 176 | .select('.ports-title'), 'height') |
| 177 | + portsTblPdg); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 178 | |
| 179 | table.style({ |
| 180 | height: tbHeight + 'px', |
| 181 | width: tbWidth + 'px', |
| 182 | overflow: 'auto', |
| 183 | display: 'block' |
| 184 | }); |
| 185 | |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 186 | detailsPanel.width(tbWidth + ctnrPdg); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 189 | function populateDetails(details) { |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 190 | var topTbs, btnsDiv, btmTbl, ports; |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 191 | setUpPanel(); |
| 192 | |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 193 | topTbs = top.select('.top-tables'); |
| 194 | btnsDiv = top.select('.actionBtns'); |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 195 | btmTbl = bottom.select('table'); |
| 196 | ports = details.ports; |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 197 | |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 198 | populateTop(topTbs, btnsDiv, details); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 199 | populateBottom(btmTbl, ports); |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 200 | |
| 201 | detailsPanel.height(pHeight); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | function respDetailsCb(data) { |
Bri Prebilic Cole | e568ead | 2015-05-01 09:51:28 -0700 | [diff] [blame] | 205 | $scope.panelData = data.details; |
Bri Prebilic Cole | 54bbfb9 | 2015-05-28 16:02:28 -0700 | [diff] [blame] | 206 | $scope.$apply(); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 209 | function createDetailsPane() { |
| 210 | detailsPanel = ps.createPanel(pName, { |
| 211 | width: wSize.width, |
| 212 | margin: 0, |
| 213 | hideMargin: 0 |
| 214 | }); |
| 215 | detailsPanel.el().style({ |
| 216 | position: 'absolute', |
| 217 | top: pStartY + 'px' |
| 218 | }); |
| 219 | detailsPanel.hide(); |
| 220 | } |
| 221 | |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 222 | angular.module('ovDevice', []) |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 223 | .controller('OvDeviceCtrl', |
Bri Prebilic Cole | e1be1b7 | 2015-05-12 16:07:24 -0700 | [diff] [blame] | 224 | ['$log', '$scope', 'TableBuilderService', 'FnService', |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 225 | 'MastService', 'PanelService', 'WebSocketService', 'IconService', |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 226 | 'ButtonService', 'NavService', 'TooltipService', |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 227 | |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 228 | function (_$log_, _$scope_, |
Bri Prebilic Cole | e1be1b7 | 2015-05-12 16:07:24 -0700 | [diff] [blame] | 229 | tbs, _fs_, _mast_, _ps_, _wss_, _is_, _bns_, _ns_, _ttip_) { |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 230 | $log = _$log_; |
| 231 | $scope = _$scope_; |
| 232 | fs = _fs_; |
| 233 | mast = _mast_; |
| 234 | ps = _ps_; |
| 235 | wss = _wss_; |
| 236 | is = _is_; |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 237 | bns = _bns_; |
| 238 | ns = _ns_; |
| 239 | ttip = _ttip_; |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 240 | var handlers = {}; |
Bri Prebilic Cole | e568ead | 2015-05-01 09:51:28 -0700 | [diff] [blame] | 241 | $scope.panelData = []; |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 242 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 243 | function selCb($event, row) { |
| 244 | selRow = angular.element($event.currentTarget); |
Bri Prebilic Cole | bfab9c7 | 2015-06-01 14:33:18 -0700 | [diff] [blame] | 245 | if ($scope.selId) { |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 246 | wss.sendEvent(detailsReq, { id: row.id }); |
| 247 | } else { |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 248 | detailsPanel.hide(); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 249 | } |
| 250 | $log.debug('Got a click on:', row); |
| 251 | } |
| 252 | |
Bri Prebilic Cole | 864cdd6 | 2015-04-02 15:46:47 -0700 | [diff] [blame] | 253 | tbs.buildTable({ |
Bri Prebilic Cole | 864cdd6 | 2015-04-02 15:46:47 -0700 | [diff] [blame] | 254 | scope: $scope, |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 255 | tag: 'device', |
| 256 | selCb: selCb |
| 257 | }); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 258 | |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 259 | // details panel handlers |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 260 | handlers[detailsResp] = respDetailsCb; |
| 261 | wss.bindHandlers(handlers); |
| 262 | |
| 263 | $scope.$on('$destroy', function () { |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 264 | wss.unbindHandlers(handlers); |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 265 | }); |
| 266 | |
Bri Prebilic Cole | 72eb6db | 2015-03-30 16:58:53 -0700 | [diff] [blame] | 267 | $log.log('OvDeviceCtrl has been created'); |
Bri Prebilic Cole | 54bbfb9 | 2015-05-28 16:02:28 -0700 | [diff] [blame] | 268 | }]) |
| 269 | |
| 270 | .directive('deviceDetailsPanel', ['$rootScope', '$window', |
| 271 | function ($rootScope, $window) { |
| 272 | return function (scope) { |
| 273 | |
| 274 | function heightCalc() { |
| 275 | pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height') |
| 276 | + mast.mastHeight() + topPdg; |
| 277 | wSize = fs.windowSize(pStartY); |
| 278 | pHeight = wSize.height; |
| 279 | } |
| 280 | heightCalc(); |
| 281 | |
| 282 | createDetailsPane(); |
| 283 | |
| 284 | scope.$watch('panelData', function () { |
| 285 | if (!fs.isEmptyObject(scope.panelData)) { |
| 286 | populateDetails(scope.panelData); |
| 287 | detailsPanel.show(); |
| 288 | } |
| 289 | }); |
| 290 | |
| 291 | $rootScope.$watchCollection( |
| 292 | function () { |
| 293 | return { |
| 294 | h: $window.innerHeight, |
| 295 | w: $window.innerWidth |
| 296 | } |
| 297 | }, function () { |
| 298 | if (!fs.isEmptyObject(scope.panelData)) { |
| 299 | heightCalc(); |
| 300 | populateDetails(scope.panelData); |
| 301 | } |
| 302 | } |
| 303 | ); |
| 304 | |
| 305 | scope.$on('$destroy', function () { |
| 306 | ps.destroyPanel(pName); |
| 307 | }); |
| 308 | }; |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 309 | }]); |
| 310 | }()); |