Simon Hunt | 1002cd8 | 2015-04-23 14:44:03 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Simon Hunt | 1002cd8 | 2015-04-23 14:44:03 -0700 | [diff] [blame] | 3 | * |
| 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 Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 24 | // injected references |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame^] | 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 = '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 Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 121 | |
Simon Hunt | 1002cd8 | 2015-04-23 14:44:03 -0700 | [diff] [blame] | 122 | angular.module('ovFlow', []) |
| 123 | .controller('OvFlowCtrl', |
Bri Prebilic Cole | 3d4d01c | 2015-04-30 13:48:36 -0700 | [diff] [blame] | 124 | ['$log', '$scope', '$location', |
Bri Prebilic Cole | 9b1fb9a | 2015-07-01 13:57:11 -0700 | [diff] [blame] | 125 | 'FnService', 'TableBuilderService', 'NavService', |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame^] | 126 | 'MastService', 'PanelService', 'KeyService', 'IconService', |
| 127 | 'WebSocketService', |
Simon Hunt | 1002cd8 | 2015-04-23 14:44:03 -0700 | [diff] [blame] | 128 | |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame^] | 129 | function (_$log_, _$scope_, _$location_, _fs_, _tbs_, _ns_, |
| 130 | _mast_, _ps_, _ks_, _is_, _wss_) { |
| 131 | var params, |
| 132 | handlers = {}; |
| 133 | |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 134 | $log = _$log_; |
| 135 | $scope = _$scope_; |
| 136 | $location = _$location_; |
| 137 | fs = _fs_; |
| 138 | tbs = _tbs_; |
Bri Prebilic Cole | 9b1fb9a | 2015-07-01 13:57:11 -0700 | [diff] [blame] | 139 | ns = _ns_; |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame^] | 140 | is = _is_; |
| 141 | wss = _wss_; |
| 142 | mast = _mast_; |
| 143 | ps = _ps_; |
Simon Hunt | 20856ec | 2015-11-16 15:58:14 -0800 | [diff] [blame] | 144 | $scope.deviceTip = 'Show device table'; |
Bri Prebilic Cole | eef67ae | 2015-07-01 16:26:59 -0700 | [diff] [blame] | 145 | $scope.portTip = 'Show port view for this device'; |
| 146 | $scope.groupTip = 'Show group view for this device'; |
Jian Li | 1f54473 | 2015-12-30 23:36:37 -0800 | [diff] [blame] | 147 | $scope.meterTip = 'Show meter view for selected device'; |
Kavitha Alagesan | eaf614c | 2016-08-22 23:46:05 -0700 | [diff] [blame] | 148 | $scope.briefTip = 'Switch to brief view'; |
| 149 | $scope.detailTip = 'Switch to detailed view'; |
| 150 | $scope.brief = true; |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 151 | params = $location.search(); |
| 152 | if (params.hasOwnProperty('devId')) { |
Bri Prebilic Cole | e568ead | 2015-05-01 09:51:28 -0700 | [diff] [blame] | 153 | $scope.devId = params['devId']; |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | tbs.buildTable({ |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 157 | scope: $scope, |
| 158 | tag: 'flow', |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame^] | 159 | selCb: selCb, |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 160 | query: params |
| 161 | }); |
Bri Prebilic Cole | 3d4d01c | 2015-04-30 13:48:36 -0700 | [diff] [blame] | 162 | |
Bri Prebilic Cole | 9b1fb9a | 2015-07-01 13:57:11 -0700 | [diff] [blame] | 163 | $scope.nav = function (path) { |
| 164 | if ($scope.devId) { |
| 165 | ns.navTo(path, { devId: $scope.devId }); |
| 166 | } |
| 167 | }; |
| 168 | |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame^] | 169 | // 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 Alagesan | eaf614c | 2016-08-22 23:46:05 -0700 | [diff] [blame] | 185 | $scope.briefToggle = function () { |
| 186 | $scope.brief = !$scope.brief; |
| 187 | }; |
| 188 | |
sisubram | 9ada8d7 | 2016-09-02 13:54:40 +0530 | [diff] [blame] | 189 | Object.defineProperty($scope, "queryFilter", { |
| 190 | get: function() { |
Simon Hunt | c8f06d9 | 2016-09-28 17:28:26 -0700 | [diff] [blame] | 191 | var out = {}; |
| 192 | out[$scope.queryBy || "$"] = $scope.queryTxt; |
| 193 | return out; |
sisubram | 9ada8d7 | 2016-09-02 13:54:40 +0530 | [diff] [blame] | 194 | } |
| 195 | }); |
| 196 | |
Simon Hunt | 1002cd8 | 2015-04-23 14:44:03 -0700 | [diff] [blame] | 197 | $log.log('OvFlowCtrl has been created'); |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame^] | 198 | }]) |
| 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 Hunt | 1002cd8 | 2015-04-23 14:44:03 -0700 | [diff] [blame] | 248 | }()); |