blob: ce3eb4ebfc3e1039cd2ee94bba9d6716f9494eff [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 Cole45069382015-04-14 15:21:38 -070040
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070041 pName = 'device-details-panel',
Bri Prebilic Coleac829e42015-05-05 13:42:06 -070042 bName = 'dev-dets-p',
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070043 detailsReq = 'deviceDetailsRequest',
44 detailsResp = 'deviceDetailsResponse',
Bri Prebilic Cole45069382015-04-14 15:21:38 -070045
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070046 propOrder = [
47 'type', 'masterid', 'chassisid',
48 'mfr', 'hw', 'sw', 'protocol', 'serial'
49 ],
50 friendlyProps = [
51 'Type', 'Master ID', 'Chassis ID',
52 'Vendor', 'H/W Version', 'S/W Version', 'Protocol', 'Serial #'
53 ],
54 portCols = [
Thomas Vachuskab52a0142015-04-21 17:48:15 -070055 'enabled', 'id', 'speed', 'type', 'elinks_dest', 'name'
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070056 ],
57 friendlyPortCols = [
Thomas Vachuskab52a0142015-04-21 17:48:15 -070058 'Enabled', 'ID', 'Speed', 'Type', 'Egress Links', 'Name'
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070059 ];
60
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070061 function addCloseBtn(div) {
Bri Prebilic Coleab582b82015-04-14 15:08:22 -070062 is.loadEmbeddedIcon(div, 'plus', 30);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070063 div.select('g').attr('transform', 'translate(25, 0) rotate(45)');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070064
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070065 div.on('click', function () {
66 detailsPanel.hide();
67 selRow.removeClass('selected');
68 });
69 }
70
71 function setUpPanel() {
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070072 var container, closeBtn, tblDiv;
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070073 detailsPanel.empty();
74
75 container = detailsPanel.append('div').classed('container', true);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070076
77 top = container.append('div').classed('top', true);
78 closeBtn = top.append('div').classed('close-btn', true);
79 addCloseBtn(closeBtn);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070080 iconDiv = top.append('div').classed('dev-icon', true);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070081 top.append('h2');
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070082
83 tblDiv = top.append('div').classed('top-tables', true);
84 tblDiv.append('div').classed('left', true).append('table');
85 tblDiv.append('div').classed('right', true).append('table');
86
87 top.append('div').classed('actionBtns', true);
Bri Prebilic Cole45069382015-04-14 15:21:38 -070088 top.append('hr');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070089
90 bottom = container.append('div').classed('bottom', true);
Bri Prebilic Cole45069382015-04-14 15:21:38 -070091 bottom.append('h2').classed('ports-title', true).html('Ports');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070092 bottom.append('table');
93 }
94
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070095 function addProp(tbody, index, value) {
96 var tr = tbody.append('tr');
97
98 function addCell(cls, txt) {
99 tr.append('td').attr('class', cls).html(txt);
100 }
101 addCell('label', friendlyProps[index] + ' :');
102 addCell('value', value);
103 }
104
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700105 function populateTop(tblDiv, btnsDiv, details) {
106 var leftTbl = tblDiv.select('.left')
107 .select('table')
108 .append('tbody'),
109 rightTbl = tblDiv.select('.right')
110 .select('table')
111 .append('tbody');
112
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700113 is.loadEmbeddedIcon(iconDiv, details._iconid_type, 40);
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700114 top.select('h2').html(details.id);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700115
116 propOrder.forEach(function (prop, i) {
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700117 // properties are split into two tables
118 addProp(i < 3 ? leftTbl : rightTbl, i, details[prop]);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700119 });
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700120
Bri Prebilic Coleac829e42015-05-05 13:42:06 -0700121 bns.button(
122 btnsDiv,
123 bName + '-flows',
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -0700124 'flowTable',
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700125 function () {
126 ns.navTo(flowPath, { devId: details.id });
127 },
Bri Prebilic Coleac829e42015-05-05 13:42:06 -0700128 'Show flow view for this device'
129 );
130 bns.button(
131 btnsDiv,
132 bName + '-ports',
Bri Prebilic Cole9467a232015-05-06 16:59:05 -0700133 'portTable',
Bri Prebilic Coleac829e42015-05-05 13:42:06 -0700134 function () {
135 ns.navTo(portPath, { devId: details.id });
136 },
137 'Show port view for this device'
138 );
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700139 }
140
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700141 function addPortRow(tbody, port) {
142 var tr = tbody.append('tr');
143
144 portCols.forEach(function (col) {
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700145 tr.append('td').html(port[col]);
146 });
147 }
148
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700149 function populateBottom(table, ports) {
150 var theader = table.append('thead').append('tr'),
151 tbody = table.append('tbody'),
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700152 tbWidth, tbHeight;
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700153
154 friendlyPortCols.forEach(function (col) {
155 theader.append('th').html(col);
156 });
157 ports.forEach(function (port) {
158 addPortRow(tbody, port);
159 });
160
161 tbWidth = fs.noPxStyle(tbody, 'width') + scrollSize;
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700162 tbHeight = pHeight
163 - (fs.noPxStyle(detailsPanel.el()
164 .select('.top'), 'height')
165 + fs.noPxStyle(detailsPanel.el()
166 .select('.ports-title'), 'height')
167 + portsTblPdg);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700168
169 table.style({
170 height: tbHeight + 'px',
171 width: tbWidth + 'px',
172 overflow: 'auto',
173 display: 'block'
174 });
175
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700176 detailsPanel.width(tbWidth + ctnrPdg);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700177 }
178
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700179 function populateDetails(details) {
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700180 var topTbs, btnsDiv, btmTbl, ports;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700181 setUpPanel();
182
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700183 topTbs = top.select('.top-tables');
184 btnsDiv = top.select('.actionBtns');
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700185 btmTbl = bottom.select('table');
186 ports = details.ports;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700187
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700188 populateTop(topTbs, btnsDiv, details);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700189 populateBottom(btmTbl, ports);
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700190
191 detailsPanel.height(pHeight);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700192 }
193
194 function respDetailsCb(data) {
Bri Prebilic Colee568ead2015-05-01 09:51:28 -0700195 $scope.panelData = data.details;
196 populateDetails($scope.panelData);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700197 detailsPanel.show();
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700198 }
199
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700200 function createDetailsPane() {
201 detailsPanel = ps.createPanel(pName, {
202 width: wSize.width,
203 margin: 0,
204 hideMargin: 0
205 });
206 detailsPanel.el().style({
207 position: 'absolute',
208 top: pStartY + 'px'
209 });
210 detailsPanel.hide();
211 }
212
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -0800213 angular.module('ovDevice', [])
Simon Hunta89f0f92015-02-26 16:47:12 -0800214 .controller('OvDeviceCtrl',
Bri Prebilic Cole3d4d01c2015-04-30 13:48:36 -0700215 ['$log', '$scope', 'TableService', 'TableBuilderService', 'FnService',
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700216 'MastService', 'PanelService', 'WebSocketService', 'IconService',
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700217 'ButtonService', 'NavService', 'TooltipService',
Simon Hunta89f0f92015-02-26 16:47:12 -0800218
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700219 function (_$log_, _$scope_,
Bri Prebilic Cole3d4d01c2015-04-30 13:48:36 -0700220 ts, tbs, _fs_, _mast_, _ps_, _wss_, _is_, _bns_, _ns_, _ttip_) {
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700221 $log = _$log_;
222 $scope = _$scope_;
223 fs = _fs_;
224 mast = _mast_;
225 ps = _ps_;
226 wss = _wss_;
227 is = _is_;
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700228 bns = _bns_;
229 ns = _ns_;
230 ttip = _ttip_;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700231 var handlers = {};
Bri Prebilic Colee568ead2015-05-01 09:51:28 -0700232 $scope.panelData = [];
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700233 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
234 + mast.mastHeight() + topPdg;
235 wSize = fs.windowSize(pStartY);
236 pHeight = wSize.height;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700237
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700238 function selCb($event, row) {
239 selRow = angular.element($event.currentTarget);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700240 if ($scope.sel) {
241 wss.sendEvent(detailsReq, { id: row.id });
242 } else {
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700243 detailsPanel.hide();
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700244 }
245 $log.debug('Got a click on:', row);
246 }
247
Bri Prebilic Cole864cdd62015-04-02 15:46:47 -0700248 tbs.buildTable({
Bri Prebilic Cole864cdd62015-04-02 15:46:47 -0700249 scope: $scope,
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700250 tag: 'device',
251 selCb: selCb
252 });
Bri Prebilic Cole3d4d01c2015-04-30 13:48:36 -0700253
254 $scope.refresh = function () {
255 $log.debug('Refreshing devices page');
256 ts.resetSortIcons();
257 $scope.sortCallback();
258 };
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700259 createDetailsPane();
260
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700261 // details panel handlers
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700262 handlers[detailsResp] = respDetailsCb;
263 wss.bindHandlers(handlers);
264
265 $scope.$on('$destroy', function () {
266 ps.destroyPanel(pName);
267 wss.unbindHandlers(handlers);
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700268 ttip.resetTooltip();
Simon Hunta89f0f92015-02-26 16:47:12 -0800269 });
270
Bri Prebilic Cole72eb6db2015-03-30 16:58:53 -0700271 $log.log('OvDeviceCtrl has been created');
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -0800272 }]);
273}());