blob: 445288dbe3016bfb94861d5767d89523dea35330 [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,
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 = 'flow-details-panel',
48 detailsReq = 'flowDetailsRequest',
49 detailsResp = 'flowDetailsResponse';
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_flows', 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 var details = data.details;
118 //TODO Use populateDetails() when merging server code
119 $log.debug('Get the details:', details.id);
120 }
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -0700121
Simon Hunt1002cd82015-04-23 14:44:03 -0700122 angular.module('ovFlow', [])
123 .controller('OvFlowCtrl',
Bri Prebilic Cole3d4d01c2015-04-30 13:48:36 -0700124 ['$log', '$scope', '$location',
Bri Prebilic Cole9b1fb9a2015-07-01 13:57:11 -0700125 'FnService', 'TableBuilderService', 'NavService',
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530126 'MastService', 'PanelService', 'KeyService', 'IconService',
127 'WebSocketService',
Simon Hunt1002cd82015-04-23 14:44:03 -0700128
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530129 function (_$log_, _$scope_, _$location_, _fs_, _tbs_, _ns_,
130 _mast_, _ps_, _ks_, _is_, _wss_) {
131 var params,
132 handlers = {};
133
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -0700134 $log = _$log_;
135 $scope = _$scope_;
136 $location = _$location_;
137 fs = _fs_;
138 tbs = _tbs_;
Bri Prebilic Cole9b1fb9a2015-07-01 13:57:11 -0700139 ns = _ns_;
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530140 is = _is_;
141 wss = _wss_;
142 mast = _mast_;
143 ps = _ps_;
Simon Hunt20856ec2015-11-16 15:58:14 -0800144 $scope.deviceTip = 'Show device table';
Bri Prebilic Coleeef67ae2015-07-01 16:26:59 -0700145 $scope.portTip = 'Show port view for this device';
146 $scope.groupTip = 'Show group view for this device';
Jian Li1f544732015-12-30 23:36:37 -0800147 $scope.meterTip = 'Show meter view for selected device';
Kavitha Alagesaneaf614c2016-08-22 23:46:05 -0700148 $scope.briefTip = 'Switch to brief view';
149 $scope.detailTip = 'Switch to detailed view';
150 $scope.brief = true;
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -0700151 params = $location.search();
152 if (params.hasOwnProperty('devId')) {
Bri Prebilic Colee568ead2015-05-01 09:51:28 -0700153 $scope.devId = params['devId'];
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -0700154 }
155
156 tbs.buildTable({
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -0700157 scope: $scope,
158 tag: 'flow',
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530159 selCb: selCb,
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -0700160 query: params
161 });
Bri Prebilic Cole3d4d01c2015-04-30 13:48:36 -0700162
Bri Prebilic Cole9b1fb9a2015-07-01 13:57:11 -0700163 $scope.nav = function (path) {
164 if ($scope.devId) {
165 ns.navTo(path, { devId: $scope.devId });
166 }
167 };
168
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530169 // details panel handlers
170 handlers[detailsResp] = respDetailsCb;
171 wss.bindHandlers(handlers);
172
173 function selCb($event, row) {
174 if ($scope.selId) {
175 wss.sendEvent(detailsReq, {flowId: row.id, appId: row.appId});
176
177 //ToDo : Remove this line when server implmentation is complete
178 populateDetails($scope.selId);
179 } else {
180 $scope.hidePanel();
181 }
182 $log.debug('Got a click on:', row);
183 }
184
Kavitha Alagesaneaf614c2016-08-22 23:46:05 -0700185 $scope.briefToggle = function () {
186 $scope.brief = !$scope.brief;
187 };
188
sisubram9ada8d72016-09-02 13:54:40 +0530189 Object.defineProperty($scope, "queryFilter", {
190 get: function() {
Simon Huntc8f06d92016-09-28 17:28:26 -0700191 var out = {};
192 out[$scope.queryBy || "$"] = $scope.queryTxt;
193 return out;
sisubram9ada8d72016-09-02 13:54:40 +0530194 }
195 });
196
Simon Hunt1002cd82015-04-23 14:44:03 -0700197 $log.log('OvFlowCtrl has been created');
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530198 }])
199
200 .directive('flowDetailsPanel',
201 ['$rootScope', '$window', '$timeout', 'KeyService',
202 function ($rootScope, $window, $timeout, ks) {
203 return function (scope) {
204 var unbindWatch;
205
206 function heightCalc() {
207 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
208 + mast.mastHeight() + topPdg;
209 wSize = fs.windowSize(pStartY);
210 pHeight = wSize.height;
211 }
212
213 function initPanel() {
214 heightCalc();
215 createDetailsPane();
216 }
217
218 // Safari has a bug where it renders the fixed-layout table wrong
219 // if you ask for the window's size too early
220 if (scope.onos.browser === 'safari') {
221 $timeout(initPanel);
222 } else {
223 initPanel();
224 }
225
226 // if the window size changes
227 unbindWatch = $rootScope.$watchCollection(
228 function () {
229 return {
230 h: $window.innerHeight,
231 w: $window.innerWidth
232 };
233 }, function () {
234 if (!fs.isEmptyObject(scope.panelData)) {
235 heightCalc();
236 populateDetails(scope.panelData);
237 }
238 }
239 );
240
241 scope.$on('$destroy', function () {
242 unbindWatch();
243 ps.destroyPanel(pName);
244 });
245 };
246 }]);
247
Simon Hunt1002cd82015-04-23 14:44:03 -0700248}());