blob: 4178653b7ca81afeb212ca61c9e552db1ae48596 [file] [log] [blame]
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -08001/*
2 * Copyright 2015 Open Networking Laboratory
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 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
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070025 var $log, $scope, fs, mast, ps, wss, is, bns, ns, ttip;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070026
27 // internal state
Bri Prebilic Colee568ead2015-05-01 09:51:28 -070028 var detailsPanel,
Bri Prebilic Cole45069382015-04-14 15:21:38 -070029 pStartY, pHeight,
30 top, bottom, iconDiv,
31 wSize, selRow;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070032
33 // constants
Bri Prebilic Cole45069382015-04-14 15:21:38 -070034 var topPdg = 13,
35 ctnrPdg = 24,
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070036 scrollSize = 17,
Bri Prebilic Cole45069382015-04-14 15:21:38 -070037 portsTblPdg = 50,
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070038 flowPath = 'flow',
Bri Prebilic Coleac829e42015-05-05 13:42:06 -070039 portPath = 'port',
Bri Prebilic Cole5c60d6e2015-05-12 09:11:03 -070040 groupPath = 'group',
Bri Prebilic Cole45069382015-04-14 15:21:38 -070041
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070042 pName = 'device-details-panel',
Bri Prebilic Coleac829e42015-05-05 13:42:06 -070043 bName = 'dev-dets-p',
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070044 detailsReq = 'deviceDetailsRequest',
45 detailsResp = 'deviceDetailsResponse',
Bri Prebilic Cole45069382015-04-14 15:21:38 -070046
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070047 propOrder = [
48 'type', 'masterid', 'chassisid',
49 'mfr', 'hw', 'sw', 'protocol', 'serial'
50 ],
51 friendlyProps = [
52 'Type', 'Master ID', 'Chassis ID',
53 'Vendor', 'H/W Version', 'S/W Version', 'Protocol', 'Serial #'
54 ],
55 portCols = [
Thomas Vachuskab52a0142015-04-21 17:48:15 -070056 'enabled', 'id', 'speed', 'type', 'elinks_dest', 'name'
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070057 ],
58 friendlyPortCols = [
Thomas Vachuskab52a0142015-04-21 17:48:15 -070059 'Enabled', 'ID', 'Speed', 'Type', 'Egress Links', 'Name'
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070060 ];
61
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070062 function addCloseBtn(div) {
Bri Prebilic Coleab582b82015-04-14 15:08:22 -070063 is.loadEmbeddedIcon(div, 'plus', 30);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070064 div.select('g').attr('transform', 'translate(25, 0) rotate(45)');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070065
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070066 div.on('click', function () {
67 detailsPanel.hide();
68 selRow.removeClass('selected');
69 });
70 }
71
72 function setUpPanel() {
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070073 var container, closeBtn, tblDiv;
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070074 detailsPanel.empty();
75
76 container = detailsPanel.append('div').classed('container', true);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070077
78 top = container.append('div').classed('top', true);
79 closeBtn = top.append('div').classed('close-btn', true);
80 addCloseBtn(closeBtn);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070081 iconDiv = top.append('div').classed('dev-icon', true);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070082 top.append('h2');
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070083
84 tblDiv = top.append('div').classed('top-tables', true);
85 tblDiv.append('div').classed('left', true).append('table');
86 tblDiv.append('div').classed('right', true).append('table');
87
88 top.append('div').classed('actionBtns', true);
Bri Prebilic Cole45069382015-04-14 15:21:38 -070089 top.append('hr');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070090
91 bottom = container.append('div').classed('bottom', true);
Bri Prebilic Cole45069382015-04-14 15:21:38 -070092 bottom.append('h2').classed('ports-title', true).html('Ports');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070093 bottom.append('table');
94 }
95
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070096 function addProp(tbody, index, value) {
97 var tr = tbody.append('tr');
98
99 function addCell(cls, txt) {
100 tr.append('td').attr('class', cls).html(txt);
101 }
102 addCell('label', friendlyProps[index] + ' :');
103 addCell('value', value);
104 }
105
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700106 function populateTop(tblDiv, btnsDiv, details) {
107 var leftTbl = tblDiv.select('.left')
108 .select('table')
109 .append('tbody'),
110 rightTbl = tblDiv.select('.right')
111 .select('table')
112 .append('tbody');
113
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700114 is.loadEmbeddedIcon(iconDiv, details._iconid_type, 40);
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700115 top.select('h2').html(details.id);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700116
117 propOrder.forEach(function (prop, i) {
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700118 // properties are split into two tables
119 addProp(i < 3 ? leftTbl : rightTbl, i, details[prop]);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700120 });
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700121
Bri Prebilic Coleac829e42015-05-05 13:42:06 -0700122 bns.button(
123 btnsDiv,
124 bName + '-flows',
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -0700125 'flowTable',
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700126 function () {
127 ns.navTo(flowPath, { devId: details.id });
128 },
Bri Prebilic Coleac829e42015-05-05 13:42:06 -0700129 'Show flow view for this device'
130 );
131 bns.button(
132 btnsDiv,
133 bName + '-ports',
Bri Prebilic Cole9467a232015-05-06 16:59:05 -0700134 'portTable',
Bri Prebilic Coleac829e42015-05-05 13:42:06 -0700135 function () {
136 ns.navTo(portPath, { devId: details.id });
137 },
138 'Show port view for this device'
139 );
Bri Prebilic Cole5c60d6e2015-05-12 09:11:03 -0700140 bns.button(
141 btnsDiv,
142 bName + '-groups',
143 'groupTable',
144 function () {
145 ns.navTo(groupPath, { devId: details.id });
146 },
147 'Show group view for this device'
148 );
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700149 }
150
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700151 function addPortRow(tbody, port) {
152 var tr = tbody.append('tr');
153
154 portCols.forEach(function (col) {
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700155 tr.append('td').html(port[col]);
156 });
157 }
158
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700159 function populateBottom(table, ports) {
160 var theader = table.append('thead').append('tr'),
161 tbody = table.append('tbody'),
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700162 tbWidth, tbHeight;
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700163
164 friendlyPortCols.forEach(function (col) {
165 theader.append('th').html(col);
166 });
167 ports.forEach(function (port) {
168 addPortRow(tbody, port);
169 });
170
171 tbWidth = fs.noPxStyle(tbody, 'width') + scrollSize;
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700172 tbHeight = pHeight
173 - (fs.noPxStyle(detailsPanel.el()
174 .select('.top'), 'height')
175 + fs.noPxStyle(detailsPanel.el()
176 .select('.ports-title'), 'height')
177 + portsTblPdg);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700178
179 table.style({
180 height: tbHeight + 'px',
181 width: tbWidth + 'px',
182 overflow: 'auto',
183 display: 'block'
184 });
185
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700186 detailsPanel.width(tbWidth + ctnrPdg);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700187 }
188
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700189 function populateDetails(details) {
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700190 var topTbs, btnsDiv, btmTbl, ports;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700191 setUpPanel();
192
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700193 topTbs = top.select('.top-tables');
194 btnsDiv = top.select('.actionBtns');
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700195 btmTbl = bottom.select('table');
196 ports = details.ports;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700197
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700198 populateTop(topTbs, btnsDiv, details);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700199 populateBottom(btmTbl, ports);
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700200
201 detailsPanel.height(pHeight);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700202 }
203
204 function respDetailsCb(data) {
Bri Prebilic Colee568ead2015-05-01 09:51:28 -0700205 $scope.panelData = data.details;
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700206 $scope.$apply();
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700207 }
208
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700209 function createDetailsPane() {
210 detailsPanel = ps.createPanel(pName, {
211 width: wSize.width,
212 margin: 0,
213 hideMargin: 0
214 });
215 detailsPanel.el().style({
216 position: 'absolute',
217 top: pStartY + 'px'
218 });
219 detailsPanel.hide();
220 }
221
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -0800222 angular.module('ovDevice', [])
Simon Hunta89f0f92015-02-26 16:47:12 -0800223 .controller('OvDeviceCtrl',
Bri Prebilic Colee1be1b72015-05-12 16:07:24 -0700224 ['$log', '$scope', 'TableBuilderService', 'FnService',
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700225 'MastService', 'PanelService', 'WebSocketService', 'IconService',
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700226 'ButtonService', 'NavService', 'TooltipService',
Simon Hunta89f0f92015-02-26 16:47:12 -0800227
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700228 function (_$log_, _$scope_,
Bri Prebilic Colee1be1b72015-05-12 16:07:24 -0700229 tbs, _fs_, _mast_, _ps_, _wss_, _is_, _bns_, _ns_, _ttip_) {
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700230 $log = _$log_;
231 $scope = _$scope_;
232 fs = _fs_;
233 mast = _mast_;
234 ps = _ps_;
235 wss = _wss_;
236 is = _is_;
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700237 bns = _bns_;
238 ns = _ns_;
239 ttip = _ttip_;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700240 var handlers = {};
Bri Prebilic Colee568ead2015-05-01 09:51:28 -0700241 $scope.panelData = [];
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700242
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700243 function selCb($event, row) {
244 selRow = angular.element($event.currentTarget);
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 Coleb699a162015-04-13 12:01:39 -0700248 detailsPanel.hide();
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',
256 selCb: selCb
257 });
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700258
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700259 // details panel handlers
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700260 handlers[detailsResp] = respDetailsCb;
261 wss.bindHandlers(handlers);
262
263 $scope.$on('$destroy', function () {
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700264 wss.unbindHandlers(handlers);
Simon Hunta89f0f92015-02-26 16:47:12 -0800265 });
266
Bri Prebilic Cole72eb6db2015-03-30 16:58:53 -0700267 $log.log('OvDeviceCtrl has been created');
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700268 }])
269
270 .directive('deviceDetailsPanel', ['$rootScope', '$window',
271 function ($rootScope, $window) {
272 return function (scope) {
273
274 function heightCalc() {
275 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
276 + mast.mastHeight() + topPdg;
277 wSize = fs.windowSize(pStartY);
278 pHeight = wSize.height;
279 }
280 heightCalc();
281
282 createDetailsPane();
283
284 scope.$watch('panelData', function () {
285 if (!fs.isEmptyObject(scope.panelData)) {
286 populateDetails(scope.panelData);
287 detailsPanel.show();
288 }
289 });
290
291 $rootScope.$watchCollection(
292 function () {
293 return {
294 h: $window.innerHeight,
295 w: $window.innerWidth
296 }
297 }, function () {
298 if (!fs.isEmptyObject(scope.panelData)) {
299 heightCalc();
300 populateDetails(scope.panelData);
301 }
302 }
303 );
304
305 scope.$on('$destroy', function () {
306 ps.destroyPanel(pName);
307 });
308 };
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -0800309 }]);
310}());