blob: 6f862fb49767da017012ac10a329703e6fd3d8ba [file] [log] [blame]
Simon Hunt1002cd82015-04-23 14:44:03 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Simon Hunt1002cd82015-04-23 14:44:03 -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 -- Flow View Module
19 */
20
21(function () {
22 'use strict';
23
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -070024 // injected references
Viswanath KSP7bdc9172016-10-19 20:19:17 +053025 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,
Viswanath KSP70e0d142016-10-28 21:58:32 +053032 topTable,
Viswanath KSP7bdc9172016-10-19 20:19:17 +053033 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 = 'flow-details-panel',
48 detailsReq = 'flowDetailsRequest',
Viswanath KSP70e0d142016-10-28 21:58:32 +053049 detailsResp = 'flowDetailsResponse',
50
51 propOrder = [
52 'flowId', 'priority'
53 ],
54 friendlyProps = [
55 'Flow ID', 'Flow Priority'
56 ];
Viswanath KSP7bdc9172016-10-19 20:19:17 +053057
58 function closePanel() {
59 if (detailsPanel.isVisible()) {
60 $scope.selId = null;
61 detailsPanel.hide();
62 return true;
63 }
64 return false;
65 }
66
67 function addCloseBtn(div) {
68 is.loadEmbeddedIcon(div, 'close', 20);
69 div.on('click', closePanel);
70 }
71
Viswanath KSP70e0d142016-10-28 21:58:32 +053072 function handleEscape() {
73 return closePanel();
74 }
75
Viswanath KSP7bdc9172016-10-19 20:19:17 +053076 function setUpPanel() {
77 var container, closeBtn, tblDiv;
78 detailsPanel.empty();
79
80 container = detailsPanel.append('div').classed('container', true);
81
82 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');
Viswanath KSP70e0d142016-10-28 21:58:32 +053087 topTable = top.append('div').classed('top-content', true)
88 .append('table');
Viswanath KSP7bdc9172016-10-19 20:19:17 +053089 top.append('hr');
90
91 //ToDo add more details
92 }
93
Viswanath KSP70e0d142016-10-28 21:58:32 +053094 function addProp(tbody, index, value) {
95 var tr = tbody.append('tr');
Viswanath KSP7bdc9172016-10-19 20:19:17 +053096
Viswanath KSP70e0d142016-10-28 21:58:32 +053097 function addCell(cls, txt) {
98 tr.append('td').attr('class', cls).html(txt);
99 }
100 addCell('label', friendlyProps[index] + ' :');
101 addCell('value', value);
102 }
103
104 function populateTop(details) {
105 is.loadEmbeddedIcon(iconDiv, 'flowTable', 40);
106 top.select('h2').html(details.flowId);
107
108 var tbody = topTable.append('tbody');
109
110 propOrder.forEach(function (prop, i) {
111 addProp(tbody, i, details[prop]);
112 });
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530113 }
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) {
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530130 setUpPanel();
131 populateTop(details);
132
133 //ToDo add more details
134 detailsPanel.height(pHeight);
135 detailsPanel.width(wtPdg);
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530136 }
137
138 function respDetailsCb(data) {
Viswanath KSP70e0d142016-10-28 21:58:32 +0530139 $log.debug("Got response from server :", data);
140 $scope.panelData = data.details;
141 $scope.$apply();
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530142 }
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -0700143
Simon Hunt1002cd82015-04-23 14:44:03 -0700144 angular.module('ovFlow', [])
145 .controller('OvFlowCtrl',
Bri Prebilic Cole3d4d01c2015-04-30 13:48:36 -0700146 ['$log', '$scope', '$location',
Bri Prebilic Cole9b1fb9a2015-07-01 13:57:11 -0700147 'FnService', 'TableBuilderService', 'NavService',
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530148 'MastService', 'PanelService', 'KeyService', 'IconService',
149 'WebSocketService',
Simon Hunt1002cd82015-04-23 14:44:03 -0700150
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530151 function (_$log_, _$scope_, _$location_, _fs_, _tbs_, _ns_,
152 _mast_, _ps_, _ks_, _is_, _wss_) {
153 var params,
154 handlers = {};
155
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -0700156 $log = _$log_;
157 $scope = _$scope_;
158 $location = _$location_;
159 fs = _fs_;
160 tbs = _tbs_;
Bri Prebilic Cole9b1fb9a2015-07-01 13:57:11 -0700161 ns = _ns_;
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530162 is = _is_;
163 wss = _wss_;
164 mast = _mast_;
165 ps = _ps_;
Simon Hunt20856ec2015-11-16 15:58:14 -0800166 $scope.deviceTip = 'Show device table';
Bri Prebilic Coleeef67ae2015-07-01 16:26:59 -0700167 $scope.portTip = 'Show port view for this device';
168 $scope.groupTip = 'Show group view for this device';
Jian Li1f544732015-12-30 23:36:37 -0800169 $scope.meterTip = 'Show meter view for selected device';
Kavitha Alagesaneaf614c2016-08-22 23:46:05 -0700170 $scope.briefTip = 'Switch to brief view';
171 $scope.detailTip = 'Switch to detailed view';
172 $scope.brief = true;
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -0700173 params = $location.search();
174 if (params.hasOwnProperty('devId')) {
Bri Prebilic Colee568ead2015-05-01 09:51:28 -0700175 $scope.devId = params['devId'];
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -0700176 }
177
178 tbs.buildTable({
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -0700179 scope: $scope,
180 tag: 'flow',
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530181 selCb: selCb,
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -0700182 query: params
183 });
Bri Prebilic Cole3d4d01c2015-04-30 13:48:36 -0700184
Bri Prebilic Cole9b1fb9a2015-07-01 13:57:11 -0700185 $scope.nav = function (path) {
186 if ($scope.devId) {
187 ns.navTo(path, { devId: $scope.devId });
188 }
189 };
190
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530191 // details panel handlers
192 handlers[detailsResp] = respDetailsCb;
193 wss.bindHandlers(handlers);
194
195 function selCb($event, row) {
196 if ($scope.selId) {
197 wss.sendEvent(detailsReq, {flowId: row.id, appId: row.appId});
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530198 } else {
199 $scope.hidePanel();
200 }
201 $log.debug('Got a click on:', row);
202 }
203
Viswanath KSP70e0d142016-10-28 21:58:32 +0530204 $scope.$on('$destroy', function () {
205 wss.unbindHandlers(handlers);
206 });
207
Kavitha Alagesaneaf614c2016-08-22 23:46:05 -0700208 $scope.briefToggle = function () {
209 $scope.brief = !$scope.brief;
210 };
211
sisubram9ada8d72016-09-02 13:54:40 +0530212 Object.defineProperty($scope, "queryFilter", {
213 get: function() {
Simon Huntc8f06d92016-09-28 17:28:26 -0700214 var out = {};
215 out[$scope.queryBy || "$"] = $scope.queryTxt;
216 return out;
sisubram9ada8d72016-09-02 13:54:40 +0530217 }
218 });
219
Simon Hunt1002cd82015-04-23 14:44:03 -0700220 $log.log('OvFlowCtrl has been created');
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530221 }])
222
223 .directive('flowDetailsPanel',
224 ['$rootScope', '$window', '$timeout', 'KeyService',
225 function ($rootScope, $window, $timeout, ks) {
226 return function (scope) {
227 var unbindWatch;
228
229 function heightCalc() {
230 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
231 + mast.mastHeight() + topPdg;
232 wSize = fs.windowSize(pStartY);
233 pHeight = wSize.height;
234 }
235
236 function initPanel() {
237 heightCalc();
238 createDetailsPane();
239 }
240
241 // Safari has a bug where it renders the fixed-layout table wrong
242 // if you ask for the window's size too early
243 if (scope.onos.browser === 'safari') {
244 $timeout(initPanel);
245 } else {
246 initPanel();
247 }
Viswanath KSP70e0d142016-10-28 21:58:32 +0530248 // create key bindings to handle panel
249 ks.keyBindings({
250 esc: [handleEscape, 'Close the details panel'],
251 _helpFormat: ['esc']
252 });
253 ks.gestureNotes([
254 ['click', 'Select a row to show cluster node details'],
255 ['scroll down', 'See available cluster nodes']
256 ]);
257 // if the panelData changes
258 scope.$watch('panelData', function () {
259 if (!fs.isEmptyObject(scope.panelData)) {
260 populateDetails(scope.panelData);
261 detailsPanel.show();
262 }
263 });
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530264 // if the window size changes
265 unbindWatch = $rootScope.$watchCollection(
266 function () {
267 return {
268 h: $window.innerHeight,
269 w: $window.innerWidth
270 };
271 }, function () {
272 if (!fs.isEmptyObject(scope.panelData)) {
273 heightCalc();
274 populateDetails(scope.panelData);
275 }
276 }
277 );
278
279 scope.$on('$destroy', function () {
280 unbindWatch();
281 ps.destroyPanel(pName);
282 });
283 };
284 }]);
285
Simon Hunt1002cd82015-04-23 14:44:03 -0700286}());