blob: 063129924d4704c63189df5b27708de8d9a15ae3 [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 Burrows57e24e92016-08-04 18:38:24 +010031 t2es, t2fs, t2is;
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);
Simon Huntd5b96732016-07-08 13:22:27 -070051 }
52
53 function setUpKeys(overlayKeys) {
54 $log.debug('topo2: set up keys....');
55 }
56
Steven Burrows57e24e92016-08-04 18:38:24 +010057 // --- Pan and Zoom --------------------------------------------------
58
59 // zoom enabled predicate. ev is a D3 source event.
60 function zoomEnabled(ev) {
61 return fs.isMobile() || (ev.metaKey || ev.altKey);
62 }
63
64 function zoomCallback() {
65 var sc = zoomer.scale(),
66 tr = zoomer.translate();
67
68 ps.setPrefs('topo_zoom', {tx:tr[0], ty:tr[1], sc:sc});
69
70 // keep the map lines constant width while zooming
71 mapG.style('stroke-width', (2.0 / sc) + 'px');
72 }
73
74 function setUpZoom() {
75 zoomLayer = svg.append('g').attr('id', 'topo-zoomlayer');
76 zoomer = zs.createZoomer({
77 svg: svg,
78 zoomLayer: zoomLayer,
79 zoomEnabled: zoomEnabled,
80 zoomCallback: zoomCallback
81 });
82 }
83
84
Simon Huntd5b96732016-07-08 13:22:27 -070085 // === Controller Definition -----------------------------------------
86
87 angular.module('ovTopo2', ['onosUtil', 'onosSvg', 'onosRemote'])
Steven Burrows57e24e92016-08-04 18:38:24 +010088 .controller('OvTopo2Ctrl',
Simon Huntd5b96732016-07-08 13:22:27 -070089 ['$scope', '$log', '$location',
90 'FnService', 'MastService', 'KeyService', 'ZoomService',
91 'GlyphService', 'MapService', 'SvgUtilService', 'FlashService',
92 'WebSocketService', 'PrefsService', 'ThemeService',
Steven Burrows57e24e92016-08-04 18:38:24 +010093 'Topo2EventService', 'Topo2ForceService', 'Topo2InstanceService',
Simon Huntd5b96732016-07-08 13:22:27 -070094
95 function (_$scope_, _$log_, _$loc_,
Steven Burrows57e24e92016-08-04 18:38:24 +010096 _fs_, _mast_, _ks_, _zs_,
97 _gs_, _ms_, _sus_, _flash_,
98 _wss_, _ps_, _th_,
99 _t2es_, _t2fs_, _t2is_) {
Simon Huntd5b96732016-07-08 13:22:27 -0700100
101 var params = _$loc_.search(),
102 projection,
103 dim,
104 wh,
105 uplink = {
106 // provides function calls back into this space
107 // showNoDevs: showNoDevs,
108 // projection: function () { return projection; },
109 // zoomLayer: function () { return zoomLayer; },
110 // zoomer: function () { return zoomer; },
111 // opacifyMap: opacifyMap,
112 // topoStartDone: topoStartDone
113 };
114
115 $scope = _$scope_;
116 $log = _$log_;
117 $loc = _$loc_;
118
119 fs = _fs_;
120 mast = _mast_;
121 ks = _ks_;
122 zs = _zs_;
123
124 gs = _gs_;
125 ms = _ms_;
126 sus = _sus_;
127 flash = _flash_;
128
129 wss = _wss_;
130 ps = _ps_;
131 th = _th_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100132
Simon Huntd5b96732016-07-08 13:22:27 -0700133 t2es = _t2es_;
134 t2fs = _t2fs_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100135 t2is = _t2is_;
Simon Huntd5b96732016-07-08 13:22:27 -0700136
137 // capture selected intent parameters (if they are set in the
138 // query string) so that the traffic overlay can highlight
139 // the path for that intent
140 if (params.intentKey && params.intentAppId && params.intentAppName) {
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();
158 });
159
160 // svg layer and initialization of components
161 ovtopo2 = d3.select('#ov-topo2');
162 svg = ovtopo2.select('svg');
163 // set the svg size to match that of the window, less the masthead
164 wh = fs.windowSize(mast.mastHeight());
165 $log.debug('setting topo SVG size to', wh);
166 svg.attr(wh);
167 dim = [wh.width, wh.height];
168
169
170 // set up our keyboard shortcut bindings
171 setUpKeys();
Steven Burrows57e24e92016-08-04 18:38:24 +0100172 setUpZoom();
173 setUpDefs();
Simon Huntd5b96732016-07-08 13:22:27 -0700174
175 // make sure we can respond to topology events from the server
176 t2es.bindHandlers();
177
178 // initialize the force layout, ready to render the topology
Steven Burrows57e24e92016-08-04 18:38:24 +0100179 forceG = zoomLayer.append('g').attr('id', 'topo-force');
180 t2fs.init(svg, forceG, uplink, dim);
Simon Huntd5b96732016-07-08 13:22:27 -0700181
182
183 // =-=-=-=-=-=-=-=-
184 // TODO: in future, we will load background map data
Steven Burrows57e24e92016-08-04 18:38:24 +0100185 // asynchronously (hence the promise) and then chain off
Simon Huntd5b96732016-07-08 13:22:27 -0700186 // there to send the topo2start event to the server.
187 // For now, we'll send the event inline...
188 t2es.start();
189
Steven Burrows57e24e92016-08-04 18:38:24 +0100190
191
192 t2is.initInst({ showMastership: t2fs.showMastership });
193
194
195
Simon Huntd5b96732016-07-08 13:22:27 -0700196 // === ORIGINAL CODE ===
Steven Burrows57e24e92016-08-04 18:38:24 +0100197
Simon Huntd5b96732016-07-08 13:22:27 -0700198 // setUpKeys();
199 // setUpToolbar();
200 // setUpDefs();
201 // setUpZoom();
202 // setUpNoDevs();
203 /*
204 setUpMap().then(
205 function (proj) {
206 var z = ps.getPrefs('topo_zoom', { tx:0, ty:0, sc:1 });
207 zoomer.panZoom([z.tx, z.ty], z.sc);
208 $log.debug('** Zoom restored:', z);
209
210 projection = proj;
211 $log.debug('** We installed the projection:', proj);
212 flash.enable(false);
213 toggleMap(prefsState.bg);
214 flash.enable(true);
215 mapShader(true);
216
217 // now we have the map projection, we are ready for
218 // the server to send us device/host data...
219 tes.start();
220 // need to do the following so we immediately get
221 // the summary panel data back from the server
222 restoreSummaryFromPrefs();
223 }
224 );
225 */
226 // tes.bindHandlers();
227 // setUpSprites();
228
229 // forceG = zoomLayer.append('g').attr('id', 'topo-force');
230 // tfs.initForce(svg, forceG, uplink, dim);
231 // tis.initInst({ showMastership: tfs.showMastership });
232 // tps.initPanels();
233
234 // restoreConfigFromPrefs();
235 // ttbs.setDefaultOverlay(prefsState.ovidx);
236
237 // $log.debug('registered overlays...', tov.list());
Steven Burrows57e24e92016-08-04 18:38:24 +0100238
Simon Huntd5b96732016-07-08 13:22:27 -0700239 $log.log('OvTopo2Ctrl has been created');
240 }]);
241}());