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