blob: 29567bce04c167abaa01a7279ce80afd1c766af4 [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,
30 container, top, bottom, iconDiv,
31 selRow;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070032
33 // constants
34 // TODO: consider having a set y height that all tables start at
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070035 // to make calculations easier
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070036 var h2Pdg = 40,
37 mastPdg = 8,
38 tbodyPdg = 5,
39 cntrPdg = 24,
40 pName = 'device-details-panel',
41 detailsReq = 'deviceDetailsRequest',
42 detailsResp = 'deviceDetailsResponse',
43 propOrder = [
44 'type', 'masterid', 'chassisid',
45 'mfr', 'hw', 'sw', 'protocol', 'serial'
46 ],
47 friendlyProps = [
48 'Type', 'Master ID', 'Chassis ID',
49 'Vendor', 'H/W Version', 'S/W Version', 'Protocol', 'Serial #'
50 ],
51 portCols = [
52 'enabled', 'id', 'speed', 'type', 'elinks_dest'
53 ],
54 friendlyPortCols = [
55 'Enabled', 'ID', 'Speed', 'Type', 'Egress Links'
56 ];
57
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070058 function addCloseBtn(div) {
59 is.loadEmbeddedIcon(div, 'appPlus', 30);
60 div.select('g').attr('transform', 'translate(25, 0) rotate(45)');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070061
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070062 div.on('click', function () {
63 detailsPanel.hide();
64 selRow.removeClass('selected');
65 });
66 }
67
68 function setUpPanel() {
69 var closeBtn;
70 detailsPanel.empty();
71
72 container = detailsPanel.append('div').classed('container', true);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070073
74 top = container.append('div').classed('top', true);
75 closeBtn = top.append('div').classed('close-btn', true);
76 addCloseBtn(closeBtn);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070077 iconDiv = top.append('div').classed('dev-icon', true);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070078 top.append('h2');
79 top.append('table');
80
81 container.append('hr');
82
83 bottom = container.append('div').classed('bottom', true);
84 bottom.append('h2').text('Ports');
85 bottom.append('table');
86 }
87
88 function createDetailsPane() {
89 var headerHeight = h2Pdg + fs.noPxStyle(d3.select('h2'), 'height'),
90 panelTop = headerHeight + tbodyPdg + mast.mastHeight() + mastPdg,
91 wSize = fs.windowSize(panelTop);
92
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070093 detailsPanel = ps.createPanel(pName, {
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070094 height: wSize.height,
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070095 margin: 0,
96 hideMargin: 0
97 });
98
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070099 detailsPanel.el().style({
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700100 position: 'absolute',
101 top: panelTop + 'px'
102 });
103
104 setUpPanel();
105
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700106 detailsPanel.hide();
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700107 }
108
109 function addProp(tbody, index, value) {
110 var tr = tbody.append('tr');
111
112 function addCell(cls, txt) {
113 tr.append('td').attr('class', cls).html(txt);
114 }
115 addCell('label', friendlyProps[index] + ' :');
116 addCell('value', value);
117 }
118
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700119 function populateTop(tbody, details) {
120 is.loadEmbeddedIcon(iconDiv, details._iconid_type, 40);
121 top.select('h2').text(details.id);
122
123 propOrder.forEach(function (prop, i) {
124 addProp(tbody, i, details[prop]);
125 });
126 }
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'),
142 tbWidth, tbHeight,
143 scrollSize = 20,
144 padding = 55;
145
146 friendlyPortCols.forEach(function (col) {
147 theader.append('th').html(col);
148 });
149 ports.forEach(function (port) {
150 addPortRow(tbody, port);
151 });
152
153 tbWidth = fs.noPxStyle(tbody, 'width') + scrollSize;
154 tbHeight = detailsPanel.height()
155 - (fs.noPxStyle(detailsPanel.el().select('.top'), 'height')
156 + fs.noPxStyle(detailsPanel.el().select('hr'), 'height')
157 + fs.noPxStyle(detailsPanel.el().select('h2'), 'height')
158 + padding);
159
160 table.style({
161 height: tbHeight + 'px',
162 width: tbWidth + 'px',
163 overflow: 'auto',
164 display: 'block'
165 });
166
167 detailsPanel.width(tbWidth + cntrPdg);
168 }
169
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700170 function populateDetails(details) {
171 setUpPanel();
172
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700173 var topTb = top.select('table').append('tbody'),
174 btmTbl = bottom.select('table'),
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700175 ports = details.ports;
176
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700177 populateTop(topTb, details);
178 populateBottom(btmTbl, ports);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700179 }
180
181 function respDetailsCb(data) {
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700182 self.panelData = data.details;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700183 populateDetails(self.panelData);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700184 detailsPanel.show();
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700185 }
186
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -0800187 angular.module('ovDevice', [])
Simon Hunta89f0f92015-02-26 16:47:12 -0800188 .controller('OvDeviceCtrl',
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700189 ['$log', '$scope', 'TableBuilderService', 'FnService',
190 'MastService', 'PanelService', 'WebSocketService', 'IconService',
Simon Hunta89f0f92015-02-26 16:47:12 -0800191
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700192 function (_$log_, _$scope_, tbs, _fs_, _mast_, _ps_, _wss_, _is_) {
193 $log = _$log_;
194 $scope = _$scope_;
195 fs = _fs_;
196 mast = _mast_;
197 ps = _ps_;
198 wss = _wss_;
199 is = _is_;
200 self = this;
201 var handlers = {};
202 self.panelData = [];
203
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700204 function selCb($event, row) {
205 selRow = angular.element($event.currentTarget);
206
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700207 if ($scope.sel) {
208 wss.sendEvent(detailsReq, { id: row.id });
209 } else {
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700210 detailsPanel.hide();
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700211 }
212 $log.debug('Got a click on:', row);
213 }
214
Bri Prebilic Cole864cdd62015-04-02 15:46:47 -0700215 tbs.buildTable({
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700216 self: self,
Bri Prebilic Cole864cdd62015-04-02 15:46:47 -0700217 scope: $scope,
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700218 tag: 'device',
219 selCb: selCb
220 });
221
222 createDetailsPane();
223
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700224 handlers[detailsResp] = respDetailsCb;
225 wss.bindHandlers(handlers);
226
227 $scope.$on('$destroy', function () {
228 ps.destroyPanel(pName);
229 wss.unbindHandlers(handlers);
Simon Hunta89f0f92015-02-26 16:47:12 -0800230 });
231
Bri Prebilic Cole72eb6db2015-03-30 16:58:53 -0700232 $log.log('OvDeviceCtrl has been created');
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -0800233 }]);
234}());