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