Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 1 | /* |
Jian Li | 1f54473 | 2015-12-30 23:36:37 -0800 | [diff] [blame] | 2 | * Copyright 2015,2016 Open Networking Laboratory |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [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 | /* |
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 |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 25 | var $log, $scope, $loc, fs, mast, ps, wss, is, ns, ks; |
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, |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 29 | pStartY, |
| 30 | pHeight, |
| 31 | top, |
| 32 | bottom, |
| 33 | iconDiv, |
| 34 | wSize, |
| 35 | editingName = false; |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 36 | |
| 37 | // constants |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 38 | var topPdg = 13, |
| 39 | ctnrPdg = 24, |
Bri Prebilic Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 40 | scrollSize = 17, |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 41 | portsTblPdg = 50, |
| 42 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 43 | pName = 'device-details-panel', |
| 44 | detailsReq = 'deviceDetailsRequest', |
| 45 | detailsResp = 'deviceDetailsResponse', |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 46 | nameChangeReq = 'deviceNameChangeRequest', |
| 47 | nameChangeResp = 'deviceNameChangeResponse', |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 48 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 49 | propOrder = [ |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 50 | 'id', 'type', 'masterid', 'chassisid', |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 51 | 'mfr', 'hw', 'sw', 'protocol', 'serial' |
| 52 | ], |
| 53 | friendlyProps = [ |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 54 | 'URI', 'Type', 'Master ID', 'Chassis ID', |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 55 | 'Vendor', 'H/W Version', 'S/W Version', 'Protocol', 'Serial #' |
| 56 | ], |
| 57 | portCols = [ |
Thomas Vachuska | b52a014 | 2015-04-21 17:48:15 -0700 | [diff] [blame] | 58 | 'enabled', 'id', 'speed', 'type', 'elinks_dest', 'name' |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 59 | ], |
| 60 | friendlyPortCols = [ |
Thomas Vachuska | b52a014 | 2015-04-21 17:48:15 -0700 | [diff] [blame] | 61 | 'Enabled', 'ID', 'Speed', 'Type', 'Egress Links', 'Name' |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 62 | ]; |
| 63 | |
Bri Prebilic Cole | 9dcaea5 | 2015-07-21 14:39:48 -0700 | [diff] [blame] | 64 | function closePanel() { |
| 65 | if (detailsPanel.isVisible()) { |
| 66 | $scope.selId = null; |
| 67 | detailsPanel.hide(); |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 68 | return true; |
Bri Prebilic Cole | 9dcaea5 | 2015-07-21 14:39:48 -0700 | [diff] [blame] | 69 | } |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 70 | return false; |
Bri Prebilic Cole | 9dcaea5 | 2015-07-21 14:39:48 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 73 | function addCloseBtn(div) { |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 74 | is.loadEmbeddedIcon(div, 'plus', 30); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 75 | div.select('g').attr('transform', 'translate(25, 0) rotate(45)'); |
Bri Prebilic Cole | 9dcaea5 | 2015-07-21 14:39:48 -0700 | [diff] [blame] | 76 | div.on('click', closePanel); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 79 | function exitEditMode(nameH2, name) { |
| 80 | nameH2.html(name); |
| 81 | nameH2.classed('editable', true); |
| 82 | editingName = false; |
| 83 | ks.enableGlobalKeys(true); |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | function editNameSave() { |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 87 | var nameH2 = top.select('h2'), |
| 88 | id = $scope.panelData.id, |
| 89 | val, |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 90 | newVal; |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 91 | |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 92 | if (editingName) { |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 93 | val = nameH2.select('input').property('value').trim(); |
| 94 | newVal = val || id; |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 95 | |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 96 | exitEditMode(nameH2, newVal); |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 97 | $scope.panelData.name = newVal; |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 98 | wss.sendEvent(nameChangeReq, { id: id, name: val }); |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
| 102 | function editNameCancel() { |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 103 | if (editingName) { |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 104 | exitEditMode(top.select('h2'), $scope.panelData.name); |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 105 | return true; |
| 106 | } |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | function editName() { |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 111 | var nameH2 = top.select('h2'), |
| 112 | tf, el; |
| 113 | |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 114 | if (!editingName) { |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 115 | nameH2.classed('editable', false); |
| 116 | nameH2.html(''); |
| 117 | tf = nameH2.append('input').classed('name-input', true) |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 118 | .attr('type', 'text') |
| 119 | .attr('value', $scope.panelData.name); |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 120 | el = tf[0][0]; |
| 121 | el.focus(); |
| 122 | el.select(); |
| 123 | editingName = true; |
| 124 | ks.enableGlobalKeys(false); |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
| 128 | function handleEscape() { |
| 129 | return editNameCancel() || closePanel(); |
| 130 | } |
| 131 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 132 | function setUpPanel() { |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 133 | var container, closeBtn, tblDiv; |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 134 | detailsPanel.empty(); |
| 135 | |
| 136 | container = detailsPanel.append('div').classed('container', true); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 137 | |
| 138 | top = container.append('div').classed('top', true); |
| 139 | closeBtn = top.append('div').classed('close-btn', true); |
| 140 | addCloseBtn(closeBtn); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 141 | iconDiv = top.append('div').classed('dev-icon', true); |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 142 | top.append('h2').classed('editable', true).on('click', editName); |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 143 | |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 144 | tblDiv = top.append('div').classed('top-tables', true); |
| 145 | tblDiv.append('div').classed('left', true).append('table'); |
| 146 | tblDiv.append('div').classed('right', true).append('table'); |
| 147 | |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 148 | top.append('hr'); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 149 | |
| 150 | bottom = container.append('div').classed('bottom', true); |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 151 | bottom.append('h2').classed('ports-title', true).html('Ports'); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 152 | bottom.append('table'); |
| 153 | } |
| 154 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 155 | function addProp(tbody, index, value) { |
| 156 | var tr = tbody.append('tr'); |
| 157 | |
| 158 | function addCell(cls, txt) { |
| 159 | tr.append('td').attr('class', cls).html(txt); |
| 160 | } |
| 161 | addCell('label', friendlyProps[index] + ' :'); |
| 162 | addCell('value', value); |
| 163 | } |
| 164 | |
Bri Prebilic Cole | 9b1fb9a | 2015-07-01 13:57:11 -0700 | [diff] [blame] | 165 | function populateTop(tblDiv, details) { |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 166 | var leftTbl = tblDiv.select('.left') |
| 167 | .select('table') |
| 168 | .append('tbody'), |
| 169 | rightTbl = tblDiv.select('.right') |
| 170 | .select('table') |
| 171 | .append('tbody'); |
| 172 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 173 | is.loadEmbeddedIcon(iconDiv, details._iconid_type, 40); |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 174 | top.select('h2').html(details.name); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 175 | |
| 176 | propOrder.forEach(function (prop, i) { |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 177 | // properties are split into two tables |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 178 | addProp(i < 4 ? leftTbl : rightTbl, i, details[prop]); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 179 | }); |
| 180 | } |
| 181 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 182 | function addPortRow(tbody, port) { |
| 183 | var tr = tbody.append('tr'); |
| 184 | |
| 185 | portCols.forEach(function (col) { |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 186 | tr.append('td').html(port[col]); |
| 187 | }); |
| 188 | } |
| 189 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 190 | function populateBottom(table, ports) { |
| 191 | var theader = table.append('thead').append('tr'), |
| 192 | tbody = table.append('tbody'), |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 193 | tbWidth, tbHeight; |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 194 | |
| 195 | friendlyPortCols.forEach(function (col) { |
| 196 | theader.append('th').html(col); |
| 197 | }); |
| 198 | ports.forEach(function (port) { |
| 199 | addPortRow(tbody, port); |
| 200 | }); |
| 201 | |
| 202 | tbWidth = fs.noPxStyle(tbody, 'width') + scrollSize; |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 203 | tbHeight = pHeight |
| 204 | - (fs.noPxStyle(detailsPanel.el() |
| 205 | .select('.top'), 'height') |
| 206 | + fs.noPxStyle(detailsPanel.el() |
| 207 | .select('.ports-title'), 'height') |
| 208 | + portsTblPdg); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 209 | |
| 210 | table.style({ |
| 211 | height: tbHeight + 'px', |
| 212 | width: tbWidth + 'px', |
| 213 | overflow: 'auto', |
| 214 | display: 'block' |
| 215 | }); |
| 216 | |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 217 | detailsPanel.width(tbWidth + ctnrPdg); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 220 | function populateName(div, name) { |
| 221 | var lab = div.select('.label'), |
| 222 | val = div.select('.value'); |
| 223 | lab.html('Friendly Name:'); |
| 224 | val.html(name); |
| 225 | } |
| 226 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 227 | function populateDetails(details) { |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 228 | var nameDiv, topTbs, btmTbl, ports; |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 229 | setUpPanel(); |
| 230 | |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 231 | nameDiv = top.select('.name-div'); |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 232 | topTbs = top.select('.top-tables'); |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 233 | btmTbl = bottom.select('table'); |
| 234 | ports = details.ports; |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 235 | |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 236 | populateName(nameDiv, details.name); |
Bri Prebilic Cole | 9b1fb9a | 2015-07-01 13:57:11 -0700 | [diff] [blame] | 237 | populateTop(topTbs, details); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 238 | populateBottom(btmTbl, ports); |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 239 | |
| 240 | detailsPanel.height(pHeight); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | function respDetailsCb(data) { |
Bri Prebilic Cole | e568ead | 2015-05-01 09:51:28 -0700 | [diff] [blame] | 244 | $scope.panelData = data.details; |
Bri Prebilic Cole | 54bbfb9 | 2015-05-28 16:02:28 -0700 | [diff] [blame] | 245 | $scope.$apply(); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 248 | function respNameCb(data) { |
| 249 | if (data.warn) { |
| 250 | $log.warn(data.warn, data.id); |
| 251 | top.select('h2').html(data.id); |
| 252 | } |
| 253 | } |
| 254 | |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 255 | function createDetailsPane() { |
| 256 | detailsPanel = ps.createPanel(pName, { |
| 257 | width: wSize.width, |
| 258 | margin: 0, |
| 259 | hideMargin: 0 |
| 260 | }); |
| 261 | detailsPanel.el().style({ |
| 262 | position: 'absolute', |
| 263 | top: pStartY + 'px' |
| 264 | }); |
Bri Prebilic Cole | 68844ba | 2015-07-22 15:41:37 -0700 | [diff] [blame] | 265 | $scope.hidePanel = function () { detailsPanel.hide(); }; |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 266 | detailsPanel.hide(); |
| 267 | } |
| 268 | |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 269 | angular.module('ovDevice', []) |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 270 | .controller('OvDeviceCtrl', |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 271 | ['$log', '$scope', '$location', 'TableBuilderService', 'FnService', |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 272 | 'MastService', 'PanelService', 'WebSocketService', 'IconService', |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 273 | 'NavService', 'KeyService', |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 274 | |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 275 | function (_$log_, _$scope_, _$location_, |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 276 | tbs, _fs_, _mast_, _ps_, _wss_, _is_, _ns_, _ks_) { |
| 277 | var params, |
| 278 | handlers = {}; |
| 279 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 280 | $log = _$log_; |
| 281 | $scope = _$scope_; |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 282 | $loc = _$location_; |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 283 | fs = _fs_; |
| 284 | mast = _mast_; |
| 285 | ps = _ps_; |
| 286 | wss = _wss_; |
| 287 | is = _is_; |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 288 | ns = _ns_; |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 289 | ks = _ks_; |
| 290 | |
| 291 | params = $loc.search(); |
| 292 | |
Bri Prebilic Cole | 68844ba | 2015-07-22 15:41:37 -0700 | [diff] [blame] | 293 | $scope.panelData = {}; |
Bri Prebilic Cole | eef67ae | 2015-07-01 16:26:59 -0700 | [diff] [blame] | 294 | $scope.flowTip = 'Show flow view for selected device'; |
| 295 | $scope.portTip = 'Show port view for selected device'; |
| 296 | $scope.groupTip = 'Show group view for selected device'; |
Jian Li | 1f54473 | 2015-12-30 23:36:37 -0800 | [diff] [blame] | 297 | $scope.meterTip = 'Show meter view for selected device'; |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 298 | |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 299 | // details panel handlers |
| 300 | handlers[detailsResp] = respDetailsCb; |
Simon Hunt | d557925 | 2015-10-06 15:09:14 -0700 | [diff] [blame] | 301 | handlers[nameChangeResp] = respNameCb; |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 302 | wss.bindHandlers(handlers); |
| 303 | |
| 304 | // query for if a certain device needs to be highlighted |
| 305 | if (params.hasOwnProperty('devId')) { |
| 306 | $scope.selId = params['devId']; |
| 307 | wss.sendEvent(detailsReq, { id: $scope.selId }); |
| 308 | } |
| 309 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 310 | function selCb($event, row) { |
Bri Prebilic Cole | bfab9c7 | 2015-06-01 14:33:18 -0700 | [diff] [blame] | 311 | if ($scope.selId) { |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 312 | wss.sendEvent(detailsReq, { id: row.id }); |
| 313 | } else { |
Bri Prebilic Cole | 68844ba | 2015-07-22 15:41:37 -0700 | [diff] [blame] | 314 | $scope.hidePanel(); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 315 | } |
| 316 | $log.debug('Got a click on:', row); |
| 317 | } |
| 318 | |
Bri Prebilic Cole | 864cdd6 | 2015-04-02 15:46:47 -0700 | [diff] [blame] | 319 | tbs.buildTable({ |
Bri Prebilic Cole | 864cdd6 | 2015-04-02 15:46:47 -0700 | [diff] [blame] | 320 | scope: $scope, |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 321 | tag: 'device', |
| 322 | selCb: selCb |
| 323 | }); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 324 | |
Bri Prebilic Cole | 9b1fb9a | 2015-07-01 13:57:11 -0700 | [diff] [blame] | 325 | $scope.nav = function (path) { |
| 326 | if ($scope.selId) { |
| 327 | ns.navTo(path, { devId: $scope.selId }); |
| 328 | } |
| 329 | }; |
| 330 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 331 | $scope.$on('$destroy', function () { |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 332 | wss.unbindHandlers(handlers); |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 333 | }); |
| 334 | |
Bri Prebilic Cole | 72eb6db | 2015-03-30 16:58:53 -0700 | [diff] [blame] | 335 | $log.log('OvDeviceCtrl has been created'); |
Bri Prebilic Cole | 54bbfb9 | 2015-05-28 16:02:28 -0700 | [diff] [blame] | 336 | }]) |
| 337 | |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 338 | .directive('deviceDetailsPanel', |
| 339 | ['$rootScope', '$window', '$timeout', 'KeyService', |
| 340 | function ($rootScope, $window, $timeout, ks) { |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 341 | return function (scope) { |
Bri Prebilic Cole | 0bc4de2 | 2015-07-20 17:07:55 -0700 | [diff] [blame] | 342 | var unbindWatch; |
Bri Prebilic Cole | 54bbfb9 | 2015-05-28 16:02:28 -0700 | [diff] [blame] | 343 | |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 344 | function heightCalc() { |
| 345 | pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height') |
| 346 | + mast.mastHeight() + topPdg; |
| 347 | wSize = fs.windowSize(pStartY); |
| 348 | pHeight = wSize.height; |
| 349 | } |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 350 | |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 351 | function initPanel() { |
| 352 | heightCalc(); |
| 353 | createDetailsPane(); |
| 354 | } |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 355 | |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 356 | // Safari has a bug where it renders the fixed-layout table wrong |
| 357 | // if you ask for the window's size too early |
| 358 | if (scope.onos.browser === 'safari') { |
| 359 | $timeout(initPanel); |
| 360 | } else { |
| 361 | initPanel(); |
| 362 | } |
Bri Prebilic Cole | 9dcaea5 | 2015-07-21 14:39:48 -0700 | [diff] [blame] | 363 | // create key bindings to handle panel |
| 364 | ks.keyBindings({ |
Simon Hunt | d766c31 | 2015-10-06 11:46:32 -0700 | [diff] [blame] | 365 | enter: editNameSave, |
| 366 | esc: [handleEscape, 'Close the details panel'], |
Bri Prebilic Cole | 9dcaea5 | 2015-07-21 14:39:48 -0700 | [diff] [blame] | 367 | _helpFormat: ['esc'] |
| 368 | }); |
| 369 | ks.gestureNotes([ |
| 370 | ['click', 'Select a row to show device details'], |
| 371 | ['scroll down', 'See more devices'] |
| 372 | ]); |
| 373 | |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 374 | // if the panelData changes |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 375 | scope.$watch('panelData', function () { |
| 376 | if (!fs.isEmptyObject(scope.panelData)) { |
| 377 | populateDetails(scope.panelData); |
| 378 | detailsPanel.show(); |
Bri Prebilic Cole | 54bbfb9 | 2015-05-28 16:02:28 -0700 | [diff] [blame] | 379 | } |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 380 | }); |
Bri Prebilic Cole | 54bbfb9 | 2015-05-28 16:02:28 -0700 | [diff] [blame] | 381 | |
Bri Prebilic Cole | 55ee09b | 2015-08-04 14:34:07 -0700 | [diff] [blame] | 382 | // if the window size changes |
Bri Prebilic Cole | 0bc4de2 | 2015-07-20 17:07:55 -0700 | [diff] [blame] | 383 | unbindWatch = $rootScope.$watchCollection( |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 384 | function () { |
| 385 | return { |
| 386 | h: $window.innerHeight, |
| 387 | w: $window.innerWidth |
| 388 | }; |
| 389 | }, function () { |
Bri Prebilic Cole | 54bbfb9 | 2015-05-28 16:02:28 -0700 | [diff] [blame] | 390 | if (!fs.isEmptyObject(scope.panelData)) { |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 391 | heightCalc(); |
Bri Prebilic Cole | 54bbfb9 | 2015-05-28 16:02:28 -0700 | [diff] [blame] | 392 | populateDetails(scope.panelData); |
Bri Prebilic Cole | 54bbfb9 | 2015-05-28 16:02:28 -0700 | [diff] [blame] | 393 | } |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 394 | } |
| 395 | ); |
Bri Prebilic Cole | 54bbfb9 | 2015-05-28 16:02:28 -0700 | [diff] [blame] | 396 | |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 397 | scope.$on('$destroy', function () { |
Bri Prebilic Cole | 0bc4de2 | 2015-07-20 17:07:55 -0700 | [diff] [blame] | 398 | unbindWatch(); |
Bri Prebilic Cole | 9dcaea5 | 2015-07-21 14:39:48 -0700 | [diff] [blame] | 399 | ks.unbindKeys(); |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 400 | ps.destroyPanel(pName); |
| 401 | }); |
| 402 | }; |
| 403 | }]); |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 404 | }()); |