blob: f62bf5c2a56521651af837e9a7ca21f9693bcada [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);
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',
Simon Huntd5b96732016-07-08 13:22:27 -070095
96 function (_$scope_, _$log_, _$loc_,
Steven Burrows57e24e92016-08-04 18:38:24 +010097 _fs_, _mast_, _ks_, _zs_,
98 _gs_, _ms_, _sus_, _flash_,
99 _wss_, _ps_, _th_,
100 _t2es_, _t2fs_, _t2is_) {
Simon Huntd5b96732016-07-08 13:22:27 -0700101
102 var params = _$loc_.search(),
103 projection,
104 dim,
105 wh,
106 uplink = {
107 // provides function calls back into this space
108 // showNoDevs: showNoDevs,
109 // projection: function () { return projection; },
110 // zoomLayer: function () { return zoomLayer; },
111 // zoomer: function () { return zoomer; },
112 // opacifyMap: opacifyMap,
113 // topoStartDone: topoStartDone
114 };
115
116 $scope = _$scope_;
117 $log = _$log_;
118 $loc = _$loc_;
119
120 fs = _fs_;
121 mast = _mast_;
122 ks = _ks_;
123 zs = _zs_;
124
125 gs = _gs_;
126 ms = _ms_;
127 sus = _sus_;
128 flash = _flash_;
129
130 wss = _wss_;
131 ps = _ps_;
132 th = _th_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100133
Simon Huntd5b96732016-07-08 13:22:27 -0700134 t2es = _t2es_;
135 t2fs = _t2fs_;
Steven Burrows57e24e92016-08-04 18:38:24 +0100136 t2is = _t2is_;
Simon Huntd5b96732016-07-08 13:22:27 -0700137
138 // capture selected intent parameters (if they are set in the
139 // query string) so that the traffic overlay can highlight
140 // the path for that intent
141 if (params.intentKey && params.intentAppId && params.intentAppName) {
142 $scope.intentData = {
143 key: params.intentKey,
144 appId: params.intentAppId,
145 appName: params.intentAppName
146 };
147 }
148
149 $scope.notifyResize = function () {
150 svgResized(fs.windowSize(mast.mastHeight()));
151 };
152
153 // Cleanup on destroyed scope..
154 $scope.$on('$destroy', function () {
155 $log.log('OvTopo2Ctrl is saying Buh-Bye!');
156 t2es.stop();
157 ks.unbindKeys();
158 t2fs.destroy();
159 });
160
161 // svg layer and initialization of components
162 ovtopo2 = d3.select('#ov-topo2');
163 svg = ovtopo2.select('svg');
164 // set the svg size to match that of the window, less the masthead
165 wh = fs.windowSize(mast.mastHeight());
166 $log.debug('setting topo SVG size to', wh);
167 svg.attr(wh);
168 dim = [wh.width, wh.height];
169
170
171 // 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
179 // initialize the force layout, ready to render the topology
Steven Burrows57e24e92016-08-04 18:38:24 +0100180 forceG = zoomLayer.append('g').attr('id', 'topo-force');
181 t2fs.init(svg, forceG, uplink, dim);
Simon Huntd5b96732016-07-08 13:22:27 -0700182
183
184 // =-=-=-=-=-=-=-=-
185 // TODO: in future, we will load background map data
Steven Burrows57e24e92016-08-04 18:38:24 +0100186 // asynchronously (hence the promise) and then chain off
Simon Huntd5b96732016-07-08 13:22:27 -0700187 // there to send the topo2start event to the server.
188 // For now, we'll send the event inline...
189 t2es.start();
190
Steven Burrows57e24e92016-08-04 18:38:24 +0100191
192
193 t2is.initInst({ showMastership: t2fs.showMastership });
194
195
196
Simon Huntd5b96732016-07-08 13:22:27 -0700197 // === ORIGINAL CODE ===
Steven Burrows57e24e92016-08-04 18:38:24 +0100198
Simon Huntd5b96732016-07-08 13:22:27 -0700199 // setUpKeys();
200 // setUpToolbar();
201 // setUpDefs();
202 // setUpZoom();
203 // setUpNoDevs();
204 /*
205 setUpMap().then(
206 function (proj) {
207 var z = ps.getPrefs('topo_zoom', { tx:0, ty:0, sc:1 });
208 zoomer.panZoom([z.tx, z.ty], z.sc);
209 $log.debug('** Zoom restored:', z);
210
211 projection = proj;
212 $log.debug('** We installed the projection:', proj);
213 flash.enable(false);
214 toggleMap(prefsState.bg);
215 flash.enable(true);
216 mapShader(true);
217
218 // now we have the map projection, we are ready for
219 // the server to send us device/host data...
220 tes.start();
221 // need to do the following so we immediately get
222 // the summary panel data back from the server
223 restoreSummaryFromPrefs();
224 }
225 );
226 */
227 // tes.bindHandlers();
228 // setUpSprites();
229
230 // forceG = zoomLayer.append('g').attr('id', 'topo-force');
231 // tfs.initForce(svg, forceG, uplink, dim);
232 // tis.initInst({ showMastership: tfs.showMastership });
233 // tps.initPanels();
234
235 // restoreConfigFromPrefs();
236 // ttbs.setDefaultOverlay(prefsState.ovidx);
237
238 // $log.debug('registered overlays...', tov.list());
Steven Burrows57e24e92016-08-04 18:38:24 +0100239
Simon Huntd5b96732016-07-08 13:22:27 -0700240 $log.log('OvTopo2Ctrl has been created');
241 }]);
242}());