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