Simon Hunt | 9818919 | 2016-07-29 19:02:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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 | * Copyright 2016-present Open Networking Laboratory |
| 19 | * |
| 20 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 21 | * you may not use this file except in compliance with the License. |
| 22 | * You may obtain a copy of the License at |
| 23 | * |
| 24 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 25 | * |
| 26 | * Unless required by applicable law or agreed to in writing, software |
| 27 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 29 | * See the License for the specific language governing permissions and |
| 30 | * limitations under the License. |
| 31 | */ |
| 32 | |
| 33 | /* |
| 34 | ONOS GUI -- Topology View Module |
| 35 | |
| 36 | NOTE: currently under development to support Regions. |
| 37 | */ |
| 38 | |
| 39 | (function () { |
| 40 | 'use strict'; |
| 41 | |
| 42 | // references to injected services |
| 43 | var $scope, $log, $loc, |
| 44 | fs, mast, ks, zs, |
| 45 | gs, ms, sus, flash, |
| 46 | wss, ps, th, |
| 47 | tXes, tXfs; |
| 48 | |
| 49 | // DOM elements |
| 50 | var ovtopoX, svg, defs, zoomLayer, mapG, spriteG, forceG, noDevsLayer; |
| 51 | |
| 52 | // Internal state |
| 53 | var zoomer, actionMap; |
| 54 | |
| 55 | |
| 56 | // === Helper Functions |
| 57 | |
| 58 | // callback invoked when the SVG view has been resized.. |
| 59 | function svgResized(s) { |
| 60 | $log.debug("topoX view resized", s); |
| 61 | } |
| 62 | |
| 63 | function setUpKeys(overlayKeys) { |
| 64 | $log.debug('topoX: set up keys....'); |
| 65 | } |
| 66 | |
| 67 | // === Controller Definition ----------------------------------------- |
| 68 | |
| 69 | angular.module('ovTopoX', ['onosUtil', 'onosSvg', 'onosRemote']) |
| 70 | .controller('OvTopoXCtrl', |
| 71 | ['$scope', '$log', '$location', |
| 72 | 'FnService', 'MastService', 'KeyService', 'ZoomService', |
| 73 | 'GlyphService', 'MapService', 'SvgUtilService', 'FlashService', |
| 74 | 'WebSocketService', 'PrefsService', 'ThemeService', |
| 75 | 'TopoXEventService', 'TopoXForceService', |
| 76 | |
| 77 | function (_$scope_, _$log_, _$loc_, |
| 78 | _fs_, _mast_, _ks_, _zs_, |
| 79 | _gs_, _ms_, _sus_, _flash_, |
| 80 | _wss_, _ps_, _th_, |
| 81 | _tXes_, _tXfs_) { |
| 82 | |
| 83 | var params = _$loc_.search(), |
| 84 | projection, |
| 85 | dim, |
| 86 | wh, |
| 87 | uplink = { |
| 88 | // provides function calls back into this space |
| 89 | // showNoDevs: showNoDevs, |
| 90 | // projection: function () { return projection; }, |
| 91 | // zoomLayer: function () { return zoomLayer; }, |
| 92 | // zoomer: function () { return zoomer; }, |
| 93 | // opacifyMap: opacifyMap, |
| 94 | // topoStartDone: topoStartDone |
| 95 | }; |
| 96 | |
| 97 | $scope = _$scope_; |
| 98 | $log = _$log_; |
| 99 | $loc = _$loc_; |
| 100 | |
| 101 | fs = _fs_; |
| 102 | mast = _mast_; |
| 103 | ks = _ks_; |
| 104 | zs = _zs_; |
| 105 | |
| 106 | gs = _gs_; |
| 107 | ms = _ms_; |
| 108 | sus = _sus_; |
| 109 | flash = _flash_; |
| 110 | |
| 111 | wss = _wss_; |
| 112 | ps = _ps_; |
| 113 | th = _th_; |
| 114 | |
| 115 | tXes = _tXes_; |
| 116 | tXfs = _tXfs_; |
| 117 | |
| 118 | // capture selected intent parameters (if they are set in the |
| 119 | // query string) so that the traffic overlay can highlight |
| 120 | // the path for that intent |
| 121 | if (params.intentKey && params.intentAppId && params.intentAppName) { |
| 122 | $scope.intentData = { |
| 123 | key: params.intentKey, |
| 124 | appId: params.intentAppId, |
| 125 | appName: params.intentAppName |
| 126 | }; |
| 127 | } |
| 128 | |
| 129 | $scope.notifyResize = function () { |
| 130 | svgResized(fs.windowSize(mast.mastHeight())); |
| 131 | }; |
| 132 | |
| 133 | // Cleanup on destroyed scope.. |
| 134 | $scope.$on('$destroy', function () { |
| 135 | $log.log('OvTopoXCtrl is saying Buh-Bye!'); |
| 136 | tXes.stop(); |
| 137 | ks.unbindKeys(); |
| 138 | tXfs.destroy(); |
| 139 | }); |
| 140 | |
| 141 | // svg layer and initialization of components |
| 142 | ovtopoX = d3.select('#ov-topoX'); |
| 143 | svg = ovtopoX.select('svg'); |
| 144 | // set the svg size to match that of the window, less the masthead |
| 145 | wh = fs.windowSize(mast.mastHeight()); |
| 146 | $log.debug('setting topo SVG size to', wh); |
| 147 | svg.attr(wh); |
| 148 | dim = [wh.width, wh.height]; |
| 149 | |
| 150 | |
| 151 | // set up our keyboard shortcut bindings |
| 152 | setUpKeys(); |
| 153 | |
| 154 | // make sure we can respond to topology events from the server |
| 155 | tXes.bindHandlers(); |
| 156 | |
| 157 | // initialize the force layout, ready to render the topology |
| 158 | tXfs.init(); |
| 159 | |
| 160 | |
| 161 | // =-=-=-=-=-=-=-=- |
| 162 | // TODO: in future, we will load background map data |
| 163 | // asynchronously (hence the promise) and then chain off |
| 164 | // there to send the topoXstart event to the server. |
| 165 | // For now, we'll send the event inline... |
| 166 | tXes.start(); |
| 167 | |
| 168 | |
| 169 | // === ORIGINAL CODE === |
| 170 | |
| 171 | // setUpKeys(); |
| 172 | // setUpToolbar(); |
| 173 | // setUpDefs(); |
| 174 | // setUpZoom(); |
| 175 | // setUpNoDevs(); |
| 176 | /* |
| 177 | setUpMap().then( |
| 178 | function (proj) { |
| 179 | var z = ps.getPrefs('topo_zoom', { tx:0, ty:0, sc:1 }); |
| 180 | zoomer.panZoom([z.tx, z.ty], z.sc); |
| 181 | $log.debug('** Zoom restored:', z); |
| 182 | |
| 183 | projection = proj; |
| 184 | $log.debug('** We installed the projection:', proj); |
| 185 | flash.enable(false); |
| 186 | toggleMap(prefsState.bg); |
| 187 | flash.enable(true); |
| 188 | mapShader(true); |
| 189 | |
| 190 | // now we have the map projection, we are ready for |
| 191 | // the server to send us device/host data... |
| 192 | tes.start(); |
| 193 | // need to do the following so we immediately get |
| 194 | // the summary panel data back from the server |
| 195 | restoreSummaryFromPrefs(); |
| 196 | } |
| 197 | ); |
| 198 | */ |
| 199 | // tes.bindHandlers(); |
| 200 | // setUpSprites(); |
| 201 | |
| 202 | // forceG = zoomLayer.append('g').attr('id', 'topo-force'); |
| 203 | // tfs.initForce(svg, forceG, uplink, dim); |
| 204 | // tis.initInst({ showMastership: tfs.showMastership }); |
| 205 | // tps.initPanels(); |
| 206 | |
| 207 | // restoreConfigFromPrefs(); |
| 208 | // ttbs.setDefaultOverlay(prefsState.ovidx); |
| 209 | |
| 210 | // $log.debug('registered overlays...', tov.list()); |
| 211 | |
| 212 | $log.log('OvTopoXCtrl has been created'); |
| 213 | }]); |
| 214 | }()); |