blob: 270ed59503369993db7b26ed2e56f925b5972c78 [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
Viswanath KSP9fcf9702016-10-23 17:13:29 +053024 // injected references
25 var $log, $scope, $location, fs, tbs, ns, mast, ps, wss, is, ks;
26
27 // internal state
28 var detailsPanel,
29 pStartY,
30 pHeight,
31 top,
32 topContent,
33 bottom,
34 iconDiv,
35 nameDiv,
36 wSize;
37
38
39 // constants
40 var topPdg = 28,
41 ctnrPdg = 24,
42 scrollSize = 17,
43 portsTblPdg = 50,
44 htPdg = 479,
45 wtPdg = 532,
46
47 pName = 'node-details-panel',
48 detailsReq = 'nodeDetailsRequest',
49 detailsResp = 'nodeDetailsResponse';
50
51 function closePanel() {
52 if (detailsPanel.isVisible()) {
53 $scope.selId = null;
54 detailsPanel.hide();
55 return true;
56 }
57 return false;
58 }
59
60 function addCloseBtn(div) {
61 is.loadEmbeddedIcon(div, 'close', 20);
62 div.on('click', closePanel);
63 }
64
65 function setUpPanel() {
66 var container, closeBtn, tblDiv;
67 detailsPanel.empty();
68
69 container = detailsPanel.append('div').classed('container', true);
70
71 top = container.append('div').classed('top', true);
72 closeBtn = top.append('div').classed('close-btn', true);
73 addCloseBtn(closeBtn);
74 iconDiv = top.append('div').classed('dev-icon', true);
75 top.append('h2');
76 topContent = top.append('div').classed('top-content', true);
77 top.append('hr');
78
79 //ToDo add more details
80 }
81
82 function populateTop(details) {
83 is.loadEmbeddedIcon(iconDiv, 'm_node', 40);
84 top.select('h2').html(details.id);
85
86 //ToDo : Add more details
87 }
88
89 function createDetailsPane() {
90 detailsPanel = ps.createPanel(pName, {
91 width: wSize.width,
92 margin: 0,
93 hideMargin: 0
94 });
95 detailsPanel.el().style({
96 position: 'absolute',
97 top: pStartY + 'px'
98 });
99 $scope.hidePanel = function () { detailsPanel.hide(); };
100 detailsPanel.hide();
101 }
102
103 function populateDetails(details) {
104
105 setUpPanel();
106 populateTop(details);
107
108 //ToDo add more details
109 detailsPanel.height(pHeight);
110 detailsPanel.width(wtPdg);
111
112 //Todo : remove this when server implementation is done
113 detailsPanel.show();
114 }
115
116 function respDetailsCb(data) {
117 $scope.panelData = data.details;
118 $scope.$apply();
119 //TODO Use populateDetails() when merging server code
120 $log.debug('Get the details:', $scope.panelData.id);
121 }
122
123
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -0700124 angular.module('ovCluster', [])
125 .controller('OvClusterCtrl',
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530126 ['$log', '$scope', 'TableBuilderService', 'NavService', 'MastService',
127 'PanelService', 'KeyService', 'IconService','WebSocketService',
128 'FnService',
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -0700129
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530130 function (_$log_, _$scope_, tbs, _ns_, _mast_, _ps_, _ks_, _is_,
131 _wss_, _fs_) {
132 var params,
133 handlers = {};
134
135 $log = _$log_;
136 $scope = _$scope_;
137 fs = _fs_;
138 ns = _ns_;
139 is = _is_;
140 wss = _wss_;
141 mast = _mast_;
142 ps = _ps_;
143
144 $scope.panelData = {};
145
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -0700146 tbs.buildTable({
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -0700147 scope: $scope,
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530148 selCb: selCb,
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -0700149 tag: 'cluster'
150 });
151
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530152 // details panel handlers
153 handlers[detailsResp] = respDetailsCb;
154 wss.bindHandlers(handlers);
155
156 function selCb($event, row) {
157 if ($scope.selId) {
158 wss.sendEvent(detailsReq, {id: row.id});
159
160 //ToDo : Remove this line when server implmentation is complete
161 populateDetails($scope.selId);
162 } else {
163 $scope.hidePanel();
164 }
165 $log.debug('Got a click on:', row);
166 }
167
168 $scope.$on('$destroy', function () {
169 wss.unbindHandlers(handlers);
170 });
171
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -0700172 $log.log('OvClusterCtrl has been created');
Viswanath KSP9fcf9702016-10-23 17:13:29 +0530173 }])
174
175
176 .directive('nodeDetailsPanel',
177 ['$rootScope', '$window', '$timeout', 'KeyService',
178 function ($rootScope, $window, $timeout, ks) {
179 return function (scope) {
180 var unbindWatch;
181
182 function heightCalc() {
183 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
184 + mast.mastHeight() + topPdg;
185 wSize = fs.windowSize(pStartY);
186 pHeight = wSize.height;
187 }
188
189 function initPanel() {
190 heightCalc();
191 createDetailsPane();
192 }
193
194 // Safari has a bug where it renders the fixed-layout table wrong
195 // if you ask for the window's size too early
196 if (scope.onos.browser === 'safari') {
197 $timeout(initPanel);
198 } else {
199 initPanel();
200 }
201
202 // if the window size changes
203 unbindWatch = $rootScope.$watchCollection(
204 function () {
205 return {
206 h: $window.innerHeight,
207 w: $window.innerWidth
208 };
209 }, function () {
210 if (!fs.isEmptyObject(scope.panelData)) {
211 heightCalc();
212 populateDetails(scope.panelData);
213 }
214 }
215 );
216
217 scope.$on('$destroy', function () {
218 unbindWatch();
219 ps.destroyPanel(pName);
220 });
221 };
222 }]);
Bri Prebilic Cole384e8dc2015-04-13 15:51:14 -0700223}());