blob: 37766c60a80f21fae491ed05ca7bb9a0a8918a2a [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
Simon Hunt6b5a9412016-10-26 19:32:04 -070072 function setUpPanel() {
73 var container, closeBtn, tblDiv;
74 detailsPanel.empty();
Viswanath KSP9fcf9702016-10-23 17:13:29 +053075
Simon Hunt6b5a9412016-10-26 19:32:04 -070076 container = detailsPanel.append('div').classed('container', true);
Viswanath KSP9fcf9702016-10-23 17:13:29 +053077
Simon Hunt6b5a9412016-10-26 19:32:04 -070078 top = container.append('div').classed('top', true);
79 closeBtn = top.append('div').classed('close-btn', true);
80 addCloseBtn(closeBtn);
81 iconDiv = top.append('div').classed('dev-icon', true);
82 top.append('h2');
83 topTable = top.append('div').classed('top-content', true)
84 .append('table');
85 top.append('hr');
86
87 //ToDo add more details
88 }
89
90 function addProp(tbody, index, value) {
91 var tr = tbody.append('tr');
92
93 function addCell(cls, txt) {
94 tr.append('td').attr('class', cls).html(txt);
Viswanath KSP9fcf9702016-10-23 17:13:29 +053095 }
Simon Hunt6b5a9412016-10-26 19:32:04 -070096 addCell('label', friendlyProps[index] + ' :');
97 addCell('value', value);
98 }
Viswanath KSP9fcf9702016-10-23 17:13:29 +053099
Simon Hunt6b5a9412016-10-26 19:32:04 -0700100 function populateTop(details) {
101 is.loadEmbeddedIcon(iconDiv, 'node', 40);
102 top.select('h2').html(details.id);
103
104 var tbody = topTable.append('tbody');
105
106 propOrder.forEach(function (prop, i) {
107 addProp(tbody, i, details[prop]);
108 });
109 }
110
111 function createDetailsPane() {
112 detailsPanel = ps.createPanel(pName, {
113 width: wSize.width,
114 margin: 0,
115 hideMargin: 0
116 });
117 detailsPanel.el().style({
118 position: 'absolute',
119 top: pStartY + 'px'
120 });
121 $scope.hidePanel = function () { detailsPanel.hide(); };
122 detailsPanel.hide();
123 }
124
125 function populateDetails(details) {
126 setUpPanel();
127 populateTop(details);
128
129 //ToDo add more details
130 detailsPanel.height(pHeight);
131 detailsPanel.width(wtPdg);
132 }
133
134 function respDetailsCb(data) {
135 $scope.panelData = data.details;
136 $scope.$apply();
137 }
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530138
139
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -0700140 angular.module('ovCluster', [])
141 .controller('OvClusterCtrl',
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530142 ['$log', '$scope', 'TableBuilderService', 'NavService', 'MastService',
143 'PanelService', 'KeyService', 'IconService','WebSocketService',
144 'FnService',
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -0700145
Simon Hunt6b5a9412016-10-26 19:32:04 -0700146 function (_$log_, _$scope_, tbs, _ns_, _mast_, _ps_, _ks_, _is_,
147 _wss_, _fs_) {
148 var handlers = {};
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530149
Simon Hunt6b5a9412016-10-26 19:32:04 -0700150 $log = _$log_;
151 $scope = _$scope_;
152 fs = _fs_;
153 ns = _ns_;
154 is = _is_;
155 wss = _wss_;
156 mast = _mast_;
157 ps = _ps_;
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530158
Simon Hunt6b5a9412016-10-26 19:32:04 -0700159 $scope.panelData = {};
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530160
Simon Hunt6b5a9412016-10-26 19:32:04 -0700161 tbs.buildTable({
162 scope: $scope,
163 selCb: selCb,
164 tag: 'cluster'
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530165 });
166
Simon Hunt6b5a9412016-10-26 19:32:04 -0700167 // details panel handlers
168 handlers[detailsResp] = respDetailsCb;
169 wss.bindHandlers(handlers);
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530170
Simon Hunt6b5a9412016-10-26 19:32:04 -0700171 function selCb($event, row) {
172 if ($scope.selId) {
173 wss.sendEvent(detailsReq, {id: row.id});
174 } else {
175 $scope.hidePanel();
176 }
177 $log.debug('Got a click on:', row);
178 }
179
180 $scope.$on('$destroy', function () {
181 wss.unbindHandlers(handlers);
182 });
183
184 $log.log('OvClusterCtrl has been created');
185 }])
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530186
Simon Hunta271e0a2016-10-26 10:59:14 -0700187 .directive('clusterDetailsPanel',
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530188 ['$rootScope', '$window', '$timeout', 'KeyService',
189 function ($rootScope, $window, $timeout, ks) {
190 return function (scope) {
191 var unbindWatch;
192
193 function heightCalc() {
194 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
195 + mast.mastHeight() + topPdg;
196 wSize = fs.windowSize(pStartY);
197 pHeight = wSize.height;
198 }
199
200 function initPanel() {
201 heightCalc();
202 createDetailsPane();
203 }
204
205 // Safari has a bug where it renders the fixed-layout table wrong
206 // if you ask for the window's size too early
207 if (scope.onos.browser === 'safari') {
208 $timeout(initPanel);
209 } else {
210 initPanel();
211 }
212
Simon Hunta271e0a2016-10-26 10:59:14 -0700213 // if the panelData changes
214 scope.$watch('panelData', function () {
215 if (!fs.isEmptyObject(scope.panelData)) {
216 populateDetails(scope.panelData);
217 detailsPanel.show();
218 }
219 });
220
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530221 // if the window size changes
222 unbindWatch = $rootScope.$watchCollection(
223 function () {
224 return {
225 h: $window.innerHeight,
226 w: $window.innerWidth
227 };
228 }, function () {
229 if (!fs.isEmptyObject(scope.panelData)) {
230 heightCalc();
231 populateDetails(scope.panelData);
232 }
233 }
234 );
235
236 scope.$on('$destroy', function () {
237 unbindWatch();
238 ps.destroyPanel(pName);
239 });
240 };
241 }]);
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -0700242}());