blob: 236f374d75073a4863454da9d8bd3056673661cf [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
28 var self,
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070029 detailsPanel,
Bri Prebilic Cole45069382015-04-14 15:21:38 -070030 pStartY, pHeight,
31 top, bottom, iconDiv,
32 wSize, selRow;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070033
34 // constants
Bri Prebilic Cole45069382015-04-14 15:21:38 -070035 var topPdg = 13,
36 ctnrPdg = 24,
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070037 scrollSize = 17,
Bri Prebilic Cole45069382015-04-14 15:21:38 -070038 portsTblPdg = 50,
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070039 flowPath = 'flow',
Bri Prebilic Cole45069382015-04-14 15:21:38 -070040
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070041 pName = 'device-details-panel',
42 detailsReq = 'deviceDetailsRequest',
43 detailsResp = 'deviceDetailsResponse',
Bri Prebilic Cole45069382015-04-14 15:21:38 -070044
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070045 propOrder = [
46 'type', 'masterid', 'chassisid',
47 'mfr', 'hw', 'sw', 'protocol', 'serial'
48 ],
49 friendlyProps = [
50 'Type', 'Master ID', 'Chassis ID',
51 'Vendor', 'H/W Version', 'S/W Version', 'Protocol', 'Serial #'
52 ],
53 portCols = [
Thomas Vachuskab52a0142015-04-21 17:48:15 -070054 'enabled', 'id', 'speed', 'type', 'elinks_dest', 'name'
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070055 ],
56 friendlyPortCols = [
Thomas Vachuskab52a0142015-04-21 17:48:15 -070057 'Enabled', 'ID', 'Speed', 'Type', 'Egress Links', 'Name'
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070058 ];
59
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070060 function addCloseBtn(div) {
Bri Prebilic Coleab582b82015-04-14 15:08:22 -070061 is.loadEmbeddedIcon(div, 'plus', 30);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070062 div.select('g').attr('transform', 'translate(25, 0) rotate(45)');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070063
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070064 div.on('click', function () {
65 detailsPanel.hide();
66 selRow.removeClass('selected');
67 });
68 }
69
70 function setUpPanel() {
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070071 var container, closeBtn, tblDiv;
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070072 detailsPanel.empty();
73
74 container = detailsPanel.append('div').classed('container', true);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070075
76 top = container.append('div').classed('top', true);
77 closeBtn = top.append('div').classed('close-btn', true);
78 addCloseBtn(closeBtn);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070079 iconDiv = top.append('div').classed('dev-icon', true);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070080 top.append('h2');
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070081
82 tblDiv = top.append('div').classed('top-tables', true);
83 tblDiv.append('div').classed('left', true).append('table');
84 tblDiv.append('div').classed('right', true).append('table');
85
86 top.append('div').classed('actionBtns', true);
Bri Prebilic Cole45069382015-04-14 15:21:38 -070087 top.append('hr');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070088
89 bottom = container.append('div').classed('bottom', true);
Bri Prebilic Cole45069382015-04-14 15:21:38 -070090 bottom.append('h2').classed('ports-title', true).html('Ports');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070091 bottom.append('table');
92 }
93
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070094 function addProp(tbody, index, value) {
95 var tr = tbody.append('tr');
96
97 function addCell(cls, txt) {
98 tr.append('td').attr('class', cls).html(txt);
99 }
100 addCell('label', friendlyProps[index] + ' :');
101 addCell('value', value);
102 }
103
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700104 function populateTop(tblDiv, btnsDiv, details) {
105 var leftTbl = tblDiv.select('.left')
106 .select('table')
107 .append('tbody'),
108 rightTbl = tblDiv.select('.right')
109 .select('table')
110 .append('tbody');
111
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700112 is.loadEmbeddedIcon(iconDiv, details._iconid_type, 40);
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700113 top.select('h2').html(details.id);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700114
115 propOrder.forEach(function (prop, i) {
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700116 // properties are split into two tables
117 addProp(i < 3 ? leftTbl : rightTbl, i, details[prop]);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700118 });
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700119
120 bns.button(btnsDiv,
121 'dev-dets-p-flows',
122 'flowsTable',
123 function () {
124 ns.navTo(flowPath, { devId: details.id });
125 },
126 'Show flows for this device');
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700127 }
128
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700129 function addPortRow(tbody, port) {
130 var tr = tbody.append('tr');
131
132 portCols.forEach(function (col) {
133 if (col === 'type' || col === 'id') {
134 port[col] = fs.cap(port[col]);
135 }
136 tr.append('td').html(port[col]);
137 });
138 }
139
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700140 function populateBottom(table, ports) {
141 var theader = table.append('thead').append('tr'),
142 tbody = table.append('tbody'),
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700143 tbWidth, tbHeight;
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700144
145 friendlyPortCols.forEach(function (col) {
146 theader.append('th').html(col);
147 });
148 ports.forEach(function (port) {
149 addPortRow(tbody, port);
150 });
151
152 tbWidth = fs.noPxStyle(tbody, 'width') + scrollSize;
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700153 tbHeight = pHeight
154 - (fs.noPxStyle(detailsPanel.el()
155 .select('.top'), 'height')
156 + fs.noPxStyle(detailsPanel.el()
157 .select('.ports-title'), 'height')
158 + portsTblPdg);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700159
160 table.style({
161 height: tbHeight + 'px',
162 width: tbWidth + 'px',
163 overflow: 'auto',
164 display: 'block'
165 });
166
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700167 detailsPanel.width(tbWidth + ctnrPdg);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700168 }
169
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700170 function populateDetails(details) {
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700171 var topTbs, btnsDiv, btmTbl, ports;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700172 setUpPanel();
173
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700174 topTbs = top.select('.top-tables');
175 btnsDiv = top.select('.actionBtns');
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700176 btmTbl = bottom.select('table');
177 ports = details.ports;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700178
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700179 populateTop(topTbs, btnsDiv, details);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700180 populateBottom(btmTbl, ports);
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700181
182 detailsPanel.height(pHeight);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700183 }
184
185 function respDetailsCb(data) {
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700186 self.panelData = data.details;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700187 populateDetails(self.panelData);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700188 detailsPanel.show();
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700189 }
190
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700191 function createDetailsPane() {
192 detailsPanel = ps.createPanel(pName, {
193 width: wSize.width,
194 margin: 0,
195 hideMargin: 0
196 });
197 detailsPanel.el().style({
198 position: 'absolute',
199 top: pStartY + 'px'
200 });
201 detailsPanel.hide();
202 }
203
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -0800204 angular.module('ovDevice', [])
Simon Hunta89f0f92015-02-26 16:47:12 -0800205 .controller('OvDeviceCtrl',
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700206 ['$log', '$scope', 'TableBuilderService', 'FnService',
207 'MastService', 'PanelService', 'WebSocketService', 'IconService',
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700208 'ButtonService', 'NavService', 'TooltipService',
Simon Hunta89f0f92015-02-26 16:47:12 -0800209
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700210 function (_$log_, _$scope_,
211 tbs, _fs_, _mast_, _ps_, _wss_, _is_, _bns_, _ns_, _ttip_) {
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700212 $log = _$log_;
213 $scope = _$scope_;
214 fs = _fs_;
215 mast = _mast_;
216 ps = _ps_;
217 wss = _wss_;
218 is = _is_;
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700219 bns = _bns_;
220 ns = _ns_;
221 ttip = _ttip_;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700222 self = this;
223 var handlers = {};
224 self.panelData = [];
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700225 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
226 + mast.mastHeight() + topPdg;
227 wSize = fs.windowSize(pStartY);
228 pHeight = wSize.height;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700229
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700230 function selCb($event, row) {
231 selRow = angular.element($event.currentTarget);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700232 if ($scope.sel) {
233 wss.sendEvent(detailsReq, { id: row.id });
234 } else {
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700235 detailsPanel.hide();
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700236 }
237 $log.debug('Got a click on:', row);
238 }
239
Bri Prebilic Cole864cdd62015-04-02 15:46:47 -0700240 tbs.buildTable({
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700241 self: self,
Bri Prebilic Cole864cdd62015-04-02 15:46:47 -0700242 scope: $scope,
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700243 tag: 'device',
244 selCb: selCb
245 });
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700246 createDetailsPane();
247
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700248 // details panel handlers
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700249 handlers[detailsResp] = respDetailsCb;
250 wss.bindHandlers(handlers);
251
252 $scope.$on('$destroy', function () {
253 ps.destroyPanel(pName);
254 wss.unbindHandlers(handlers);
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700255 ttip.resetTooltip();
Simon Hunta89f0f92015-02-26 16:47:12 -0800256 });
257
Bri Prebilic Cole72eb6db2015-03-30 16:58:53 -0700258 $log.log('OvDeviceCtrl has been created');
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -0800259 }]);
260}());