blob: 2415282a685314112726a14794587c64540ad06e [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.
Simon Huntc7ae7952015-04-08 18:59:27 -070032 var $log, $cookies, fs, ks, zs, gs, ms, sus, flash, wss, ps,
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070033 tes, tfs, tps, tis, tss, tls, tts, tos, fltr, ttbs, ttip;
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'],
70 A: [tts.showAllTrafficAction, 'Monitor all traffic'],
71 F: [tts.showDeviceLinkFlowsAction, 'Show device link flows'],
Simon Huntac4c6f72015-02-03 19:50:53 -080072
Simon Hunt0e48c292015-02-19 16:11:37 -080073 E: [equalizeMasters, 'Equalize mastership roles'],
Simon Huntac4c6f72015-02-03 19:50:53 -080074
Simon Hunt08f841d02015-02-10 14:39:20 -080075 esc: handleEscape,
Simon Huntac4c6f72015-02-03 19:50:53 -080076
Simon Hunt09060142015-03-18 20:23:32 -070077 _keyListener: ttbs.keyListener,
78
Simon Hunt5724fb42015-02-05 16:59:40 -080079 _helpFormat: [
Simon Hunt86b7c882015-04-02 23:06:08 -070080 ['I', 'O', 'D', '-', 'H', 'M', 'P', 'dash', 'B' ],
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -070081 ['X', 'Z', 'N', 'L', 'U', 'R', '-', 'dot'],
Simon Hunt5724fb42015-02-05 16:59:40 -080082 ['V', 'rightArrow', 'leftArrow', 'W', 'A', 'F', '-', 'E' ]
83 ]
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -070084 };
85
86 ks.keyBindings(actionMap);
Simon Huntac4c6f72015-02-03 19:50:53 -080087
Simon Hunt639dc662015-02-18 14:19:20 -080088 ks.gestureNotes([
Simon Hunt5724fb42015-02-05 16:59:40 -080089 ['click', 'Select the item and show details'],
90 ['shift-click', 'Toggle selection state'],
91 ['drag', 'Reposition (and pin) device / host'],
92 ['cmd-scroll', 'Zoom in / out'],
93 ['cmd-drag', 'Pan']
Simon Hunt639dc662015-02-18 14:19:20 -080094 ]);
Simon Hunt5724fb42015-02-05 16:59:40 -080095 }
Simon Hunt6cc53692015-01-07 11:33:45 -080096
Simon Hunt08f841d02015-02-10 14:39:20 -080097 // --- Keystroke functions -------------------------------------------
Simon Huntac4c6f72015-02-03 19:50:53 -080098
Simon Hunt36a58c62015-04-08 11:00:07 -070099 function toggleInstances(x) {
Simon Huntee7a3ce2015-04-09 13:28:37 -0700100 updatePrefsState('insts', tis.toggle(x));
Simon Huntac4c6f72015-02-03 19:50:53 -0800101 tfs.updateDeviceColors();
Simon Hunt6cc53692015-01-07 11:33:45 -0800102 }
Simon Huntac4c6f72015-02-03 19:50:53 -0800103
Simon Huntee7a3ce2015-04-09 13:28:37 -0700104 function toggleSummary(x) {
105 updatePrefsState('summary', tps.toggleSummary(x));
Simon Hunt18bf9822015-02-12 17:35:45 -0800106 }
107
Simon Hunt239e5882015-04-23 15:07:04 -0700108 function toggleUseDetailsFlag(x) {
109 updatePrefsState('detail', tps.toggleUseDetailsFlag(x));
Simon Huntee7a3ce2015-04-09 13:28:37 -0700110 }
111
Simon Huntfcbde892015-04-16 12:05:28 -0700112 function toggleHosts(x) {
113 updatePrefsState('hosts', tfs.toggleHosts(x));
114 }
115
116 function toggleOffline(x) {
117 updatePrefsState('offdev', tfs.toggleOffline(x));
118 }
119
120 function togglePorts(x) {
121 updatePrefsState('porthl', tfs.togglePorts(x));
122 }
123
124 function _togSvgLayer(x, G, tag, what) {
125 var on = (x === 'keyev') ? !sus.visible(G) : !!x,
Simon Huntee7a3ce2015-04-09 13:28:37 -0700126 verb = on ? 'Show' : 'Hide';
Simon Huntfcbde892015-04-16 12:05:28 -0700127 sus.visible(G, on);
128 updatePrefsState(tag, on);
129 flash.flash(verb + ' ' + what);
130 }
131
132 function toggleMap(x) {
133 _togSvgLayer(x, mapG, 'bg', 'background map');
Simon Huntee7a3ce2015-04-09 13:28:37 -0700134 }
Simon Hunt36a58c62015-04-08 11:00:07 -0700135
Simon Hunt2052e5d2015-04-13 17:40:44 -0700136 function toggleSprites(x) {
Simon Huntfcbde892015-04-16 12:05:28 -0700137 _togSvgLayer(x, spriteG, 'spr', 'sprite layer');
Simon Hunt2052e5d2015-04-13 17:40:44 -0700138 }
139
Simon Hunt08f841d02015-02-10 14:39:20 -0800140 function resetZoom() {
141 zoomer.reset();
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -0700142 flash.flash('Pan and zoom reset');
Simon Hunt08f841d02015-02-10 14:39:20 -0800143 }
144
Simon Hunt0e48c292015-02-19 16:11:37 -0800145 function equalizeMasters() {
Simon Hunt237676b52015-03-10 19:04:26 -0700146 wss.sendEvent('equalizeMasters');
Simon Hunt0e48c292015-02-19 16:11:37 -0800147 flash.flash('Equalizing master roles');
148 }
149
Simon Hunt08f841d02015-02-10 14:39:20 -0800150 function handleEscape() {
Simon Hunta142dd22015-02-12 22:07:51 -0800151 if (tis.showMaster()) {
152 // if an instance is selected, cancel the affinity mapping
153 tis.cancelAffinity()
Simon Hunt08f841d02015-02-10 14:39:20 -0800154
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700155 } else if (tss.deselectAll()) {
Simon Hunta0eb0a82015-02-11 12:30:06 -0800156 // else if we have node selections, deselect them all
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700157 // (work already done)
158
159 } else if (tls.deselectLink()) {
160 // else if we have a link selected, deselect it
161 // (work already done)
Simon Hunt08f841d02015-02-10 14:39:20 -0800162
Simon Hunta0eb0a82015-02-11 12:30:06 -0800163 } else if (tis.isVisible()) {
164 // else if the Instance Panel is visible, hide it
165 tis.hide();
166 tfs.updateDeviceColors();
Simon Hunt08f841d02015-02-10 14:39:20 -0800167
Simon Hunta0eb0a82015-02-11 12:30:06 -0800168 } else if (tps.summaryVisible()) {
169 // else if the Summary Panel is visible, hide it
170 tps.hideSummaryPanel();
Simon Hunt08f841d02015-02-10 14:39:20 -0800171
Simon Hunta0eb0a82015-02-11 12:30:06 -0800172 } else {
173 // TODO: set hover mode to hoverModeNone
Simon Hunt62c2f8f2015-02-19 14:19:10 -0800174 // talk to Thomas about this: shouldn't it be done
175 // when we deselect the node (if tss.haveDetails()...)
Simon Hunta0eb0a82015-02-11 12:30:06 -0800176 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800177 }
Simon Huntcacce342015-01-07 16:13:05 -0800178
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700179 // --- Toolbar Functions ---------------------------------------------
180
181 function getActionEntry(key) {
182 var entry = actionMap[key];
183 return fs.isA(entry) || [entry, ''];
184 }
185
186 function setUpToolbar() {
187 ttbs.init({
188 getActionEntry: getActionEntry
189 });
190 ttbs.createToolbar();
191 }
192
Simon Huntcacce342015-01-07 16:13:05 -0800193 // --- Glyphs, Icons, and the like -----------------------------------
194
Simon Hunt6cc53692015-01-07 11:33:45 -0800195 function setUpDefs() {
Simon Huntcacce342015-01-07 16:13:05 -0800196 defs = svg.append('defs');
Simon Hunt6cc53692015-01-07 11:33:45 -0800197 gs.loadDefs(defs);
Simon Hunt0ee28682015-02-12 20:48:11 -0800198 sus.loadGlowDefs(defs);
Simon Hunt6cc53692015-01-07 11:33:45 -0800199 }
200
201
Simon Huntcacce342015-01-07 16:13:05 -0800202 // --- Pan and Zoom --------------------------------------------------
203
204 // zoom enabled predicate. ev is a D3 source event.
205 function zoomEnabled(ev) {
Simon Huntd552ee92015-04-02 17:06:35 -0700206 return fs.isMobile() || (ev.metaKey || ev.altKey);
Simon Huntcacce342015-01-07 16:13:05 -0800207 }
208
209 function zoomCallback() {
Simon Huntbb5e0d82015-04-16 14:25:46 -0700210 var sc = zoomer.scale(),
211 tr = zoomer.translate();
212
213 ps.setPrefs('topo_zoom', {tx:tr[0], ty:tr[1], sc:sc});
Simon Huntcacce342015-01-07 16:13:05 -0800214
Simon Hunt0541fb82015-01-14 18:59:57 -0800215 // keep the map lines constant width while zooming
Simon Hunt737c89f2015-01-28 12:23:19 -0800216 mapG.style('stroke-width', (2.0 / sc) + 'px');
Simon Huntcacce342015-01-07 16:13:05 -0800217 }
218
219 function setUpZoom() {
Simon Hunta7b6a6b2015-01-13 19:53:09 -0800220 zoomLayer = svg.append('g').attr('id', 'topo-zoomlayer');
Simon Huntcacce342015-01-07 16:13:05 -0800221 zoomer = zs.createZoomer({
222 svg: svg,
223 zoomLayer: zoomLayer,
224 zoomEnabled: zoomEnabled,
225 zoomCallback: zoomCallback
226 });
227 }
228
229
Simon Hunt0541fb82015-01-14 18:59:57 -0800230 // callback invoked when the SVG view has been resized..
Simon Hunt3a6eec02015-02-09 21:16:43 -0800231 function svgResized(s) {
232 tfs.newDim([s.width, s.height]);
Simon Hunt0541fb82015-01-14 18:59:57 -0800233 }
234
Simon Hunta7b6a6b2015-01-13 19:53:09 -0800235 // --- Background Map ------------------------------------------------
236
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800237 function setUpNoDevs() {
238 var g, box;
239 noDevsLayer = svg.append('g').attr({
240 id: 'topo-noDevsLayer',
241 transform: sus.translate(500,500)
242 });
243 // Note, SVG viewbox is '0 0 1000 1000', defined in topo.html.
244 // We are translating this layer to have its origin at the center
245
246 g = noDevsLayer.append('g');
247 gs.addGlyph(g, 'bird', 100).attr('class', 'noDevsBird');
248 g.append('text').text('No devices are connected')
249 .attr({ x: 120, y: 80});
250
251 box = g.node().getBBox();
252 box.x -= box.width/2;
253 box.y -= box.height/2;
254 g.attr('transform', sus.translate(box.x, box.y));
255
256 showNoDevs(true);
257 }
258
259 function showNoDevs(b) {
Simon Hunt18bf9822015-02-12 17:35:45 -0800260 sus.visible(noDevsLayer, b);
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800261 }
262
Simon Hunt0541fb82015-01-14 18:59:57 -0800263 function setUpMap() {
Simon Hunt737c89f2015-01-28 12:23:19 -0800264 mapG = zoomLayer.append('g').attr('id', 'topo-map');
Simon Huntac4c6f72015-02-03 19:50:53 -0800265 // returns a promise for the projection...
266 return ms.loadMapInto(mapG, '*continental_us');
Simon Hunt0541fb82015-01-14 18:59:57 -0800267 }
268
Simon Huntc3c5b672015-02-20 11:32:13 -0800269 function opacifyMap(b) {
270 mapG.transition()
271 .duration(1000)
272 .attr('opacity', b ? 1 : 0);
273 }
Simon Hunt737c89f2015-01-28 12:23:19 -0800274
Simon Huntf9fc0e72015-04-16 15:10:57 -0700275 function setUpSprites($loc, tspr) {
276 var s1 = $loc.search().sprites,
277 s2 = ps.getPrefs('topo_sprites'),
278 sprId = s1 || (s2 && s2.id);
279
280 spriteG = zoomLayer.append ('g').attr('id', 'topo-sprites');
281 if (sprId) {
282 ps.setPrefs('topo_sprites', {id:sprId});
283 tspr.loadSprites(spriteG, defs, sprId);
284 }
285 }
Simon Hunt9c1c45e2015-04-10 13:38:27 -0700286
Simon Huntc7ae7952015-04-08 18:59:27 -0700287 // --- User Preferemces ----------------------------------------------
Simon Hunt36a58c62015-04-08 11:00:07 -0700288
Simon Huntc7ae7952015-04-08 18:59:27 -0700289 var prefsState = {};
Simon Hunt36a58c62015-04-08 11:00:07 -0700290
Simon Huntc7ae7952015-04-08 18:59:27 -0700291 function updatePrefsState(what, b) {
292 prefsState[what] = b ? 1 : 0;
293 ps.setPrefs('topo_prefs', prefsState);
Simon Hunt36a58c62015-04-08 11:00:07 -0700294 }
295
Simon Hunt36a58c62015-04-08 11:00:07 -0700296
Simon Huntc7ae7952015-04-08 18:59:27 -0700297 function restoreConfigFromPrefs() {
298 // NOTE: toolbar will have set this for us..
Simon Huntfcbde892015-04-16 12:05:28 -0700299 prefsState = ps.asNumbers(ps.getPrefs('topo_prefs'));
Simon Hunt36a58c62015-04-08 11:00:07 -0700300
Simon Huntc7ae7952015-04-08 18:59:27 -0700301 $log.debug('TOPO---- Prefs State:', prefsState);
302
Simon Huntf41f3092015-04-16 10:33:26 -0700303 flash.enable(false);
Simon Huntc7ae7952015-04-08 18:59:27 -0700304 toggleInstances(prefsState.insts);
Simon Huntee7a3ce2015-04-09 13:28:37 -0700305 toggleSummary(prefsState.summary);
Simon Hunt239e5882015-04-23 15:07:04 -0700306 toggleUseDetailsFlag(prefsState.detail);
Simon Huntf9fc0e72015-04-16 15:10:57 -0700307 toggleSprites(prefsState.spr);
Simon Huntf41f3092015-04-16 10:33:26 -0700308 flash.enable(true);
Simon Hunt36a58c62015-04-08 11:00:07 -0700309 }
310
311
Simon Huntcacce342015-01-07 16:13:05 -0800312 // --- Controller Definition -----------------------------------------
313
Simon Hunt6cc53692015-01-07 11:33:45 -0800314 angular.module('ovTopo', moduleDependencies)
Simon Hunt237676b52015-03-10 19:04:26 -0700315 .controller('OvTopoCtrl', ['$scope', '$log', '$location', '$timeout',
Simon Hunt36a58c62015-04-08 11:00:07 -0700316 '$cookies', 'FnService', 'MastService', 'KeyService', 'ZoomService',
Simon Hunt0e48c292015-02-19 16:11:37 -0800317 'GlyphService', 'MapService', 'SvgUtilService', 'FlashService',
Simon Huntc7ae7952015-04-08 18:59:27 -0700318 'WebSocketService', 'PrefsService',
Simon Huntb0ec1e52015-01-28 18:13:49 -0800319 'TopoEventService', 'TopoForceService', 'TopoPanelService',
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700320 'TopoInstService', 'TopoSelectService', 'TopoLinkService',
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -0700321 'TopoTrafficService', 'TopoObliqueService', 'TopoFilterService',
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700322 'TopoToolbarService', 'TopoSpriteService', 'TooltipService',
Simon Hunt6cc53692015-01-07 11:33:45 -0800323
Simon Hunt36a58c62015-04-08 11:00:07 -0700324 function ($scope, _$log_, $loc, $timeout, _$cookies_, _fs_, mast, _ks_,
Simon Huntc7ae7952015-04-08 18:59:27 -0700325 _zs_, _gs_, _ms_, _sus_, _flash_, _wss_, _ps_, _tes_, _tfs_,
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700326 _tps_, _tis_, _tss_, _tls_, _tts_, _tos_, _fltr_, _ttbs_, tspr,
327 _ttip_) {
Simon Huntac4c6f72015-02-03 19:50:53 -0800328 var self = this,
Simon Hunt1894d792015-02-04 17:09:20 -0800329 projection,
Simon Hunt3a6eec02015-02-09 21:16:43 -0800330 dim,
Simon Hunt1894d792015-02-04 17:09:20 -0800331 uplink = {
332 // provides function calls back into this space
333 showNoDevs: showNoDevs,
334 projection: function () { return projection; },
Simon Huntc3c5b672015-02-20 11:32:13 -0800335 zoomLayer: function () { return zoomLayer; },
Simon Huntfb8ea1f2015-02-24 21:38:09 -0800336 zoomer: function () { return zoomer; },
Simon Hunt237676b52015-03-10 19:04:26 -0700337 opacifyMap: opacifyMap
Simon Huntac4c6f72015-02-03 19:50:53 -0800338 };
339
Simon Hunt6cc53692015-01-07 11:33:45 -0800340 $log = _$log_;
Simon Hunt36a58c62015-04-08 11:00:07 -0700341 $cookies = _$cookies_;
Simon Hunta11b4eb2015-01-28 16:20:50 -0800342 fs = _fs_;
Simon Hunt6cc53692015-01-07 11:33:45 -0800343 ks = _ks_;
Simon Huntcacce342015-01-07 16:13:05 -0800344 zs = _zs_;
Simon Hunt6cc53692015-01-07 11:33:45 -0800345 gs = _gs_;
Simon Hunt1e8eff42015-01-08 17:19:02 -0800346 ms = _ms_;
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800347 sus = _sus_;
Simon Hunt0e48c292015-02-19 16:11:37 -0800348 flash = _flash_;
Simon Hunt237676b52015-03-10 19:04:26 -0700349 wss = _wss_;
Simon Huntc7ae7952015-04-08 18:59:27 -0700350 ps = _ps_;
Simon Huntc252aa62015-02-10 16:45:39 -0800351 tes = _tes_;
Simon Hunt737c89f2015-01-28 12:23:19 -0800352 tfs = _tfs_;
Simon Hunt96f88c62015-02-19 17:57:25 -0800353 // TODO: consider funnelling actions through TopoForceService...
354 // rather than injecting references to these 'sub-modules',
355 // just so we can invoke functions on them.
Simon Huntc252aa62015-02-10 16:45:39 -0800356 tps = _tps_;
Simon Huntac4c6f72015-02-03 19:50:53 -0800357 tis = _tis_;
Simon Hunt6036b192015-02-11 11:20:26 -0800358 tss = _tss_;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700359 tls = _tls_;
Simon Huntf542d842015-02-11 16:20:33 -0800360 tts = _tts_;
Simon Hunt96f88c62015-02-19 17:57:25 -0800361 tos = _tos_;
Bri Prebilic Coleb5f2b152015-04-07 14:58:09 -0700362 fltr = _fltr_;
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700363 ttbs = _ttbs_;
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700364 ttip = _ttip_;
Simon Huntef31fb22014-12-19 13:16:44 -0800365
Simon Hunt426bd862015-01-14 16:48:41 -0800366 self.notifyResize = function () {
Simon Huntb0ec1e52015-01-28 18:13:49 -0800367 svgResized(fs.windowSize(mast.mastHeight()));
Simon Hunt426bd862015-01-14 16:48:41 -0800368 };
Simon Huntef31fb22014-12-19 13:16:44 -0800369
Simon Hunt54442fa2015-01-26 14:17:38 -0800370 // Cleanup on destroyed scope..
Simon Hunt584122a2015-01-21 15:32:40 -0800371 $scope.$on('$destroy', function () {
372 $log.log('OvTopoCtrl is saying Buh-Bye!');
Thomas Vachuska329af532015-03-10 02:08:33 -0700373 tes.stop();
Simon Hunt626d2102015-01-29 11:54:50 -0800374 tps.destroyPanels();
Simon Hunt4b668592015-01-29 17:33:53 -0800375 tis.destroyInst();
Simon Hunt3a6eec02015-02-09 21:16:43 -0800376 tfs.destroyForce();
Bri Prebilic Coled6219052015-03-19 14:34:02 -0700377 ttbs.destroyToolbar();
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700378 ttip.resetTooltip();
Simon Hunt584122a2015-01-21 15:32:40 -0800379 });
380
Simon Huntcacce342015-01-07 16:13:05 -0800381 // svg layer and initialization of components
Simon Hunt426bd862015-01-14 16:48:41 -0800382 ovtopo = d3.select('#ov-topo');
383 svg = ovtopo.select('svg');
Simon Hunta11b4eb2015-01-28 16:20:50 -0800384 // set the svg size to match that of the window, less the masthead
385 svg.attr(fs.windowSize(mast.mastHeight()));
Simon Hunt3a6eec02015-02-09 21:16:43 -0800386 dim = [svg.attr('width'), svg.attr('height')];
Simon Hunt426bd862015-01-14 16:48:41 -0800387
Simon Hunt6cc53692015-01-07 11:33:45 -0800388 setUpKeys();
Bri Prebilic Cole4db8dce2015-03-18 13:57:24 -0700389 setUpToolbar();
Simon Hunt6cc53692015-01-07 11:33:45 -0800390 setUpDefs();
Simon Huntcacce342015-01-07 16:13:05 -0800391 setUpZoom();
Simon Hunt7c8ab8d2015-02-03 15:05:15 -0800392 setUpNoDevs();
Simon Hunt1894d792015-02-04 17:09:20 -0800393 setUpMap().then(
394 function (proj) {
Simon Huntbb5e0d82015-04-16 14:25:46 -0700395 var z = ps.getPrefs('topo_zoom') || {tx:0, ty:0, sc:1};
396 zoomer.panZoom([z.tx, z.ty], z.sc);
397 $log.debug('** Zoom restored:', z);
398
Simon Hunt1894d792015-02-04 17:09:20 -0800399 projection = proj;
Simon Huntbb5e0d82015-04-16 14:25:46 -0700400 $log.debug('** We installed the projection:', proj);
Simon Huntf41f3092015-04-16 10:33:26 -0700401 flash.enable(false);
Simon Huntc7ae7952015-04-08 18:59:27 -0700402 toggleMap(prefsState.bg);
Simon Huntf41f3092015-04-16 10:33:26 -0700403 flash.enable(true);
Simon Hunt1894d792015-02-04 17:09:20 -0800404 }
405 );
Simon Huntf9fc0e72015-04-16 15:10:57 -0700406 setUpSprites($loc, tspr);
Simon Huntfd1231a2015-01-26 22:14:51 -0800407
Simon Hunt1894d792015-02-04 17:09:20 -0800408 forceG = zoomLayer.append('g').attr('id', 'topo-force');
Simon Huntfb8ea1f2015-02-24 21:38:09 -0800409 tfs.initForce(svg, forceG, uplink, dim);
Simon Hunta142dd22015-02-12 22:07:51 -0800410 tis.initInst({ showMastership: tfs.showMastership });
Simon Hunt237676b52015-03-10 19:04:26 -0700411 tps.initPanels();
Thomas Vachuska329af532015-03-10 02:08:33 -0700412 tes.start();
Simon Hunt6cc53692015-01-07 11:33:45 -0800413
Simon Hunt36a58c62015-04-08 11:00:07 -0700414 // temporary solution for persisting user settings
Simon Huntc7ae7952015-04-08 18:59:27 -0700415 restoreConfigFromPrefs();
Simon Hunt36a58c62015-04-08 11:00:07 -0700416
Simon Hunt6cc53692015-01-07 11:33:45 -0800417 $log.log('OvTopoCtrl has been created');
Simon Huntef31fb22014-12-19 13:16:44 -0800418 }]);
419}());