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