Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 1 | /* |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 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 | */ |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 16 | |
| 17 | /* |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 18 | ONOS GUI -- Topology (2) View Module |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 19 | |
| 20 | NOTE: currently under development to support Regions. |
| 21 | */ |
| 22 | |
| 23 | (function () { |
| 24 | 'use strict'; |
| 25 | |
| 26 | // references to injected services |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 27 | var $scope, $log, fs, mast, ks, |
Steven Burrows | 0616e80 | 2016-10-06 21:45:07 -0500 | [diff] [blame] | 28 | gs, sus, ps, t2es, t2fs, t2is, t2bcs, t2kcs, t2ms, t2mcs, t2zs; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 29 | |
| 30 | // DOM elements |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 31 | var ovtopo2, svg, defs, zoomLayer, forceG; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 32 | |
| 33 | // Internal state |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 34 | var zoomer, |
| 35 | currentLayoutId = '_default_'; // NOTE: see UiTopoLayoutId.DEFAULT_STR |
| 36 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 37 | |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 38 | // --- Glyphs, Icons, and the like ----------------------------------- |
| 39 | |
| 40 | function setUpDefs() { |
| 41 | defs = svg.append('defs'); |
| 42 | gs.loadDefs(defs); |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 43 | |
| 44 | // TODO: consider using something other than the "glow" styles |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 45 | sus.loadGlowDefs(defs); |
| 46 | } |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 47 | |
| 48 | // callback invoked when the SVG view has been resized.. |
| 49 | function svgResized(s) { |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 50 | $log.debug('topo2 view resized', s); |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 51 | t2fs.newDim([s.width, s.height]); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | function setUpKeys(overlayKeys) { |
| 55 | $log.debug('topo2: set up keys....'); |
| 56 | } |
| 57 | |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 58 | // --- Pan and Zoom -------------------------------------------------- |
| 59 | |
| 60 | // zoom enabled predicate. ev is a D3 source event. |
| 61 | function zoomEnabled(ev) { |
| 62 | return fs.isMobile() || (ev.metaKey || ev.altKey); |
| 63 | } |
| 64 | |
| 65 | function zoomCallback() { |
| 66 | var sc = zoomer.scale(), |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 67 | tr = zoomer.translate(), |
| 68 | sparse = {}; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 69 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 70 | sparse[currentLayoutId] = { |
| 71 | zoomScale: sc, |
| 72 | zoomPanX: tr[0], |
| 73 | zoomPanY: tr[1] |
| 74 | }; |
| 75 | |
| 76 | ps.mergePrefs('topo2_zoom', sparse); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | function setUpZoom() { |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 80 | zoomLayer = svg.append('g').attr('id', 'topo2-zoomlayer'); |
Steven Burrows | 0616e80 | 2016-10-06 21:45:07 -0500 | [diff] [blame] | 81 | |
| 82 | zoomer = t2zs.createZoomer({ |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 83 | svg: svg, |
| 84 | zoomLayer: zoomLayer, |
| 85 | zoomEnabled: zoomEnabled, |
| 86 | zoomCallback: zoomCallback |
| 87 | }); |
| 88 | } |
| 89 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 90 | // === Controller Definition ----------------------------------------- |
| 91 | |
| 92 | angular.module('ovTopo2', ['onosUtil', 'onosSvg', 'onosRemote']) |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 93 | .controller('OvTopo2Ctrl', [ |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 94 | '$scope', '$log', '$location', |
| 95 | 'FnService', 'MastService', 'KeyService', 'GlyphService', 'MapService', |
| 96 | 'SvgUtilService', 'FlashService', 'WebSocketService', |
| 97 | 'PrefsService', 'ThemeService', |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 98 | 'Topo2EventService', 'Topo2ForceService', 'Topo2InstanceService', |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 99 | 'Topo2BreadcrumbService', 'Topo2KeyCommandService', 'Topo2MapService', |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 100 | 'Topo2MapConfigService', 'Topo2ZoomService', 'Topo2SpriteLayerService', |
| 101 | 'Topo2SummaryPanelService', 'Topo2DeviceDetailsPanel', |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 102 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 103 | function ( |
| 104 | _$scope_, _$log_, _$loc_, |
| 105 | _fs_, _mast_, _ks_, _gs_, _ms_, |
| 106 | _sus_, _flash_, _wss_, |
| 107 | _ps_, _th_, |
| 108 | _t2es_, _t2fs_, _t2is_, |
| 109 | _t2bcs_, _t2kcs_, _t2ms_, |
| 110 | _t2mcs_, _t2zs_, t2sls, |
| 111 | summaryPanel, detailsPanel |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 112 | ) { |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 113 | var params = _$loc_.search(), |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 114 | dim, |
| 115 | wh, |
| 116 | uplink = { |
| 117 | // provides function calls back into this space |
| 118 | // showNoDevs: showNoDevs, |
| 119 | // projection: function () { return projection; }, |
Steven Burrows | 9edc7e0 | 2016-08-29 11:52:07 +0100 | [diff] [blame] | 120 | zoomLayer: function () { return zoomLayer; }, |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 121 | zoomer: function () { return zoomer; } |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 122 | // opacifyMap: opacifyMap, |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | $scope = _$scope_; |
| 126 | $log = _$log_; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 127 | |
| 128 | fs = _fs_; |
| 129 | mast = _mast_; |
| 130 | ks = _ks_; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 131 | gs = _gs_; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 132 | sus = _sus_; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 133 | ps = _ps_; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 134 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 135 | t2es = _t2es_; |
| 136 | t2fs = _t2fs_; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 137 | t2is = _t2is_; |
Steven Burrows | af3159d | 2016-08-25 14:54:30 +0100 | [diff] [blame] | 138 | t2bcs = _t2bcs_; |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 139 | t2kcs = _t2kcs_; |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 140 | t2ms = _t2ms_; |
Steven Burrows | e7cc308 | 2016-09-27 11:24:58 -0700 | [diff] [blame] | 141 | t2mcs = _t2mcs_; |
Steven Burrows | 0616e80 | 2016-10-06 21:45:07 -0500 | [diff] [blame] | 142 | t2zs = _t2zs_; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 143 | |
| 144 | // capture selected intent parameters (if they are set in the |
| 145 | // query string) so that the traffic overlay can highlight |
| 146 | // the path for that intent |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 147 | if (params.intentKey && |
| 148 | params.intentAppId && |
| 149 | params.intentAppName) { |
| 150 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 151 | $scope.intentData = { |
| 152 | key: params.intentKey, |
| 153 | appId: params.intentAppId, |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 154 | appName: params.intentAppName, |
| 155 | intentType: params.intentType |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 156 | }; |
| 157 | } |
| 158 | |
| 159 | $scope.notifyResize = function () { |
| 160 | svgResized(fs.windowSize(mast.mastHeight())); |
| 161 | }; |
| 162 | |
| 163 | // Cleanup on destroyed scope.. |
| 164 | $scope.$on('$destroy', function () { |
| 165 | $log.log('OvTopo2Ctrl is saying Buh-Bye!'); |
| 166 | t2es.stop(); |
| 167 | ks.unbindKeys(); |
| 168 | t2fs.destroy(); |
Steven Burrows | 7a9d04e | 2016-09-26 17:05:37 -0700 | [diff] [blame] | 169 | t2is.destroy(); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 170 | summaryPanel.destroy(); |
| 171 | detailsPanel.destroy(); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 172 | }); |
| 173 | |
| 174 | // svg layer and initialization of components |
| 175 | ovtopo2 = d3.select('#ov-topo2'); |
| 176 | svg = ovtopo2.select('svg'); |
| 177 | // set the svg size to match that of the window, less the masthead |
| 178 | wh = fs.windowSize(mast.mastHeight()); |
| 179 | $log.debug('setting topo SVG size to', wh); |
| 180 | svg.attr(wh); |
| 181 | dim = [wh.width, wh.height]; |
| 182 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 183 | // set up our keyboard shortcut bindings |
| 184 | setUpKeys(); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 185 | setUpZoom(); |
| 186 | setUpDefs(); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 187 | |
| 188 | // make sure we can respond to topology events from the server |
| 189 | t2es.bindHandlers(); |
| 190 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 191 | // Add the map SVG Group, but don't load a map yet... |
| 192 | // we will wait until the server tells us whether we should |
| 193 | // be loading a geomap or a sprite layer |
| 194 | t2ms.init(zoomLayer, zoomer); |
Steven Burrows | e7cc308 | 2016-09-27 11:24:58 -0700 | [diff] [blame] | 195 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 196 | // TODO: figure out from where to call this code... |
| 197 | // we still need to do the equivalent of this when we load |
| 198 | // a geo map, just not here. |
| 199 | // |
| 200 | // ... NOTE: we still have to position the nodes AFTER the map |
| 201 | // has loaded and the projection has been established... |
| 202 | // maybe another promise ending with a "positionNodes()" |
| 203 | // call? |
Steven Burrows | e7cc308 | 2016-09-27 11:24:58 -0700 | [diff] [blame] | 204 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 205 | // .then( |
| 206 | // function (proj) { |
| 207 | // var z = ps.getPrefs('topo2_zoom', { tx: 0, ty: 0, sc: 1 }); |
| 208 | // zoomer.panZoom([z.tx, z.ty], z.sc); |
| 209 | // |
| 210 | // t2mcs.projection(proj); |
| 211 | // $log.debug('** Zoom restored:', z); |
| 212 | // $log.debug('** We installed the projection:', proj); |
| 213 | // |
| 214 | // // Now the map has load and we have a projection we can |
| 215 | // // get the info from the server |
| 216 | // t2es.start(); |
| 217 | // } |
| 218 | // ); |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 219 | |
Steven Burrows | 3cc0c37 | 2017-02-10 15:15:24 +0000 | [diff] [blame] | 220 | t2sls.init(svg, zoomLayer); |
Steven Burrows | 1aa4f58 | 2016-12-13 15:05:41 -0500 | [diff] [blame] | 221 | t2fs.init(svg, forceG, uplink, dim, zoomer); |
Steven Burrows | af3159d | 2016-08-25 14:54:30 +0100 | [diff] [blame] | 222 | t2bcs.init(); |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 223 | t2kcs.init(t2fs); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 224 | t2is.initInst({ showMastership: t2fs.showMastership }); |
| 225 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 226 | // === ORIGINAL CODE === |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 227 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 228 | // setUpToolbar(); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 229 | // setUpNoDevs(); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 230 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 231 | // tes.bindHandlers(); |
| 232 | // setUpSprites(); |
| 233 | |
| 234 | // forceG = zoomLayer.append('g').attr('id', 'topo-force'); |
| 235 | // tfs.initForce(svg, forceG, uplink, dim); |
| 236 | // tis.initInst({ showMastership: tfs.showMastership }); |
| 237 | // tps.initPanels(); |
| 238 | |
| 239 | // restoreConfigFromPrefs(); |
Simon Hunt | fc5c584 | 2017-02-01 23:32:18 -0800 | [diff] [blame] | 240 | // ttbs.setDefaultOverlay(prefsState.ovid); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 241 | |
| 242 | // $log.debug('registered overlays...', tov.list()); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 243 | |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 244 | summaryPanel.init(); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 245 | detailsPanel.init(); |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 246 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame^] | 247 | // Now that we are initialized, ask the server for what we |
| 248 | // need to show. |
| 249 | t2es.start(); |
| 250 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 251 | $log.log('OvTopo2Ctrl has been created'); |
| 252 | }]); |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 253 | })(); |