blob: fa4dcf970ed1b7588c8cfbd39f613b53bf528d25 [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
25 var $log, $scope, fs, mast, ps, wss, is;
26
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,
39
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 Cole45069382015-04-14 15:21:38 -070070 var container, closeBtn;
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');
80 top.append('table');
Bri Prebilic Cole45069382015-04-14 15:21:38 -070081 top.append('hr');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070082
83 bottom = container.append('div').classed('bottom', true);
Bri Prebilic Cole45069382015-04-14 15:21:38 -070084 bottom.append('h2').classed('ports-title', true).html('Ports');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070085 bottom.append('table');
86 }
87
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070088 function addProp(tbody, index, value) {
89 var tr = tbody.append('tr');
90
91 function addCell(cls, txt) {
92 tr.append('td').attr('class', cls).html(txt);
93 }
94 addCell('label', friendlyProps[index] + ' :');
95 addCell('value', value);
96 }
97
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070098 function populateTop(tbody, details) {
99 is.loadEmbeddedIcon(iconDiv, details._iconid_type, 40);
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700100 top.select('h2').html(details.id);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700101
102 propOrder.forEach(function (prop, i) {
103 addProp(tbody, i, details[prop]);
104 });
105 }
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) {
111 if (col === 'type' || col === 'id') {
112 port[col] = fs.cap(port[col]);
113 }
114 tr.append('td').html(port[col]);
115 });
116 }
117
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700118 function populateBottom(table, ports) {
119 var theader = table.append('thead').append('tr'),
120 tbody = table.append('tbody'),
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700121 tbWidth, tbHeight;
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700122
123 friendlyPortCols.forEach(function (col) {
124 theader.append('th').html(col);
125 });
126 ports.forEach(function (port) {
127 addPortRow(tbody, port);
128 });
129
130 tbWidth = fs.noPxStyle(tbody, 'width') + scrollSize;
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700131 tbHeight = pHeight
132 - (fs.noPxStyle(detailsPanel.el()
133 .select('.top'), 'height')
134 + fs.noPxStyle(detailsPanel.el()
135 .select('.ports-title'), 'height')
136 + portsTblPdg);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700137
138 table.style({
139 height: tbHeight + 'px',
140 width: tbWidth + 'px',
141 overflow: 'auto',
142 display: 'block'
143 });
144
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700145 detailsPanel.width(tbWidth + ctnrPdg);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700146 }
147
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700148 function populateDetails(details) {
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700149 var topTb, btmTbl, ports;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700150 setUpPanel();
151
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700152 topTb = top.select('table').append('tbody');
153 btmTbl = bottom.select('table');
154 ports = details.ports;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700155
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700156 populateTop(topTb, details);
157 populateBottom(btmTbl, ports);
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700158
159 detailsPanel.height(pHeight);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700160 }
161
162 function respDetailsCb(data) {
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700163 self.panelData = data.details;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700164 populateDetails(self.panelData);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700165 detailsPanel.show();
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700166 }
167
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700168 function createDetailsPane() {
169 detailsPanel = ps.createPanel(pName, {
170 width: wSize.width,
171 margin: 0,
172 hideMargin: 0
173 });
174 detailsPanel.el().style({
175 position: 'absolute',
176 top: pStartY + 'px'
177 });
178 detailsPanel.hide();
179 }
180
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -0800181 angular.module('ovDevice', [])
Simon Hunta89f0f92015-02-26 16:47:12 -0800182 .controller('OvDeviceCtrl',
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700183 ['$log', '$scope', 'TableBuilderService', 'FnService',
184 'MastService', 'PanelService', 'WebSocketService', 'IconService',
Simon Hunta89f0f92015-02-26 16:47:12 -0800185
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700186 function (_$log_, _$scope_, tbs, _fs_, _mast_, _ps_, _wss_, _is_) {
187 $log = _$log_;
188 $scope = _$scope_;
189 fs = _fs_;
190 mast = _mast_;
191 ps = _ps_;
192 wss = _wss_;
193 is = _is_;
194 self = this;
195 var handlers = {};
196 self.panelData = [];
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700197 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
198 + mast.mastHeight() + topPdg;
199 wSize = fs.windowSize(pStartY);
200 pHeight = wSize.height;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700201
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700202 function selCb($event, row) {
203 selRow = angular.element($event.currentTarget);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700204 if ($scope.sel) {
205 wss.sendEvent(detailsReq, { id: row.id });
206 } else {
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700207 detailsPanel.hide();
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700208 }
209 $log.debug('Got a click on:', row);
210 }
211
Bri Prebilic Cole864cdd62015-04-02 15:46:47 -0700212 tbs.buildTable({
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700213 self: self,
Bri Prebilic Cole864cdd62015-04-02 15:46:47 -0700214 scope: $scope,
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700215 tag: 'device',
216 selCb: selCb
217 });
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700218 createDetailsPane();
219
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700220 handlers[detailsResp] = respDetailsCb;
221 wss.bindHandlers(handlers);
222
223 $scope.$on('$destroy', function () {
224 ps.destroyPanel(pName);
225 wss.unbindHandlers(handlers);
Simon Hunta89f0f92015-02-26 16:47:12 -0800226 });
227
Bri Prebilic Cole72eb6db2015-03-30 16:58:53 -0700228 $log.log('OvDeviceCtrl has been created');
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -0800229 }]);
230}());