blob: ee6fa78f4eb6718f70fbc56c4445526870a5ac2e [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
27 var $scope, $log, $loc,
28 fs, mast, ks, zs,
29 gs, ms, sus, flash,
30 wss, ps, th,
Steven Burrowsaf3159d2016-08-25 14:54:30 +010031 t2es, t2fs, t2is, t2bcs;
Simon Huntd5b96732016-07-08 13:22:27 -070032
33 // DOM elements
34 var ovtopo2, svg, defs, zoomLayer, mapG, spriteG, forceG, noDevsLayer;
35
36 // Internal state
37 var zoomer, actionMap;
38
39
Steven Burrows57e24e92016-08-04 18:38:24 +010040 // --- Glyphs, Icons, and the like -----------------------------------
41
42 function setUpDefs() {
43 defs = svg.append('defs');
44 gs.loadDefs(defs);
45 sus.loadGlowDefs(defs);
46 }
Simon Huntd5b96732016-07-08 13:22:27 -070047
48 // callback invoked when the SVG view has been resized..
49 function svgResized(s) {
Steven Burrows57e24e92016-08-04 18:38:24 +010050 $log.debug('topo2 view resized', s);
Steven Burrowsec1f45c2016-08-08 16:14:41 +010051 t2fs.newDim([s.width, s.height]);
Simon Huntd5b96732016-07-08 13:22:27 -070052 }
53
54 function setUpKeys(overlayKeys) {
55 $log.debug('topo2: set up keys....');
56 }
57
Steven Burrows57e24e92016-08-04 18:38:24 +010058 // --- 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(),
67 tr = zoomer.translate();
68
69 ps.setPrefs('topo_zoom', {tx:tr[0], ty:tr[1], sc:sc});
70
71 // keep the map lines constant width while zooming
Steven Burrowsec1f45c2016-08-08 16:14:41 +010072// mapG.style('stroke-width', (2.0 / sc) + 'px');
Steven Burrows57e24e92016-08-04 18:38:24 +010073 }
74
75 function setUpZoom() {
76 zoomLayer = svg.append('g').attr('id', 'topo-zoomlayer');
77 zoomer = zs.createZoomer({
78 svg: svg,
79 zoomLayer: zoomLayer,
80 zoomEnabled: zoomEnabled,
81 zoomCallback: zoomCallback
82 });
83 }
84
85
Simon Huntd5b96732016-07-08 13:22:27 -070086 // === Controller Definition -----------------------------------------
87
88 angular.module('ovTopo2', ['onosUtil', 'onosSvg', 'onosRemote'])
Steven Burrows57e24e92016-08-04 18:38:24 +010089 .controller('OvTopo2Ctrl',
Simon Huntd5b96732016-07-08 13:22:27 -070090 ['$scope', '$log', '$location',
91 'FnService', 'MastService', 'KeyService', 'ZoomService',
92 'GlyphService', 'MapService', 'SvgUtilService', 'FlashService',
93 'WebSocketService', 'PrefsService', 'ThemeService',
Steven Burrows57e24e92016-08-04 18:38:24 +010094 'Topo2EventService', 'Topo2ForceService', 'Topo2InstanceService',
Steven Burrowsaf3159d2016-08-25 14:54:30 +010095 'Topo2BreadcrumbService',
Simon Huntd5b96732016-07-08 13:22:27 -070096
97 function (_$scope_, _$log_, _$loc_,
Steven Burrows57e24e92016-08-04 18:38:24 +010098 _fs_, _mast_, _ks_, _zs_,
99 _gs_, _ms_, _sus_, _flash_,
100 _wss_, _ps_, _th_,
Steven Burrowsaf3159d2016-08-25 14:54:30 +0100101 _t2es_, _t2fs_, _t2is_, _t2bcs_) {
Simon Huntd5b96732016-07-08 13:22:27 -0700102
103 var params = _$loc_.search(),
104 projection,
105 dim,
106 wh,
107 uplink = {
108 // provides function calls back into this space
109 // showNoDevs: showNoDevs,
110 // projection: function () { return projection; },
111 // zoomLayer: function () { return zoomLayer; },
112 // zoomer: function () { return zoomer; },
113 // opacifyMap: opacifyMap,
114 // topoStartDone: topoStartDone
115 };
116
117 $scope = _$scope_;
118 $log = _$log_;
119 $loc = _$loc_;
120
121 fs = _fs_;
122 mast = _mast_;
123 ks = _ks_;
124 zs = _zs_;
125
126 gs = _gs_;
127 ms = _ms_;
128 sus = _sus_;
129 flash = _flash_;
130
131 wss = _wss_;
132 ps = _ps_;
133 th = _th_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100134
Simon Huntd5b96732016-07-08 13:22:27 -0700135 t2es = _t2es_;
136 t2fs = _t2fs_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100137 t2is = _t2is_;
Steven Burrowsaf3159d2016-08-25 14:54:30 +0100138 t2bcs = _t2bcs_;
Simon Huntd5b96732016-07-08 13:22:27 -0700139
140 // capture selected intent parameters (if they are set in the
141 // query string) so that the traffic overlay can highlight
142 // the path for that intent
143 if (params.intentKey && params.intentAppId && params.intentAppName) {
144 $scope.intentData = {
145 key: params.intentKey,
146 appId: params.intentAppId,
147 appName: params.intentAppName
148 };
149 }
150
151 $scope.notifyResize = function () {
152 svgResized(fs.windowSize(mast.mastHeight()));
153 };
154
155 // Cleanup on destroyed scope..
156 $scope.$on('$destroy', function () {
157 $log.log('OvTopo2Ctrl is saying Buh-Bye!');
158 t2es.stop();
159 ks.unbindKeys();
160 t2fs.destroy();
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
172
173 // set up our keyboard shortcut bindings
174 setUpKeys();
Steven Burrows57e24e92016-08-04 18:38:24 +0100175 setUpZoom();
176 setUpDefs();
Simon Huntd5b96732016-07-08 13:22:27 -0700177
178 // make sure we can respond to topology events from the server
179 t2es.bindHandlers();
180
181 // initialize the force layout, ready to render the topology
Steven Burrows57e24e92016-08-04 18:38:24 +0100182 forceG = zoomLayer.append('g').attr('id', 'topo-force');
183 t2fs.init(svg, forceG, uplink, dim);
Steven Burrowsaf3159d2016-08-25 14:54:30 +0100184 t2bcs.init();
Simon Huntd5b96732016-07-08 13:22:27 -0700185
186
187 // =-=-=-=-=-=-=-=-
188 // TODO: in future, we will load background map data
Steven Burrows57e24e92016-08-04 18:38:24 +0100189 // asynchronously (hence the promise) and then chain off
Simon Huntd5b96732016-07-08 13:22:27 -0700190 // there to send the topo2start event to the server.
191 // For now, we'll send the event inline...
192 t2es.start();
193
Steven Burrows57e24e92016-08-04 18:38:24 +0100194
195
196 t2is.initInst({ showMastership: t2fs.showMastership });
197
198
199
Simon Huntd5b96732016-07-08 13:22:27 -0700200 // === ORIGINAL CODE ===
Steven Burrows57e24e92016-08-04 18:38:24 +0100201
Simon Huntd5b96732016-07-08 13:22:27 -0700202 // setUpKeys();
203 // setUpToolbar();
204 // setUpDefs();
205 // setUpZoom();
206 // setUpNoDevs();
207 /*
208 setUpMap().then(
209 function (proj) {
210 var z = ps.getPrefs('topo_zoom', { tx:0, ty:0, sc:1 });
211 zoomer.panZoom([z.tx, z.ty], z.sc);
212 $log.debug('** Zoom restored:', z);
213
214 projection = proj;
215 $log.debug('** We installed the projection:', proj);
216 flash.enable(false);
217 toggleMap(prefsState.bg);
218 flash.enable(true);
219 mapShader(true);
220
221 // now we have the map projection, we are ready for
222 // the server to send us device/host data...
223 tes.start();
224 // need to do the following so we immediately get
225 // the summary panel data back from the server
226 restoreSummaryFromPrefs();
227 }
228 );
229 */
230 // tes.bindHandlers();
231 // setUpSprites();
232
233 // forceG = zoomLayer.append('g').attr('id', 'topo-force');
234 // tfs.initForce(svg, forceG, uplink, dim);
235 // tis.initInst({ showMastership: tfs.showMastership });
236 // tps.initPanels();
237
238 // restoreConfigFromPrefs();
239 // ttbs.setDefaultOverlay(prefsState.ovidx);
240
241 // $log.debug('registered overlays...', tov.list());
Steven Burrows57e24e92016-08-04 18:38:24 +0100242
Simon Huntd5b96732016-07-08 13:22:27 -0700243 $log.log('OvTopo2Ctrl has been created');
244 }]);
245}());