blob: be3f65b2f251e12238afa767729f72ed54f9974c [file] [log] [blame]
Simon Huntd5b96732016-07-08 13:22:27 -07001/*
Steven Burrows57e24e92016-08-04 18:38:24 +01002* 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 Huntd5b96732016-07-08 13:22:27 -070016
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 Burrows1c5c8612016-10-05 13:45:13 -050027 var $scope, $log, fs, mast, ks,
Steven Burrows0616e802016-10-06 21:45:07 -050028 gs, sus, ps, t2es, t2fs, t2is, t2bcs, t2kcs, t2ms, t2mcs, t2zs;
Simon Huntd5b96732016-07-08 13:22:27 -070029
30 // DOM elements
Steven Burrowsdfa52b02016-09-02 13:50:43 +010031 var ovtopo2, svg, defs, zoomLayer, forceG;
Simon Huntd5b96732016-07-08 13:22:27 -070032
33 // Internal state
Steven Burrowsdfa52b02016-09-02 13:50:43 +010034 var zoomer;
Simon Huntd5b96732016-07-08 13:22:27 -070035
Steven Burrows57e24e92016-08-04 18:38:24 +010036 // --- Glyphs, Icons, and the like -----------------------------------
37
38 function setUpDefs() {
39 defs = svg.append('defs');
40 gs.loadDefs(defs);
41 sus.loadGlowDefs(defs);
42 }
Simon Huntd5b96732016-07-08 13:22:27 -070043
44 // callback invoked when the SVG view has been resized..
45 function svgResized(s) {
Steven Burrows57e24e92016-08-04 18:38:24 +010046 $log.debug('topo2 view resized', s);
Steven Burrowsec1f45c2016-08-08 16:14:41 +010047 t2fs.newDim([s.width, s.height]);
Simon Huntd5b96732016-07-08 13:22:27 -070048 }
49
50 function setUpKeys(overlayKeys) {
51 $log.debug('topo2: set up keys....');
52 }
53
Steven Burrows57e24e92016-08-04 18:38:24 +010054 // --- 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 Burrowsdfa52b02016-09-02 13:50:43 +010065 ps.setPrefs('topo_zoom', { tx: tr[0], ty: tr[1], sc: sc });
Steven Burrows57e24e92016-08-04 18:38:24 +010066 }
67
68 function setUpZoom() {
69 zoomLayer = svg.append('g').attr('id', 'topo-zoomlayer');
Steven Burrows0616e802016-10-06 21:45:07 -050070
71 zoomer = t2zs.createZoomer({
Steven Burrows57e24e92016-08-04 18:38:24 +010072 svg: svg,
73 zoomLayer: zoomLayer,
74 zoomEnabled: zoomEnabled,
75 zoomCallback: zoomCallback
76 });
77 }
78
Simon Huntd5b96732016-07-08 13:22:27 -070079 // === Controller Definition -----------------------------------------
80
81 angular.module('ovTopo2', ['onosUtil', 'onosSvg', 'onosRemote'])
Steven Burrowsaf96a212016-12-28 12:57:02 +000082 .controller('OvTopo2Ctrl', [
83 '$scope', '$log', '$location', 'FnService', 'MastService', 'KeyService',
Simon Huntd5b96732016-07-08 13:22:27 -070084 'GlyphService', 'MapService', 'SvgUtilService', 'FlashService',
85 'WebSocketService', 'PrefsService', 'ThemeService',
Steven Burrows57e24e92016-08-04 18:38:24 +010086 'Topo2EventService', 'Topo2ForceService', 'Topo2InstanceService',
Steven Burrowse3a18842016-09-22 15:33:33 +010087 'Topo2BreadcrumbService', 'Topo2KeyCommandService', 'Topo2MapService',
Steven Burrows1c5c8612016-10-05 13:45:13 -050088 'Topo2MapConfigService', 'Topo2ZoomService',
Steven Burrows3cc0c372017-02-10 15:15:24 +000089 'Topo2SummaryPanelService', 'Topo2DeviceDetailsPanel', 'Topo2SpriteLayerService',
Simon Huntd5b96732016-07-08 13:22:27 -070090
91 function (_$scope_, _$log_, _$loc_,
Steven Burrows1c5c8612016-10-05 13:45:13 -050092 _fs_, _mast_, _ks_,
Steven Burrows57e24e92016-08-04 18:38:24 +010093 _gs_, _ms_, _sus_, _flash_,
94 _wss_, _ps_, _th_,
Steven Burrows5570d1b2016-09-28 14:21:00 -070095 _t2es_, _t2fs_, _t2is_, _t2bcs_, _t2kcs_, _t2ms_, _t2mcs_,
Steven Burrows3cc0c372017-02-10 15:15:24 +000096 _t2zs_, summaryPanel, detailsPanel, t2sls
Steven Burrows5570d1b2016-09-28 14:21:00 -070097 ) {
Simon Huntd5b96732016-07-08 13:22:27 -070098
99 var params = _$loc_.search(),
Simon Huntd5b96732016-07-08 13:22:27 -0700100 dim,
101 wh,
102 uplink = {
103 // provides function calls back into this space
104 // showNoDevs: showNoDevs,
105 // projection: function () { return projection; },
Steven Burrows9edc7e02016-08-29 11:52:07 +0100106 zoomLayer: function () { return zoomLayer; },
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100107 zoomer: function () { return zoomer; }
Simon Huntd5b96732016-07-08 13:22:27 -0700108 // opacifyMap: opacifyMap,
109 // topoStartDone: topoStartDone
110 };
111
112 $scope = _$scope_;
113 $log = _$log_;
Simon Huntd5b96732016-07-08 13:22:27 -0700114
115 fs = _fs_;
116 mast = _mast_;
117 ks = _ks_;
Simon Huntd5b96732016-07-08 13:22:27 -0700118
119 gs = _gs_;
Simon Huntd5b96732016-07-08 13:22:27 -0700120 sus = _sus_;
Simon Huntd5b96732016-07-08 13:22:27 -0700121
Simon Huntd5b96732016-07-08 13:22:27 -0700122 ps = _ps_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100123
Simon Huntd5b96732016-07-08 13:22:27 -0700124 t2es = _t2es_;
125 t2fs = _t2fs_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100126 t2is = _t2is_;
Steven Burrowsaf3159d2016-08-25 14:54:30 +0100127 t2bcs = _t2bcs_;
Steven Burrows37549ee2016-09-21 14:41:39 +0100128 t2kcs = _t2kcs_;
Steven Burrowse3a18842016-09-22 15:33:33 +0100129 t2ms = _t2ms_;
Steven Burrowse7cc3082016-09-27 11:24:58 -0700130 t2mcs = _t2mcs_;
Steven Burrows0616e802016-10-06 21:45:07 -0500131 t2zs = _t2zs_;
Simon Huntd5b96732016-07-08 13:22:27 -0700132
133 // capture selected intent parameters (if they are set in the
134 // query string) so that the traffic overlay can highlight
135 // the path for that intent
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100136 if (params.intentKey &&
137 params.intentAppId &&
138 params.intentAppName) {
139
Simon Huntd5b96732016-07-08 13:22:27 -0700140 $scope.intentData = {
141 key: params.intentKey,
142 appId: params.intentAppId,
143 appName: params.intentAppName
144 };
145 }
146
147 $scope.notifyResize = function () {
148 svgResized(fs.windowSize(mast.mastHeight()));
149 };
150
151 // Cleanup on destroyed scope..
152 $scope.$on('$destroy', function () {
153 $log.log('OvTopo2Ctrl is saying Buh-Bye!');
154 t2es.stop();
155 ks.unbindKeys();
156 t2fs.destroy();
Steven Burrows7a9d04e2016-09-26 17:05:37 -0700157 t2is.destroy();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500158 summaryPanel.destroy();
159 detailsPanel.destroy();
Simon Huntd5b96732016-07-08 13:22:27 -0700160 });
161
162 // svg layer and initialization of components
163 ovtopo2 = d3.select('#ov-topo2');
164 svg = ovtopo2.select('svg');
165 // set the svg size to match that of the window, less the masthead
166 wh = fs.windowSize(mast.mastHeight());
167 $log.debug('setting topo SVG size to', wh);
168 svg.attr(wh);
169 dim = [wh.width, wh.height];
170
Simon Huntd5b96732016-07-08 13:22:27 -0700171 // set up our keyboard shortcut bindings
172 setUpKeys();
Steven Burrows57e24e92016-08-04 18:38:24 +0100173 setUpZoom();
174 setUpDefs();
Simon Huntd5b96732016-07-08 13:22:27 -0700175
176 // make sure we can respond to topology events from the server
177 t2es.bindHandlers();
178
Steven Burrowse3a18842016-09-22 15:33:33 +0100179 // Add the map SVG Group
Steven Burrows1c5c8612016-10-05 13:45:13 -0500180 t2ms.init(zoomLayer, zoomer).then(
Steven Burrowse3a18842016-09-22 15:33:33 +0100181 function (proj) {
182 var z = ps.getPrefs('topo_zoom', { tx: 0, ty: 0, sc: 1 });
183 zoomer.panZoom([z.tx, z.ty], z.sc);
Steven Burrowse7cc3082016-09-27 11:24:58 -0700184
185 t2mcs.projection(proj);
Steven Burrowse3a18842016-09-22 15:33:33 +0100186 $log.debug('** Zoom restored:', z);
187 $log.debug('** We installed the projection:', proj);
Steven Burrowse7cc3082016-09-27 11:24:58 -0700188
189 // Now the map has load and we have a projection we can
190 // get the info from the server
191 t2es.start();
Steven Burrowse3a18842016-09-22 15:33:33 +0100192 }
193 );
194
Steven Burrows3cc0c372017-02-10 15:15:24 +0000195 t2sls.init(svg, zoomLayer);
Steven Burrows1aa4f582016-12-13 15:05:41 -0500196 t2fs.init(svg, forceG, uplink, dim, zoomer);
Steven Burrowsaf3159d2016-08-25 14:54:30 +0100197 t2bcs.init();
Steven Burrowse3a18842016-09-22 15:33:33 +0100198 t2kcs.init(t2fs);
Steven Burrows57e24e92016-08-04 18:38:24 +0100199 t2is.initInst({ showMastership: t2fs.showMastership });
200
Simon Huntd5b96732016-07-08 13:22:27 -0700201 // === ORIGINAL CODE ===
Steven Burrows57e24e92016-08-04 18:38:24 +0100202
Simon Huntd5b96732016-07-08 13:22:27 -0700203 // setUpToolbar();
Simon Huntd5b96732016-07-08 13:22:27 -0700204 // setUpNoDevs();
Simon Huntd5b96732016-07-08 13:22:27 -0700205
Simon Huntd5b96732016-07-08 13:22:27 -0700206 // tes.bindHandlers();
207 // setUpSprites();
208
209 // forceG = zoomLayer.append('g').attr('id', 'topo-force');
210 // tfs.initForce(svg, forceG, uplink, dim);
211 // tis.initInst({ showMastership: tfs.showMastership });
212 // tps.initPanels();
213
214 // restoreConfigFromPrefs();
Simon Huntfc5c5842017-02-01 23:32:18 -0800215 // ttbs.setDefaultOverlay(prefsState.ovid);
Simon Huntd5b96732016-07-08 13:22:27 -0700216
217 // $log.debug('registered overlays...', tov.list());
Steven Burrows57e24e92016-08-04 18:38:24 +0100218
Steven Burrows5570d1b2016-09-28 14:21:00 -0700219 summaryPanel.init();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500220 detailsPanel.init();
Steven Burrows5570d1b2016-09-28 14:21:00 -0700221
Simon Huntd5b96732016-07-08 13:22:27 -0700222 $log.log('OvTopo2Ctrl has been created');
223 }]);
Steven Burrowsdfa52b02016-09-02 13:50:43 +0100224})();