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