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