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 |
Simon Hunt | f0c6f54 | 2017-03-22 18:31:18 -0700 | [diff] [blame] | 27 | var $scope, $log, fs, mast, ks, wss, |
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, |
Simon Hunt | b3656d4 | 2017-04-07 18:15:35 -0700 | [diff] [blame^] | 35 | currentLayoutId = 'root'; // NOTE: see UiTopoLayoutId.DEFAULT_STR |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 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(), |
Simon Hunt | f0c6f54 | 2017-03-22 18:31:18 -0700 | [diff] [blame] | 68 | metaUi = isNaN(sc) ? { |
| 69 | useCfg: 1 |
| 70 | } : { |
| 71 | scale: sc, |
| 72 | offsetX: tr[0], |
| 73 | offsetY: tr[1] |
| 74 | }; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 75 | |
Simon Hunt | c43a59d | 2017-04-05 13:56:13 -0700 | [diff] [blame] | 76 | // Allow map service to react to change in zoom parameters |
| 77 | t2ms.zoomCallback(sc, tr); |
| 78 | |
Simon Hunt | f0c6f54 | 2017-03-22 18:31:18 -0700 | [diff] [blame] | 79 | // Note: Meta data stored in the context of the current layout, |
| 80 | // automatically, by the server |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 81 | |
Simon Hunt | f0c6f54 | 2017-03-22 18:31:18 -0700 | [diff] [blame] | 82 | wss.sendEvent('updateMeta2', { |
| 83 | id: 'layoutZoom', |
| 84 | memento: metaUi |
| 85 | }); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | function setUpZoom() { |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 89 | zoomLayer = svg.append('g').attr('id', 'topo2-zoomlayer'); |
Steven Burrows | 0616e80 | 2016-10-06 21:45:07 -0500 | [diff] [blame] | 90 | |
| 91 | zoomer = t2zs.createZoomer({ |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 92 | svg: svg, |
| 93 | zoomLayer: zoomLayer, |
| 94 | zoomEnabled: zoomEnabled, |
| 95 | zoomCallback: zoomCallback |
| 96 | }); |
| 97 | } |
| 98 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 99 | // === Controller Definition ----------------------------------------- |
| 100 | |
| 101 | angular.module('ovTopo2', ['onosUtil', 'onosSvg', 'onosRemote']) |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 102 | .controller('OvTopo2Ctrl', [ |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 103 | '$scope', '$log', '$location', |
| 104 | 'FnService', 'MastService', 'KeyService', 'GlyphService', 'MapService', |
| 105 | 'SvgUtilService', 'FlashService', 'WebSocketService', |
| 106 | 'PrefsService', 'ThemeService', |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 107 | 'Topo2EventService', 'Topo2ForceService', 'Topo2InstanceService', |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 108 | 'Topo2BreadcrumbService', 'Topo2KeyCommandService', 'Topo2MapService', |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 109 | 'Topo2MapConfigService', 'Topo2ZoomService', 'Topo2SpriteLayerService', |
Steven Burrows | c846893 | 2017-03-17 16:13:41 +0000 | [diff] [blame] | 110 | 'Topo2SummaryPanelService', 'Topo2DeviceDetailsPanel', 'Topo2ToolbarService', |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 111 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 112 | function ( |
| 113 | _$scope_, _$log_, _$loc_, |
| 114 | _fs_, _mast_, _ks_, _gs_, _ms_, |
| 115 | _sus_, _flash_, _wss_, |
| 116 | _ps_, _th_, |
| 117 | _t2es_, _t2fs_, _t2is_, |
| 118 | _t2bcs_, _t2kcs_, _t2ms_, |
| 119 | _t2mcs_, _t2zs_, t2sls, |
Steven Burrows | c846893 | 2017-03-17 16:13:41 +0000 | [diff] [blame] | 120 | summaryPanel, detailsPanel, t2tbs |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 121 | ) { |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 122 | var params = _$loc_.search(), |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 123 | dim, |
| 124 | wh, |
| 125 | uplink = { |
| 126 | // provides function calls back into this space |
| 127 | // showNoDevs: showNoDevs, |
| 128 | // projection: function () { return projection; }, |
Steven Burrows | 9edc7e0 | 2016-08-29 11:52:07 +0100 | [diff] [blame] | 129 | zoomLayer: function () { return zoomLayer; }, |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 130 | zoomer: function () { return zoomer; } |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 131 | // opacifyMap: opacifyMap, |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | $scope = _$scope_; |
| 135 | $log = _$log_; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 136 | |
| 137 | fs = _fs_; |
| 138 | mast = _mast_; |
| 139 | ks = _ks_; |
Simon Hunt | f0c6f54 | 2017-03-22 18:31:18 -0700 | [diff] [blame] | 140 | wss = _wss_; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 141 | gs = _gs_; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 142 | sus = _sus_; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 143 | ps = _ps_; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 144 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 145 | t2es = _t2es_; |
| 146 | t2fs = _t2fs_; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 147 | t2is = _t2is_; |
Steven Burrows | af3159d | 2016-08-25 14:54:30 +0100 | [diff] [blame] | 148 | t2bcs = _t2bcs_; |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 149 | t2kcs = _t2kcs_; |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 150 | t2ms = _t2ms_; |
Steven Burrows | e7cc308 | 2016-09-27 11:24:58 -0700 | [diff] [blame] | 151 | t2mcs = _t2mcs_; |
Steven Burrows | 0616e80 | 2016-10-06 21:45:07 -0500 | [diff] [blame] | 152 | t2zs = _t2zs_; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 153 | |
| 154 | // capture selected intent parameters (if they are set in the |
| 155 | // query string) so that the traffic overlay can highlight |
| 156 | // the path for that intent |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 157 | if (params.intentKey && |
| 158 | params.intentAppId && |
| 159 | params.intentAppName) { |
| 160 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 161 | $scope.intentData = { |
| 162 | key: params.intentKey, |
| 163 | appId: params.intentAppId, |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 164 | appName: params.intentAppName, |
| 165 | intentType: params.intentType |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 166 | }; |
| 167 | } |
| 168 | |
| 169 | $scope.notifyResize = function () { |
| 170 | svgResized(fs.windowSize(mast.mastHeight())); |
| 171 | }; |
| 172 | |
| 173 | // Cleanup on destroyed scope.. |
| 174 | $scope.$on('$destroy', function () { |
| 175 | $log.log('OvTopo2Ctrl is saying Buh-Bye!'); |
| 176 | t2es.stop(); |
| 177 | ks.unbindKeys(); |
| 178 | t2fs.destroy(); |
Steven Burrows | 7a9d04e | 2016-09-26 17:05:37 -0700 | [diff] [blame] | 179 | t2is.destroy(); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 180 | summaryPanel.destroy(); |
| 181 | detailsPanel.destroy(); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 182 | }); |
| 183 | |
| 184 | // svg layer and initialization of components |
| 185 | ovtopo2 = d3.select('#ov-topo2'); |
| 186 | svg = ovtopo2.select('svg'); |
| 187 | // set the svg size to match that of the window, less the masthead |
| 188 | wh = fs.windowSize(mast.mastHeight()); |
| 189 | $log.debug('setting topo SVG size to', wh); |
| 190 | svg.attr(wh); |
| 191 | dim = [wh.width, wh.height]; |
| 192 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 193 | // set up our keyboard shortcut bindings |
| 194 | setUpKeys(); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 195 | setUpZoom(); |
| 196 | setUpDefs(); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 197 | |
| 198 | // make sure we can respond to topology events from the server |
| 199 | t2es.bindHandlers(); |
| 200 | |
Steven Burrows | af3159d | 2016-08-25 14:54:30 +0100 | [diff] [blame] | 201 | t2bcs.init(); |
Steven Burrows | c846893 | 2017-03-17 16:13:41 +0000 | [diff] [blame] | 202 | t2kcs.init(t2fs, t2tbs); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 203 | t2is.initInst({ showMastership: t2fs.showMastership }); |
Steven Burrows | c846893 | 2017-03-17 16:13:41 +0000 | [diff] [blame] | 204 | t2fs.init(svg, forceG, uplink, dim, zoomer); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 205 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 206 | // === ORIGINAL CODE === |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 207 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 208 | // setUpToolbar(); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 209 | // setUpNoDevs(); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 210 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 211 | // tes.bindHandlers(); |
| 212 | // setUpSprites(); |
| 213 | |
| 214 | // forceG = zoomLayer.append('g').attr('id', 'topo-force'); |
| 215 | // tfs.initForce(svg, forceG, uplink, dim); |
| 216 | // tis.initInst({ showMastership: tfs.showMastership }); |
| 217 | // tps.initPanels(); |
| 218 | |
| 219 | // restoreConfigFromPrefs(); |
Simon Hunt | fc5c584 | 2017-02-01 23:32:18 -0800 | [diff] [blame] | 220 | // ttbs.setDefaultOverlay(prefsState.ovid); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 221 | |
| 222 | // $log.debug('registered overlays...', tov.list()); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 223 | |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 224 | summaryPanel.init(); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 225 | detailsPanel.init(); |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 226 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 227 | // Now that we are initialized, ask the server for what we |
| 228 | // need to show. |
| 229 | t2es.start(); |
| 230 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 231 | $log.log('OvTopo2Ctrl has been created'); |
| 232 | }]); |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 233 | })(); |