blob: b4dd391ff1be8a8861bbb47fe97941fc27f2334c [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'
56 ];
Viswanath KSP9fcf9702016-10-23 17:13:29 +053057
Simon Hunt6b5a9412016-10-26 19:32:04 -070058 function closePanel() {
59 if (detailsPanel.isVisible()) {
60 $scope.selId = null;
Viswanath KSP9fcf9702016-10-23 17:13:29 +053061 detailsPanel.hide();
Simon Hunt6b5a9412016-10-26 19:32:04 -070062 return true;
Viswanath KSP9fcf9702016-10-23 17:13:29 +053063 }
Simon Hunt6b5a9412016-10-26 19:32:04 -070064 return false;
65 }
Viswanath KSP9fcf9702016-10-23 17:13:29 +053066
Simon Hunt6b5a9412016-10-26 19:32:04 -070067 function addCloseBtn(div) {
68 is.loadEmbeddedIcon(div, 'close', 20);
69 div.on('click', closePanel);
70 }
Viswanath KSP9fcf9702016-10-23 17:13:29 +053071
Viswanath KSP86016272016-10-27 09:49:46 +053072 function handleEscape() {
73 return closePanel();
74 }
75
Simon Hunt6b5a9412016-10-26 19:32:04 -070076 function setUpPanel() {
77 var container, closeBtn, tblDiv;
78 detailsPanel.empty();
Viswanath KSP9fcf9702016-10-23 17:13:29 +053079
Simon Hunt6b5a9412016-10-26 19:32:04 -070080 container = detailsPanel.append('div').classed('container', true);
Viswanath KSP9fcf9702016-10-23 17:13:29 +053081
Simon Hunt6b5a9412016-10-26 19:32:04 -070082 top = container.append('div').classed('top', true);
83 closeBtn = top.append('div').classed('close-btn', true);
84 addCloseBtn(closeBtn);
85 iconDiv = top.append('div').classed('dev-icon', true);
86 top.append('h2');
87 topTable = top.append('div').classed('top-content', true)
88 .append('table');
89 top.append('hr');
90
91 //ToDo add more details
92 }
93
94 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);
Viswanath KSP9fcf9702016-10-23 17:13:29 +053099 }
Simon Hunt6b5a9412016-10-26 19:32:04 -0700100 addCell('label', friendlyProps[index] + ' :');
101 addCell('value', value);
102 }
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530103
Simon Hunt6b5a9412016-10-26 19:32:04 -0700104 function populateTop(details) {
105 is.loadEmbeddedIcon(iconDiv, 'node', 40);
106 top.select('h2').html(details.id);
107
108 var tbody = topTable.append('tbody');
109
110 propOrder.forEach(function (prop, i) {
111 addProp(tbody, i, details[prop]);
112 });
113 }
114
115 function createDetailsPane() {
116 detailsPanel = ps.createPanel(pName, {
117 width: wSize.width,
118 margin: 0,
119 hideMargin: 0
120 });
121 detailsPanel.el().style({
122 position: 'absolute',
123 top: pStartY + 'px'
124 });
125 $scope.hidePanel = function () { detailsPanel.hide(); };
126 detailsPanel.hide();
127 }
128
129 function populateDetails(details) {
130 setUpPanel();
131 populateTop(details);
132
133 //ToDo add more details
134 detailsPanel.height(pHeight);
135 detailsPanel.width(wtPdg);
136 }
137
138 function respDetailsCb(data) {
139 $scope.panelData = data.details;
140 $scope.$apply();
141 }
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530142
143
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -0700144 angular.module('ovCluster', [])
145 .controller('OvClusterCtrl',
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530146 ['$log', '$scope', 'TableBuilderService', 'NavService', 'MastService',
147 'PanelService', 'KeyService', 'IconService','WebSocketService',
148 'FnService',
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -0700149
Simon Hunt6b5a9412016-10-26 19:32:04 -0700150 function (_$log_, _$scope_, tbs, _ns_, _mast_, _ps_, _ks_, _is_,
151 _wss_, _fs_) {
152 var handlers = {};
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530153
Simon Hunt6b5a9412016-10-26 19:32:04 -0700154 $log = _$log_;
155 $scope = _$scope_;
156 fs = _fs_;
157 ns = _ns_;
158 is = _is_;
159 wss = _wss_;
160 mast = _mast_;
161 ps = _ps_;
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530162
Simon Hunt6b5a9412016-10-26 19:32:04 -0700163 $scope.panelData = {};
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530164
Simon Hunt6b5a9412016-10-26 19:32:04 -0700165 tbs.buildTable({
166 scope: $scope,
167 selCb: selCb,
168 tag: 'cluster'
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530169 });
170
Simon Hunt6b5a9412016-10-26 19:32:04 -0700171 // details panel handlers
172 handlers[detailsResp] = respDetailsCb;
173 wss.bindHandlers(handlers);
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530174
Simon Hunt6b5a9412016-10-26 19:32:04 -0700175 function selCb($event, row) {
176 if ($scope.selId) {
177 wss.sendEvent(detailsReq, {id: row.id});
178 } else {
179 $scope.hidePanel();
180 }
181 $log.debug('Got a click on:', row);
182 }
183
184 $scope.$on('$destroy', function () {
185 wss.unbindHandlers(handlers);
186 });
187
188 $log.log('OvClusterCtrl has been created');
189 }])
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530190
Simon Hunta271e0a2016-10-26 10:59:14 -0700191 .directive('clusterDetailsPanel',
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530192 ['$rootScope', '$window', '$timeout', 'KeyService',
193 function ($rootScope, $window, $timeout, ks) {
194 return function (scope) {
195 var unbindWatch;
196
197 function heightCalc() {
198 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
199 + mast.mastHeight() + topPdg;
200 wSize = fs.windowSize(pStartY);
201 pHeight = wSize.height;
202 }
203
204 function initPanel() {
205 heightCalc();
206 createDetailsPane();
207 }
208
209 // Safari has a bug where it renders the fixed-layout table wrong
210 // if you ask for the window's size too early
211 if (scope.onos.browser === 'safari') {
212 $timeout(initPanel);
213 } else {
214 initPanel();
215 }
Viswanath KSP86016272016-10-27 09:49:46 +0530216 // create key bindings to handle panel
217 ks.keyBindings({
218 esc: [handleEscape, 'Close the details panel'],
219 _helpFormat: ['esc']
220 });
221 ks.gestureNotes([
222 ['click', 'Select a row to show cluster node details'],
223 ['scroll down', 'See available cluster nodes']
224 ]);
Simon Hunta271e0a2016-10-26 10:59:14 -0700225 // if the panelData changes
226 scope.$watch('panelData', function () {
227 if (!fs.isEmptyObject(scope.panelData)) {
228 populateDetails(scope.panelData);
229 detailsPanel.show();
230 }
231 });
232
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530233 // if the window size changes
234 unbindWatch = $rootScope.$watchCollection(
235 function () {
236 return {
237 h: $window.innerHeight,
238 w: $window.innerWidth
239 };
240 }, function () {
241 if (!fs.isEmptyObject(scope.panelData)) {
242 heightCalc();
243 populateDetails(scope.panelData);
244 }
245 }
246 );
247
248 scope.$on('$destroy', function () {
249 unbindWatch();
250 ps.destroyPanel(pName);
251 });
252 };
253 }]);
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -0700254}());