blob: 960fe6fbc627efec9f8bd197a0594a148d6f8ecf [file] [log] [blame]
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -08003 *
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 Coleaa0f0882015-02-04 15:27:55 -080018 ONOS GUI -- Device View Module
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -080019 */
20
21(function () {
22 'use strict';
23
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070024 // injected refs
Steven Burrowsf50a1772017-09-14 11:58:15 +010025 var $log, $scope, $loc, fs, mast, ps, wss, is, ns, ks, dps;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070026
27 // internal state
Bri Prebilic Colee568ead2015-05-01 09:51:28 -070028 var detailsPanel,
Simon Huntd766c312015-10-06 11:46:32 -070029 pStartY,
30 pHeight,
31 top,
Simon Huntd766c312015-10-06 11:46:32 -070032 wSize,
Alan Deikman8d858752017-02-14 18:08:29 -080033 device;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070034
35 // constants
Simon Hunt986b92f2016-06-03 15:46:59 -070036 var topPdg = 28,
Bri Prebilic Cole45069382015-04-14 15:21:38 -070037 ctnrPdg = 24,
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070038 scrollSize = 17,
Bri Prebilic Cole45069382015-04-14 15:21:38 -070039 portsTblPdg = 50,
40
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070041 pName = 'device-details-panel',
42 detailsReq = 'deviceDetailsRequest',
43 detailsResp = 'deviceDetailsResponse',
Simon Huntd5579252015-10-06 15:09:14 -070044 nameChangeReq = 'deviceNameChangeRequest',
45 nameChangeResp = 'deviceNameChangeResponse',
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070046 portCols = [
Steven Burrows1c2a9682017-07-14 16:52:46 +010047 'enabled', 'id', 'speed', 'type', 'elinks_dest', 'name',
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070048 ],
49 friendlyPortCols = [
Steven Burrows1c2a9682017-07-14 16:52:46 +010050 'Enabled', 'ID', 'Speed', 'Type', 'Egress Links', 'Name',
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070051 ];
52
Steven Burrowsf50a1772017-09-14 11:58:15 +010053 var keyBindings = {
54 esc: [closePanel, 'Close the details panel'],
55 _helpFormat: ['esc'],
56 };
57
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -070058 function closePanel() {
59 if (detailsPanel.isVisible()) {
60 $scope.selId = null;
61 detailsPanel.hide();
Simon Huntd766c312015-10-06 11:46:32 -070062 return true;
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -070063 }
Simon Huntd766c312015-10-06 11:46:32 -070064 return false;
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -070065 }
66
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070067 function setUpPanel() {
Steven Burrowsf50a1772017-09-14 11:58:15 +010068 // var container, closeBtn, tblDiv;
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070069
Steven Burrowsf50a1772017-09-14 11:58:15 +010070 dps.empty();
71 dps.addContainers();
72 dps.addCloseButton(closePanel);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070073
Steven Burrowsf50a1772017-09-14 11:58:15 +010074 var top = dps.top();
75 var bottom = dps.bottom();
Simon Huntd766c312015-10-06 11:46:32 -070076
Simon Huntc9e83212017-10-09 16:52:07 -070077 dps.addHeading('dev-icon', true);
Steven Burrowsf50a1772017-09-14 11:58:15 +010078 top.append('div').classed('top-content', true);
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070079
Bri Prebilic Cole45069382015-04-14 15:21:38 -070080 top.append('hr');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070081
Simon Hunt239f09e2017-05-18 13:10:09 -070082 bottom.append('h2').classed('ports-title', true).text('Ports');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070083 bottom.append('table');
84 }
85
Steven Burrowsf50a1772017-09-14 11:58:15 +010086 function friendlyPropsList(details) {
87 return {
88 'URI': device.id,
89 'Type': device.type,
90 'Master ID': details['masterid'],
Andrea Campanellaab7d9ab2018-05-02 15:13:54 +020091 'Chassis ID': details['chassisid'],
Steven Burrowsf50a1772017-09-14 11:58:15 +010092 '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 Cole0feedc02015-04-09 14:17:37 -070099 }
100
Bri Prebilic Cole9b1fb9a2015-07-01 13:57:11 -0700101 function populateTop(tblDiv, details) {
Steven Burrowsf50a1772017-09-14 11:58:15 +0100102 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 Coleb699a162015-04-13 12:01:39 -0700105 }
106
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700107 function addPortRow(tbody, port) {
108 var tr = tbody.append('tr');
109
110 portCols.forEach(function (col) {
Simon Hunt239f09e2017-05-18 13:10:09 -0700111 tr.append('td').text(port[col]);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700112 });
113 }
114
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700115 function populateBottom(table, ports) {
Steven Burrowsf50a1772017-09-14 11:58:15 +0100116
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700117 var theader = table.append('thead').append('tr'),
118 tbody = table.append('tbody'),
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700119 tbWidth, tbHeight;
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700120
121 friendlyPortCols.forEach(function (col) {
Simon Hunt239f09e2017-05-18 13:10:09 -0700122 theader.append('th').text(col);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700123 });
Steven Burrowsf50a1772017-09-14 11:58:15 +0100124
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700125 ports.forEach(function (port) {
126 addPortRow(tbody, port);
127 });
128
129 tbWidth = fs.noPxStyle(tbody, 'width') + scrollSize;
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700130 tbHeight = pHeight
Steven Burrowsf50a1772017-09-14 11:58:15 +0100131 - (fs.noPxStyle(detailsPanel.el().select('.top'), 'height')
132 + fs.noPxStyle(detailsPanel.el().select('.ports-title'), 'height')
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700133 + portsTblPdg);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700134
135 table.style({
136 height: tbHeight + 'px',
137 width: tbWidth + 'px',
138 overflow: 'auto',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100139 display: 'block',
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700140 });
141
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700142 detailsPanel.width(tbWidth + ctnrPdg);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700143 }
144
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700145 function populateDetails(details) {
Steven Burrowsf50a1772017-09-14 11:58:15 +0100146 var btmTbl, ports;
Simon Hunta9301bb2016-10-20 11:38:10 -0700147
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700148 setUpPanel();
149
Steven Burrowsf50a1772017-09-14 11:58:15 +0100150 btmTbl = dps.bottom().select('table');
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700151 ports = details.ports;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700152
Steven Burrowsf50a1772017-09-14 11:58:15 +0100153 populateTop(dps.select('.top-content'), details);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700154 populateBottom(btmTbl, ports);
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700155
156 detailsPanel.height(pHeight);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700157 }
158
159 function respDetailsCb(data) {
Bri Prebilic Colee568ead2015-05-01 09:51:28 -0700160 $scope.panelData = data.details;
Alan Deikman8d858752017-02-14 18:08:29 -0800161 device = data.device;
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700162 $scope.$apply();
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700163 }
164
Simon Huntd5579252015-10-06 15:09:14 -0700165 function respNameCb(data) {
166 if (data.warn) {
167 $log.warn(data.warn, data.id);
Simon Hunt239f09e2017-05-18 13:10:09 -0700168 top.select('h2').text(data.id);
Simon Huntd5579252015-10-06 15:09:14 -0700169 }
170 }
171
Steven Burrowsf50a1772017-09-14 11:58:15 +0100172 function createDetailsPanel() {
173 detailsPanel = dps.create(pName, {
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700174 width: wSize.width,
175 margin: 0,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100176 hideMargin: 0,
Steven Burrowsf50a1772017-09-14 11:58:15 +0100177 scope: $scope,
178 keyBindings: keyBindings,
179 nameChangeRequest: nameChangeReq,
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700180 });
Steven Burrowsf50a1772017-09-14 11:58:15 +0100181
182 dps.setResponse(detailsResp, respDetailsCb);
183
Bri Prebilic Cole68844ba2015-07-22 15:41:37 -0700184 $scope.hidePanel = function () { detailsPanel.hide(); };
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700185 }
186
Simon Hunt400ebbf2017-01-06 20:07:50 -0800187 // 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 Cole7c92a3d2015-01-09 16:50:03 -0800201 angular.module('ovDevice', [])
Simon Hunta89f0f92015-02-26 16:47:12 -0800202 .controller('OvDeviceCtrl',
Simon Hunt400ebbf2017-01-06 20:07:50 -0800203 ['$log', '$scope', '$location', 'TableBuilderService',
204 'TableDetailService', 'FnService',
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700205 'MastService', 'PanelService', 'WebSocketService', 'IconService',
Steven Burrowsf50a1772017-09-14 11:58:15 +0100206 'NavService', 'KeyService', 'DetailsPanelService',
Simon Hunta89f0f92015-02-26 16:47:12 -0800207
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700208 function (_$log_, _$scope_, _$location_,
Steven Burrowsf50a1772017-09-14 11:58:15 +0100209 tbs, tds, _fs_, _mast_, _ps_, _wss_, _is_, _ns_, _ks_, _dps_) {
Simon Huntd5579252015-10-06 15:09:14 -0700210 var params,
211 handlers = {};
212
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700213 $log = _$log_;
214 $scope = _$scope_;
Simon Huntd5579252015-10-06 15:09:14 -0700215 $loc = _$location_;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700216 fs = _fs_;
217 mast = _mast_;
218 ps = _ps_;
219 wss = _wss_;
220 is = _is_;
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700221 ns = _ns_;
Simon Huntd5579252015-10-06 15:09:14 -0700222 ks = _ks_;
Steven Burrowsf50a1772017-09-14 11:58:15 +0100223 dps = _dps_;
Simon Huntd5579252015-10-06 15:09:14 -0700224
225 params = $loc.search();
226
Bri Prebilic Cole68844ba2015-07-22 15:41:37 -0700227 $scope.panelData = {};
Bri Prebilic Coleeef67ae2015-07-01 16:26:59 -0700228 $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 Li1f544732015-12-30 23:36:37 -0800231 $scope.meterTip = 'Show meter view for selected device';
Yi Tsenga87b40c2017-09-10 00:59:03 -0700232 $scope.pipeconfTip = 'Show pipeconf view for selected device';
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700233
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700234 // details panel handlers
Simon Huntd5579252015-10-06 15:09:14 -0700235 handlers[nameChangeResp] = respNameCb;
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700236 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 Coleb699a162015-04-13 12:01:39 -0700244 function selCb($event, row) {
Bri Prebilic Colebfab9c72015-06-01 14:33:18 -0700245 if ($scope.selId) {
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700246 wss.sendEvent(detailsReq, { id: row.id });
247 } else {
Bri Prebilic Cole68844ba2015-07-22 15:41:37 -0700248 $scope.hidePanel();
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700249 }
250 $log.debug('Got a click on:', row);
251 }
252
Bri Prebilic Cole864cdd62015-04-02 15:46:47 -0700253 tbs.buildTable({
Bri Prebilic Cole864cdd62015-04-02 15:46:47 -0700254 scope: $scope,
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700255 tag: 'device',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100256 selCb: selCb,
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700257 });
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700258
Simon Hunt400ebbf2017-01-06 20:07:50 -0800259
260 // ==================== for testing for now ===============
261 // TODO: more than just an example
262 tds.buildBasePanel({
263 popTop: popTop,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100264 popMid: popMid,
Simon Hunt400ebbf2017-01-06 20:07:50 -0800265 });
266 // ==================== for testing for now ===============
267
268
Bri Prebilic Cole9b1fb9a2015-07-01 13:57:11 -0700269 $scope.nav = function (path) {
270 if ($scope.selId) {
271 ns.navTo(path, { devId: $scope.selId });
272 }
273 };
274
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700275 $scope.$on('$destroy', function () {
Steven Burrowsf50a1772017-09-14 11:58:15 +0100276 dps.destroy();
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700277 wss.unbindHandlers(handlers);
Simon Hunta89f0f92015-02-26 16:47:12 -0800278 });
279
Bri Prebilic Cole72eb6db2015-03-30 16:58:53 -0700280 $log.log('OvDeviceCtrl has been created');
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700281 }])
282
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700283 .directive('deviceDetailsPanel',
284 ['$rootScope', '$window', '$timeout', 'KeyService',
285 function ($rootScope, $window, $timeout, ks) {
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700286 return function (scope) {
Bri Prebilic Cole0bc4de22015-07-20 17:07:55 -0700287 var unbindWatch;
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700288
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700289 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 Cole17c6d0a2015-07-16 14:56:40 -0700295
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700296 function initPanel() {
297 heightCalc();
Steven Burrowsf50a1772017-09-14 11:58:15 +0100298 createDetailsPanel();
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700299 }
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700300
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700301 // 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 Cole9dcaea52015-07-21 14:39:48 -0700308 // create key bindings to handle panel
Steven Burrowsf50a1772017-09-14 11:58:15 +0100309 ks.keyBindings(keyBindings);
310
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -0700311 ks.gestureNotes([
312 ['click', 'Select a row to show device details'],
Steven Burrows1c2a9682017-07-14 16:52:46 +0100313 ['scroll down', 'See more devices'],
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -0700314 ]);
315
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700316 // if the panelData changes
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700317 scope.$watch('panelData', function () {
318 if (!fs.isEmptyObject(scope.panelData)) {
319 populateDetails(scope.panelData);
320 detailsPanel.show();
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700321 }
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700322 });
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700323
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700324 // if the window size changes
Bri Prebilic Cole0bc4de22015-07-20 17:07:55 -0700325 unbindWatch = $rootScope.$watchCollection(
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700326 function () {
327 return {
328 h: $window.innerHeight,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100329 w: $window.innerWidth,
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700330 };
331 }, function () {
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700332 if (!fs.isEmptyObject(scope.panelData)) {
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700333 heightCalc();
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700334 populateDetails(scope.panelData);
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700335 }
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700336 }
337 );
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700338
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700339 scope.$on('$destroy', function () {
Bri Prebilic Cole0bc4de22015-07-20 17:07:55 -0700340 unbindWatch();
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -0700341 ks.unbindKeys();
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700342 ps.destroyPanel(pName);
343 });
344 };
345 }]);
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -0800346}());