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