blob: cac8f4cf089b9ba767bface6e4a4e2d5505ccd52 [file] [log] [blame]
Simon Huntef31fb22014-12-19 13:16:44 -08001/*
Simon Hunt8ead3a22015-01-06 11:00:15 -08002 * Copyright 2014,2015 Open Networking Laboratory
Simon Huntef31fb22014-12-19 13:16:44 -08003 *
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 */
16
17/*
18 ONOS GUI -- Topology View Module
Simon Huntef31fb22014-12-19 13:16:44 -080019 */
20
21(function () {
22 'use strict';
Simon Hunt6cc53692015-01-07 11:33:45 -080023
24 var moduleDependencies = [
Simon Hunt36a58c62015-04-08 11:00:07 -070025 'ngCookies',
Simon Hunt6cc53692015-01-07 11:33:45 -080026 'onosUtil',
Simon Hunt1e4a0012015-01-21 11:36:08 -080027 'onosSvg',
28 'onosRemote'
Simon Hunt6cc53692015-01-07 11:33:45 -080029 ];
30
31 // references to injected services etc.
Bri Prebilic Cole068814d2015-05-14 16:06:38 -070032 var $scope, $log, $cookies, fs, ks, zs, gs, ms, sus, flash, wss, ps,
Simon Hunt72e44bf2015-07-21 21:34:20 -070033 tes, tfs, tps, tis, tss, tls, tts, tos, fltr, ttbs, ttip, tov;
Simon Hunt6cc53692015-01-07 11:33:45 -080034
35 // DOM elements
Simon Hunt2052e5d2015-04-13 17:40:44 -070036 var ovtopo, svg, defs, zoomLayer, mapG, spriteG, forceG, noDevsLayer;
Simon Hunt6cc53692015-01-07 11:33:45 -080037
38 // Internal state
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070039 var zoomer, actionMap;
Simon Hunt6cc53692015-01-07 11:33:45 -080040
Simon Huntcacce342015-01-07 16:13:05 -080041 // --- Short Cut Keys ------------------------------------------------
42
Simon Hunt5724fb42015-02-05 16:59:40 -080043 function setUpKeys() {
44 // key bindings need to be made after the services have been injected
45 // thus, deferred to here...
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070046 actionMap = {
Simon Hunt36a58c62015-04-08 11:00:07 -070047 I: [toggleInstances, 'Toggle ONOS instances panel'],
Simon Huntee7a3ce2015-04-09 13:28:37 -070048 O: [toggleSummary, 'Toggle ONOS summary panel'],
Simon Hunt239e5882015-04-23 15:07:04 -070049 D: [toggleUseDetailsFlag, 'Disable / enable details panel'],
Simon Huntac4c6f72015-02-03 19:50:53 -080050
Simon Huntfcbde892015-04-16 12:05:28 -070051 H: [toggleHosts, 'Toggle host visibility'],
52 M: [toggleOffline, 'Toggle offline visibility'],
53 P: [togglePorts, 'Toggle Port Highlighting'],
Simon Hunt86b7c882015-04-02 23:06:08 -070054 dash: [tfs.showBadLinks, 'Show bad links'],
55 B: [toggleMap, 'Toggle background map'],
Simon Hunt2052e5d2015-04-13 17:40:44 -070056 S: [toggleSprites, 'Toggle sprite layer'],
Simon Huntac4c6f72015-02-03 19:50:53 -080057
Simon Hunt5724fb42015-02-05 16:59:40 -080058 //X: [toggleNodeLock, 'Lock / unlock node positions'],
Simon Hunt96f88c62015-02-19 17:57:25 -080059 Z: [tos.toggleOblique, 'Toggle oblique view (Experimental)'],
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070060 N: [fltr.clickAction, 'Cycle node layers'],
Simon Hunt5724fb42015-02-05 16:59:40 -080061 L: [tfs.cycleDeviceLabels, 'Cycle device labels'],
Simon Hunt445e8152015-02-06 13:00:12 -080062 U: [tfs.unpin, 'Unpin node (hover mouse over)'],
Simon Hunt5724fb42015-02-05 16:59:40 -080063 R: [resetZoom, 'Reset pan / zoom'],
Simon Hunt90dcc3e2015-03-25 15:01:27 -070064 dot: [ttbs.toggleToolbar, 'Toggle Toolbar'],
Simon Huntac4c6f72015-02-03 19:50:53 -080065
Simon Huntf542d842015-02-11 16:20:33 -080066 V: [tts.showRelatedIntentsAction, 'Show all related intents'],
67 rightArrow: [tts.showNextIntentAction, 'Show next related intent'],
68 leftArrow: [tts.showPrevIntentAction, 'Show previous related intent'],
69 W: [tts.showSelectedIntentTrafficAction, 'Monitor traffic of selected intent'],
Thomas Vachuskaf0397b52015-05-29 13:50:17 -070070 A: [tts.showAllFlowTrafficAction, 'Monitor all traffic using flow stats'],
71 Q: [tts.showAllPortTrafficAction, 'Monitor all traffic using port stats'],
Simon Huntf542d842015-02-11 16:20:33 -080072 F: [tts.showDeviceLinkFlowsAction, 'Show device link flows'],
Simon Huntac4c6f72015-02-03 19:50:53 -080073
Simon Hunt0e48c292015-02-19 16:11:37 -080074 E: [equalizeMasters, 'Equalize mastership roles'],
Simon Huntac4c6f72015-02-03 19:50:53 -080075
Simon Hunt08f841d02015-02-10 14:39:20 -080076 esc: handleEscape,
Simon Huntac4c6f72015-02-03 19:50:53 -080077
Simon Hunt09060142015-03-18 20:23:32 -070078 _keyListener: ttbs.keyListener,
79
Simon Hunt5724fb42015-02-05 16:59:40 -080080 _helpFormat: [
Simon Hunt86b7c882015-04-02 23:06:08 -070081 ['I', 'O', 'D', '-', 'H', 'M', 'P', 'dash', 'B' ],
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070082 ['X', 'Z', 'N', 'L', 'U', 'R', '-', 'dot'],
Simon Hunt5724fb42015-02-05 16:59:40 -080083 ['V', 'rightArrow', 'leftArrow', 'W', 'A', 'F', '-', 'E' ]
84 ]
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070085 };
86
87 ks.keyBindings(actionMap);
Simon Huntac4c6f72015-02-03 19:50:53 -080088
Simon Hunt639dc662015-02-18 14:19:20 -080089 ks.gestureNotes([
Simon Hunt5724fb42015-02-05 16:59:40 -080090 ['click', 'Select the item and show details'],
91 ['shift-click', 'Toggle selection state'],
92 ['drag', 'Reposition (and pin) device / host'],
93 ['cmd-scroll', 'Zoom in / out'],
94 ['cmd-drag', 'Pan']
Simon Hunt639dc662015-02-18 14:19:20 -080095 ]);
Simon Hunt5724fb42015-02-05 16:59:40 -080096 }
Simon Hunt6cc53692015-01-07 11:33:45 -080097
Simon Hunt08f841d02015-02-10 14:39:20 -080098 // --- Keystroke functions -------------------------------------------
Simon Huntac4c6f72015-02-03 19:50:53 -080099
Simon Hunt36a58c62015-04-08 11:00:07 -0700100 function toggleInstances(x) {
Simon Huntee7a3ce2015-04-09 13:28:37 -0700101 updatePrefsState('insts', tis.toggle(x));
Simon Huntac4c6f72015-02-03 19:50:53 -0800102 tfs.updateDeviceColors();
Simon Hunt6cc53692015-01-07 11:33:45 -0800103 }
Simon Huntac4c6f72015-02-03 19:50:53 -0800104
Simon Huntee7a3ce2015-04-09 13:28:37 -0700105 function toggleSummary(x) {
106 updatePrefsState('summary', tps.toggleSummary(x));
Simon Hunt18bf9822015-02-12 17:35:45 -0800107 }
108
Simon Hunt239e5882015-04-23 15:07:04 -0700109 function toggleUseDetailsFlag(x) {
110 updatePrefsState('detail', tps.toggleUseDetailsFlag(x));
Simon Huntee7a3ce2015-04-09 13:28:37 -0700111 }
112
Simon Huntfcbde892015-04-16 12:05:28 -0700113 function toggleHosts(x) {
114 updatePrefsState('hosts', tfs.toggleHosts(x));
115 }
116
117 function toggleOffline(x) {
118 updatePrefsState('offdev', tfs.toggleOffline(x));
119 }
120
121 function togglePorts(x) {
122 updatePrefsState('porthl', tfs.togglePorts(x));
123 }
124
125 function _togSvgLayer(x, G, tag, what) {
126 var on = (x === 'keyev') ? !sus.visible(G) : !!x,
Simon Huntee7a3ce2015-04-09 13:28:37 -0700127 verb = on ? 'Show' : 'Hide';
Simon Huntfcbde892015-04-16 12:05:28 -0700128 sus.visible(G, on);
129 updatePrefsState(tag, on);
130 flash.flash(verb + ' ' + what);
131 }
132
133 function toggleMap(x) {
134 _togSvgLayer(x, mapG, 'bg', 'background map');
Simon Huntee7a3ce2015-04-09 13:28:37 -0700135 }
Simon Hunt36a58c62015-04-08 11:00:07 -0700136
Simon Hunt2052e5d2015-04-13 17:40:44 -0700137 function toggleSprites(x) {
Simon Huntfcbde892015-04-16 12:05:28 -0700138 _togSvgLayer(x, spriteG, 'spr', 'sprite layer');
Simon Hunt2052e5d2015-04-13 17:40:44 -0700139 }
140
Simon Hunt08f841d02015-02-10 14:39:20 -0800141 function resetZoom() {
142 zoomer.reset();
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -0700143 flash.flash('Pan and zoom reset');
Simon Hunt08f841d02015-02-10 14:39:20 -0800144 }
145
Simon Hunt0e48c292015-02-19 16:11:37 -0800146 function equalizeMasters() {
Simon Hunt237676b52015-03-10 19:04:26 -0700147 wss.sendEvent('equalizeMasters');
Simon Hunt0e48c292015-02-19 16:11:37 -0800148 flash.flash('Equalizing master roles');
149 }
150
Simon Hunt08f841d02015-02-10 14:39:20 -0800151 function handleEscape() {
Simon Hunta142dd22015-02-12 22:07:51 -0800152 if (tis.showMaster()) {
153 // if an instance is selected, cancel the affinity mapping
154 tis.cancelAffinity()
Simon Hunt08f841d02015-02-10 14:39:20 -0800155
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700156 } else if (tss.deselectAll()) {
Simon Hunta0eb0a82015-02-11 12:30:06 -0800157 // else if we have node selections, deselect them all
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700158 // (work already done)
159
160 } else if (tls.deselectLink()) {
161 // else if we have a link selected, deselect it
162 // (work already done)
Simon Hunt08f841d02015-02-10 14:39:20 -0800163
Simon Hunta0eb0a82015-02-11 12:30:06 -0800164 } else if (tis.isVisible()) {
165 // else if the Instance Panel is visible, hide it
166 tis.hide();
167 tfs.updateDeviceColors();
Simon Hunt08f841d02015-02-10 14:39:20 -0800168
Simon Hunta0eb0a82015-02-11 12:30:06 -0800169 } else if (tps.summaryVisible()) {
170 // else if the Summary Panel is visible, hide it
171 tps.hideSummaryPanel();
Simon Hunt08f841d02015-02-10 14:39:20 -0800172
Simon Hunta0eb0a82015-02-11 12:30:06 -0800173 } else {
174 // TODO: set hover mode to hoverModeNone
Simon Hunt62c2f8f2015-02-19 14:19:10 -0800175 // talk to Thomas about this: shouldn't it be done
176 // when we deselect the node (if tss.haveDetails()...)
Simon Hunta0eb0a82015-02-11 12:30:06 -0800177 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800178 }
Simon Huntcacce342015-01-07 16:13:05 -0800179
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700180 // --- Toolbar Functions ---------------------------------------------
181
Bri Prebilic Cole2efc7152015-04-29 15:47:06 -0700182 function notValid(what) {
183 $log.warn('Topo.js getActionEntry(): Not a valid ' + what);
184 }
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700185 function getActionEntry(key) {
Bri Prebilic Cole2efc7152015-04-29 15:47:06 -0700186 var entry;
187
188 if (!key) {
189 notValid('key');
190 return null;
191 }
192
193 entry = actionMap[key];
194
195 if (!entry) {
196 notValid('actionMap entry');
197 return null;
198 }
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700199 return fs.isA(entry) || [entry, ''];
200 }
201
202 function setUpToolbar() {
203 ttbs.init({
204 getActionEntry: getActionEntry
205 });
206 ttbs.createToolbar();
207 }
208
Simon Huntcacce342015-01-07 16:13:05 -0800209 // --- Glyphs, Icons, and the like -----------------------------------
210
Simon Hunt6cc53692015-01-07 11:33:45 -0800211 function setUpDefs() {
Simon Huntcacce342015-01-07 16:13:05 -0800212 defs = svg.append('defs');
Simon Hunt6cc53692015-01-07 11:33:45 -0800213 gs.loadDefs(defs);
Simon Hunt0ee28682015-02-12 20:48:11 -0800214 sus.loadGlowDefs(defs);
Simon Hunt6cc53692015-01-07 11:33:45 -0800215 }
216
217
Simon Huntcacce342015-01-07 16:13:05 -0800218 // --- Pan and Zoom --------------------------------------------------
219
220 // zoom enabled predicate. ev is a D3 source event.
221 function zoomEnabled(ev) {
Simon Huntd552ee92015-04-02 17:06:35 -0700222 return fs.isMobile() || (ev.metaKey || ev.altKey);
Simon Huntcacce342015-01-07 16:13:05 -0800223 }
224
225 function zoomCallback() {
Simon Huntbb5e0d82015-04-16 14:25:46 -0700226 var sc = zoomer.scale(),
227 tr = zoomer.translate();
228
229 ps.setPrefs('topo_zoom', {tx:tr[0], ty:tr[1], sc:sc});
Simon Huntcacce342015-01-07 16:13:05 -0800230
Simon Hunt0541fb82015-01-14 18:59:57 -0800231 // keep the map lines constant width while zooming
Simon Hunt737c89f2015-01-28 12:23:19 -0800232 mapG.style('stroke-width', (2.0 / sc) + 'px');
Simon Huntcacce342015-01-07 16:13:05 -0800233 }
234
235 function setUpZoom() {
Simon Hunta7b6a6b2015-01-13 19:53:09 -0800236 zoomLayer = svg.append('g').attr('id', 'topo-zoomlayer');
Simon Huntcacce342015-01-07 16:13:05 -0800237 zoomer = zs.createZoomer({
238 svg: svg,
239 zoomLayer: zoomLayer,
240 zoomEnabled: zoomEnabled,
241 zoomCallback: zoomCallback
242 });
243 }
244
245
Simon Hunt0541fb82015-01-14 18:59:57 -0800246 // callback invoked when the SVG view has been resized..
Simon Hunt3a6eec02015-02-09 21:16:43 -0800247 function svgResized(s) {
248 tfs.newDim([s.width, s.height]);
Simon Hunt0541fb82015-01-14 18:59:57 -0800249 }
250
Simon Hunta7b6a6b2015-01-13 19:53:09 -0800251 // --- Background Map ------------------------------------------------
252
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800253 function setUpNoDevs() {
254 var g, box;
255 noDevsLayer = svg.append('g').attr({
256 id: 'topo-noDevsLayer',
257 transform: sus.translate(500,500)
258 });
259 // Note, SVG viewbox is '0 0 1000 1000', defined in topo.html.
260 // We are translating this layer to have its origin at the center
261
262 g = noDevsLayer.append('g');
263 gs.addGlyph(g, 'bird', 100).attr('class', 'noDevsBird');
264 g.append('text').text('No devices are connected')
265 .attr({ x: 120, y: 80});
266
267 box = g.node().getBBox();
268 box.x -= box.width/2;
269 box.y -= box.height/2;
270 g.attr('transform', sus.translate(box.x, box.y));
271
272 showNoDevs(true);
273 }
274
275 function showNoDevs(b) {
Simon Hunt18bf9822015-02-12 17:35:45 -0800276 sus.visible(noDevsLayer, b);
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800277 }
278
Simon Hunt2362b072015-06-11 20:08:22 -0700279
280 var countryFilters = {
281 world: function (c) {
282 return c.properties.continent !== 'Antarctica';
283 },
284
285 // NOTE: for "usa" we are using our hand-crafted topojson file
286
287 s_america: function (c) {
288 return c.properties.continent === 'South America';
289 },
290
291 japan: function (c) {
292 return c.properties.geounit === 'Japan';
293 },
294
295 europe: function (c) {
296 return c.properties.continent === 'Europe';
297 },
298
299 italy: function (c) {
300 return c.properties.geounit === 'Italy';
301 },
302
303 uk: function (c) {
304 // technically, Ireland is not part of the United Kingdom,
305 // but the map looks weird without it showing.
306 return c.properties.adm0_a3 === 'GBR' ||
307 c.properties.adm0_a3 === 'IRL';
308 }
309 };
310
311
312 function setUpMap($loc) {
313 var s1 = $loc.search().mapid,
314 s2 = ps.getPrefs('topo_mapid'),
Simon Huntf65c3782015-06-12 13:33:48 -0700315 mapId = s1 || (s2 && s2.id) || 'usa',
Simon Hunt2362b072015-06-11 20:08:22 -0700316 promise,
317 cfilter,
318 opts;
319
Simon Hunt737c89f2015-01-28 12:23:19 -0800320 mapG = zoomLayer.append('g').attr('id', 'topo-map');
Simon Hunt2362b072015-06-11 20:08:22 -0700321 if (mapId === 'usa') {
322 promise = ms.loadMapInto(mapG, '*continental_us');
323 } else {
324 ps.setPrefs('topo_mapid', {id:mapId});
325 cfilter = countryFilters[mapId] || countryFilters.world;
326 opts = { countryFilter: cfilter };
327 promise = ms.loadMapRegionInto(mapG, opts);
328 }
329 return promise;
Simon Hunt0541fb82015-01-14 18:59:57 -0800330 }
331
Simon Huntc3c5b672015-02-20 11:32:13 -0800332 function opacifyMap(b) {
333 mapG.transition()
334 .duration(1000)
335 .attr('opacity', b ? 1 : 0);
336 }
Simon Hunt737c89f2015-01-28 12:23:19 -0800337
Simon Huntf9fc0e72015-04-16 15:10:57 -0700338 function setUpSprites($loc, tspr) {
339 var s1 = $loc.search().sprites,
340 s2 = ps.getPrefs('topo_sprites'),
341 sprId = s1 || (s2 && s2.id);
342
343 spriteG = zoomLayer.append ('g').attr('id', 'topo-sprites');
344 if (sprId) {
345 ps.setPrefs('topo_sprites', {id:sprId});
346 tspr.loadSprites(spriteG, defs, sprId);
347 }
348 }
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700349
Simon Huntc7ae7952015-04-08 18:59:27 -0700350 // --- User Preferemces ----------------------------------------------
Simon Hunt36a58c62015-04-08 11:00:07 -0700351
Simon Huntc7ae7952015-04-08 18:59:27 -0700352 var prefsState = {};
Simon Hunt36a58c62015-04-08 11:00:07 -0700353
Simon Huntc7ae7952015-04-08 18:59:27 -0700354 function updatePrefsState(what, b) {
355 prefsState[what] = b ? 1 : 0;
356 ps.setPrefs('topo_prefs', prefsState);
Simon Hunt36a58c62015-04-08 11:00:07 -0700357 }
358
Simon Hunt36a58c62015-04-08 11:00:07 -0700359
Simon Huntc7ae7952015-04-08 18:59:27 -0700360 function restoreConfigFromPrefs() {
361 // NOTE: toolbar will have set this for us..
Simon Huntfcbde892015-04-16 12:05:28 -0700362 prefsState = ps.asNumbers(ps.getPrefs('topo_prefs'));
Simon Hunt36a58c62015-04-08 11:00:07 -0700363
Simon Hunte1ce4292015-06-12 13:07:02 -0700364 $log.debug('TOPO- Prefs State:', prefsState);
Simon Huntc7ae7952015-04-08 18:59:27 -0700365
Simon Huntf41f3092015-04-16 10:33:26 -0700366 flash.enable(false);
Simon Huntc7ae7952015-04-08 18:59:27 -0700367 toggleInstances(prefsState.insts);
Simon Huntee7a3ce2015-04-09 13:28:37 -0700368 toggleSummary(prefsState.summary);
Simon Hunt239e5882015-04-23 15:07:04 -0700369 toggleUseDetailsFlag(prefsState.detail);
Simon Huntf9fc0e72015-04-16 15:10:57 -0700370 toggleSprites(prefsState.spr);
Simon Huntf41f3092015-04-16 10:33:26 -0700371 flash.enable(true);
Simon Hunt36a58c62015-04-08 11:00:07 -0700372 }
373
374
Simon Hunte1ce4292015-06-12 13:07:02 -0700375 // somewhat hackish, because summary update cannot happen until we
376 // have opened the websocket to the server; hence this extra function
377 // invoked after tes.start()
378 function restoreSummaryFromPrefs() {
379 prefsState = ps.asNumbers(ps.getPrefs('topo_prefs'));
380 $log.debug('TOPO- Prefs SUMMARY State:', prefsState.summary);
381
382 flash.enable(false);
383 toggleSummary(prefsState.summary);
384 flash.enable(true);
385 }
386
387
Simon Huntcacce342015-01-07 16:13:05 -0800388 // --- Controller Definition -----------------------------------------
389
Simon Hunt6cc53692015-01-07 11:33:45 -0800390 angular.module('ovTopo', moduleDependencies)
Simon Hunt237676b52015-03-10 19:04:26 -0700391 .controller('OvTopoCtrl', ['$scope', '$log', '$location', '$timeout',
Simon Hunt36a58c62015-04-08 11:00:07 -0700392 '$cookies', 'FnService', 'MastService', 'KeyService', 'ZoomService',
Simon Hunt0e48c292015-02-19 16:11:37 -0800393 'GlyphService', 'MapService', 'SvgUtilService', 'FlashService',
Simon Huntc7ae7952015-04-08 18:59:27 -0700394 'WebSocketService', 'PrefsService',
Simon Huntb0ec1e52015-01-28 18:13:49 -0800395 'TopoEventService', 'TopoForceService', 'TopoPanelService',
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700396 'TopoInstService', 'TopoSelectService', 'TopoLinkService',
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -0700397 'TopoTrafficService', 'TopoObliqueService', 'TopoFilterService',
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700398 'TopoToolbarService', 'TopoSpriteService', 'TooltipService',
Simon Hunt72e44bf2015-07-21 21:34:20 -0700399 'TopoOverlayService',
Simon Hunt6cc53692015-01-07 11:33:45 -0800400
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700401 function (_$scope_, _$log_, $loc, $timeout, _$cookies_, _fs_, mast, _ks_,
Simon Huntc7ae7952015-04-08 18:59:27 -0700402 _zs_, _gs_, _ms_, _sus_, _flash_, _wss_, _ps_, _tes_, _tfs_,
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700403 _tps_, _tis_, _tss_, _tls_, _tts_, _tos_, _fltr_, _ttbs_, tspr,
Simon Hunt72e44bf2015-07-21 21:34:20 -0700404 _ttip_, _tov_) {
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700405 var projection,
Simon Hunt3a6eec02015-02-09 21:16:43 -0800406 dim,
Simon Hunt1894d792015-02-04 17:09:20 -0800407 uplink = {
408 // provides function calls back into this space
409 showNoDevs: showNoDevs,
410 projection: function () { return projection; },
Simon Huntc3c5b672015-02-20 11:32:13 -0800411 zoomLayer: function () { return zoomLayer; },
Simon Huntfb8ea1f2015-02-24 21:38:09 -0800412 zoomer: function () { return zoomer; },
Simon Hunt237676b52015-03-10 19:04:26 -0700413 opacifyMap: opacifyMap
Simon Huntac4c6f72015-02-03 19:50:53 -0800414 };
415
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700416 $scope = _$scope_;
Simon Hunt6cc53692015-01-07 11:33:45 -0800417 $log = _$log_;
Simon Hunt36a58c62015-04-08 11:00:07 -0700418 $cookies = _$cookies_;
Simon Hunta11b4eb2015-01-28 16:20:50 -0800419 fs = _fs_;
Simon Hunt6cc53692015-01-07 11:33:45 -0800420 ks = _ks_;
Simon Huntcacce342015-01-07 16:13:05 -0800421 zs = _zs_;
Simon Hunt6cc53692015-01-07 11:33:45 -0800422 gs = _gs_;
Simon Hunt1e8eff42015-01-08 17:19:02 -0800423 ms = _ms_;
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800424 sus = _sus_;
Simon Hunt0e48c292015-02-19 16:11:37 -0800425 flash = _flash_;
Simon Hunt237676b52015-03-10 19:04:26 -0700426 wss = _wss_;
Simon Huntc7ae7952015-04-08 18:59:27 -0700427 ps = _ps_;
Simon Huntc252aa62015-02-10 16:45:39 -0800428 tes = _tes_;
Simon Hunt737c89f2015-01-28 12:23:19 -0800429 tfs = _tfs_;
Simon Hunt96f88c62015-02-19 17:57:25 -0800430 // TODO: consider funnelling actions through TopoForceService...
431 // rather than injecting references to these 'sub-modules',
432 // just so we can invoke functions on them.
Simon Huntc252aa62015-02-10 16:45:39 -0800433 tps = _tps_;
Simon Huntac4c6f72015-02-03 19:50:53 -0800434 tis = _tis_;
Simon Hunt6036b192015-02-11 11:20:26 -0800435 tss = _tss_;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700436 tls = _tls_;
Simon Huntf542d842015-02-11 16:20:33 -0800437 tts = _tts_;
Simon Hunt96f88c62015-02-19 17:57:25 -0800438 tos = _tos_;
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -0700439 fltr = _fltr_;
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700440 ttbs = _ttbs_;
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700441 ttip = _ttip_;
Simon Hunt72e44bf2015-07-21 21:34:20 -0700442 tov = _tov_;
Simon Huntef31fb22014-12-19 13:16:44 -0800443
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700444 $scope.notifyResize = function () {
Simon Huntb0ec1e52015-01-28 18:13:49 -0800445 svgResized(fs.windowSize(mast.mastHeight()));
Simon Hunt426bd862015-01-14 16:48:41 -0800446 };
Simon Huntef31fb22014-12-19 13:16:44 -0800447
Simon Hunt54442fa2015-01-26 14:17:38 -0800448 // Cleanup on destroyed scope..
Simon Hunt584122a2015-01-21 15:32:40 -0800449 $scope.$on('$destroy', function () {
450 $log.log('OvTopoCtrl is saying Buh-Bye!');
Thomas Vachuska329af532015-03-10 02:08:33 -0700451 tes.stop();
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -0700452 ks.unbindKeys();
Simon Hunt626d2102015-01-29 11:54:50 -0800453 tps.destroyPanels();
Simon Hunt4b668592015-01-29 17:33:53 -0800454 tis.destroyInst();
Simon Hunt3a6eec02015-02-09 21:16:43 -0800455 tfs.destroyForce();
Bri Prebilic Coled6219052015-03-19 14:34:02 -0700456 ttbs.destroyToolbar();
Simon Hunt584122a2015-01-21 15:32:40 -0800457 });
458
Simon Huntcacce342015-01-07 16:13:05 -0800459 // svg layer and initialization of components
Simon Hunt426bd862015-01-14 16:48:41 -0800460 ovtopo = d3.select('#ov-topo');
461 svg = ovtopo.select('svg');
Simon Hunta11b4eb2015-01-28 16:20:50 -0800462 // set the svg size to match that of the window, less the masthead
463 svg.attr(fs.windowSize(mast.mastHeight()));
Simon Hunt3a6eec02015-02-09 21:16:43 -0800464 dim = [svg.attr('width'), svg.attr('height')];
Simon Hunt426bd862015-01-14 16:48:41 -0800465
Simon Hunt6cc53692015-01-07 11:33:45 -0800466 setUpKeys();
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700467 setUpToolbar();
Simon Hunt6cc53692015-01-07 11:33:45 -0800468 setUpDefs();
Simon Huntcacce342015-01-07 16:13:05 -0800469 setUpZoom();
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800470 setUpNoDevs();
Simon Hunt2362b072015-06-11 20:08:22 -0700471 setUpMap($loc).then(
Simon Hunt1894d792015-02-04 17:09:20 -0800472 function (proj) {
Simon Huntbb5e0d82015-04-16 14:25:46 -0700473 var z = ps.getPrefs('topo_zoom') || {tx:0, ty:0, sc:1};
474 zoomer.panZoom([z.tx, z.ty], z.sc);
475 $log.debug('** Zoom restored:', z);
476
Simon Hunt1894d792015-02-04 17:09:20 -0800477 projection = proj;
Simon Huntbb5e0d82015-04-16 14:25:46 -0700478 $log.debug('** We installed the projection:', proj);
Simon Huntf41f3092015-04-16 10:33:26 -0700479 flash.enable(false);
Simon Huntc7ae7952015-04-08 18:59:27 -0700480 toggleMap(prefsState.bg);
Simon Huntf41f3092015-04-16 10:33:26 -0700481 flash.enable(true);
Simon Hunte1ce4292015-06-12 13:07:02 -0700482
483 // now we have the map projection, we are ready for
484 // the server to send us device/host data...
485 tes.start();
486 // need to do the following so we immediately get
487 // the summary panel data back from the server
488 restoreSummaryFromPrefs();
Simon Hunt1894d792015-02-04 17:09:20 -0800489 }
490 );
Simon Huntf9fc0e72015-04-16 15:10:57 -0700491 setUpSprites($loc, tspr);
Simon Huntfd1231a2015-01-26 22:14:51 -0800492
Simon Hunt1894d792015-02-04 17:09:20 -0800493 forceG = zoomLayer.append('g').attr('id', 'topo-force');
Simon Huntfb8ea1f2015-02-24 21:38:09 -0800494 tfs.initForce(svg, forceG, uplink, dim);
Simon Hunta142dd22015-02-12 22:07:51 -0800495 tis.initInst({ showMastership: tfs.showMastership });
Simon Hunt237676b52015-03-10 19:04:26 -0700496 tps.initPanels();
Simon Hunt6cc53692015-01-07 11:33:45 -0800497
Simon Hunt36a58c62015-04-08 11:00:07 -0700498 // temporary solution for persisting user settings
Simon Huntc7ae7952015-04-08 18:59:27 -0700499 restoreConfigFromPrefs();
Simon Hunt36a58c62015-04-08 11:00:07 -0700500
Simon Hunt72e44bf2015-07-21 21:34:20 -0700501 $log.debug('registered overlays...', tov.list());
502
Simon Hunt6cc53692015-01-07 11:33:45 -0800503 $log.log('OvTopoCtrl has been created');
Simon Huntef31fb22014-12-19 13:16:44 -0800504 }]);
505}());