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 |
Steven Burrows | 448468c | 2017-04-13 16:09:30 -0700 | [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); |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 41 | |
| 42 | // TODO: consider using something other than the "glow" styles |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 43 | sus.loadGlowDefs(defs); |
| 44 | } |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 45 | |
| 46 | // callback invoked when the SVG view has been resized.. |
| 47 | function svgResized(s) { |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 48 | t2fs.newDim([s.width, s.height]); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 51 | // --- Pan and Zoom -------------------------------------------------- |
| 52 | |
| 53 | // zoom enabled predicate. ev is a D3 source event. |
| 54 | function zoomEnabled(ev) { |
| 55 | return fs.isMobile() || (ev.metaKey || ev.altKey); |
| 56 | } |
| 57 | |
| 58 | function zoomCallback() { |
| 59 | var sc = zoomer.scale(), |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 60 | tr = zoomer.translate(), |
Simon Hunt | f0c6f54 | 2017-03-22 18:31:18 -0700 | [diff] [blame] | 61 | metaUi = isNaN(sc) ? { |
| 62 | useCfg: 1 |
| 63 | } : { |
| 64 | scale: sc, |
| 65 | offsetX: tr[0], |
| 66 | offsetY: tr[1] |
| 67 | }; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 68 | |
Simon Hunt | c43a59d | 2017-04-05 13:56:13 -0700 | [diff] [blame] | 69 | // Allow map service to react to change in zoom parameters |
| 70 | t2ms.zoomCallback(sc, tr); |
| 71 | |
Simon Hunt | f0c6f54 | 2017-03-22 18:31:18 -0700 | [diff] [blame] | 72 | // Note: Meta data stored in the context of the current layout, |
| 73 | // automatically, by the server |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 74 | |
Simon Hunt | f0c6f54 | 2017-03-22 18:31:18 -0700 | [diff] [blame] | 75 | wss.sendEvent('updateMeta2', { |
| 76 | id: 'layoutZoom', |
| 77 | memento: metaUi |
| 78 | }); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | function setUpZoom() { |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 82 | zoomLayer = svg.append('g').attr('id', 'topo2-zoomlayer'); |
Steven Burrows | 0616e80 | 2016-10-06 21:45:07 -0500 | [diff] [blame] | 83 | |
| 84 | zoomer = t2zs.createZoomer({ |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 85 | svg: svg, |
| 86 | zoomLayer: zoomLayer, |
| 87 | zoomEnabled: zoomEnabled, |
| 88 | zoomCallback: zoomCallback |
| 89 | }); |
| 90 | } |
| 91 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 92 | // === Controller Definition ----------------------------------------- |
| 93 | |
| 94 | angular.module('ovTopo2', ['onosUtil', 'onosSvg', 'onosRemote']) |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 95 | .controller('OvTopo2Ctrl', [ |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 96 | '$scope', '$log', '$location', |
| 97 | 'FnService', 'MastService', 'KeyService', 'GlyphService', 'MapService', |
| 98 | 'SvgUtilService', 'FlashService', 'WebSocketService', |
| 99 | 'PrefsService', 'ThemeService', |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 100 | 'Topo2EventService', 'Topo2ForceService', 'Topo2InstanceService', |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 101 | 'Topo2BreadcrumbService', 'Topo2KeyCommandService', 'Topo2MapService', |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 102 | 'Topo2MapConfigService', 'Topo2ZoomService', 'Topo2SpriteLayerService', |
Steven Burrows | c846893 | 2017-03-17 16:13:41 +0000 | [diff] [blame] | 103 | 'Topo2SummaryPanelService', 'Topo2DeviceDetailsPanel', 'Topo2ToolbarService', |
Simon Hunt | e6f6461 | 2017-04-28 00:01:48 -0700 | [diff] [blame] | 104 | 'Topo2NoDevicesConnectedService', 'Topo2OverlayService', |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 105 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 106 | function ( |
| 107 | _$scope_, _$log_, _$loc_, |
| 108 | _fs_, _mast_, _ks_, _gs_, _ms_, |
| 109 | _sus_, _flash_, _wss_, |
| 110 | _ps_, _th_, |
| 111 | _t2es_, _t2fs_, _t2is_, |
| 112 | _t2bcs_, _t2kcs_, _t2ms_, |
| 113 | _t2mcs_, _t2zs_, t2sls, |
Simon Hunt | e6f6461 | 2017-04-28 00:01:48 -0700 | [diff] [blame] | 114 | summaryPanel, detailsPanel, t2tbs, t2ndcs, t2os |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 115 | ) { |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 116 | var params = _$loc_.search(), |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 117 | dim, |
| 118 | wh, |
| 119 | uplink = { |
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 | }; |
| 123 | |
| 124 | $scope = _$scope_; |
| 125 | $log = _$log_; |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 126 | |
| 127 | fs = _fs_; |
| 128 | mast = _mast_; |
| 129 | ks = _ks_; |
Simon Hunt | f0c6f54 | 2017-03-22 18:31:18 -0700 | [diff] [blame] | 130 | wss = _wss_; |
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 |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 184 | setUpZoom(); |
| 185 | setUpDefs(); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 186 | |
Steven Burrows | 6501de9 | 2017-04-12 15:10:34 -0700 | [diff] [blame] | 187 | t2ndcs.init(); |
| 188 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 189 | // make sure we can respond to topology events from the server |
| 190 | t2es.bindHandlers(); |
| 191 | |
Steven Burrows | af3159d | 2016-08-25 14:54:30 +0100 | [diff] [blame] | 192 | t2bcs.init(); |
Steven Burrows | c846893 | 2017-03-17 16:13:41 +0000 | [diff] [blame] | 193 | t2kcs.init(t2fs, t2tbs); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 194 | t2is.initInst({ showMastership: t2fs.showMastership }); |
Steven Burrows | c846893 | 2017-03-17 16:13:41 +0000 | [diff] [blame] | 195 | t2fs.init(svg, forceG, uplink, dim, zoomer); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 196 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 197 | // === ORIGINAL CODE === |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 198 | // restoreConfigFromPrefs(); |
Simon Hunt | fc5c584 | 2017-02-01 23:32:18 -0800 | [diff] [blame] | 199 | // ttbs.setDefaultOverlay(prefsState.ovid); |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 200 | |
Simon Hunt | e6f6461 | 2017-04-28 00:01:48 -0700 | [diff] [blame] | 201 | // ++ TEMPORARY HARD-CODE TRAFFIC OVERLAY ++ |
| 202 | t2os.setOverlay('traffic-2-overlay'); |
| 203 | |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 204 | summaryPanel.init(detailsPanel); |
| 205 | detailsPanel.init(summaryPanel); |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 206 | |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 207 | // Now that we are initialized, ask the server for what we |
Steven Burrows | 448468c | 2017-04-13 16:09:30 -0700 | [diff] [blame] | 208 | // need to show. |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 209 | t2es.start(); |
| 210 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 211 | $log.log('OvTopo2Ctrl has been created'); |
| 212 | }]); |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 213 | })(); |