blob: cd0799bdfc915f764c4abcb5c933eab1ae6e0dca [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 Cole45069382015-04-14 15:21:38 -070039
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070040 pName = 'device-details-panel',
41 detailsReq = 'deviceDetailsRequest',
42 detailsResp = 'deviceDetailsResponse',
Bri Prebilic Cole45069382015-04-14 15:21:38 -070043
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070044 propOrder = [
45 'type', 'masterid', 'chassisid',
46 'mfr', 'hw', 'sw', 'protocol', 'serial'
47 ],
48 friendlyProps = [
49 'Type', 'Master ID', 'Chassis ID',
50 'Vendor', 'H/W Version', 'S/W Version', 'Protocol', 'Serial #'
51 ],
52 portCols = [
Thomas Vachuskab52a0142015-04-21 17:48:15 -070053 'enabled', 'id', 'speed', 'type', 'elinks_dest', 'name'
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070054 ],
55 friendlyPortCols = [
Thomas Vachuskab52a0142015-04-21 17:48:15 -070056 'Enabled', 'ID', 'Speed', 'Type', 'Egress Links', 'Name'
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070057 ];
58
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070059 function addCloseBtn(div) {
Bri Prebilic Coleab582b82015-04-14 15:08:22 -070060 is.loadEmbeddedIcon(div, 'plus', 30);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070061 div.select('g').attr('transform', 'translate(25, 0) rotate(45)');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070062
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070063 div.on('click', function () {
64 detailsPanel.hide();
65 selRow.removeClass('selected');
66 });
67 }
68
69 function setUpPanel() {
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070070 var container, closeBtn, tblDiv;
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070071 detailsPanel.empty();
72
73 container = detailsPanel.append('div').classed('container', true);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070074
75 top = container.append('div').classed('top', true);
76 closeBtn = top.append('div').classed('close-btn', true);
77 addCloseBtn(closeBtn);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070078 iconDiv = top.append('div').classed('dev-icon', true);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070079 top.append('h2');
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070080
81 tblDiv = top.append('div').classed('top-tables', true);
82 tblDiv.append('div').classed('left', true).append('table');
83 tblDiv.append('div').classed('right', true).append('table');
84
85 top.append('div').classed('actionBtns', true);
Bri Prebilic Cole45069382015-04-14 15:21:38 -070086 top.append('hr');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070087
88 bottom = container.append('div').classed('bottom', true);
Bri Prebilic Cole45069382015-04-14 15:21:38 -070089 bottom.append('h2').classed('ports-title', true).html('Ports');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070090 bottom.append('table');
91 }
92
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070093 function addProp(tbody, index, value) {
94 var tr = tbody.append('tr');
95
96 function addCell(cls, txt) {
97 tr.append('td').attr('class', cls).html(txt);
98 }
99 addCell('label', friendlyProps[index] + ' :');
100 addCell('value', value);
101 }
102
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700103 function populateTop(tblDiv, btnsDiv, details) {
104 var leftTbl = tblDiv.select('.left')
105 .select('table')
106 .append('tbody'),
107 rightTbl = tblDiv.select('.right')
108 .select('table')
109 .append('tbody');
110
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700111 is.loadEmbeddedIcon(iconDiv, details._iconid_type, 40);
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700112 top.select('h2').html(details.id);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700113
114 propOrder.forEach(function (prop, i) {
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700115 // properties are split into two tables
116 addProp(i < 3 ? leftTbl : rightTbl, i, details[prop]);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700117 });
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700118
119 bns.button(btnsDiv,
120 'dev-dets-p-flows',
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -0700121 'flowTable',
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700122 function () {
123 ns.navTo(flowPath, { devId: details.id });
124 },
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -0700125 'Show flows table for this device');
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700126 }
127
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700128 function addPortRow(tbody, port) {
129 var tr = tbody.append('tr');
130
131 portCols.forEach(function (col) {
132 if (col === 'type' || col === 'id') {
133 port[col] = fs.cap(port[col]);
134 }
135 tr.append('td').html(port[col]);
136 });
137 }
138
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700139 function populateBottom(table, ports) {
140 var theader = table.append('thead').append('tr'),
141 tbody = table.append('tbody'),
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700142 tbWidth, tbHeight;
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700143
144 friendlyPortCols.forEach(function (col) {
145 theader.append('th').html(col);
146 });
147 ports.forEach(function (port) {
148 addPortRow(tbody, port);
149 });
150
151 tbWidth = fs.noPxStyle(tbody, 'width') + scrollSize;
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700152 tbHeight = pHeight
153 - (fs.noPxStyle(detailsPanel.el()
154 .select('.top'), 'height')
155 + fs.noPxStyle(detailsPanel.el()
156 .select('.ports-title'), 'height')
157 + portsTblPdg);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700158
159 table.style({
160 height: tbHeight + 'px',
161 width: tbWidth + 'px',
162 overflow: 'auto',
163 display: 'block'
164 });
165
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700166 detailsPanel.width(tbWidth + ctnrPdg);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700167 }
168
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700169 function populateDetails(details) {
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700170 var topTbs, btnsDiv, btmTbl, ports;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700171 setUpPanel();
172
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700173 topTbs = top.select('.top-tables');
174 btnsDiv = top.select('.actionBtns');
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700175 btmTbl = bottom.select('table');
176 ports = details.ports;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700177
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700178 populateTop(topTbs, btnsDiv, details);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700179 populateBottom(btmTbl, ports);
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700180
181 detailsPanel.height(pHeight);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700182 }
183
184 function respDetailsCb(data) {
Bri Prebilic Colee568ead2015-05-01 09:51:28 -0700185 $scope.panelData = data.details;
186 populateDetails($scope.panelData);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700187 detailsPanel.show();
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700188 }
189
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700190 function createDetailsPane() {
191 detailsPanel = ps.createPanel(pName, {
192 width: wSize.width,
193 margin: 0,
194 hideMargin: 0
195 });
196 detailsPanel.el().style({
197 position: 'absolute',
198 top: pStartY + 'px'
199 });
200 detailsPanel.hide();
201 }
202
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -0800203 angular.module('ovDevice', [])
Simon Hunta89f0f92015-02-26 16:47:12 -0800204 .controller('OvDeviceCtrl',
Bri Prebilic Cole3d4d01c2015-04-30 13:48:36 -0700205 ['$log', '$scope', 'TableService', 'TableBuilderService', 'FnService',
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700206 'MastService', 'PanelService', 'WebSocketService', 'IconService',
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700207 'ButtonService', 'NavService', 'TooltipService',
Simon Hunta89f0f92015-02-26 16:47:12 -0800208
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700209 function (_$log_, _$scope_,
Bri Prebilic Cole3d4d01c2015-04-30 13:48:36 -0700210 ts, tbs, _fs_, _mast_, _ps_, _wss_, _is_, _bns_, _ns_, _ttip_) {
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700211 $log = _$log_;
212 $scope = _$scope_;
213 fs = _fs_;
214 mast = _mast_;
215 ps = _ps_;
216 wss = _wss_;
217 is = _is_;
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700218 bns = _bns_;
219 ns = _ns_;
220 ttip = _ttip_;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700221 var handlers = {};
Bri Prebilic Colee568ead2015-05-01 09:51:28 -0700222 $scope.panelData = [];
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700223 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
224 + mast.mastHeight() + topPdg;
225 wSize = fs.windowSize(pStartY);
226 pHeight = wSize.height;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700227
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700228 function selCb($event, row) {
229 selRow = angular.element($event.currentTarget);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700230 if ($scope.sel) {
231 wss.sendEvent(detailsReq, { id: row.id });
232 } else {
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700233 detailsPanel.hide();
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700234 }
235 $log.debug('Got a click on:', row);
236 }
237
Bri Prebilic Cole864cdd62015-04-02 15:46:47 -0700238 tbs.buildTable({
Bri Prebilic Cole864cdd62015-04-02 15:46:47 -0700239 scope: $scope,
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700240 tag: 'device',
241 selCb: selCb
242 });
Bri Prebilic Cole3d4d01c2015-04-30 13:48:36 -0700243
244 $scope.refresh = function () {
245 $log.debug('Refreshing devices page');
246 ts.resetSortIcons();
247 $scope.sortCallback();
248 };
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700249 createDetailsPane();
250
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700251 // details panel handlers
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700252 handlers[detailsResp] = respDetailsCb;
253 wss.bindHandlers(handlers);
254
255 $scope.$on('$destroy', function () {
256 ps.destroyPanel(pName);
257 wss.unbindHandlers(handlers);
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700258 ttip.resetTooltip();
Simon Hunta89f0f92015-02-26 16:47:12 -0800259 });
260
Bri Prebilic Cole72eb6db2015-03-30 16:58:53 -0700261 $log.log('OvDeviceCtrl has been created');
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -0800262 }]);
263}());