blob: 702584af3b3e39488cea3d4516482a7411a6ed18 [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 Hunta211f7f2015-11-09 12:48:23 -080033 tds, 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 Hunt8d22c4b2015-08-06 16:24:43 -070043 function setUpKeys(overlayKeys) {
Simon Hunt5724fb42015-02-05 16:59:40 -080044 // 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 Hunt0e48c292015-02-19 16:11:37 -080066 E: [equalizeMasters, 'Equalize mastership roles'],
Simon Huntac4c6f72015-02-03 19:50:53 -080067
Simon Hunt08f841d02015-02-10 14:39:20 -080068 esc: handleEscape,
Simon Huntac4c6f72015-02-03 19:50:53 -080069
Simon Hunt09060142015-03-18 20:23:32 -070070 _keyListener: ttbs.keyListener,
71
Simon Hunt5724fb42015-02-05 16:59:40 -080072 _helpFormat: [
Simon Hunt8d22c4b2015-08-06 16:24:43 -070073 ['I', 'O', 'D', 'H', 'M', 'P', 'dash', 'B', 'S' ],
74 ['X', 'Z', 'N', 'L', 'U', 'R', '-', 'E', '-', 'dot'],
75 [] // this column reserved for overlay actions
Simon Hunt5724fb42015-02-05 16:59:40 -080076 ]
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070077 };
78
Simon Hunt8d22c4b2015-08-06 16:24:43 -070079 if (fs.isO(overlayKeys)) {
80 mergeKeys(overlayKeys);
81 }
82
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070083 ks.keyBindings(actionMap);
Simon Huntac4c6f72015-02-03 19:50:53 -080084
Simon Hunt639dc662015-02-18 14:19:20 -080085 ks.gestureNotes([
Simon Hunt5724fb42015-02-05 16:59:40 -080086 ['click', 'Select the item and show details'],
87 ['shift-click', 'Toggle selection state'],
88 ['drag', 'Reposition (and pin) device / host'],
89 ['cmd-scroll', 'Zoom in / out'],
90 ['cmd-drag', 'Pan']
Simon Hunt639dc662015-02-18 14:19:20 -080091 ]);
Simon Hunt5724fb42015-02-05 16:59:40 -080092 }
Simon Hunt6cc53692015-01-07 11:33:45 -080093
Simon Hunt8d22c4b2015-08-06 16:24:43 -070094 // when a topology overlay is activated, we need to bind their keystrokes
95 // and include them in the quick-help panel
96 function mergeKeys(extra) {
97 var _hf = actionMap._helpFormat[2];
Simon Hunt71892222015-09-29 13:39:40 -070098
99 ks.checkNotGlobal(extra);
100
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700101 extra._keyOrder.forEach(function (k) {
102 var d = extra[k],
103 cb = d && d.cb,
104 tt = d && d.tt;
105 // NOTE: ignore keys that are already defined
106 if (d && !actionMap[k]) {
107 actionMap[k] = [cb, tt];
108 _hf.push(k);
109 }
110 });
111 }
112
Simon Hunt08f841d02015-02-10 14:39:20 -0800113 // --- Keystroke functions -------------------------------------------
Simon Huntac4c6f72015-02-03 19:50:53 -0800114
Simon Hunt36a58c62015-04-08 11:00:07 -0700115 function toggleInstances(x) {
Simon Huntee7a3ce2015-04-09 13:28:37 -0700116 updatePrefsState('insts', tis.toggle(x));
Simon Huntac4c6f72015-02-03 19:50:53 -0800117 tfs.updateDeviceColors();
Simon Hunt6cc53692015-01-07 11:33:45 -0800118 }
Simon Huntac4c6f72015-02-03 19:50:53 -0800119
Simon Huntee7a3ce2015-04-09 13:28:37 -0700120 function toggleSummary(x) {
121 updatePrefsState('summary', tps.toggleSummary(x));
Simon Hunt18bf9822015-02-12 17:35:45 -0800122 }
123
Simon Hunt239e5882015-04-23 15:07:04 -0700124 function toggleUseDetailsFlag(x) {
125 updatePrefsState('detail', tps.toggleUseDetailsFlag(x));
Simon Huntee7a3ce2015-04-09 13:28:37 -0700126 }
127
Simon Huntfcbde892015-04-16 12:05:28 -0700128 function toggleHosts(x) {
129 updatePrefsState('hosts', tfs.toggleHosts(x));
130 }
131
132 function toggleOffline(x) {
133 updatePrefsState('offdev', tfs.toggleOffline(x));
134 }
135
136 function togglePorts(x) {
137 updatePrefsState('porthl', tfs.togglePorts(x));
138 }
139
140 function _togSvgLayer(x, G, tag, what) {
141 var on = (x === 'keyev') ? !sus.visible(G) : !!x,
Simon Huntee7a3ce2015-04-09 13:28:37 -0700142 verb = on ? 'Show' : 'Hide';
Simon Huntfcbde892015-04-16 12:05:28 -0700143 sus.visible(G, on);
144 updatePrefsState(tag, on);
145 flash.flash(verb + ' ' + what);
146 }
147
148 function toggleMap(x) {
149 _togSvgLayer(x, mapG, 'bg', 'background map');
Simon Huntee7a3ce2015-04-09 13:28:37 -0700150 }
Simon Hunt36a58c62015-04-08 11:00:07 -0700151
Simon Hunt2052e5d2015-04-13 17:40:44 -0700152 function toggleSprites(x) {
Simon Huntfcbde892015-04-16 12:05:28 -0700153 _togSvgLayer(x, spriteG, 'spr', 'sprite layer');
Simon Hunt2052e5d2015-04-13 17:40:44 -0700154 }
155
Simon Hunt08f841d02015-02-10 14:39:20 -0800156 function resetZoom() {
157 zoomer.reset();
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -0700158 flash.flash('Pan and zoom reset');
Simon Hunt08f841d02015-02-10 14:39:20 -0800159 }
160
Simon Hunt0e48c292015-02-19 16:11:37 -0800161 function equalizeMasters() {
Simon Hunt237676b52015-03-10 19:04:26 -0700162 wss.sendEvent('equalizeMasters');
Simon Hunt0e48c292015-02-19 16:11:37 -0800163 flash.flash('Equalizing master roles');
164 }
165
Simon Hunt08f841d02015-02-10 14:39:20 -0800166 function handleEscape() {
Simon Hunta142dd22015-02-12 22:07:51 -0800167 if (tis.showMaster()) {
168 // if an instance is selected, cancel the affinity mapping
169 tis.cancelAffinity()
Simon Hunt08f841d02015-02-10 14:39:20 -0800170
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700171 } else if (tov.hooks.escape()) {
172 // else if the overlay consumed the ESC event...
173 // (work already done)
174
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700175 } else if (tss.deselectAll()) {
Simon Hunta0eb0a82015-02-11 12:30:06 -0800176 // else if we have node selections, deselect them all
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700177 // (work already done)
178
179 } else if (tls.deselectLink()) {
180 // else if we have a link selected, deselect it
181 // (work already done)
Simon Hunt08f841d02015-02-10 14:39:20 -0800182
Simon Hunta0eb0a82015-02-11 12:30:06 -0800183 } else if (tis.isVisible()) {
184 // else if the Instance Panel is visible, hide it
185 tis.hide();
186 tfs.updateDeviceColors();
Simon Hunt08f841d02015-02-10 14:39:20 -0800187
Simon Hunta0eb0a82015-02-11 12:30:06 -0800188 } else if (tps.summaryVisible()) {
189 // else if the Summary Panel is visible, hide it
190 tps.hideSummaryPanel();
Simon Hunta0eb0a82015-02-11 12:30:06 -0800191 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800192 }
Simon Huntcacce342015-01-07 16:13:05 -0800193
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700194 // --- Toolbar Functions ---------------------------------------------
195
Bri Prebilic Cole2efc7152015-04-29 15:47:06 -0700196 function notValid(what) {
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700197 $log.warn('topo.js getActionEntry(): Not a valid ' + what);
Bri Prebilic Cole2efc7152015-04-29 15:47:06 -0700198 }
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700199
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700200 function getActionEntry(key) {
Bri Prebilic Cole2efc7152015-04-29 15:47:06 -0700201 var entry;
202
203 if (!key) {
204 notValid('key');
205 return null;
206 }
207
208 entry = actionMap[key];
209
210 if (!entry) {
211 notValid('actionMap entry');
212 return null;
213 }
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700214 return fs.isA(entry) || [entry, ''];
215 }
216
217 function setUpToolbar() {
218 ttbs.init({
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700219 getActionEntry: getActionEntry,
220 setUpKeys: setUpKeys
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700221 });
222 ttbs.createToolbar();
223 }
224
Simon Huntcacce342015-01-07 16:13:05 -0800225 // --- Glyphs, Icons, and the like -----------------------------------
226
Simon Hunt6cc53692015-01-07 11:33:45 -0800227 function setUpDefs() {
Simon Huntcacce342015-01-07 16:13:05 -0800228 defs = svg.append('defs');
Simon Hunt6cc53692015-01-07 11:33:45 -0800229 gs.loadDefs(defs);
Simon Hunt0ee28682015-02-12 20:48:11 -0800230 sus.loadGlowDefs(defs);
Simon Hunt6cc53692015-01-07 11:33:45 -0800231 }
232
233
Simon Huntcacce342015-01-07 16:13:05 -0800234 // --- Pan and Zoom --------------------------------------------------
235
236 // zoom enabled predicate. ev is a D3 source event.
237 function zoomEnabled(ev) {
Simon Huntd552ee92015-04-02 17:06:35 -0700238 return fs.isMobile() || (ev.metaKey || ev.altKey);
Simon Huntcacce342015-01-07 16:13:05 -0800239 }
240
241 function zoomCallback() {
Simon Huntbb5e0d82015-04-16 14:25:46 -0700242 var sc = zoomer.scale(),
243 tr = zoomer.translate();
244
245 ps.setPrefs('topo_zoom', {tx:tr[0], ty:tr[1], sc:sc});
Simon Huntcacce342015-01-07 16:13:05 -0800246
Simon Hunt0541fb82015-01-14 18:59:57 -0800247 // keep the map lines constant width while zooming
Simon Hunt737c89f2015-01-28 12:23:19 -0800248 mapG.style('stroke-width', (2.0 / sc) + 'px');
Simon Huntcacce342015-01-07 16:13:05 -0800249 }
250
251 function setUpZoom() {
Simon Hunta7b6a6b2015-01-13 19:53:09 -0800252 zoomLayer = svg.append('g').attr('id', 'topo-zoomlayer');
Simon Huntcacce342015-01-07 16:13:05 -0800253 zoomer = zs.createZoomer({
254 svg: svg,
255 zoomLayer: zoomLayer,
256 zoomEnabled: zoomEnabled,
257 zoomCallback: zoomCallback
258 });
259 }
260
261
Simon Hunt0541fb82015-01-14 18:59:57 -0800262 // callback invoked when the SVG view has been resized..
Simon Hunt3a6eec02015-02-09 21:16:43 -0800263 function svgResized(s) {
264 tfs.newDim([s.width, s.height]);
Simon Hunt0541fb82015-01-14 18:59:57 -0800265 }
266
Simon Hunta7b6a6b2015-01-13 19:53:09 -0800267 // --- Background Map ------------------------------------------------
268
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800269 function setUpNoDevs() {
270 var g, box;
271 noDevsLayer = svg.append('g').attr({
272 id: 'topo-noDevsLayer',
273 transform: sus.translate(500,500)
274 });
275 // Note, SVG viewbox is '0 0 1000 1000', defined in topo.html.
276 // We are translating this layer to have its origin at the center
277
278 g = noDevsLayer.append('g');
279 gs.addGlyph(g, 'bird', 100).attr('class', 'noDevsBird');
280 g.append('text').text('No devices are connected')
281 .attr({ x: 120, y: 80});
282
283 box = g.node().getBBox();
284 box.x -= box.width/2;
285 box.y -= box.height/2;
286 g.attr('transform', sus.translate(box.x, box.y));
287
288 showNoDevs(true);
289 }
290
291 function showNoDevs(b) {
Simon Hunt18bf9822015-02-12 17:35:45 -0800292 sus.visible(noDevsLayer, b);
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800293 }
294
Simon Hunt2362b072015-06-11 20:08:22 -0700295
296 var countryFilters = {
297 world: function (c) {
298 return c.properties.continent !== 'Antarctica';
299 },
300
301 // NOTE: for "usa" we are using our hand-crafted topojson file
302
303 s_america: function (c) {
304 return c.properties.continent === 'South America';
305 },
306
307 japan: function (c) {
308 return c.properties.geounit === 'Japan';
309 },
310
311 europe: function (c) {
312 return c.properties.continent === 'Europe';
313 },
314
315 italy: function (c) {
316 return c.properties.geounit === 'Italy';
317 },
318
319 uk: function (c) {
320 // technically, Ireland is not part of the United Kingdom,
321 // but the map looks weird without it showing.
322 return c.properties.adm0_a3 === 'GBR' ||
323 c.properties.adm0_a3 === 'IRL';
Simon Hunt1178d5b2015-09-02 17:02:37 -0700324 },
325
326 s_korea: function (c) {
327 return c.properties.adm0_a3 === 'KOR';
328 },
329
330 australia: function (c) {
331 return c.properties.adm0_a3 === 'AUS';
Simon Hunt2362b072015-06-11 20:08:22 -0700332 }
333 };
334
335
336 function setUpMap($loc) {
337 var s1 = $loc.search().mapid,
338 s2 = ps.getPrefs('topo_mapid'),
Simon Huntf65c3782015-06-12 13:33:48 -0700339 mapId = s1 || (s2 && s2.id) || 'usa',
Simon Hunt2362b072015-06-11 20:08:22 -0700340 promise,
341 cfilter,
342 opts;
343
Simon Hunt737c89f2015-01-28 12:23:19 -0800344 mapG = zoomLayer.append('g').attr('id', 'topo-map');
Simon Hunt2362b072015-06-11 20:08:22 -0700345 if (mapId === 'usa') {
346 promise = ms.loadMapInto(mapG, '*continental_us');
347 } else {
348 ps.setPrefs('topo_mapid', {id:mapId});
349 cfilter = countryFilters[mapId] || countryFilters.world;
350 opts = { countryFilter: cfilter };
351 promise = ms.loadMapRegionInto(mapG, opts);
352 }
353 return promise;
Simon Hunt0541fb82015-01-14 18:59:57 -0800354 }
355
Simon Huntc3c5b672015-02-20 11:32:13 -0800356 function opacifyMap(b) {
357 mapG.transition()
358 .duration(1000)
359 .attr('opacity', b ? 1 : 0);
360 }
Simon Hunt737c89f2015-01-28 12:23:19 -0800361
Simon Huntf9fc0e72015-04-16 15:10:57 -0700362 function setUpSprites($loc, tspr) {
363 var s1 = $loc.search().sprites,
364 s2 = ps.getPrefs('topo_sprites'),
365 sprId = s1 || (s2 && s2.id);
366
367 spriteG = zoomLayer.append ('g').attr('id', 'topo-sprites');
368 if (sprId) {
369 ps.setPrefs('topo_sprites', {id:sprId});
370 tspr.loadSprites(spriteG, defs, sprId);
371 }
372 }
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700373
Simon Huntc7ae7952015-04-08 18:59:27 -0700374 // --- User Preferemces ----------------------------------------------
Simon Hunt36a58c62015-04-08 11:00:07 -0700375
Simon Huntc7ae7952015-04-08 18:59:27 -0700376 var prefsState = {};
Simon Hunt36a58c62015-04-08 11:00:07 -0700377
Simon Huntc7ae7952015-04-08 18:59:27 -0700378 function updatePrefsState(what, b) {
379 prefsState[what] = b ? 1 : 0;
380 ps.setPrefs('topo_prefs', prefsState);
Simon Hunt36a58c62015-04-08 11:00:07 -0700381 }
382
Simon Hunt36a58c62015-04-08 11:00:07 -0700383
Simon Huntc7ae7952015-04-08 18:59:27 -0700384 function restoreConfigFromPrefs() {
385 // NOTE: toolbar will have set this for us..
Simon Huntfcbde892015-04-16 12:05:28 -0700386 prefsState = ps.asNumbers(ps.getPrefs('topo_prefs'));
Simon Hunt36a58c62015-04-08 11:00:07 -0700387
Simon Hunte1ce4292015-06-12 13:07:02 -0700388 $log.debug('TOPO- Prefs State:', prefsState);
Simon Huntc7ae7952015-04-08 18:59:27 -0700389
Simon Huntf41f3092015-04-16 10:33:26 -0700390 flash.enable(false);
Simon Huntc7ae7952015-04-08 18:59:27 -0700391 toggleInstances(prefsState.insts);
Simon Huntee7a3ce2015-04-09 13:28:37 -0700392 toggleSummary(prefsState.summary);
Simon Hunt239e5882015-04-23 15:07:04 -0700393 toggleUseDetailsFlag(prefsState.detail);
Bri Prebilic Cole9b80ca02015-08-03 11:26:54 -0700394 toggleHosts(prefsState.hosts);
395 toggleOffline(prefsState.offdev);
396 togglePorts(prefsState.porthl);
397 toggleMap(prefsState.bg);
Simon Huntf9fc0e72015-04-16 15:10:57 -0700398 toggleSprites(prefsState.spr);
Simon Huntf41f3092015-04-16 10:33:26 -0700399 flash.enable(true);
Simon Hunt36a58c62015-04-08 11:00:07 -0700400 }
401
402
Simon Hunte1ce4292015-06-12 13:07:02 -0700403 // somewhat hackish, because summary update cannot happen until we
404 // have opened the websocket to the server; hence this extra function
405 // invoked after tes.start()
406 function restoreSummaryFromPrefs() {
407 prefsState = ps.asNumbers(ps.getPrefs('topo_prefs'));
408 $log.debug('TOPO- Prefs SUMMARY State:', prefsState.summary);
409
410 flash.enable(false);
411 toggleSummary(prefsState.summary);
412 flash.enable(true);
413 }
414
Simon Hunt4a6b54b2015-10-27 22:08:25 -0700415 function topoStartDone() {
416 var d = $scope.intentData;
417 if (d) {
418 tts.selectIntent(d);
419 }
420 }
Simon Hunte1ce4292015-06-12 13:07:02 -0700421
Simon Huntcacce342015-01-07 16:13:05 -0800422 // --- Controller Definition -----------------------------------------
423
Simon Hunt6cc53692015-01-07 11:33:45 -0800424 angular.module('ovTopo', moduleDependencies)
Simon Hunt237676b52015-03-10 19:04:26 -0700425 .controller('OvTopoCtrl', ['$scope', '$log', '$location', '$timeout',
Simon Hunt36a58c62015-04-08 11:00:07 -0700426 '$cookies', 'FnService', 'MastService', 'KeyService', 'ZoomService',
Simon Hunt0e48c292015-02-19 16:11:37 -0800427 'GlyphService', 'MapService', 'SvgUtilService', 'FlashService',
Simon Hunta211f7f2015-11-09 12:48:23 -0800428 'WebSocketService', 'PrefsService', 'TopoDialogService',
Simon Huntb0ec1e52015-01-28 18:13:49 -0800429 'TopoEventService', 'TopoForceService', 'TopoPanelService',
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700430 'TopoInstService', 'TopoSelectService', 'TopoLinkService',
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -0700431 'TopoTrafficService', 'TopoObliqueService', 'TopoFilterService',
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700432 'TopoToolbarService', 'TopoSpriteService', 'TooltipService',
Simon Hunt72e44bf2015-07-21 21:34:20 -0700433 'TopoOverlayService',
Simon Hunt6cc53692015-01-07 11:33:45 -0800434
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700435 function (_$scope_, _$log_, $loc, $timeout, _$cookies_, _fs_, mast, _ks_,
Simon Hunta211f7f2015-11-09 12:48:23 -0800436 _zs_, _gs_, _ms_, _sus_, _flash_, _wss_, _ps_, _tds_, _tes_,
437 _tfs_, _tps_, _tis_, _tss_, _tls_, _tts_, _tos_, _fltr_,
438 _ttbs_, tspr, _ttip_, _tov_) {
Simon Hunt4a6b54b2015-10-27 22:08:25 -0700439 var params = $loc.search(),
440 projection,
Simon Hunt3a6eec02015-02-09 21:16:43 -0800441 dim,
Simon Hunt1894d792015-02-04 17:09:20 -0800442 uplink = {
443 // provides function calls back into this space
444 showNoDevs: showNoDevs,
445 projection: function () { return projection; },
Simon Huntc3c5b672015-02-20 11:32:13 -0800446 zoomLayer: function () { return zoomLayer; },
Simon Huntfb8ea1f2015-02-24 21:38:09 -0800447 zoomer: function () { return zoomer; },
Simon Hunt4a6b54b2015-10-27 22:08:25 -0700448 opacifyMap: opacifyMap,
449 topoStartDone: topoStartDone
Simon Huntac4c6f72015-02-03 19:50:53 -0800450 };
451
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700452 $scope = _$scope_;
Simon Hunt6cc53692015-01-07 11:33:45 -0800453 $log = _$log_;
Simon Hunt36a58c62015-04-08 11:00:07 -0700454 $cookies = _$cookies_;
Simon Hunta11b4eb2015-01-28 16:20:50 -0800455 fs = _fs_;
Simon Hunt6cc53692015-01-07 11:33:45 -0800456 ks = _ks_;
Simon Huntcacce342015-01-07 16:13:05 -0800457 zs = _zs_;
Simon Hunt6cc53692015-01-07 11:33:45 -0800458 gs = _gs_;
Simon Hunt1e8eff42015-01-08 17:19:02 -0800459 ms = _ms_;
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800460 sus = _sus_;
Simon Hunt0e48c292015-02-19 16:11:37 -0800461 flash = _flash_;
Simon Hunt237676b52015-03-10 19:04:26 -0700462 wss = _wss_;
Simon Huntc7ae7952015-04-08 18:59:27 -0700463 ps = _ps_;
Simon Hunta211f7f2015-11-09 12:48:23 -0800464 tds = _tds_;
Simon Huntc252aa62015-02-10 16:45:39 -0800465 tes = _tes_;
Simon Hunt737c89f2015-01-28 12:23:19 -0800466 tfs = _tfs_;
Simon Hunt96f88c62015-02-19 17:57:25 -0800467 // TODO: consider funnelling actions through TopoForceService...
468 // rather than injecting references to these 'sub-modules',
469 // just so we can invoke functions on them.
Simon Huntc252aa62015-02-10 16:45:39 -0800470 tps = _tps_;
Simon Huntac4c6f72015-02-03 19:50:53 -0800471 tis = _tis_;
Simon Hunt6036b192015-02-11 11:20:26 -0800472 tss = _tss_;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700473 tls = _tls_;
Simon Huntf542d842015-02-11 16:20:33 -0800474 tts = _tts_;
Simon Hunt96f88c62015-02-19 17:57:25 -0800475 tos = _tos_;
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -0700476 fltr = _fltr_;
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700477 ttbs = _ttbs_;
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700478 ttip = _ttip_;
Simon Hunt72e44bf2015-07-21 21:34:20 -0700479 tov = _tov_;
Simon Huntef31fb22014-12-19 13:16:44 -0800480
Simon Hunt4a6b54b2015-10-27 22:08:25 -0700481 if (params.intentKey && params.intentAppId && params.intentAppName) {
482 $scope.intentData = {
483 key: params.intentKey,
484 appId: params.intentAppId,
485 appName: params.intentAppName
486 };
487 }
488
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700489 $scope.notifyResize = function () {
Simon Huntb0ec1e52015-01-28 18:13:49 -0800490 svgResized(fs.windowSize(mast.mastHeight()));
Simon Hunt426bd862015-01-14 16:48:41 -0800491 };
Simon Huntef31fb22014-12-19 13:16:44 -0800492
Simon Hunt54442fa2015-01-26 14:17:38 -0800493 // Cleanup on destroyed scope..
Simon Hunt584122a2015-01-21 15:32:40 -0800494 $scope.$on('$destroy', function () {
495 $log.log('OvTopoCtrl is saying Buh-Bye!');
Thomas Vachuska329af532015-03-10 02:08:33 -0700496 tes.stop();
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -0700497 ks.unbindKeys();
Simon Hunt626d2102015-01-29 11:54:50 -0800498 tps.destroyPanels();
Simon Hunta211f7f2015-11-09 12:48:23 -0800499 tds.closeDialog();
Simon Hunt4b668592015-01-29 17:33:53 -0800500 tis.destroyInst();
Simon Hunt3a6eec02015-02-09 21:16:43 -0800501 tfs.destroyForce();
Bri Prebilic Coled6219052015-03-19 14:34:02 -0700502 ttbs.destroyToolbar();
Simon Hunt584122a2015-01-21 15:32:40 -0800503 });
504
Simon Huntcacce342015-01-07 16:13:05 -0800505 // svg layer and initialization of components
Simon Hunt426bd862015-01-14 16:48:41 -0800506 ovtopo = d3.select('#ov-topo');
507 svg = ovtopo.select('svg');
Simon Hunta11b4eb2015-01-28 16:20:50 -0800508 // set the svg size to match that of the window, less the masthead
509 svg.attr(fs.windowSize(mast.mastHeight()));
Simon Hunt3a6eec02015-02-09 21:16:43 -0800510 dim = [svg.attr('width'), svg.attr('height')];
Simon Hunt426bd862015-01-14 16:48:41 -0800511
Simon Hunt6cc53692015-01-07 11:33:45 -0800512 setUpKeys();
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700513 setUpToolbar();
Simon Hunt6cc53692015-01-07 11:33:45 -0800514 setUpDefs();
Simon Huntcacce342015-01-07 16:13:05 -0800515 setUpZoom();
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800516 setUpNoDevs();
Simon Hunt2362b072015-06-11 20:08:22 -0700517 setUpMap($loc).then(
Simon Hunt1894d792015-02-04 17:09:20 -0800518 function (proj) {
Simon Huntbb5e0d82015-04-16 14:25:46 -0700519 var z = ps.getPrefs('topo_zoom') || {tx:0, ty:0, sc:1};
520 zoomer.panZoom([z.tx, z.ty], z.sc);
521 $log.debug('** Zoom restored:', z);
522
Simon Hunt1894d792015-02-04 17:09:20 -0800523 projection = proj;
Simon Huntbb5e0d82015-04-16 14:25:46 -0700524 $log.debug('** We installed the projection:', proj);
Simon Huntf41f3092015-04-16 10:33:26 -0700525 flash.enable(false);
Simon Huntc7ae7952015-04-08 18:59:27 -0700526 toggleMap(prefsState.bg);
Simon Huntf41f3092015-04-16 10:33:26 -0700527 flash.enable(true);
Simon Hunte1ce4292015-06-12 13:07:02 -0700528
529 // now we have the map projection, we are ready for
530 // the server to send us device/host data...
531 tes.start();
532 // need to do the following so we immediately get
533 // the summary panel data back from the server
534 restoreSummaryFromPrefs();
Simon Hunt1894d792015-02-04 17:09:20 -0800535 }
536 );
Simon Huntf9fc0e72015-04-16 15:10:57 -0700537 setUpSprites($loc, tspr);
Simon Huntfd1231a2015-01-26 22:14:51 -0800538
Simon Hunt1894d792015-02-04 17:09:20 -0800539 forceG = zoomLayer.append('g').attr('id', 'topo-force');
Simon Huntfb8ea1f2015-02-24 21:38:09 -0800540 tfs.initForce(svg, forceG, uplink, dim);
Simon Hunta142dd22015-02-12 22:07:51 -0800541 tis.initInst({ showMastership: tfs.showMastership });
Simon Hunt237676b52015-03-10 19:04:26 -0700542 tps.initPanels();
Simon Hunt6cc53692015-01-07 11:33:45 -0800543
Simon Hunt36a58c62015-04-08 11:00:07 -0700544 // temporary solution for persisting user settings
Simon Huntc7ae7952015-04-08 18:59:27 -0700545 restoreConfigFromPrefs();
Simon Hunta5b53af2015-10-12 15:56:40 -0700546 ttbs.setDefaultOverlay();
Simon Hunt36a58c62015-04-08 11:00:07 -0700547
Simon Hunt72e44bf2015-07-21 21:34:20 -0700548 $log.debug('registered overlays...', tov.list());
Simon Hunt6cc53692015-01-07 11:33:45 -0800549 $log.log('OvTopoCtrl has been created');
Simon Huntef31fb22014-12-19 13:16:44 -0800550 }]);
551}());