blob: 451a067c2d355efb0bf79a3c09692fef4794aeab [file] [log] [blame]
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -07003 *
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/*
18 ONOS GUI -- Cluster View Module
19 */
20
21(function () {
22 'use strict';
23
Simon Hunt6b5a9412016-10-26 19:32:04 -070024 // injected references
25 var $log, $scope, $location, fs, tbs, ns, mast, ps, wss, is, ks;
Viswanath KSP9fcf9702016-10-23 17:13:29 +053026
Simon Hunt6b5a9412016-10-26 19:32:04 -070027 // internal state
28 var detailsPanel,
29 pStartY,
30 pHeight,
31 top,
32 topTable,
33 bottom,
34 iconDiv,
35 nameDiv,
36 wSize;
Viswanath KSP9fcf9702016-10-23 17:13:29 +053037
38
Simon Hunt6b5a9412016-10-26 19:32:04 -070039 // constants
40 var topPdg = 28,
41 ctnrPdg = 24,
42 scrollSize = 17,
43 portsTblPdg = 50,
44 htPdg = 479,
45 wtPdg = 532,
Viswanath KSP9fcf9702016-10-23 17:13:29 +053046
Simon Hunt6b5a9412016-10-26 19:32:04 -070047 pName = 'cluster-details-panel',
48 detailsReq = 'clusterDetailsRequest',
49 detailsResp = 'clusterDetailsResponse',
Viswanath KSP9fcf9702016-10-23 17:13:29 +053050
Simon Hunt6b5a9412016-10-26 19:32:04 -070051 propOrder = [
52 'id', 'ip'
53 ],
54 friendlyProps = [
55 'Node ID', 'IP Address'
Viswanath KSP116f0c12016-11-21 00:02:51 +053056 ],
57 deviceCols = [
58 'id', 'type', 'chassisid', 'mfr',
59 'hw', 'sw', 'protocol', 'serial'
60 ],
61 friendlyDeviceCols = [
62 'URI', 'Type', 'Chassis ID', 'Vendor',
63 'H/W Version', 'S/W Version', 'Protocol',
64 'Serial #'
Simon Hunt6b5a9412016-10-26 19:32:04 -070065 ];
Viswanath KSP9fcf9702016-10-23 17:13:29 +053066
Simon Hunt6b5a9412016-10-26 19:32:04 -070067 function closePanel() {
68 if (detailsPanel.isVisible()) {
69 $scope.selId = null;
Viswanath KSP9fcf9702016-10-23 17:13:29 +053070 detailsPanel.hide();
Simon Hunt6b5a9412016-10-26 19:32:04 -070071 return true;
Viswanath KSP9fcf9702016-10-23 17:13:29 +053072 }
Simon Hunt6b5a9412016-10-26 19:32:04 -070073 return false;
74 }
Viswanath KSP9fcf9702016-10-23 17:13:29 +053075
Simon Hunt6b5a9412016-10-26 19:32:04 -070076 function addCloseBtn(div) {
77 is.loadEmbeddedIcon(div, 'close', 20);
78 div.on('click', closePanel);
79 }
Viswanath KSP9fcf9702016-10-23 17:13:29 +053080
Viswanath KSP86016272016-10-27 09:49:46 +053081 function handleEscape() {
82 return closePanel();
83 }
84
Simon Hunt6b5a9412016-10-26 19:32:04 -070085 function setUpPanel() {
86 var container, closeBtn, tblDiv;
87 detailsPanel.empty();
Viswanath KSP9fcf9702016-10-23 17:13:29 +053088
Simon Hunt6b5a9412016-10-26 19:32:04 -070089 container = detailsPanel.append('div').classed('container', true);
Viswanath KSP9fcf9702016-10-23 17:13:29 +053090
Simon Hunt6b5a9412016-10-26 19:32:04 -070091 top = container.append('div').classed('top', true);
92 closeBtn = top.append('div').classed('close-btn', true);
93 addCloseBtn(closeBtn);
94 iconDiv = top.append('div').classed('dev-icon', true);
95 top.append('h2');
96 topTable = top.append('div').classed('top-content', true)
97 .append('table');
98 top.append('hr');
99
Viswanath KSP116f0c12016-11-21 00:02:51 +0530100 bottom = container.append('div').classed('bottom', true);
Simon Hunt239f09e2017-05-18 13:10:09 -0700101 bottom.append('h2').classed('devices-title', true).text('Devices');
Viswanath KSP116f0c12016-11-21 00:02:51 +0530102 bottom.append('table');
Simon Hunt6b5a9412016-10-26 19:32:04 -0700103 //ToDo add more details
104 }
105
106 function addProp(tbody, index, value) {
107 var tr = tbody.append('tr');
108
109 function addCell(cls, txt) {
Simon Hunt239f09e2017-05-18 13:10:09 -0700110 tr.append('td').attr('class', cls).text(txt);
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530111 }
Simon Hunt6b5a9412016-10-26 19:32:04 -0700112 addCell('label', friendlyProps[index] + ' :');
113 addCell('value', value);
114 }
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530115
Simon Hunt6b5a9412016-10-26 19:32:04 -0700116 function populateTop(details) {
117 is.loadEmbeddedIcon(iconDiv, 'node', 40);
Simon Hunt239f09e2017-05-18 13:10:09 -0700118 top.select('h2').text(details.id);
Simon Hunt6b5a9412016-10-26 19:32:04 -0700119
120 var tbody = topTable.append('tbody');
121
122 propOrder.forEach(function (prop, i) {
123 addProp(tbody, i, details[prop]);
124 });
125 }
126
Viswanath KSP116f0c12016-11-21 00:02:51 +0530127 function addDeviceRow(tbody, device) {
128 var tr = tbody.append('tr');
129
130 deviceCols.forEach(function (col) {
Simon Hunt239f09e2017-05-18 13:10:09 -0700131 tr.append('td').text(device[col]);
Viswanath KSP116f0c12016-11-21 00:02:51 +0530132 });
133 }
134
135 function populateBottom(devices) {
136 var table = bottom.select('table'),
137 theader = table.append('thead').append('tr'),
138 tbody = table.append('tbody'),
139 tbWidth, tbHeight;
140
141 friendlyDeviceCols.forEach(function (col) {
Simon Hunt239f09e2017-05-18 13:10:09 -0700142 theader.append('th').text(col);
Viswanath KSP116f0c12016-11-21 00:02:51 +0530143 });
144 devices.forEach(function (device) {
145 addDeviceRow(tbody, device);
146 });
147
148 tbWidth = fs.noPxStyle(tbody, 'width') + scrollSize;
149 tbHeight = pHeight
150 - (fs.noPxStyle(detailsPanel.el()
151 .select('.top'), 'height')
152 + fs.noPxStyle(detailsPanel.el()
153 .select('.devices-title'), 'height')
154 + portsTblPdg);
155
156 table.style({
157 height: tbHeight + 'px',
158 width: tbWidth + 'px',
159 overflow: 'auto',
160 display: 'block'
161 });
162
163 detailsPanel.width(tbWidth + ctnrPdg);
164 }
165
Simon Hunt6b5a9412016-10-26 19:32:04 -0700166 function createDetailsPane() {
167 detailsPanel = ps.createPanel(pName, {
168 width: wSize.width,
169 margin: 0,
170 hideMargin: 0
171 });
172 detailsPanel.el().style({
173 position: 'absolute',
174 top: pStartY + 'px'
175 });
176 $scope.hidePanel = function () { detailsPanel.hide(); };
177 detailsPanel.hide();
178 }
179
180 function populateDetails(details) {
181 setUpPanel();
Viswanath KSP116f0c12016-11-21 00:02:51 +0530182
Simon Hunt6b5a9412016-10-26 19:32:04 -0700183 populateTop(details);
Viswanath KSP116f0c12016-11-21 00:02:51 +0530184 populateBottom(details.devices);
Simon Hunt6b5a9412016-10-26 19:32:04 -0700185
186 //ToDo add more details
187 detailsPanel.height(pHeight);
Viswanath KSP116f0c12016-11-21 00:02:51 +0530188 //detailsPanel.width(wtPdg); ToDO Use this when needed!
Simon Hunt6b5a9412016-10-26 19:32:04 -0700189 }
190
191 function respDetailsCb(data) {
192 $scope.panelData = data.details;
193 $scope.$apply();
194 }
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530195
196
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -0700197 angular.module('ovCluster', [])
198 .controller('OvClusterCtrl',
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530199 ['$log', '$scope', 'TableBuilderService', 'NavService', 'MastService',
200 'PanelService', 'KeyService', 'IconService','WebSocketService',
201 'FnService',
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -0700202
Simon Hunt6b5a9412016-10-26 19:32:04 -0700203 function (_$log_, _$scope_, tbs, _ns_, _mast_, _ps_, _ks_, _is_,
204 _wss_, _fs_) {
205 var handlers = {};
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530206
Simon Hunt6b5a9412016-10-26 19:32:04 -0700207 $log = _$log_;
208 $scope = _$scope_;
209 fs = _fs_;
210 ns = _ns_;
211 is = _is_;
212 wss = _wss_;
213 mast = _mast_;
214 ps = _ps_;
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530215
Simon Hunt6b5a9412016-10-26 19:32:04 -0700216 $scope.panelData = {};
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530217
Simon Hunt6b5a9412016-10-26 19:32:04 -0700218 tbs.buildTable({
219 scope: $scope,
220 selCb: selCb,
221 tag: 'cluster'
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530222 });
223
Simon Hunt6b5a9412016-10-26 19:32:04 -0700224 // details panel handlers
225 handlers[detailsResp] = respDetailsCb;
226 wss.bindHandlers(handlers);
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530227
Simon Hunt6b5a9412016-10-26 19:32:04 -0700228 function selCb($event, row) {
229 if ($scope.selId) {
230 wss.sendEvent(detailsReq, {id: row.id});
231 } else {
232 $scope.hidePanel();
233 }
234 $log.debug('Got a click on:', row);
235 }
236
237 $scope.$on('$destroy', function () {
238 wss.unbindHandlers(handlers);
239 });
240
241 $log.log('OvClusterCtrl has been created');
242 }])
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530243
Simon Hunta271e0a2016-10-26 10:59:14 -0700244 .directive('clusterDetailsPanel',
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530245 ['$rootScope', '$window', '$timeout', 'KeyService',
246 function ($rootScope, $window, $timeout, ks) {
247 return function (scope) {
248 var unbindWatch;
249
250 function heightCalc() {
251 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
252 + mast.mastHeight() + topPdg;
253 wSize = fs.windowSize(pStartY);
254 pHeight = wSize.height;
255 }
256
257 function initPanel() {
258 heightCalc();
259 createDetailsPane();
260 }
261
262 // Safari has a bug where it renders the fixed-layout table wrong
263 // if you ask for the window's size too early
264 if (scope.onos.browser === 'safari') {
265 $timeout(initPanel);
266 } else {
267 initPanel();
268 }
Viswanath KSP86016272016-10-27 09:49:46 +0530269 // create key bindings to handle panel
270 ks.keyBindings({
271 esc: [handleEscape, 'Close the details panel'],
272 _helpFormat: ['esc']
273 });
274 ks.gestureNotes([
275 ['click', 'Select a row to show cluster node details'],
276 ['scroll down', 'See available cluster nodes']
277 ]);
Simon Hunta271e0a2016-10-26 10:59:14 -0700278 // if the panelData changes
279 scope.$watch('panelData', function () {
280 if (!fs.isEmptyObject(scope.panelData)) {
281 populateDetails(scope.panelData);
282 detailsPanel.show();
283 }
284 });
285
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530286 // if the window size changes
287 unbindWatch = $rootScope.$watchCollection(
288 function () {
289 return {
290 h: $window.innerHeight,
291 w: $window.innerWidth
292 };
293 }, function () {
294 if (!fs.isEmptyObject(scope.panelData)) {
295 heightCalc();
296 populateDetails(scope.panelData);
297 }
298 }
299 );
300
301 scope.$on('$destroy', function () {
302 unbindWatch();
303 ps.destroyPanel(pName);
304 });
305 };
306 }]);
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -0700307}());