blob: 29f149f86bd77c760c06c3505f4bf46a4ffb551c [file] [log] [blame]
Simon Huntef31fb22014-12-19 13:16:44 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present 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
Simon Hunta4281242016-02-26 20:18:45 -080031 // references to injected services
Simon Hunt7faabd52016-08-18 16:16:19 -070032 var $scope, $log, $loc, $timeout, $cookies,
33 fs, ks, zs, gs, ms, sus, flash, wss, ps, th, tds, t3s, tes, tfs, tps,
34 tis, tms, tss, tls, tts, tos, fltr, ttbs, tspr, ttip, tov;
Simon Hunt6cc53692015-01-07 11:33:45 -080035
36 // DOM elements
Simon Hunt2052e5d2015-04-13 17:40:44 -070037 var ovtopo, svg, defs, zoomLayer, mapG, spriteG, forceG, noDevsLayer;
Simon Hunt6cc53692015-01-07 11:33:45 -080038
39 // Internal state
Simon Huntf51bf462016-06-29 16:22:57 -070040 var zoomer, actionMap;
Simon Hunt6cc53692015-01-07 11:33:45 -080041
Simon Huntcacce342015-01-07 16:13:05 -080042 // --- Short Cut Keys ------------------------------------------------
43
Simon Hunt8d22c4b2015-08-06 16:24:43 -070044 function setUpKeys(overlayKeys) {
Simon Hunt5724fb42015-02-05 16:59:40 -080045 // key bindings need to be made after the services have been injected
46 // thus, deferred to here...
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070047 actionMap = {
Simon Hunt36a58c62015-04-08 11:00:07 -070048 I: [toggleInstances, 'Toggle ONOS instances panel'],
Simon Huntee7a3ce2015-04-09 13:28:37 -070049 O: [toggleSummary, 'Toggle ONOS summary panel'],
Simon Hunt239e5882015-04-23 15:07:04 -070050 D: [toggleUseDetailsFlag, 'Disable / enable details panel'],
Simon Huntac4c6f72015-02-03 19:50:53 -080051
Simon Huntfcbde892015-04-16 12:05:28 -070052 H: [toggleHosts, 'Toggle host visibility'],
53 M: [toggleOffline, 'Toggle offline visibility'],
54 P: [togglePorts, 'Toggle Port Highlighting'],
Simon Hunt86b7c882015-04-02 23:06:08 -070055 dash: [tfs.showBadLinks, 'Show bad links'],
Thomas Vachuska26be4f32016-03-31 01:10:27 -070056 B: [toggleMap, 'Toggle background geo map'],
57 G: [openMapSelection, 'Select background geo map'],
Simon Hunt2052e5d2015-04-13 17:40:44 -070058 S: [toggleSprites, 'Toggle sprite layer'],
Simon Huntac4c6f72015-02-03 19:50:53 -080059
Simon Huntfd7106c2016-02-09 15:05:26 -080060 X: [tfs.resetAllLocations, 'Reset node locations'],
Simon Hunt96f88c62015-02-19 17:57:25 -080061 Z: [tos.toggleOblique, 'Toggle oblique view (Experimental)'],
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070062 N: [fltr.clickAction, 'Cycle node layers'],
Simon Hunt5724fb42015-02-05 16:59:40 -080063 L: [tfs.cycleDeviceLabels, 'Cycle device labels'],
Simon Hunt10618f62017-06-15 19:30:52 -070064 'shift-L': [tfs.cycleHostLabels, 'Cycle host labels'],
Simon Hunt445e8152015-02-06 13:00:12 -080065 U: [tfs.unpin, 'Unpin node (hover mouse over)'],
Simon Hunt5724fb42015-02-05 16:59:40 -080066 R: [resetZoom, 'Reset pan / zoom'],
Simon Hunt90dcc3e2015-03-25 15:01:27 -070067 dot: [ttbs.toggleToolbar, 'Toggle Toolbar'],
Simon Huntac4c6f72015-02-03 19:50:53 -080068
Simon Hunt0e48c292015-02-19 16:11:37 -080069 E: [equalizeMasters, 'Equalize mastership roles'],
Simon Huntac4c6f72015-02-03 19:50:53 -080070
Simon Hunta9761342016-06-10 18:02:53 -070071 //-- instance color palette debug
72 // 9: function () { sus.cat7().testCard(svg); },
73
Simon Hunt5b024d72016-01-29 11:02:43 -080074 // topology overlay selections
75 F1: function () { ttbs.fnkey(0); },
76 F2: function () { ttbs.fnkey(1); },
77 F3: function () { ttbs.fnkey(2); },
78 F4: function () { ttbs.fnkey(3); },
79 F5: function () { ttbs.fnkey(4); },
80
Simon Hunt08f841d02015-02-10 14:39:20 -080081 esc: handleEscape,
Simon Huntac4c6f72015-02-03 19:50:53 -080082
Simon Hunt09060142015-03-18 20:23:32 -070083 _keyListener: ttbs.keyListener,
84
Simon Hunt5724fb42015-02-05 16:59:40 -080085 _helpFormat: [
Thomas Vachuska26be4f32016-03-31 01:10:27 -070086 ['I', 'O', 'D', 'H', 'M', 'P', 'dash', 'B', 'G', 'S' ],
Simon Hunt10618f62017-06-15 19:30:52 -070087 ['X', 'Z', 'N', 'L', 'shift-L', 'U', 'R', '-', 'E', '-', 'dot'],
Simon Hunt8d22c4b2015-08-06 16:24:43 -070088 [] // this column reserved for overlay actions
Simon Hunt5724fb42015-02-05 16:59:40 -080089 ]
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070090 };
91
Simon Hunt8d22c4b2015-08-06 16:24:43 -070092 if (fs.isO(overlayKeys)) {
93 mergeKeys(overlayKeys);
94 }
95
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070096 ks.keyBindings(actionMap);
Simon Huntac4c6f72015-02-03 19:50:53 -080097
Simon Hunt639dc662015-02-18 14:19:20 -080098 ks.gestureNotes([
Simon Hunt5724fb42015-02-05 16:59:40 -080099 ['click', 'Select the item and show details'],
100 ['shift-click', 'Toggle selection state'],
101 ['drag', 'Reposition (and pin) device / host'],
102 ['cmd-scroll', 'Zoom in / out'],
103 ['cmd-drag', 'Pan']
Simon Hunt639dc662015-02-18 14:19:20 -0800104 ]);
Simon Hunt5724fb42015-02-05 16:59:40 -0800105 }
Simon Hunt6cc53692015-01-07 11:33:45 -0800106
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700107 // when a topology overlay is activated, we need to bind their keystrokes
108 // and include them in the quick-help panel
109 function mergeKeys(extra) {
110 var _hf = actionMap._helpFormat[2];
Simon Hunt71892222015-09-29 13:39:40 -0700111
112 ks.checkNotGlobal(extra);
113
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700114 extra._keyOrder.forEach(function (k) {
115 var d = extra[k],
116 cb = d && d.cb,
117 tt = d && d.tt;
118 // NOTE: ignore keys that are already defined
119 if (d && !actionMap[k]) {
120 actionMap[k] = [cb, tt];
121 _hf.push(k);
122 }
123 });
124 }
125
Simon Hunt08f841d02015-02-10 14:39:20 -0800126 // --- Keystroke functions -------------------------------------------
Simon Huntac4c6f72015-02-03 19:50:53 -0800127
Simon Hunt36a58c62015-04-08 11:00:07 -0700128 function toggleInstances(x) {
Simon Huntee7a3ce2015-04-09 13:28:37 -0700129 updatePrefsState('insts', tis.toggle(x));
Simon Huntac4c6f72015-02-03 19:50:53 -0800130 tfs.updateDeviceColors();
Simon Hunt6cc53692015-01-07 11:33:45 -0800131 }
Simon Huntac4c6f72015-02-03 19:50:53 -0800132
Simon Huntee7a3ce2015-04-09 13:28:37 -0700133 function toggleSummary(x) {
134 updatePrefsState('summary', tps.toggleSummary(x));
Simon Hunt18bf9822015-02-12 17:35:45 -0800135 }
136
Simon Hunt239e5882015-04-23 15:07:04 -0700137 function toggleUseDetailsFlag(x) {
138 updatePrefsState('detail', tps.toggleUseDetailsFlag(x));
Simon Huntee7a3ce2015-04-09 13:28:37 -0700139 }
140
Simon Huntfcbde892015-04-16 12:05:28 -0700141 function toggleHosts(x) {
142 updatePrefsState('hosts', tfs.toggleHosts(x));
143 }
144
145 function toggleOffline(x) {
146 updatePrefsState('offdev', tfs.toggleOffline(x));
147 }
148
149 function togglePorts(x) {
150 updatePrefsState('porthl', tfs.togglePorts(x));
151 }
152
153 function _togSvgLayer(x, G, tag, what) {
154 var on = (x === 'keyev') ? !sus.visible(G) : !!x,
Simon Huntee7a3ce2015-04-09 13:28:37 -0700155 verb = on ? 'Show' : 'Hide';
Simon Huntfcbde892015-04-16 12:05:28 -0700156 sus.visible(G, on);
157 updatePrefsState(tag, on);
158 flash.flash(verb + ' ' + what);
159 }
160
161 function toggleMap(x) {
162 _togSvgLayer(x, mapG, 'bg', 'background map');
Simon Huntee7a3ce2015-04-09 13:28:37 -0700163 }
Simon Hunt36a58c62015-04-08 11:00:07 -0700164
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700165 function openMapSelection() {
166 tms.openMapSelection();
167 }
168
Simon Hunt2052e5d2015-04-13 17:40:44 -0700169 function toggleSprites(x) {
Simon Huntfcbde892015-04-16 12:05:28 -0700170 _togSvgLayer(x, spriteG, 'spr', 'sprite layer');
Simon Hunt2052e5d2015-04-13 17:40:44 -0700171 }
172
Simon Hunt08f841d02015-02-10 14:39:20 -0800173 function resetZoom() {
174 zoomer.reset();
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -0700175 flash.flash('Pan and zoom reset');
Simon Hunt08f841d02015-02-10 14:39:20 -0800176 }
177
Simon Hunt0e48c292015-02-19 16:11:37 -0800178 function equalizeMasters() {
Simon Hunt237676b52015-03-10 19:04:26 -0700179 wss.sendEvent('equalizeMasters');
Simon Hunt0e48c292015-02-19 16:11:37 -0800180 flash.flash('Equalizing master roles');
181 }
182
Simon Hunt08f841d02015-02-10 14:39:20 -0800183 function handleEscape() {
Simon Hunta142dd22015-02-12 22:07:51 -0800184 if (tis.showMaster()) {
185 // if an instance is selected, cancel the affinity mapping
186 tis.cancelAffinity()
Simon Hunt08f841d02015-02-10 14:39:20 -0800187
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700188 } else if (tov.hooks.escape()) {
189 // else if the overlay consumed the ESC event...
190 // (work already done)
191
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700192 } else if (tss.deselectAll()) {
Simon Hunta0eb0a82015-02-11 12:30:06 -0800193 // else if we have node selections, deselect them all
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700194 // (work already done)
195
Prince Pereira46c82d42016-09-19 13:30:50 +0530196 } else if (tls.deselectAllLinks()) {
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700197 // else if we have a link selected, deselect it
198 // (work already done)
Simon Hunt08f841d02015-02-10 14:39:20 -0800199
Simon Hunta0eb0a82015-02-11 12:30:06 -0800200 } else if (tis.isVisible()) {
201 // else if the Instance Panel is visible, hide it
202 tis.hide();
203 tfs.updateDeviceColors();
Simon Hunt08f841d02015-02-10 14:39:20 -0800204
Simon Hunta0eb0a82015-02-11 12:30:06 -0800205 } else if (tps.summaryVisible()) {
206 // else if the Summary Panel is visible, hide it
Simon Hunt356da762016-05-27 11:54:02 -0700207 tps.hideSummary();
Simon Hunta0eb0a82015-02-11 12:30:06 -0800208 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800209 }
Simon Huntcacce342015-01-07 16:13:05 -0800210
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700211 // --- Toolbar Functions ---------------------------------------------
212
Bri Prebilic Cole2efc7152015-04-29 15:47:06 -0700213 function notValid(what) {
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700214 $log.warn('topo.js getActionEntry(): Not a valid ' + what);
Bri Prebilic Cole2efc7152015-04-29 15:47:06 -0700215 }
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700216
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700217 function getActionEntry(key) {
Bri Prebilic Cole2efc7152015-04-29 15:47:06 -0700218 var entry;
219
220 if (!key) {
221 notValid('key');
222 return null;
223 }
224
225 entry = actionMap[key];
226
227 if (!entry) {
228 notValid('actionMap entry');
229 return null;
230 }
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700231 return fs.isA(entry) || [entry, ''];
232 }
233
234 function setUpToolbar() {
235 ttbs.init({
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700236 getActionEntry: getActionEntry,
237 setUpKeys: setUpKeys
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700238 });
239 ttbs.createToolbar();
240 }
241
Simon Huntcacce342015-01-07 16:13:05 -0800242 // --- Glyphs, Icons, and the like -----------------------------------
243
Simon Hunt6cc53692015-01-07 11:33:45 -0800244 function setUpDefs() {
Simon Huntcacce342015-01-07 16:13:05 -0800245 defs = svg.append('defs');
Simon Hunt6cc53692015-01-07 11:33:45 -0800246 gs.loadDefs(defs);
Simon Hunt0ee28682015-02-12 20:48:11 -0800247 sus.loadGlowDefs(defs);
Simon Hunt6cc53692015-01-07 11:33:45 -0800248 }
249
250
Simon Huntcacce342015-01-07 16:13:05 -0800251 // --- Pan and Zoom --------------------------------------------------
252
253 // zoom enabled predicate. ev is a D3 source event.
254 function zoomEnabled(ev) {
Simon Huntd552ee92015-04-02 17:06:35 -0700255 return fs.isMobile() || (ev.metaKey || ev.altKey);
Simon Huntcacce342015-01-07 16:13:05 -0800256 }
257
258 function zoomCallback() {
Simon Huntbb5e0d82015-04-16 14:25:46 -0700259 var sc = zoomer.scale(),
260 tr = zoomer.translate();
261
262 ps.setPrefs('topo_zoom', {tx:tr[0], ty:tr[1], sc:sc});
Simon Huntcacce342015-01-07 16:13:05 -0800263
Simon Hunt0541fb82015-01-14 18:59:57 -0800264 // keep the map lines constant width while zooming
Simon Hunt737c89f2015-01-28 12:23:19 -0800265 mapG.style('stroke-width', (2.0 / sc) + 'px');
Steven Burrowsf17f0ab2017-04-11 11:03:58 -0700266
267 tfs.setNodeScale(sc);
Simon Huntcacce342015-01-07 16:13:05 -0800268 }
269
270 function setUpZoom() {
Simon Hunta7b6a6b2015-01-13 19:53:09 -0800271 zoomLayer = svg.append('g').attr('id', 'topo-zoomlayer');
Simon Huntcacce342015-01-07 16:13:05 -0800272 zoomer = zs.createZoomer({
273 svg: svg,
274 zoomLayer: zoomLayer,
275 zoomEnabled: zoomEnabled,
276 zoomCallback: zoomCallback
277 });
278 }
279
280
Simon Hunt0541fb82015-01-14 18:59:57 -0800281 // callback invoked when the SVG view has been resized..
Simon Hunt3a6eec02015-02-09 21:16:43 -0800282 function svgResized(s) {
283 tfs.newDim([s.width, s.height]);
Simon Hunt0541fb82015-01-14 18:59:57 -0800284 }
285
Simon Hunta7b6a6b2015-01-13 19:53:09 -0800286 // --- Background Map ------------------------------------------------
287
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800288 function setUpNoDevs() {
289 var g, box;
290 noDevsLayer = svg.append('g').attr({
291 id: 'topo-noDevsLayer',
292 transform: sus.translate(500,500)
293 });
294 // Note, SVG viewbox is '0 0 1000 1000', defined in topo.html.
295 // We are translating this layer to have its origin at the center
296
297 g = noDevsLayer.append('g');
298 gs.addGlyph(g, 'bird', 100).attr('class', 'noDevsBird');
299 g.append('text').text('No devices are connected')
300 .attr({ x: 120, y: 80});
301
302 box = g.node().getBBox();
303 box.x -= box.width/2;
304 box.y -= box.height/2;
305 g.attr('transform', sus.translate(box.x, box.y));
306
307 showNoDevs(true);
308 }
309
310 function showNoDevs(b) {
Simon Hunt18bf9822015-02-12 17:35:45 -0800311 sus.visible(noDevsLayer, b);
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800312 }
313
Simon Hunt2362b072015-06-11 20:08:22 -0700314
315 var countryFilters = {
Simon Hunt2362b072015-06-11 20:08:22 -0700316 s_america: function (c) {
317 return c.properties.continent === 'South America';
318 },
319
Simon Huntac099e82015-12-03 09:17:47 -0800320 ns_america: function (c) {
321 return c.properties.custom === 'US-cont' ||
322 c.properties.subregion === 'Central America' ||
Simon Huntd4712622015-12-02 11:19:50 -0800323 c.properties.continent === 'South America';
324 },
325
Simon Hunt2362b072015-06-11 20:08:22 -0700326 japan: function (c) {
327 return c.properties.geounit === 'Japan';
328 },
329
330 europe: function (c) {
331 return c.properties.continent === 'Europe';
332 },
333
334 italy: function (c) {
335 return c.properties.geounit === 'Italy';
336 },
337
338 uk: function (c) {
339 // technically, Ireland is not part of the United Kingdom,
340 // but the map looks weird without it showing.
341 return c.properties.adm0_a3 === 'GBR' ||
342 c.properties.adm0_a3 === 'IRL';
Simon Hunt1178d5b2015-09-02 17:02:37 -0700343 },
344
345 s_korea: function (c) {
346 return c.properties.adm0_a3 === 'KOR';
347 },
348
349 australia: function (c) {
350 return c.properties.adm0_a3 === 'AUS';
Simon Hunt2362b072015-06-11 20:08:22 -0700351 }
352 };
353
Simon Hunta34fcb52016-02-25 16:27:32 -0800354 var tintOn = 0,
355 shadeFlip = 0,
356 shadePalette = {
357 light: {
358 sea: 'aliceblue',
359 land: 'white',
360 outline: '#ddd'
361 },
362 dark: {
363 sea: '#001830',
364 land: '#232331',
365 outline: '#3a3a3a'
366 }
367 };
368
369 function shading() {
370 return tintOn ? {
371 palette: shadePalette[th.theme()],
372 flip: shadeFlip
373 } : '';
374 }
Simon Hunt2362b072015-06-11 20:08:22 -0700375
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700376 function setMap(map) {
377 ps.setPrefs('topo_mapid', map);
Simon Hunt90053ed2016-04-06 12:49:02 -0700378 setUpMap();
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700379 opacifyMap(true);
380 }
381
382 function currentMap() {
383 return ps.getPrefs(
384 'topo_mapid',
Steven Burrows3a9a6442016-05-05 15:31:16 +0100385 {
386 mapid: 'usa',
387 mapscale: 1,
388 mapfilepath: '*continental_us',
389 tint: 'off'
390 },
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700391 $loc.search()
392 );
393 }
394
Simon Hunt90053ed2016-04-06 12:49:02 -0700395 function setUpMap() {
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700396 var prefs = currentMap(),
Simon Hunt8a119b02016-03-29 16:00:32 -0700397 mapId = prefs.mapid,
Steven Burrows3a9a6442016-05-05 15:31:16 +0100398 mapFilePath = prefs.mapfilepath,
Simon Hunt8a119b02016-03-29 16:00:32 -0700399 mapScale = prefs.mapscale,
400 tint = prefs.tint,
Simon Hunt2362b072015-06-11 20:08:22 -0700401 promise,
Simon Huntfacad992016-02-25 09:58:33 -0800402 cfilter;
Simon Hunt2362b072015-06-11 20:08:22 -0700403
Simon Hunta34fcb52016-02-25 16:27:32 -0800404 tintOn = tint === 'on' ? 1 : 0;
405
Simon Hunt18491362016-03-04 11:09:42 -0800406 $log.debug('setUpMap() mapId:', mapId, ', mapScale:', mapScale,
407 ', tint:', tint);
408
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700409 mapG = d3.select('#topo-map');
410 if (mapG.empty()) {
411 mapG = zoomLayer.append('g').attr('id', 'topo-map');
412 } else {
413 mapG.each(function(d,i) {
414 d3.selectAll(this.childNodes).remove();
415 });
416 }
Steven Burrows3a9a6442016-05-05 15:31:16 +0100417
418 if (mapFilePath === '*countries') {
419
Simon Hunt90053ed2016-04-06 12:49:02 -0700420 cfilter = countryFilters[mapId] || countryFilters.uk;
Steven Burrows3a9a6442016-05-05 15:31:16 +0100421
Simon Hunta34fcb52016-02-25 16:27:32 -0800422 promise = ms.loadMapRegionInto(mapG, {
423 countryFilter: cfilter,
424 adjustScale: mapScale,
425 shading: shading()
426 });
Steven Burrows3a9a6442016-05-05 15:31:16 +0100427 } else {
428
429 promise = ms.loadMapInto(mapG, mapFilePath, mapId, {
430 adjustScale: mapScale,
431 shading: shading()
432 });
Simon Hunt2362b072015-06-11 20:08:22 -0700433 }
Steven Burrows3a9a6442016-05-05 15:31:16 +0100434
Simon Hunt8a119b02016-03-29 16:00:32 -0700435 ps.setPrefs('topo_mapid', prefs);
Simon Hunt2362b072015-06-11 20:08:22 -0700436 return promise;
Simon Hunt0541fb82015-01-14 18:59:57 -0800437 }
438
Simon Huntf51bf462016-06-29 16:22:57 -0700439 function mapReshader() {
440 $log.debug('... Re-shading map ...')
441 ms.reshade(shading());
442 }
443
Simon Hunta34fcb52016-02-25 16:27:32 -0800444 // set up theme listener to re-shade the map when required.
445 function mapShader(on) {
446 if (on) {
Simon Huntf51bf462016-06-29 16:22:57 -0700447 th.addListener(mapReshader);
Simon Hunta34fcb52016-02-25 16:27:32 -0800448 } else {
Simon Huntf51bf462016-06-29 16:22:57 -0700449 th.removeListener(mapReshader);
Simon Hunta34fcb52016-02-25 16:27:32 -0800450 }
451 }
452
Simon Huntc3c5b672015-02-20 11:32:13 -0800453 function opacifyMap(b) {
454 mapG.transition()
455 .duration(1000)
456 .attr('opacity', b ? 1 : 0);
457 }
Simon Hunt737c89f2015-01-28 12:23:19 -0800458
Simon Hunt90053ed2016-04-06 12:49:02 -0700459 function setUpSprites() {
Simon Hunt8a119b02016-03-29 16:00:32 -0700460 var prefs = ps.getPrefs('topo_sprites', { sprites: '' }, $loc.search()),
461 sprId = prefs.sprites;
Simon Huntf9fc0e72015-04-16 15:10:57 -0700462
463 spriteG = zoomLayer.append ('g').attr('id', 'topo-sprites');
464 if (sprId) {
Simon Hunt8a119b02016-03-29 16:00:32 -0700465 ps.setPrefs('topo_sprites', prefs);
Simon Huntf9fc0e72015-04-16 15:10:57 -0700466 tspr.loadSprites(spriteG, defs, sprId);
467 }
468 }
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700469
Simon Huntc7ae7952015-04-08 18:59:27 -0700470 // --- User Preferemces ----------------------------------------------
Simon Hunt36a58c62015-04-08 11:00:07 -0700471
Simon Huntc7ae7952015-04-08 18:59:27 -0700472 var prefsState = {};
Simon Hunt36a58c62015-04-08 11:00:07 -0700473
Simon Huntc7ae7952015-04-08 18:59:27 -0700474 function updatePrefsState(what, b) {
475 prefsState[what] = b ? 1 : 0;
476 ps.setPrefs('topo_prefs', prefsState);
Simon Hunt36a58c62015-04-08 11:00:07 -0700477 }
478
Simon Hunt36a58c62015-04-08 11:00:07 -0700479
Simon Huntc7ae7952015-04-08 18:59:27 -0700480 function restoreConfigFromPrefs() {
481 // NOTE: toolbar will have set this for us..
Simon Huntfc5c5842017-02-01 23:32:18 -0800482 prefsState = ps.asNumbers(
483 ps.getPrefs('topo_prefs', ttbs.defaultPrefs), ['ovid'], true
484 );
Simon Hunt36a58c62015-04-08 11:00:07 -0700485
Simon Hunte1ce4292015-06-12 13:07:02 -0700486 $log.debug('TOPO- Prefs State:', prefsState);
Simon Huntc7ae7952015-04-08 18:59:27 -0700487
Simon Huntf41f3092015-04-16 10:33:26 -0700488 flash.enable(false);
Simon Huntc7ae7952015-04-08 18:59:27 -0700489 toggleInstances(prefsState.insts);
Simon Huntee7a3ce2015-04-09 13:28:37 -0700490 toggleSummary(prefsState.summary);
Simon Hunt239e5882015-04-23 15:07:04 -0700491 toggleUseDetailsFlag(prefsState.detail);
Bri Prebilic Cole9b80ca02015-08-03 11:26:54 -0700492 toggleHosts(prefsState.hosts);
493 toggleOffline(prefsState.offdev);
494 togglePorts(prefsState.porthl);
495 toggleMap(prefsState.bg);
Simon Huntf9fc0e72015-04-16 15:10:57 -0700496 toggleSprites(prefsState.spr);
Thomas Vachuska0af26912016-03-21 21:37:30 -0700497 t3s.setDevLabIndex(prefsState.dlbls);
Simon Hunt10618f62017-06-15 19:30:52 -0700498 t3s.setHostLabIndex(prefsState.hlbls);
Simon Huntf41f3092015-04-16 10:33:26 -0700499 flash.enable(true);
Simon Hunt36a58c62015-04-08 11:00:07 -0700500 }
501
502
Simon Hunte1ce4292015-06-12 13:07:02 -0700503 // somewhat hackish, because summary update cannot happen until we
504 // have opened the websocket to the server; hence this extra function
505 // invoked after tes.start()
506 function restoreSummaryFromPrefs() {
Simon Huntfc5c5842017-02-01 23:32:18 -0800507 prefsState = ps.asNumbers(
508 ps.getPrefs('topo_prefs', ttbs.defaultPrefs), ['ovid'], true
509 );
Simon Hunte1ce4292015-06-12 13:07:02 -0700510 $log.debug('TOPO- Prefs SUMMARY State:', prefsState.summary);
511
512 flash.enable(false);
513 toggleSummary(prefsState.summary);
514 flash.enable(true);
515 }
516
Simon Hunt8419efd2017-01-12 12:36:28 -0800517 // initial set of topo events received, now do post-processing
Simon Hunt4a6b54b2015-10-27 22:08:25 -0700518 function topoStartDone() {
Simon Hunt8419efd2017-01-12 12:36:28 -0800519 // give a small delay before attempting to reselect node(s) and
520 // highlight elements, since they have to be re-added to the DOM first...
Simon Hunt7faabd52016-08-18 16:16:19 -0700521 $timeout(function () {
Simon Hunt8419efd2017-01-12 12:36:28 -0800522 $log.debug('^^ topo.topoStartDone() ^^');
523
524 // reselect the previous selection...
Simon Hunt7faabd52016-08-18 16:16:19 -0700525 tss.reselect();
Simon Hunt8419efd2017-01-12 12:36:28 -0800526
527 // if an intent should be shown, invoke the appropriate callback
528 if ($scope.intentData) {
Simon Hunt8419efd2017-01-12 12:36:28 -0800529 tov.hooks.showIntent($scope.intentData);
Simon Hunt7faabd52016-08-18 16:16:19 -0700530 }
Simon Hunt8419efd2017-01-12 12:36:28 -0800531
Simon Hunt7faabd52016-08-18 16:16:19 -0700532 }, 200);
Simon Hunt4a6b54b2015-10-27 22:08:25 -0700533 }
Simon Hunte1ce4292015-06-12 13:07:02 -0700534
Simon Huntcacce342015-01-07 16:13:05 -0800535 // --- Controller Definition -----------------------------------------
536
Simon Hunt6cc53692015-01-07 11:33:45 -0800537 angular.module('ovTopo', moduleDependencies)
Simon Hunt237676b52015-03-10 19:04:26 -0700538 .controller('OvTopoCtrl', ['$scope', '$log', '$location', '$timeout',
Simon Hunt36a58c62015-04-08 11:00:07 -0700539 '$cookies', 'FnService', 'MastService', 'KeyService', 'ZoomService',
Simon Hunt0e48c292015-02-19 16:11:37 -0800540 'GlyphService', 'MapService', 'SvgUtilService', 'FlashService',
Simon Hunta34fcb52016-02-25 16:27:32 -0800541 'WebSocketService', 'PrefsService', 'ThemeService',
Thomas Vachuska0af26912016-03-21 21:37:30 -0700542 'TopoDialogService', 'TopoD3Service',
Simon Huntb0ec1e52015-01-28 18:13:49 -0800543 'TopoEventService', 'TopoForceService', 'TopoPanelService',
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700544 'TopoInstService', 'TopoSelectService', 'TopoLinkService',
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -0700545 'TopoTrafficService', 'TopoObliqueService', 'TopoFilterService',
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700546 'TopoToolbarService', 'TopoMapService', 'TopoSpriteService',
547 'TooltipService', 'TopoOverlayService',
Simon Hunt6cc53692015-01-07 11:33:45 -0800548
Simon Hunt7faabd52016-08-18 16:16:19 -0700549 function (_$scope_, _$log_, _$loc_, _$timeout_, _$cookies_, _fs_, mast, _ks_,
Simon Hunta34fcb52016-02-25 16:27:32 -0800550 _zs_, _gs_, _ms_, _sus_, _flash_, _wss_, _ps_, _th_,
Thomas Vachuska0af26912016-03-21 21:37:30 -0700551 _tds_, _t3s_, _tes_,
Simon Hunta211f7f2015-11-09 12:48:23 -0800552 _tfs_, _tps_, _tis_, _tss_, _tls_, _tts_, _tos_, _fltr_,
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700553 _ttbs_, _tms_, _tspr_, _ttip_, _tov_) {
Simon Huntfc5c5842017-02-01 23:32:18 -0800554
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700555 var params = _$loc_.search(),
Simon Huntfc5c5842017-02-01 23:32:18 -0800556 selOverlay = params.overlayId,
Simon Hunt4a6b54b2015-10-27 22:08:25 -0700557 projection,
Simon Hunt3a6eec02015-02-09 21:16:43 -0800558 dim,
Simon Hunt1894d792015-02-04 17:09:20 -0800559 uplink = {
560 // provides function calls back into this space
561 showNoDevs: showNoDevs,
562 projection: function () { return projection; },
Simon Huntc3c5b672015-02-20 11:32:13 -0800563 zoomLayer: function () { return zoomLayer; },
Simon Huntfb8ea1f2015-02-24 21:38:09 -0800564 zoomer: function () { return zoomer; },
Simon Hunt4a6b54b2015-10-27 22:08:25 -0700565 opacifyMap: opacifyMap,
566 topoStartDone: topoStartDone
Simon Huntac4c6f72015-02-03 19:50:53 -0800567 };
568
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700569 $scope = _$scope_;
Simon Hunt6cc53692015-01-07 11:33:45 -0800570 $log = _$log_;
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700571 $loc = _$loc_;
Simon Hunt7faabd52016-08-18 16:16:19 -0700572 $timeout = _$timeout_;
Simon Hunt36a58c62015-04-08 11:00:07 -0700573 $cookies = _$cookies_;
Simon Hunta11b4eb2015-01-28 16:20:50 -0800574 fs = _fs_;
Simon Hunt6cc53692015-01-07 11:33:45 -0800575 ks = _ks_;
Simon Huntcacce342015-01-07 16:13:05 -0800576 zs = _zs_;
Simon Hunt6cc53692015-01-07 11:33:45 -0800577 gs = _gs_;
Simon Hunt1e8eff42015-01-08 17:19:02 -0800578 ms = _ms_;
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800579 sus = _sus_;
Simon Hunt0e48c292015-02-19 16:11:37 -0800580 flash = _flash_;
Simon Hunt237676b52015-03-10 19:04:26 -0700581 wss = _wss_;
Simon Huntc7ae7952015-04-08 18:59:27 -0700582 ps = _ps_;
Simon Hunta34fcb52016-02-25 16:27:32 -0800583 th = _th_;
Simon Hunta211f7f2015-11-09 12:48:23 -0800584 tds = _tds_;
Thomas Vachuska0af26912016-03-21 21:37:30 -0700585 t3s = _t3s_;
Simon Huntc252aa62015-02-10 16:45:39 -0800586 tes = _tes_;
Simon Hunt737c89f2015-01-28 12:23:19 -0800587 tfs = _tfs_;
Simon Hunt96f88c62015-02-19 17:57:25 -0800588 // TODO: consider funnelling actions through TopoForceService...
589 // rather than injecting references to these 'sub-modules',
590 // just so we can invoke functions on them.
Simon Huntc252aa62015-02-10 16:45:39 -0800591 tps = _tps_;
Simon Huntac4c6f72015-02-03 19:50:53 -0800592 tis = _tis_;
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700593 tms = _tms_;
Simon Hunt6036b192015-02-11 11:20:26 -0800594 tss = _tss_;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700595 tls = _tls_;
Simon Huntf542d842015-02-11 16:20:33 -0800596 tts = _tts_;
Simon Hunt96f88c62015-02-19 17:57:25 -0800597 tos = _tos_;
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -0700598 fltr = _fltr_;
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700599 ttbs = _ttbs_;
Simon Hunta4281242016-02-26 20:18:45 -0800600 tspr = _tspr_;
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700601 ttip = _ttip_;
Simon Hunt72e44bf2015-07-21 21:34:20 -0700602 tov = _tov_;
Simon Huntef31fb22014-12-19 13:16:44 -0800603
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700604 tms.start({
605 toggleMap: toggleMap,
606 currentMap: currentMap,
607 setMap: setMap
608 });
609
Simon Hunt441c9ae2017-02-03 18:22:31 -0800610 // pull intent data from the query string...
Viswanath KSP0f297702016-08-13 18:02:43 +0530611 if (params.key && params.appId && params.appName) {
Simon Hunt4a6b54b2015-10-27 22:08:25 -0700612 $scope.intentData = {
Viswanath KSP0f297702016-08-13 18:02:43 +0530613 key: params.key,
614 appId: params.appId,
Simon Hunt441c9ae2017-02-03 18:22:31 -0800615 appName: params.appName,
616 intentType: params.intentType
Simon Hunt4a6b54b2015-10-27 22:08:25 -0700617 };
618 }
619
Bri Prebilic Cole068814d2015-05-14 16:06:38 -0700620 $scope.notifyResize = function () {
Simon Huntb0ec1e52015-01-28 18:13:49 -0800621 svgResized(fs.windowSize(mast.mastHeight()));
Simon Hunt426bd862015-01-14 16:48:41 -0800622 };
Simon Huntef31fb22014-12-19 13:16:44 -0800623
Simon Hunt54442fa2015-01-26 14:17:38 -0800624 // Cleanup on destroyed scope..
Simon Hunt584122a2015-01-21 15:32:40 -0800625 $scope.$on('$destroy', function () {
626 $log.log('OvTopoCtrl is saying Buh-Bye!');
Thomas Vachuska329af532015-03-10 02:08:33 -0700627 tes.stop();
Thomas Vachuska26be4f32016-03-31 01:10:27 -0700628 tms.stop();
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -0700629 ks.unbindKeys();
Simon Hunt626d2102015-01-29 11:54:50 -0800630 tps.destroyPanels();
Simon Hunta211f7f2015-11-09 12:48:23 -0800631 tds.closeDialog();
Simon Hunt4b668592015-01-29 17:33:53 -0800632 tis.destroyInst();
Simon Hunt3a6eec02015-02-09 21:16:43 -0800633 tfs.destroyForce();
Bri Prebilic Coled6219052015-03-19 14:34:02 -0700634 ttbs.destroyToolbar();
Simon Hunta34fcb52016-02-25 16:27:32 -0800635 mapShader(false);
Simon Hunt584122a2015-01-21 15:32:40 -0800636 });
637
Simon Huntcacce342015-01-07 16:13:05 -0800638 // svg layer and initialization of components
Simon Hunt426bd862015-01-14 16:48:41 -0800639 ovtopo = d3.select('#ov-topo');
640 svg = ovtopo.select('svg');
Simon Hunta11b4eb2015-01-28 16:20:50 -0800641 // set the svg size to match that of the window, less the masthead
642 svg.attr(fs.windowSize(mast.mastHeight()));
Simon Hunt3a6eec02015-02-09 21:16:43 -0800643 dim = [svg.attr('width'), svg.attr('height')];
Simon Hunt426bd862015-01-14 16:48:41 -0800644
Simon Hunt6cc53692015-01-07 11:33:45 -0800645 setUpKeys();
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700646 setUpToolbar();
Simon Hunt6cc53692015-01-07 11:33:45 -0800647 setUpDefs();
Simon Huntcacce342015-01-07 16:13:05 -0800648 setUpZoom();
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800649 setUpNoDevs();
Simon Hunt90053ed2016-04-06 12:49:02 -0700650 setUpMap().then(
Simon Hunt1894d792015-02-04 17:09:20 -0800651 function (proj) {
Thomas Vachuska0af26912016-03-21 21:37:30 -0700652 var z = ps.getPrefs('topo_zoom', { tx:0, ty:0, sc:1 });
Simon Huntbb5e0d82015-04-16 14:25:46 -0700653 zoomer.panZoom([z.tx, z.ty], z.sc);
654 $log.debug('** Zoom restored:', z);
655
Simon Hunt1894d792015-02-04 17:09:20 -0800656 projection = proj;
Simon Huntbb5e0d82015-04-16 14:25:46 -0700657 $log.debug('** We installed the projection:', proj);
Simon Huntf41f3092015-04-16 10:33:26 -0700658 flash.enable(false);
Simon Huntc7ae7952015-04-08 18:59:27 -0700659 toggleMap(prefsState.bg);
Simon Huntf41f3092015-04-16 10:33:26 -0700660 flash.enable(true);
Simon Hunta34fcb52016-02-25 16:27:32 -0800661 mapShader(true);
Simon Hunte1ce4292015-06-12 13:07:02 -0700662
663 // now we have the map projection, we are ready for
664 // the server to send us device/host data...
665 tes.start();
666 // need to do the following so we immediately get
667 // the summary panel data back from the server
668 restoreSummaryFromPrefs();
Simon Hunt1894d792015-02-04 17:09:20 -0800669 }
670 );
Simon Hunta4281242016-02-26 20:18:45 -0800671 tes.bindHandlers();
Simon Hunt90053ed2016-04-06 12:49:02 -0700672 setUpSprites();
Simon Huntfd1231a2015-01-26 22:14:51 -0800673
Simon Hunt1894d792015-02-04 17:09:20 -0800674 forceG = zoomLayer.append('g').attr('id', 'topo-force');
Simon Huntfb8ea1f2015-02-24 21:38:09 -0800675 tfs.initForce(svg, forceG, uplink, dim);
Simon Hunta142dd22015-02-12 22:07:51 -0800676 tis.initInst({ showMastership: tfs.showMastership });
Simon Hunt237676b52015-03-10 19:04:26 -0700677 tps.initPanels();
Simon Hunt6cc53692015-01-07 11:33:45 -0800678
Simon Huntc7ae7952015-04-08 18:59:27 -0700679 restoreConfigFromPrefs();
Simon Huntfc5c5842017-02-01 23:32:18 -0800680
681 ttbs.selectOverlay(selOverlay || prefsState.ovid);
Simon Hunt36a58c62015-04-08 11:00:07 -0700682
Simon Hunt72e44bf2015-07-21 21:34:20 -0700683 $log.debug('registered overlays...', tov.list());
Simon Hunt6cc53692015-01-07 11:33:45 -0800684 $log.log('OvTopoCtrl has been created');
Simon Huntef31fb22014-12-19 13:16:44 -0800685 }]);
686}());