Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 3 | * |
| 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 Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | (function () { |
| 22 | 'use strict'; |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 23 | |
| 24 | var moduleDependencies = [ |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame] | 25 | 'ngCookies', |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 26 | 'onosUtil', |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 27 | 'onosSvg', |
| 28 | 'onosRemote' |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 29 | ]; |
| 30 | |
Simon Hunt | a428124 | 2016-02-26 20:18:45 -0800 | [diff] [blame] | 31 | // references to injected services |
Simon Hunt | 7faabd5 | 2016-08-18 16:16:19 -0700 | [diff] [blame] | 32 | 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 Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 35 | |
| 36 | // DOM elements |
Simon Hunt | 2052e5d | 2015-04-13 17:40:44 -0700 | [diff] [blame] | 37 | var ovtopo, svg, defs, zoomLayer, mapG, spriteG, forceG, noDevsLayer; |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 38 | |
| 39 | // Internal state |
Simon Hunt | f51bf46 | 2016-06-29 16:22:57 -0700 | [diff] [blame] | 40 | var zoomer, actionMap; |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 41 | |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 42 | // --- Short Cut Keys ------------------------------------------------ |
| 43 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 44 | function setUpKeys(overlayKeys) { |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 45 | // key bindings need to be made after the services have been injected |
| 46 | // thus, deferred to here... |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 47 | actionMap = { |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame] | 48 | I: [toggleInstances, 'Toggle ONOS instances panel'], |
Simon Hunt | ee7a3ce | 2015-04-09 13:28:37 -0700 | [diff] [blame] | 49 | O: [toggleSummary, 'Toggle ONOS summary panel'], |
Simon Hunt | 239e588 | 2015-04-23 15:07:04 -0700 | [diff] [blame] | 50 | D: [toggleUseDetailsFlag, 'Disable / enable details panel'], |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 51 | |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 52 | H: [toggleHosts, 'Toggle host visibility'], |
| 53 | M: [toggleOffline, 'Toggle offline visibility'], |
| 54 | P: [togglePorts, 'Toggle Port Highlighting'], |
Simon Hunt | 86b7c88 | 2015-04-02 23:06:08 -0700 | [diff] [blame] | 55 | dash: [tfs.showBadLinks, 'Show bad links'], |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 56 | B: [toggleMap, 'Toggle background geo map'], |
| 57 | G: [openMapSelection, 'Select background geo map'], |
Simon Hunt | 2052e5d | 2015-04-13 17:40:44 -0700 | [diff] [blame] | 58 | S: [toggleSprites, 'Toggle sprite layer'], |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 59 | |
Simon Hunt | fd7106c | 2016-02-09 15:05:26 -0800 | [diff] [blame] | 60 | X: [tfs.resetAllLocations, 'Reset node locations'], |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 61 | Z: [tos.toggleOblique, 'Toggle oblique view (Experimental)'], |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 62 | N: [fltr.clickAction, 'Cycle node layers'], |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 63 | L: [tfs.cycleDeviceLabels, 'Cycle device labels'], |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 64 | 'shift-L': [tfs.cycleHostLabels, 'Cycle host labels'], |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 65 | U: [tfs.unpin, 'Unpin node (hover mouse over)'], |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 66 | R: [resetZoom, 'Reset pan / zoom'], |
Simon Hunt | 90dcc3e | 2015-03-25 15:01:27 -0700 | [diff] [blame] | 67 | dot: [ttbs.toggleToolbar, 'Toggle Toolbar'], |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 68 | |
Simon Hunt | 0e48c29 | 2015-02-19 16:11:37 -0800 | [diff] [blame] | 69 | E: [equalizeMasters, 'Equalize mastership roles'], |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 70 | |
Simon Hunt | a976134 | 2016-06-10 18:02:53 -0700 | [diff] [blame] | 71 | //-- instance color palette debug |
| 72 | // 9: function () { sus.cat7().testCard(svg); }, |
| 73 | |
Simon Hunt | 5b024d7 | 2016-01-29 11:02:43 -0800 | [diff] [blame] | 74 | // 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 Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 81 | esc: handleEscape, |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 82 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 83 | _keyListener: ttbs.keyListener, |
| 84 | |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 85 | _helpFormat: [ |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 86 | ['I', 'O', 'D', 'H', 'M', 'P', 'dash', 'B', 'G', 'S' ], |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 87 | ['X', 'Z', 'N', 'L', 'shift-L', 'U', 'R', '-', 'E', '-', 'dot'], |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 88 | [] // this column reserved for overlay actions |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 89 | ] |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 92 | if (fs.isO(overlayKeys)) { |
| 93 | mergeKeys(overlayKeys); |
| 94 | } |
| 95 | |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 96 | ks.keyBindings(actionMap); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 97 | |
Simon Hunt | 639dc66 | 2015-02-18 14:19:20 -0800 | [diff] [blame] | 98 | ks.gestureNotes([ |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 99 | ['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 Hunt | 639dc66 | 2015-02-18 14:19:20 -0800 | [diff] [blame] | 104 | ]); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 105 | } |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 106 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 107 | // 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 Hunt | 7189222 | 2015-09-29 13:39:40 -0700 | [diff] [blame] | 111 | |
| 112 | ks.checkNotGlobal(extra); |
| 113 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 114 | 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 Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 126 | // --- Keystroke functions ------------------------------------------- |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 127 | |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame] | 128 | function toggleInstances(x) { |
Simon Hunt | ee7a3ce | 2015-04-09 13:28:37 -0700 | [diff] [blame] | 129 | updatePrefsState('insts', tis.toggle(x)); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 130 | tfs.updateDeviceColors(); |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 131 | } |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 132 | |
Simon Hunt | ee7a3ce | 2015-04-09 13:28:37 -0700 | [diff] [blame] | 133 | function toggleSummary(x) { |
| 134 | updatePrefsState('summary', tps.toggleSummary(x)); |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 135 | } |
| 136 | |
Simon Hunt | 239e588 | 2015-04-23 15:07:04 -0700 | [diff] [blame] | 137 | function toggleUseDetailsFlag(x) { |
| 138 | updatePrefsState('detail', tps.toggleUseDetailsFlag(x)); |
Simon Hunt | ee7a3ce | 2015-04-09 13:28:37 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 141 | 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 Hunt | ee7a3ce | 2015-04-09 13:28:37 -0700 | [diff] [blame] | 155 | verb = on ? 'Show' : 'Hide'; |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 156 | 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 Hunt | ee7a3ce | 2015-04-09 13:28:37 -0700 | [diff] [blame] | 163 | } |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame] | 164 | |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 165 | function openMapSelection() { |
| 166 | tms.openMapSelection(); |
| 167 | } |
| 168 | |
Simon Hunt | 2052e5d | 2015-04-13 17:40:44 -0700 | [diff] [blame] | 169 | function toggleSprites(x) { |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 170 | _togSvgLayer(x, spriteG, 'spr', 'sprite layer'); |
Simon Hunt | 2052e5d | 2015-04-13 17:40:44 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 173 | function resetZoom() { |
| 174 | zoomer.reset(); |
Bri Prebilic Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 175 | flash.flash('Pan and zoom reset'); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 176 | } |
| 177 | |
Simon Hunt | 0e48c29 | 2015-02-19 16:11:37 -0800 | [diff] [blame] | 178 | function equalizeMasters() { |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 179 | wss.sendEvent('equalizeMasters'); |
Simon Hunt | 0e48c29 | 2015-02-19 16:11:37 -0800 | [diff] [blame] | 180 | flash.flash('Equalizing master roles'); |
| 181 | } |
| 182 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 183 | function handleEscape() { |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 184 | if (tis.showMaster()) { |
| 185 | // if an instance is selected, cancel the affinity mapping |
| 186 | tis.cancelAffinity() |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 187 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 188 | } else if (tov.hooks.escape()) { |
| 189 | // else if the overlay consumed the ESC event... |
| 190 | // (work already done) |
| 191 | |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 192 | } else if (tss.deselectAll()) { |
Simon Hunt | a0eb0a8 | 2015-02-11 12:30:06 -0800 | [diff] [blame] | 193 | // else if we have node selections, deselect them all |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 194 | // (work already done) |
| 195 | |
Prince Pereira | 46c82d4 | 2016-09-19 13:30:50 +0530 | [diff] [blame] | 196 | } else if (tls.deselectAllLinks()) { |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 197 | // else if we have a link selected, deselect it |
| 198 | // (work already done) |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 199 | |
Simon Hunt | a0eb0a8 | 2015-02-11 12:30:06 -0800 | [diff] [blame] | 200 | } else if (tis.isVisible()) { |
| 201 | // else if the Instance Panel is visible, hide it |
| 202 | tis.hide(); |
| 203 | tfs.updateDeviceColors(); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 204 | |
Simon Hunt | a0eb0a8 | 2015-02-11 12:30:06 -0800 | [diff] [blame] | 205 | } else if (tps.summaryVisible()) { |
| 206 | // else if the Summary Panel is visible, hide it |
Simon Hunt | 356da76 | 2016-05-27 11:54:02 -0700 | [diff] [blame] | 207 | tps.hideSummary(); |
Simon Hunt | a0eb0a8 | 2015-02-11 12:30:06 -0800 | [diff] [blame] | 208 | } |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 209 | } |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 210 | |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 211 | // --- Toolbar Functions --------------------------------------------- |
| 212 | |
Bri Prebilic Cole | 2efc715 | 2015-04-29 15:47:06 -0700 | [diff] [blame] | 213 | function notValid(what) { |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 214 | $log.warn('topo.js getActionEntry(): Not a valid ' + what); |
Bri Prebilic Cole | 2efc715 | 2015-04-29 15:47:06 -0700 | [diff] [blame] | 215 | } |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 216 | |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 217 | function getActionEntry(key) { |
Bri Prebilic Cole | 2efc715 | 2015-04-29 15:47:06 -0700 | [diff] [blame] | 218 | 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 Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 231 | return fs.isA(entry) || [entry, '']; |
| 232 | } |
| 233 | |
| 234 | function setUpToolbar() { |
| 235 | ttbs.init({ |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 236 | getActionEntry: getActionEntry, |
| 237 | setUpKeys: setUpKeys |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 238 | }); |
| 239 | ttbs.createToolbar(); |
| 240 | } |
| 241 | |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 242 | // --- Glyphs, Icons, and the like ----------------------------------- |
| 243 | |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 244 | function setUpDefs() { |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 245 | defs = svg.append('defs'); |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 246 | gs.loadDefs(defs); |
Simon Hunt | 0ee2868 | 2015-02-12 20:48:11 -0800 | [diff] [blame] | 247 | sus.loadGlowDefs(defs); |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 251 | // --- Pan and Zoom -------------------------------------------------- |
| 252 | |
| 253 | // zoom enabled predicate. ev is a D3 source event. |
| 254 | function zoomEnabled(ev) { |
Simon Hunt | d552ee9 | 2015-04-02 17:06:35 -0700 | [diff] [blame] | 255 | return fs.isMobile() || (ev.metaKey || ev.altKey); |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | function zoomCallback() { |
Simon Hunt | bb5e0d8 | 2015-04-16 14:25:46 -0700 | [diff] [blame] | 259 | var sc = zoomer.scale(), |
| 260 | tr = zoomer.translate(); |
| 261 | |
| 262 | ps.setPrefs('topo_zoom', {tx:tr[0], ty:tr[1], sc:sc}); |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 263 | |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 264 | // keep the map lines constant width while zooming |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 265 | mapG.style('stroke-width', (2.0 / sc) + 'px'); |
Steven Burrows | f17f0ab | 2017-04-11 11:03:58 -0700 | [diff] [blame] | 266 | |
| 267 | tfs.setNodeScale(sc); |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | function setUpZoom() { |
Simon Hunt | a7b6a6b | 2015-01-13 19:53:09 -0800 | [diff] [blame] | 271 | zoomLayer = svg.append('g').attr('id', 'topo-zoomlayer'); |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 272 | zoomer = zs.createZoomer({ |
| 273 | svg: svg, |
| 274 | zoomLayer: zoomLayer, |
| 275 | zoomEnabled: zoomEnabled, |
| 276 | zoomCallback: zoomCallback |
| 277 | }); |
| 278 | } |
| 279 | |
| 280 | |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 281 | // callback invoked when the SVG view has been resized.. |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 282 | function svgResized(s) { |
| 283 | tfs.newDim([s.width, s.height]); |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Simon Hunt | a7b6a6b | 2015-01-13 19:53:09 -0800 | [diff] [blame] | 286 | // --- Background Map ------------------------------------------------ |
| 287 | |
Simon Hunt | 7c8ab8d | 2015-02-03 15:05:15 -0800 | [diff] [blame] | 288 | 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 Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 311 | sus.visible(noDevsLayer, b); |
Simon Hunt | 7c8ab8d | 2015-02-03 15:05:15 -0800 | [diff] [blame] | 312 | } |
| 313 | |
Simon Hunt | 2362b07 | 2015-06-11 20:08:22 -0700 | [diff] [blame] | 314 | |
| 315 | var countryFilters = { |
Simon Hunt | 2362b07 | 2015-06-11 20:08:22 -0700 | [diff] [blame] | 316 | s_america: function (c) { |
| 317 | return c.properties.continent === 'South America'; |
| 318 | }, |
| 319 | |
Simon Hunt | ac099e8 | 2015-12-03 09:17:47 -0800 | [diff] [blame] | 320 | ns_america: function (c) { |
| 321 | return c.properties.custom === 'US-cont' || |
| 322 | c.properties.subregion === 'Central America' || |
Simon Hunt | d471262 | 2015-12-02 11:19:50 -0800 | [diff] [blame] | 323 | c.properties.continent === 'South America'; |
| 324 | }, |
| 325 | |
Simon Hunt | 2362b07 | 2015-06-11 20:08:22 -0700 | [diff] [blame] | 326 | 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 Hunt | 1178d5b | 2015-09-02 17:02:37 -0700 | [diff] [blame] | 343 | }, |
| 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 Hunt | 2362b07 | 2015-06-11 20:08:22 -0700 | [diff] [blame] | 351 | } |
| 352 | }; |
| 353 | |
Simon Hunt | a34fcb5 | 2016-02-25 16:27:32 -0800 | [diff] [blame] | 354 | 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 Hunt | 2362b07 | 2015-06-11 20:08:22 -0700 | [diff] [blame] | 375 | |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 376 | function setMap(map) { |
| 377 | ps.setPrefs('topo_mapid', map); |
Simon Hunt | 90053ed | 2016-04-06 12:49:02 -0700 | [diff] [blame] | 378 | setUpMap(); |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 379 | opacifyMap(true); |
| 380 | } |
| 381 | |
| 382 | function currentMap() { |
| 383 | return ps.getPrefs( |
| 384 | 'topo_mapid', |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 385 | { |
| 386 | mapid: 'usa', |
| 387 | mapscale: 1, |
| 388 | mapfilepath: '*continental_us', |
| 389 | tint: 'off' |
| 390 | }, |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 391 | $loc.search() |
| 392 | ); |
| 393 | } |
| 394 | |
Simon Hunt | 90053ed | 2016-04-06 12:49:02 -0700 | [diff] [blame] | 395 | function setUpMap() { |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 396 | var prefs = currentMap(), |
Simon Hunt | 8a119b0 | 2016-03-29 16:00:32 -0700 | [diff] [blame] | 397 | mapId = prefs.mapid, |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 398 | mapFilePath = prefs.mapfilepath, |
Simon Hunt | 8a119b0 | 2016-03-29 16:00:32 -0700 | [diff] [blame] | 399 | mapScale = prefs.mapscale, |
| 400 | tint = prefs.tint, |
Simon Hunt | 2362b07 | 2015-06-11 20:08:22 -0700 | [diff] [blame] | 401 | promise, |
Simon Hunt | facad99 | 2016-02-25 09:58:33 -0800 | [diff] [blame] | 402 | cfilter; |
Simon Hunt | 2362b07 | 2015-06-11 20:08:22 -0700 | [diff] [blame] | 403 | |
Simon Hunt | a34fcb5 | 2016-02-25 16:27:32 -0800 | [diff] [blame] | 404 | tintOn = tint === 'on' ? 1 : 0; |
| 405 | |
Simon Hunt | 1849136 | 2016-03-04 11:09:42 -0800 | [diff] [blame] | 406 | $log.debug('setUpMap() mapId:', mapId, ', mapScale:', mapScale, |
| 407 | ', tint:', tint); |
| 408 | |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 409 | 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 Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 417 | |
| 418 | if (mapFilePath === '*countries') { |
| 419 | |
Simon Hunt | 90053ed | 2016-04-06 12:49:02 -0700 | [diff] [blame] | 420 | cfilter = countryFilters[mapId] || countryFilters.uk; |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 421 | |
Simon Hunt | a34fcb5 | 2016-02-25 16:27:32 -0800 | [diff] [blame] | 422 | promise = ms.loadMapRegionInto(mapG, { |
| 423 | countryFilter: cfilter, |
| 424 | adjustScale: mapScale, |
| 425 | shading: shading() |
| 426 | }); |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 427 | } else { |
| 428 | |
| 429 | promise = ms.loadMapInto(mapG, mapFilePath, mapId, { |
| 430 | adjustScale: mapScale, |
| 431 | shading: shading() |
| 432 | }); |
Simon Hunt | 2362b07 | 2015-06-11 20:08:22 -0700 | [diff] [blame] | 433 | } |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 434 | |
Simon Hunt | 8a119b0 | 2016-03-29 16:00:32 -0700 | [diff] [blame] | 435 | ps.setPrefs('topo_mapid', prefs); |
Simon Hunt | 2362b07 | 2015-06-11 20:08:22 -0700 | [diff] [blame] | 436 | return promise; |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 437 | } |
| 438 | |
Simon Hunt | f51bf46 | 2016-06-29 16:22:57 -0700 | [diff] [blame] | 439 | function mapReshader() { |
| 440 | $log.debug('... Re-shading map ...') |
| 441 | ms.reshade(shading()); |
| 442 | } |
| 443 | |
Simon Hunt | a34fcb5 | 2016-02-25 16:27:32 -0800 | [diff] [blame] | 444 | // set up theme listener to re-shade the map when required. |
| 445 | function mapShader(on) { |
| 446 | if (on) { |
Simon Hunt | f51bf46 | 2016-06-29 16:22:57 -0700 | [diff] [blame] | 447 | th.addListener(mapReshader); |
Simon Hunt | a34fcb5 | 2016-02-25 16:27:32 -0800 | [diff] [blame] | 448 | } else { |
Simon Hunt | f51bf46 | 2016-06-29 16:22:57 -0700 | [diff] [blame] | 449 | th.removeListener(mapReshader); |
Simon Hunt | a34fcb5 | 2016-02-25 16:27:32 -0800 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 453 | function opacifyMap(b) { |
| 454 | mapG.transition() |
| 455 | .duration(1000) |
| 456 | .attr('opacity', b ? 1 : 0); |
| 457 | } |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 458 | |
Simon Hunt | 90053ed | 2016-04-06 12:49:02 -0700 | [diff] [blame] | 459 | function setUpSprites() { |
Simon Hunt | 8a119b0 | 2016-03-29 16:00:32 -0700 | [diff] [blame] | 460 | var prefs = ps.getPrefs('topo_sprites', { sprites: '' }, $loc.search()), |
| 461 | sprId = prefs.sprites; |
Simon Hunt | f9fc0e7 | 2015-04-16 15:10:57 -0700 | [diff] [blame] | 462 | |
| 463 | spriteG = zoomLayer.append ('g').attr('id', 'topo-sprites'); |
| 464 | if (sprId) { |
Simon Hunt | 8a119b0 | 2016-03-29 16:00:32 -0700 | [diff] [blame] | 465 | ps.setPrefs('topo_sprites', prefs); |
Simon Hunt | f9fc0e7 | 2015-04-16 15:10:57 -0700 | [diff] [blame] | 466 | tspr.loadSprites(spriteG, defs, sprId); |
| 467 | } |
| 468 | } |
Simon Hunt | 9c1c45e | 2015-04-10 13:38:27 -0700 | [diff] [blame] | 469 | |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 470 | // --- User Preferemces ---------------------------------------------- |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame] | 471 | |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 472 | var prefsState = {}; |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame] | 473 | |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 474 | function updatePrefsState(what, b) { |
| 475 | prefsState[what] = b ? 1 : 0; |
| 476 | ps.setPrefs('topo_prefs', prefsState); |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame] | 479 | |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 480 | function restoreConfigFromPrefs() { |
| 481 | // NOTE: toolbar will have set this for us.. |
Simon Hunt | fc5c584 | 2017-02-01 23:32:18 -0800 | [diff] [blame] | 482 | prefsState = ps.asNumbers( |
| 483 | ps.getPrefs('topo_prefs', ttbs.defaultPrefs), ['ovid'], true |
| 484 | ); |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame] | 485 | |
Simon Hunt | e1ce429 | 2015-06-12 13:07:02 -0700 | [diff] [blame] | 486 | $log.debug('TOPO- Prefs State:', prefsState); |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 487 | |
Simon Hunt | f41f309 | 2015-04-16 10:33:26 -0700 | [diff] [blame] | 488 | flash.enable(false); |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 489 | toggleInstances(prefsState.insts); |
Simon Hunt | ee7a3ce | 2015-04-09 13:28:37 -0700 | [diff] [blame] | 490 | toggleSummary(prefsState.summary); |
Simon Hunt | 239e588 | 2015-04-23 15:07:04 -0700 | [diff] [blame] | 491 | toggleUseDetailsFlag(prefsState.detail); |
Bri Prebilic Cole | 9b80ca0 | 2015-08-03 11:26:54 -0700 | [diff] [blame] | 492 | toggleHosts(prefsState.hosts); |
| 493 | toggleOffline(prefsState.offdev); |
| 494 | togglePorts(prefsState.porthl); |
| 495 | toggleMap(prefsState.bg); |
Simon Hunt | f9fc0e7 | 2015-04-16 15:10:57 -0700 | [diff] [blame] | 496 | toggleSprites(prefsState.spr); |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 497 | t3s.setDevLabIndex(prefsState.dlbls); |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 498 | t3s.setHostLabIndex(prefsState.hlbls); |
Simon Hunt | f41f309 | 2015-04-16 10:33:26 -0700 | [diff] [blame] | 499 | flash.enable(true); |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | |
Simon Hunt | e1ce429 | 2015-06-12 13:07:02 -0700 | [diff] [blame] | 503 | // 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 Hunt | fc5c584 | 2017-02-01 23:32:18 -0800 | [diff] [blame] | 507 | prefsState = ps.asNumbers( |
| 508 | ps.getPrefs('topo_prefs', ttbs.defaultPrefs), ['ovid'], true |
| 509 | ); |
Simon Hunt | e1ce429 | 2015-06-12 13:07:02 -0700 | [diff] [blame] | 510 | $log.debug('TOPO- Prefs SUMMARY State:', prefsState.summary); |
| 511 | |
| 512 | flash.enable(false); |
| 513 | toggleSummary(prefsState.summary); |
| 514 | flash.enable(true); |
| 515 | } |
| 516 | |
Simon Hunt | 8419efd | 2017-01-12 12:36:28 -0800 | [diff] [blame] | 517 | // initial set of topo events received, now do post-processing |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 518 | function topoStartDone() { |
Simon Hunt | 8419efd | 2017-01-12 12:36:28 -0800 | [diff] [blame] | 519 | // 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 Hunt | 7faabd5 | 2016-08-18 16:16:19 -0700 | [diff] [blame] | 521 | $timeout(function () { |
Simon Hunt | 8419efd | 2017-01-12 12:36:28 -0800 | [diff] [blame] | 522 | $log.debug('^^ topo.topoStartDone() ^^'); |
| 523 | |
| 524 | // reselect the previous selection... |
Simon Hunt | 7faabd5 | 2016-08-18 16:16:19 -0700 | [diff] [blame] | 525 | tss.reselect(); |
Simon Hunt | 8419efd | 2017-01-12 12:36:28 -0800 | [diff] [blame] | 526 | |
| 527 | // if an intent should be shown, invoke the appropriate callback |
| 528 | if ($scope.intentData) { |
Simon Hunt | 8419efd | 2017-01-12 12:36:28 -0800 | [diff] [blame] | 529 | tov.hooks.showIntent($scope.intentData); |
Simon Hunt | 7faabd5 | 2016-08-18 16:16:19 -0700 | [diff] [blame] | 530 | } |
Simon Hunt | 8419efd | 2017-01-12 12:36:28 -0800 | [diff] [blame] | 531 | |
Simon Hunt | 7faabd5 | 2016-08-18 16:16:19 -0700 | [diff] [blame] | 532 | }, 200); |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 533 | } |
Simon Hunt | e1ce429 | 2015-06-12 13:07:02 -0700 | [diff] [blame] | 534 | |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 535 | // --- Controller Definition ----------------------------------------- |
| 536 | |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 537 | angular.module('ovTopo', moduleDependencies) |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 538 | .controller('OvTopoCtrl', ['$scope', '$log', '$location', '$timeout', |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame] | 539 | '$cookies', 'FnService', 'MastService', 'KeyService', 'ZoomService', |
Simon Hunt | 0e48c29 | 2015-02-19 16:11:37 -0800 | [diff] [blame] | 540 | 'GlyphService', 'MapService', 'SvgUtilService', 'FlashService', |
Simon Hunt | a34fcb5 | 2016-02-25 16:27:32 -0800 | [diff] [blame] | 541 | 'WebSocketService', 'PrefsService', 'ThemeService', |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 542 | 'TopoDialogService', 'TopoD3Service', |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 543 | 'TopoEventService', 'TopoForceService', 'TopoPanelService', |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 544 | 'TopoInstService', 'TopoSelectService', 'TopoLinkService', |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 545 | 'TopoTrafficService', 'TopoObliqueService', 'TopoFilterService', |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 546 | 'TopoToolbarService', 'TopoMapService', 'TopoSpriteService', |
| 547 | 'TooltipService', 'TopoOverlayService', |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 548 | |
Simon Hunt | 7faabd5 | 2016-08-18 16:16:19 -0700 | [diff] [blame] | 549 | function (_$scope_, _$log_, _$loc_, _$timeout_, _$cookies_, _fs_, mast, _ks_, |
Simon Hunt | a34fcb5 | 2016-02-25 16:27:32 -0800 | [diff] [blame] | 550 | _zs_, _gs_, _ms_, _sus_, _flash_, _wss_, _ps_, _th_, |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 551 | _tds_, _t3s_, _tes_, |
Simon Hunt | a211f7f | 2015-11-09 12:48:23 -0800 | [diff] [blame] | 552 | _tfs_, _tps_, _tis_, _tss_, _tls_, _tts_, _tos_, _fltr_, |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 553 | _ttbs_, _tms_, _tspr_, _ttip_, _tov_) { |
Simon Hunt | fc5c584 | 2017-02-01 23:32:18 -0800 | [diff] [blame] | 554 | |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 555 | var params = _$loc_.search(), |
Simon Hunt | fc5c584 | 2017-02-01 23:32:18 -0800 | [diff] [blame] | 556 | selOverlay = params.overlayId, |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 557 | projection, |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 558 | dim, |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 559 | uplink = { |
| 560 | // provides function calls back into this space |
| 561 | showNoDevs: showNoDevs, |
| 562 | projection: function () { return projection; }, |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 563 | zoomLayer: function () { return zoomLayer; }, |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 564 | zoomer: function () { return zoomer; }, |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 565 | opacifyMap: opacifyMap, |
| 566 | topoStartDone: topoStartDone |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 567 | }; |
| 568 | |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 569 | $scope = _$scope_; |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 570 | $log = _$log_; |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 571 | $loc = _$loc_; |
Simon Hunt | 7faabd5 | 2016-08-18 16:16:19 -0700 | [diff] [blame] | 572 | $timeout = _$timeout_; |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame] | 573 | $cookies = _$cookies_; |
Simon Hunt | a11b4eb | 2015-01-28 16:20:50 -0800 | [diff] [blame] | 574 | fs = _fs_; |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 575 | ks = _ks_; |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 576 | zs = _zs_; |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 577 | gs = _gs_; |
Simon Hunt | 1e8eff4 | 2015-01-08 17:19:02 -0800 | [diff] [blame] | 578 | ms = _ms_; |
Simon Hunt | 7c8ab8d | 2015-02-03 15:05:15 -0800 | [diff] [blame] | 579 | sus = _sus_; |
Simon Hunt | 0e48c29 | 2015-02-19 16:11:37 -0800 | [diff] [blame] | 580 | flash = _flash_; |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 581 | wss = _wss_; |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 582 | ps = _ps_; |
Simon Hunt | a34fcb5 | 2016-02-25 16:27:32 -0800 | [diff] [blame] | 583 | th = _th_; |
Simon Hunt | a211f7f | 2015-11-09 12:48:23 -0800 | [diff] [blame] | 584 | tds = _tds_; |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 585 | t3s = _t3s_; |
Simon Hunt | c252aa6 | 2015-02-10 16:45:39 -0800 | [diff] [blame] | 586 | tes = _tes_; |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 587 | tfs = _tfs_; |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 588 | // 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 Hunt | c252aa6 | 2015-02-10 16:45:39 -0800 | [diff] [blame] | 591 | tps = _tps_; |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 592 | tis = _tis_; |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 593 | tms = _tms_; |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 594 | tss = _tss_; |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 595 | tls = _tls_; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 596 | tts = _tts_; |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 597 | tos = _tos_; |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 598 | fltr = _fltr_; |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 599 | ttbs = _ttbs_; |
Simon Hunt | a428124 | 2016-02-26 20:18:45 -0800 | [diff] [blame] | 600 | tspr = _tspr_; |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 601 | ttip = _ttip_; |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 602 | tov = _tov_; |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 603 | |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 604 | tms.start({ |
| 605 | toggleMap: toggleMap, |
| 606 | currentMap: currentMap, |
| 607 | setMap: setMap |
| 608 | }); |
| 609 | |
Simon Hunt | 441c9ae | 2017-02-03 18:22:31 -0800 | [diff] [blame] | 610 | // pull intent data from the query string... |
Viswanath KSP | 0f29770 | 2016-08-13 18:02:43 +0530 | [diff] [blame] | 611 | if (params.key && params.appId && params.appName) { |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 612 | $scope.intentData = { |
Viswanath KSP | 0f29770 | 2016-08-13 18:02:43 +0530 | [diff] [blame] | 613 | key: params.key, |
| 614 | appId: params.appId, |
Simon Hunt | 441c9ae | 2017-02-03 18:22:31 -0800 | [diff] [blame] | 615 | appName: params.appName, |
| 616 | intentType: params.intentType |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 617 | }; |
| 618 | } |
| 619 | |
Bri Prebilic Cole | 068814d | 2015-05-14 16:06:38 -0700 | [diff] [blame] | 620 | $scope.notifyResize = function () { |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 621 | svgResized(fs.windowSize(mast.mastHeight())); |
Simon Hunt | 426bd86 | 2015-01-14 16:48:41 -0800 | [diff] [blame] | 622 | }; |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 623 | |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 624 | // Cleanup on destroyed scope.. |
Simon Hunt | 584122a | 2015-01-21 15:32:40 -0800 | [diff] [blame] | 625 | $scope.$on('$destroy', function () { |
| 626 | $log.log('OvTopoCtrl is saying Buh-Bye!'); |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 627 | tes.stop(); |
Thomas Vachuska | 26be4f3 | 2016-03-31 01:10:27 -0700 | [diff] [blame] | 628 | tms.stop(); |
Bri Prebilic Cole | 9dcaea5 | 2015-07-21 14:39:48 -0700 | [diff] [blame] | 629 | ks.unbindKeys(); |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 630 | tps.destroyPanels(); |
Simon Hunt | a211f7f | 2015-11-09 12:48:23 -0800 | [diff] [blame] | 631 | tds.closeDialog(); |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 632 | tis.destroyInst(); |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 633 | tfs.destroyForce(); |
Bri Prebilic Cole | d621905 | 2015-03-19 14:34:02 -0700 | [diff] [blame] | 634 | ttbs.destroyToolbar(); |
Simon Hunt | a34fcb5 | 2016-02-25 16:27:32 -0800 | [diff] [blame] | 635 | mapShader(false); |
Simon Hunt | 584122a | 2015-01-21 15:32:40 -0800 | [diff] [blame] | 636 | }); |
| 637 | |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 638 | // svg layer and initialization of components |
Simon Hunt | 426bd86 | 2015-01-14 16:48:41 -0800 | [diff] [blame] | 639 | ovtopo = d3.select('#ov-topo'); |
| 640 | svg = ovtopo.select('svg'); |
Simon Hunt | a11b4eb | 2015-01-28 16:20:50 -0800 | [diff] [blame] | 641 | // set the svg size to match that of the window, less the masthead |
| 642 | svg.attr(fs.windowSize(mast.mastHeight())); |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 643 | dim = [svg.attr('width'), svg.attr('height')]; |
Simon Hunt | 426bd86 | 2015-01-14 16:48:41 -0800 | [diff] [blame] | 644 | |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 645 | setUpKeys(); |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 646 | setUpToolbar(); |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 647 | setUpDefs(); |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 648 | setUpZoom(); |
Simon Hunt | 7c8ab8d | 2015-02-03 15:05:15 -0800 | [diff] [blame] | 649 | setUpNoDevs(); |
Simon Hunt | 90053ed | 2016-04-06 12:49:02 -0700 | [diff] [blame] | 650 | setUpMap().then( |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 651 | function (proj) { |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 652 | var z = ps.getPrefs('topo_zoom', { tx:0, ty:0, sc:1 }); |
Simon Hunt | bb5e0d8 | 2015-04-16 14:25:46 -0700 | [diff] [blame] | 653 | zoomer.panZoom([z.tx, z.ty], z.sc); |
| 654 | $log.debug('** Zoom restored:', z); |
| 655 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 656 | projection = proj; |
Simon Hunt | bb5e0d8 | 2015-04-16 14:25:46 -0700 | [diff] [blame] | 657 | $log.debug('** We installed the projection:', proj); |
Simon Hunt | f41f309 | 2015-04-16 10:33:26 -0700 | [diff] [blame] | 658 | flash.enable(false); |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 659 | toggleMap(prefsState.bg); |
Simon Hunt | f41f309 | 2015-04-16 10:33:26 -0700 | [diff] [blame] | 660 | flash.enable(true); |
Simon Hunt | a34fcb5 | 2016-02-25 16:27:32 -0800 | [diff] [blame] | 661 | mapShader(true); |
Simon Hunt | e1ce429 | 2015-06-12 13:07:02 -0700 | [diff] [blame] | 662 | |
| 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 Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 669 | } |
| 670 | ); |
Simon Hunt | a428124 | 2016-02-26 20:18:45 -0800 | [diff] [blame] | 671 | tes.bindHandlers(); |
Simon Hunt | 90053ed | 2016-04-06 12:49:02 -0700 | [diff] [blame] | 672 | setUpSprites(); |
Simon Hunt | fd1231a | 2015-01-26 22:14:51 -0800 | [diff] [blame] | 673 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 674 | forceG = zoomLayer.append('g').attr('id', 'topo-force'); |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 675 | tfs.initForce(svg, forceG, uplink, dim); |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 676 | tis.initInst({ showMastership: tfs.showMastership }); |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 677 | tps.initPanels(); |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 678 | |
Simon Hunt | c7ae795 | 2015-04-08 18:59:27 -0700 | [diff] [blame] | 679 | restoreConfigFromPrefs(); |
Simon Hunt | fc5c584 | 2017-02-01 23:32:18 -0800 | [diff] [blame] | 680 | |
| 681 | ttbs.selectOverlay(selOverlay || prefsState.ovid); |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame] | 682 | |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 683 | $log.debug('registered overlays...', tov.list()); |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 684 | $log.log('OvTopoCtrl has been created'); |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 685 | }]); |
| 686 | }()); |