blob: 3564eb330eb33c2ea929d5f63171ed942303b10e [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
Simon Huntac099e82015-12-03 09:17:47 -0800307 ns_america: function (c) {
308 return c.properties.custom === 'US-cont' ||
309 c.properties.subregion === 'Central America' ||
Simon Huntd4712622015-12-02 11:19:50 -0800310 c.properties.continent === 'South America';
311 },
312
Simon Hunt2362b072015-06-11 20:08:22 -0700313 japan: function (c) {
314 return c.properties.geounit === 'Japan';
315 },
316
317 europe: function (c) {
318 return c.properties.continent === 'Europe';
319 },
320
321 italy: function (c) {
322 return c.properties.geounit === 'Italy';
323 },
324
325 uk: function (c) {
326 // technically, Ireland is not part of the United Kingdom,
327 // but the map looks weird without it showing.
328 return c.properties.adm0_a3 === 'GBR' ||
329 c.properties.adm0_a3 === 'IRL';
Simon Hunt1178d5b2015-09-02 17:02:37 -0700330 },
331
332 s_korea: function (c) {
333 return c.properties.adm0_a3 === 'KOR';
334 },
335
336 australia: function (c) {
337 return c.properties.adm0_a3 === 'AUS';
Simon Hunt2362b072015-06-11 20:08:22 -0700338 }
339 };
340
341
342 function setUpMap($loc) {
343 var s1 = $loc.search().mapid,
344 s2 = ps.getPrefs('topo_mapid'),
Simon Huntf65c3782015-06-12 13:33:48 -0700345 mapId = s1 || (s2 && s2.id) || 'usa',
Simon Hunt2362b072015-06-11 20:08:22 -0700346 promise,
347 cfilter,
348 opts;
349
Simon Hunt737c89f2015-01-28 12:23:19 -0800350 mapG = zoomLayer.append('g').attr('id', 'topo-map');
Simon Hunt2362b072015-06-11 20:08:22 -0700351 if (mapId === 'usa') {
352 promise = ms.loadMapInto(mapG, '*continental_us');
353 } else {
354 ps.setPrefs('topo_mapid', {id:mapId});
355 cfilter = countryFilters[mapId] || countryFilters.world;
356 opts = { countryFilter: cfilter };
357 promise = ms.loadMapRegionInto(mapG, opts);
358 }
359 return promise;
Simon Hunt0541fb82015-01-14 18:59:57 -0800360 }
361
Simon Huntc3c5b672015-02-20 11:32:13 -0800362 function opacifyMap(b) {
363 mapG.transition()
364 .duration(1000)
365 .attr('opacity', b ? 1 : 0);
366 }
Simon Hunt737c89f2015-01-28 12:23:19 -0800367
Simon Huntf9fc0e72015-04-16 15:10:57 -0700368 function setUpSprites($loc, tspr) {
369 var s1 = $loc.search().sprites,
370 s2 = ps.getPrefs('topo_sprites'),
371 sprId = s1 || (s2 && s2.id);
372
373 spriteG = zoomLayer.append ('g').attr('id', 'topo-sprites');
374 if (sprId) {
375 ps.setPrefs('topo_sprites', {id:sprId});
376 tspr.loadSprites(spriteG, defs, sprId);
377 }
378 }
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700379
Simon Huntc7ae7952015-04-08 18:59:27 -0700380 // --- User Preferemces ----------------------------------------------
Simon Hunt36a58c62015-04-08 11:00:07 -0700381
Simon Huntc7ae7952015-04-08 18:59:27 -0700382 var prefsState = {};
Simon Hunt36a58c62015-04-08 11:00:07 -0700383
Simon Huntc7ae7952015-04-08 18:59:27 -0700384 function updatePrefsState(what, b) {
385 prefsState[what] = b ? 1 : 0;
386 ps.setPrefs('topo_prefs', prefsState);
Simon Hunt36a58c62015-04-08 11:00:07 -0700387 }
388
Simon Hunt36a58c62015-04-08 11:00:07 -0700389
Simon Huntc7ae7952015-04-08 18:59:27 -0700390 function restoreConfigFromPrefs() {
391 // NOTE: toolbar will have set this for us..
Simon Huntfcbde892015-04-16 12:05:28 -0700392 prefsState = ps.asNumbers(ps.getPrefs('topo_prefs'));
Simon Hunt36a58c62015-04-08 11:00:07 -0700393
Simon Hunte1ce4292015-06-12 13:07:02 -0700394 $log.debug('TOPO- Prefs State:', prefsState);
Simon Huntc7ae7952015-04-08 18:59:27 -0700395
Simon Huntf41f3092015-04-16 10:33:26 -0700396 flash.enable(false);
Simon Huntc7ae7952015-04-08 18:59:27 -0700397 toggleInstances(prefsState.insts);
Simon Huntee7a3ce2015-04-09 13:28:37 -0700398 toggleSummary(prefsState.summary);
Simon Hunt239e5882015-04-23 15:07:04 -0700399 toggleUseDetailsFlag(prefsState.detail);
Bri Prebilic Cole9b80ca02015-08-03 11:26:54 -0700400 toggleHosts(prefsState.hosts);
401 toggleOffline(prefsState.offdev);
402 togglePorts(prefsState.porthl);
403 toggleMap(prefsState.bg);
Simon Huntf9fc0e72015-04-16 15:10:57 -0700404 toggleSprites(prefsState.spr);
Simon Huntf41f3092015-04-16 10:33:26 -0700405 flash.enable(true);
Simon Hunt36a58c62015-04-08 11:00:07 -0700406 }
407
408
Simon Hunte1ce4292015-06-12 13:07:02 -0700409 // somewhat hackish, because summary update cannot happen until we
410 // have opened the websocket to the server; hence this extra function
411 // invoked after tes.start()
412 function restoreSummaryFromPrefs() {
413 prefsState = ps.asNumbers(ps.getPrefs('topo_prefs'));
414 $log.debug('TOPO- Prefs SUMMARY State:', prefsState.summary);
415
416 flash.enable(false);
417 toggleSummary(prefsState.summary);
418 flash.enable(true);
419 }
420
Simon Hunt4a6b54b2015-10-27 22:08:25 -0700421 function topoStartDone() {
422 var d = $scope.intentData;
423 if (d) {
424 tts.selectIntent(d);
425 }
426 }
Simon Hunte1ce4292015-06-12 13:07:02 -0700427
Simon Huntcacce342015-01-07 16:13:05 -0800428 // --- Controller Definition -----------------------------------------
429
Simon Hunt6cc53692015-01-07 11:33:45 -0800430 angular.module('ovTopo', moduleDependencies)
Simon Hunt237676b52015-03-10 19:04:26 -0700431 .controller('OvTopoCtrl', ['$scope', '$log', '$location', '$timeout',
Simon Hunt36a58c62015-04-08 11:00:07 -0700432 '$cookies', 'FnService', 'MastService', 'KeyService', 'ZoomService',
Simon Hunt0e48c292015-02-19 16:11:37 -0800433 'GlyphService', 'MapService', 'SvgUtilService', 'FlashService',
Simon Hunta211f7f2015-11-09 12:48:23 -0800434 'WebSocketService', 'PrefsService', 'TopoDialogService',
Simon Huntb0ec1e52015-01-28 18:13:49 -0800435 'TopoEventService', 'TopoForceService', 'TopoPanelService',
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700436 'TopoInstService', 'TopoSelectService', 'TopoLinkService',
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -0700437 'TopoTrafficService', 'TopoObliqueService', 'TopoFilterService',
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700438 'TopoToolbarService', 'TopoSpriteService', 'TooltipService',
Simon Hunt72e44bf2015-07-21 21:34:20 -0700439 'TopoOverlayService',
Simon Hunt6cc53692015-01-07 11:33:45 -0800440
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700441 function (_$scope_, _$log_, $loc, $timeout, _$cookies_, _fs_, mast, _ks_,
Simon Hunta211f7f2015-11-09 12:48:23 -0800442 _zs_, _gs_, _ms_, _sus_, _flash_, _wss_, _ps_, _tds_, _tes_,
443 _tfs_, _tps_, _tis_, _tss_, _tls_, _tts_, _tos_, _fltr_,
444 _ttbs_, tspr, _ttip_, _tov_) {
Simon Hunt4a6b54b2015-10-27 22:08:25 -0700445 var params = $loc.search(),
446 projection,
Simon Hunt3a6eec02015-02-09 21:16:43 -0800447 dim,
Simon Hunt1894d792015-02-04 17:09:20 -0800448 uplink = {
449 // provides function calls back into this space
450 showNoDevs: showNoDevs,
451 projection: function () { return projection; },
Simon Huntc3c5b672015-02-20 11:32:13 -0800452 zoomLayer: function () { return zoomLayer; },
Simon Huntfb8ea1f2015-02-24 21:38:09 -0800453 zoomer: function () { return zoomer; },
Simon Hunt4a6b54b2015-10-27 22:08:25 -0700454 opacifyMap: opacifyMap,
455 topoStartDone: topoStartDone
Simon Huntac4c6f72015-02-03 19:50:53 -0800456 };
457
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700458 $scope = _$scope_;
Simon Hunt6cc53692015-01-07 11:33:45 -0800459 $log = _$log_;
Simon Hunt36a58c62015-04-08 11:00:07 -0700460 $cookies = _$cookies_;
Simon Hunta11b4eb2015-01-28 16:20:50 -0800461 fs = _fs_;
Simon Hunt6cc53692015-01-07 11:33:45 -0800462 ks = _ks_;
Simon Huntcacce342015-01-07 16:13:05 -0800463 zs = _zs_;
Simon Hunt6cc53692015-01-07 11:33:45 -0800464 gs = _gs_;
Simon Hunt1e8eff42015-01-08 17:19:02 -0800465 ms = _ms_;
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800466 sus = _sus_;
Simon Hunt0e48c292015-02-19 16:11:37 -0800467 flash = _flash_;
Simon Hunt237676b52015-03-10 19:04:26 -0700468 wss = _wss_;
Simon Huntc7ae7952015-04-08 18:59:27 -0700469 ps = _ps_;
Simon Hunta211f7f2015-11-09 12:48:23 -0800470 tds = _tds_;
Simon Huntc252aa62015-02-10 16:45:39 -0800471 tes = _tes_;
Simon Hunt737c89f2015-01-28 12:23:19 -0800472 tfs = _tfs_;
Simon Hunt96f88c62015-02-19 17:57:25 -0800473 // TODO: consider funnelling actions through TopoForceService...
474 // rather than injecting references to these 'sub-modules',
475 // just so we can invoke functions on them.
Simon Huntc252aa62015-02-10 16:45:39 -0800476 tps = _tps_;
Simon Huntac4c6f72015-02-03 19:50:53 -0800477 tis = _tis_;
Simon Hunt6036b192015-02-11 11:20:26 -0800478 tss = _tss_;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700479 tls = _tls_;
Simon Huntf542d842015-02-11 16:20:33 -0800480 tts = _tts_;
Simon Hunt96f88c62015-02-19 17:57:25 -0800481 tos = _tos_;
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -0700482 fltr = _fltr_;
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700483 ttbs = _ttbs_;
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700484 ttip = _ttip_;
Simon Hunt72e44bf2015-07-21 21:34:20 -0700485 tov = _tov_;
Simon Huntef31fb22014-12-19 13:16:44 -0800486
Simon Hunt4a6b54b2015-10-27 22:08:25 -0700487 if (params.intentKey && params.intentAppId && params.intentAppName) {
488 $scope.intentData = {
489 key: params.intentKey,
490 appId: params.intentAppId,
491 appName: params.intentAppName
492 };
493 }
494
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700495 $scope.notifyResize = function () {
Simon Huntb0ec1e52015-01-28 18:13:49 -0800496 svgResized(fs.windowSize(mast.mastHeight()));
Simon Hunt426bd862015-01-14 16:48:41 -0800497 };
Simon Huntef31fb22014-12-19 13:16:44 -0800498
Simon Hunt54442fa2015-01-26 14:17:38 -0800499 // Cleanup on destroyed scope..
Simon Hunt584122a2015-01-21 15:32:40 -0800500 $scope.$on('$destroy', function () {
501 $log.log('OvTopoCtrl is saying Buh-Bye!');
Thomas Vachuska329af532015-03-10 02:08:33 -0700502 tes.stop();
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -0700503 ks.unbindKeys();
Simon Hunt626d2102015-01-29 11:54:50 -0800504 tps.destroyPanels();
Simon Hunta211f7f2015-11-09 12:48:23 -0800505 tds.closeDialog();
Simon Hunt4b668592015-01-29 17:33:53 -0800506 tis.destroyInst();
Simon Hunt3a6eec02015-02-09 21:16:43 -0800507 tfs.destroyForce();
Bri Prebilic Coled6219052015-03-19 14:34:02 -0700508 ttbs.destroyToolbar();
Simon Hunt584122a2015-01-21 15:32:40 -0800509 });
510
Simon Huntcacce342015-01-07 16:13:05 -0800511 // svg layer and initialization of components
Simon Hunt426bd862015-01-14 16:48:41 -0800512 ovtopo = d3.select('#ov-topo');
513 svg = ovtopo.select('svg');
Simon Hunta11b4eb2015-01-28 16:20:50 -0800514 // set the svg size to match that of the window, less the masthead
515 svg.attr(fs.windowSize(mast.mastHeight()));
Simon Hunt3a6eec02015-02-09 21:16:43 -0800516 dim = [svg.attr('width'), svg.attr('height')];
Simon Hunt426bd862015-01-14 16:48:41 -0800517
Simon Hunt6cc53692015-01-07 11:33:45 -0800518 setUpKeys();
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700519 setUpToolbar();
Simon Hunt6cc53692015-01-07 11:33:45 -0800520 setUpDefs();
Simon Huntcacce342015-01-07 16:13:05 -0800521 setUpZoom();
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800522 setUpNoDevs();
Simon Hunt2362b072015-06-11 20:08:22 -0700523 setUpMap($loc).then(
Simon Hunt1894d792015-02-04 17:09:20 -0800524 function (proj) {
Simon Huntbb5e0d82015-04-16 14:25:46 -0700525 var z = ps.getPrefs('topo_zoom') || {tx:0, ty:0, sc:1};
526 zoomer.panZoom([z.tx, z.ty], z.sc);
527 $log.debug('** Zoom restored:', z);
528
Simon Hunt1894d792015-02-04 17:09:20 -0800529 projection = proj;
Simon Huntbb5e0d82015-04-16 14:25:46 -0700530 $log.debug('** We installed the projection:', proj);
Simon Huntf41f3092015-04-16 10:33:26 -0700531 flash.enable(false);
Simon Huntc7ae7952015-04-08 18:59:27 -0700532 toggleMap(prefsState.bg);
Simon Huntf41f3092015-04-16 10:33:26 -0700533 flash.enable(true);
Simon Hunte1ce4292015-06-12 13:07:02 -0700534
535 // now we have the map projection, we are ready for
536 // the server to send us device/host data...
537 tes.start();
538 // need to do the following so we immediately get
539 // the summary panel data back from the server
540 restoreSummaryFromPrefs();
Simon Hunt1894d792015-02-04 17:09:20 -0800541 }
542 );
Simon Huntf9fc0e72015-04-16 15:10:57 -0700543 setUpSprites($loc, tspr);
Simon Huntfd1231a2015-01-26 22:14:51 -0800544
Simon Hunt1894d792015-02-04 17:09:20 -0800545 forceG = zoomLayer.append('g').attr('id', 'topo-force');
Simon Huntfb8ea1f2015-02-24 21:38:09 -0800546 tfs.initForce(svg, forceG, uplink, dim);
Simon Hunta142dd22015-02-12 22:07:51 -0800547 tis.initInst({ showMastership: tfs.showMastership });
Simon Hunt237676b52015-03-10 19:04:26 -0700548 tps.initPanels();
Simon Hunt6cc53692015-01-07 11:33:45 -0800549
Simon Hunt36a58c62015-04-08 11:00:07 -0700550 // temporary solution for persisting user settings
Simon Huntc7ae7952015-04-08 18:59:27 -0700551 restoreConfigFromPrefs();
Simon Hunta5b53af2015-10-12 15:56:40 -0700552 ttbs.setDefaultOverlay();
Simon Hunt36a58c62015-04-08 11:00:07 -0700553
Simon Hunt72e44bf2015-07-21 21:34:20 -0700554 $log.debug('registered overlays...', tov.list());
Simon Hunt6cc53692015-01-07 11:33:45 -0800555 $log.log('OvTopoCtrl has been created');
Simon Huntef31fb22014-12-19 13:16:44 -0800556 }]);
557}());