Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 1 | /* |
Simon Hunt | 8ead3a2 | 2015-01-06 11:00:15 -0800 | [diff] [blame] | 2 | * Copyright 2014,2015 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 | |
| 31 | // references to injected services etc. |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame^] | 32 | var $log, $cookies, fs, ks, zs, gs, ms, sus, flash, wss, |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 33 | tes, tfs, tps, tis, tss, tls, tts, tos, fltr, ttbs; |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 34 | |
| 35 | // DOM elements |
Simon Hunt | 7c8ab8d | 2015-02-03 15:05:15 -0800 | [diff] [blame] | 36 | var ovtopo, svg, defs, zoomLayer, mapG, forceG, noDevsLayer; |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 37 | |
| 38 | // Internal state |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 39 | var zoomer, actionMap; |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 40 | |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 41 | // --- Short Cut Keys ------------------------------------------------ |
| 42 | |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 43 | function setUpKeys() { |
| 44 | // key bindings need to be made after the services have been injected |
| 45 | // thus, deferred to here... |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 46 | actionMap = { |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame^] | 47 | I: [toggleInstances, 'Toggle ONOS instances panel'], |
| 48 | O: [tps.toggleSummary, 'Toggle ONOS summary panel'], |
| 49 | D: [tps.toggleDetails, 'Disable / enable details panel'], |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 50 | |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 51 | H: [tfs.toggleHosts, 'Toggle host visibility'], |
| 52 | M: [tfs.toggleOffline, 'Toggle offline visibility'], |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 53 | P: [tfs.togglePorts, 'Toggle Port Highlighting'], |
Simon Hunt | 86b7c88 | 2015-04-02 23:06:08 -0700 | [diff] [blame] | 54 | dash: [tfs.showBadLinks, 'Show bad links'], |
| 55 | B: [toggleMap, 'Toggle background map'], |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 56 | |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 57 | //X: [toggleNodeLock, 'Lock / unlock node positions'], |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 58 | Z: [tos.toggleOblique, 'Toggle oblique view (Experimental)'], |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 59 | N: [fltr.clickAction, 'Cycle node layers'], |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 60 | L: [tfs.cycleDeviceLabels, 'Cycle device labels'], |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 61 | U: [tfs.unpin, 'Unpin node (hover mouse over)'], |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 62 | R: [resetZoom, 'Reset pan / zoom'], |
Simon Hunt | 90dcc3e | 2015-03-25 15:01:27 -0700 | [diff] [blame] | 63 | dot: [ttbs.toggleToolbar, 'Toggle Toolbar'], |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 64 | |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 65 | V: [tts.showRelatedIntentsAction, 'Show all related intents'], |
| 66 | rightArrow: [tts.showNextIntentAction, 'Show next related intent'], |
| 67 | leftArrow: [tts.showPrevIntentAction, 'Show previous related intent'], |
| 68 | W: [tts.showSelectedIntentTrafficAction, 'Monitor traffic of selected intent'], |
| 69 | A: [tts.showAllTrafficAction, 'Monitor all traffic'], |
| 70 | F: [tts.showDeviceLinkFlowsAction, 'Show device link flows'], |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 71 | |
Simon Hunt | 0e48c29 | 2015-02-19 16:11:37 -0800 | [diff] [blame] | 72 | E: [equalizeMasters, 'Equalize mastership roles'], |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 73 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 74 | esc: handleEscape, |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 75 | |
Simon Hunt | 0906014 | 2015-03-18 20:23:32 -0700 | [diff] [blame] | 76 | _keyListener: ttbs.keyListener, |
| 77 | |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 78 | _helpFormat: [ |
Simon Hunt | 86b7c88 | 2015-04-02 23:06:08 -0700 | [diff] [blame] | 79 | ['I', 'O', 'D', '-', 'H', 'M', 'P', 'dash', 'B' ], |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 80 | ['X', 'Z', 'N', 'L', 'U', 'R', '-', 'dot'], |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 81 | ['V', 'rightArrow', 'leftArrow', 'W', 'A', 'F', '-', 'E' ] |
| 82 | ] |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | ks.keyBindings(actionMap); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 86 | |
Simon Hunt | 639dc66 | 2015-02-18 14:19:20 -0800 | [diff] [blame] | 87 | ks.gestureNotes([ |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 88 | ['click', 'Select the item and show details'], |
| 89 | ['shift-click', 'Toggle selection state'], |
| 90 | ['drag', 'Reposition (and pin) device / host'], |
| 91 | ['cmd-scroll', 'Zoom in / out'], |
| 92 | ['cmd-drag', 'Pan'] |
Simon Hunt | 639dc66 | 2015-02-18 14:19:20 -0800 | [diff] [blame] | 93 | ]); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 94 | } |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 95 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 96 | // --- Keystroke functions ------------------------------------------- |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 97 | |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 98 | // NOTE: this really belongs in the TopoPanelService -- but how to |
| 99 | // cleanly link in the updateDeviceColors() call? To be fixed later. |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame^] | 100 | function toggleInstances(x) { |
| 101 | if (x === 'keyev') { |
| 102 | tis.toggle(); |
| 103 | updateCookieState('insts', tis.isVisible()); |
| 104 | } else if (x) { |
| 105 | tis.show(); |
| 106 | } else { |
| 107 | tis.hide(); |
| 108 | } |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 109 | tfs.updateDeviceColors(); |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 110 | } |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 111 | |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame^] | 112 | function toggleMap(x) { |
| 113 | var on = (x === 'keyev') ? !sus.visible(mapG) : !!x; |
| 114 | sus.visible(mapG, on); |
| 115 | updateCookieState('bg', on); |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame^] | 118 | // TODO: need wrapper functions for state changes needed in cookies |
| 119 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 120 | function resetZoom() { |
| 121 | zoomer.reset(); |
| 122 | } |
| 123 | |
Simon Hunt | 0e48c29 | 2015-02-19 16:11:37 -0800 | [diff] [blame] | 124 | function equalizeMasters() { |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 125 | wss.sendEvent('equalizeMasters'); |
Simon Hunt | 0e48c29 | 2015-02-19 16:11:37 -0800 | [diff] [blame] | 126 | flash.flash('Equalizing master roles'); |
| 127 | } |
| 128 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 129 | function handleEscape() { |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 130 | if (tis.showMaster()) { |
| 131 | // if an instance is selected, cancel the affinity mapping |
| 132 | tis.cancelAffinity() |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 133 | |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 134 | } else if (tss.deselectAll()) { |
Simon Hunt | a0eb0a8 | 2015-02-11 12:30:06 -0800 | [diff] [blame] | 135 | // else if we have node selections, deselect them all |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 136 | // (work already done) |
| 137 | |
| 138 | } else if (tls.deselectLink()) { |
| 139 | // else if we have a link selected, deselect it |
| 140 | // (work already done) |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 141 | |
Simon Hunt | a0eb0a8 | 2015-02-11 12:30:06 -0800 | [diff] [blame] | 142 | } else if (tis.isVisible()) { |
| 143 | // else if the Instance Panel is visible, hide it |
| 144 | tis.hide(); |
| 145 | tfs.updateDeviceColors(); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 146 | |
Simon Hunt | a0eb0a8 | 2015-02-11 12:30:06 -0800 | [diff] [blame] | 147 | } else if (tps.summaryVisible()) { |
| 148 | // else if the Summary Panel is visible, hide it |
| 149 | tps.hideSummaryPanel(); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 150 | |
Simon Hunt | a0eb0a8 | 2015-02-11 12:30:06 -0800 | [diff] [blame] | 151 | } else { |
| 152 | // TODO: set hover mode to hoverModeNone |
Simon Hunt | 62c2f8f | 2015-02-19 14:19:10 -0800 | [diff] [blame] | 153 | // talk to Thomas about this: shouldn't it be done |
| 154 | // when we deselect the node (if tss.haveDetails()...) |
Simon Hunt | a0eb0a8 | 2015-02-11 12:30:06 -0800 | [diff] [blame] | 155 | } |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 156 | } |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 157 | |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 158 | // --- Toolbar Functions --------------------------------------------- |
| 159 | |
| 160 | function getActionEntry(key) { |
| 161 | var entry = actionMap[key]; |
| 162 | return fs.isA(entry) || [entry, '']; |
| 163 | } |
| 164 | |
| 165 | function setUpToolbar() { |
| 166 | ttbs.init({ |
| 167 | getActionEntry: getActionEntry |
| 168 | }); |
| 169 | ttbs.createToolbar(); |
| 170 | } |
| 171 | |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 172 | // --- Glyphs, Icons, and the like ----------------------------------- |
| 173 | |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 174 | function setUpDefs() { |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 175 | defs = svg.append('defs'); |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 176 | gs.loadDefs(defs); |
Simon Hunt | 0ee2868 | 2015-02-12 20:48:11 -0800 | [diff] [blame] | 177 | sus.loadGlowDefs(defs); |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 181 | // --- Pan and Zoom -------------------------------------------------- |
| 182 | |
| 183 | // zoom enabled predicate. ev is a D3 source event. |
| 184 | function zoomEnabled(ev) { |
Simon Hunt | d552ee9 | 2015-04-02 17:06:35 -0700 | [diff] [blame] | 185 | return fs.isMobile() || (ev.metaKey || ev.altKey); |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | function zoomCallback() { |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 189 | var sc = zoomer.scale(); |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 190 | |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 191 | // keep the map lines constant width while zooming |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 192 | mapG.style('stroke-width', (2.0 / sc) + 'px'); |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | function setUpZoom() { |
Simon Hunt | a7b6a6b | 2015-01-13 19:53:09 -0800 | [diff] [blame] | 196 | zoomLayer = svg.append('g').attr('id', 'topo-zoomlayer'); |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 197 | zoomer = zs.createZoomer({ |
| 198 | svg: svg, |
| 199 | zoomLayer: zoomLayer, |
| 200 | zoomEnabled: zoomEnabled, |
| 201 | zoomCallback: zoomCallback |
| 202 | }); |
| 203 | } |
| 204 | |
| 205 | |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 206 | // callback invoked when the SVG view has been resized.. |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 207 | function svgResized(s) { |
| 208 | tfs.newDim([s.width, s.height]); |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 209 | } |
| 210 | |
Simon Hunt | a7b6a6b | 2015-01-13 19:53:09 -0800 | [diff] [blame] | 211 | // --- Background Map ------------------------------------------------ |
| 212 | |
Simon Hunt | 7c8ab8d | 2015-02-03 15:05:15 -0800 | [diff] [blame] | 213 | function setUpNoDevs() { |
| 214 | var g, box; |
| 215 | noDevsLayer = svg.append('g').attr({ |
| 216 | id: 'topo-noDevsLayer', |
| 217 | transform: sus.translate(500,500) |
| 218 | }); |
| 219 | // Note, SVG viewbox is '0 0 1000 1000', defined in topo.html. |
| 220 | // We are translating this layer to have its origin at the center |
| 221 | |
| 222 | g = noDevsLayer.append('g'); |
| 223 | gs.addGlyph(g, 'bird', 100).attr('class', 'noDevsBird'); |
| 224 | g.append('text').text('No devices are connected') |
| 225 | .attr({ x: 120, y: 80}); |
| 226 | |
| 227 | box = g.node().getBBox(); |
| 228 | box.x -= box.width/2; |
| 229 | box.y -= box.height/2; |
| 230 | g.attr('transform', sus.translate(box.x, box.y)); |
| 231 | |
| 232 | showNoDevs(true); |
| 233 | } |
| 234 | |
| 235 | function showNoDevs(b) { |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 236 | sus.visible(noDevsLayer, b); |
Simon Hunt | 7c8ab8d | 2015-02-03 15:05:15 -0800 | [diff] [blame] | 237 | } |
| 238 | |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 239 | function setUpMap() { |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 240 | mapG = zoomLayer.append('g').attr('id', 'topo-map'); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 241 | // returns a promise for the projection... |
| 242 | return ms.loadMapInto(mapG, '*continental_us'); |
Simon Hunt | 0541fb8 | 2015-01-14 18:59:57 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 245 | function opacifyMap(b) { |
| 246 | mapG.transition() |
| 247 | .duration(1000) |
| 248 | .attr('opacity', b ? 1 : 0); |
| 249 | } |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 250 | |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame^] | 251 | // --- Config from Cookies ------------------------------------------- |
| 252 | |
| 253 | // TODO: write a general purpose cookie service, rather than custom here |
| 254 | |
| 255 | // NOTE: in Angular 1.3.5, $cookies is just a simple object, and |
| 256 | // cookie values are just strings. From the 1.3.5 docs: |
| 257 | // |
| 258 | // "Only a simple Object is exposed and by adding or removing |
| 259 | // properties to/from this object, new cookies are created/deleted |
| 260 | // at the end of current $eval. The object's properties can only |
| 261 | // be strings." |
| 262 | // |
| 263 | // We may want to upgrade the version of Angular sometime soon |
| 264 | // since later version support objects as cookie values. |
| 265 | |
| 266 | var defaultCookieState = { |
| 267 | bg: 1, |
| 268 | insts: 1, |
| 269 | summary: 1, |
| 270 | detail: 1, |
| 271 | hosts: 0 |
| 272 | }; |
| 273 | |
| 274 | var cookieState = {}; |
| 275 | |
| 276 | function writeCookieState() { |
| 277 | var bits = [], |
| 278 | str; |
| 279 | angular.forEach(cookieState, function (value, key) { |
| 280 | bits.push(key + ':' + value); |
| 281 | }); |
| 282 | str = bits.join(','); |
| 283 | |
| 284 | // The angular way of doing this... |
| 285 | // $cookies.topo_state = str; |
| 286 | // ...but it appears that this gets delayed, and doesn't 'stick' ?? |
| 287 | |
| 288 | // FORCE cookie to be set by writing directly to document.cookie... |
| 289 | document.cookie = 'topo_state=' + encodeURIComponent(str); |
| 290 | $log.debug('<<>> Wrote cookie:', str); |
| 291 | } |
| 292 | |
| 293 | function readCookieState() { |
| 294 | var cook = $cookies.topo_state || '', |
| 295 | bits; |
| 296 | |
| 297 | if (!cook) { |
| 298 | cookieState = angular.extend({}, defaultCookieState); |
| 299 | writeCookieState(); // seed the pot |
| 300 | |
| 301 | } else { |
| 302 | bits = cook.split(','); |
| 303 | bits.forEach(function (value) { |
| 304 | var x = value.split(':'); |
| 305 | cookieState[x[0]] = Number(x[1]); |
| 306 | }); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | function updateCookieState(what, b) { |
| 311 | cookieState[what] = b ? 1 : 0; |
| 312 | writeCookieState(); |
| 313 | } |
| 314 | |
| 315 | function restoreConfigFromCookies() { |
| 316 | readCookieState(); |
| 317 | $log.debug('Cookie State:', cookieState); |
| 318 | |
| 319 | toggleInstances(cookieState.insts); |
| 320 | tps.toggleSummary(cookieState.summary); |
| 321 | tps.toggleDetails(cookieState.detail); |
| 322 | } |
| 323 | |
| 324 | |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 325 | // --- Controller Definition ----------------------------------------- |
| 326 | |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 327 | angular.module('ovTopo', moduleDependencies) |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 328 | .controller('OvTopoCtrl', ['$scope', '$log', '$location', '$timeout', |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame^] | 329 | '$cookies', 'FnService', 'MastService', 'KeyService', 'ZoomService', |
Simon Hunt | 0e48c29 | 2015-02-19 16:11:37 -0800 | [diff] [blame] | 330 | 'GlyphService', 'MapService', 'SvgUtilService', 'FlashService', |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 331 | 'WebSocketService', |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 332 | 'TopoEventService', 'TopoForceService', 'TopoPanelService', |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 333 | 'TopoInstService', 'TopoSelectService', 'TopoLinkService', |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 334 | 'TopoTrafficService', 'TopoObliqueService', 'TopoFilterService', |
| 335 | 'TopoToolbarService', |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 336 | |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame^] | 337 | function ($scope, _$log_, $loc, $timeout, _$cookies_, _fs_, mast, _ks_, |
| 338 | _zs_, _gs_, _ms_, _sus_, _flash_, _wss_, _tes_, _tfs_, _tps_, |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 339 | _tis_, _tss_, _tls_, _tts_, _tos_, _fltr_, _ttbs_) { |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 340 | var self = this, |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 341 | projection, |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 342 | dim, |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 343 | uplink = { |
| 344 | // provides function calls back into this space |
| 345 | showNoDevs: showNoDevs, |
| 346 | projection: function () { return projection; }, |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 347 | zoomLayer: function () { return zoomLayer; }, |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 348 | zoomer: function () { return zoomer; }, |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 349 | opacifyMap: opacifyMap |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 350 | }; |
| 351 | |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 352 | $log = _$log_; |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame^] | 353 | $cookies = _$cookies_; |
Simon Hunt | a11b4eb | 2015-01-28 16:20:50 -0800 | [diff] [blame] | 354 | fs = _fs_; |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 355 | ks = _ks_; |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 356 | zs = _zs_; |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 357 | gs = _gs_; |
Simon Hunt | 1e8eff4 | 2015-01-08 17:19:02 -0800 | [diff] [blame] | 358 | ms = _ms_; |
Simon Hunt | 7c8ab8d | 2015-02-03 15:05:15 -0800 | [diff] [blame] | 359 | sus = _sus_; |
Simon Hunt | 0e48c29 | 2015-02-19 16:11:37 -0800 | [diff] [blame] | 360 | flash = _flash_; |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 361 | wss = _wss_; |
Simon Hunt | c252aa6 | 2015-02-10 16:45:39 -0800 | [diff] [blame] | 362 | tes = _tes_; |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 363 | tfs = _tfs_; |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 364 | // TODO: consider funnelling actions through TopoForceService... |
| 365 | // rather than injecting references to these 'sub-modules', |
| 366 | // just so we can invoke functions on them. |
Simon Hunt | c252aa6 | 2015-02-10 16:45:39 -0800 | [diff] [blame] | 367 | tps = _tps_; |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 368 | tis = _tis_; |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 369 | tss = _tss_; |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 370 | tls = _tls_; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 371 | tts = _tts_; |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 372 | tos = _tos_; |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 373 | fltr = _fltr_; |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 374 | ttbs = _ttbs_; |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 375 | |
Simon Hunt | 426bd86 | 2015-01-14 16:48:41 -0800 | [diff] [blame] | 376 | self.notifyResize = function () { |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 377 | svgResized(fs.windowSize(mast.mastHeight())); |
Simon Hunt | 426bd86 | 2015-01-14 16:48:41 -0800 | [diff] [blame] | 378 | }; |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 379 | |
Simon Hunt | 54442fa | 2015-01-26 14:17:38 -0800 | [diff] [blame] | 380 | // Cleanup on destroyed scope.. |
Simon Hunt | 584122a | 2015-01-21 15:32:40 -0800 | [diff] [blame] | 381 | $scope.$on('$destroy', function () { |
| 382 | $log.log('OvTopoCtrl is saying Buh-Bye!'); |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 383 | tes.stop(); |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 384 | tps.destroyPanels(); |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 385 | tis.destroyInst(); |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 386 | tfs.destroyForce(); |
Bri Prebilic Cole | d621905 | 2015-03-19 14:34:02 -0700 | [diff] [blame] | 387 | ttbs.destroyToolbar(); |
Simon Hunt | 584122a | 2015-01-21 15:32:40 -0800 | [diff] [blame] | 388 | }); |
| 389 | |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 390 | // svg layer and initialization of components |
Simon Hunt | 426bd86 | 2015-01-14 16:48:41 -0800 | [diff] [blame] | 391 | ovtopo = d3.select('#ov-topo'); |
| 392 | svg = ovtopo.select('svg'); |
Simon Hunt | a11b4eb | 2015-01-28 16:20:50 -0800 | [diff] [blame] | 393 | // set the svg size to match that of the window, less the masthead |
| 394 | svg.attr(fs.windowSize(mast.mastHeight())); |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 395 | dim = [svg.attr('width'), svg.attr('height')]; |
Simon Hunt | 426bd86 | 2015-01-14 16:48:41 -0800 | [diff] [blame] | 396 | |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 397 | setUpKeys(); |
Bri Prebilic Cole | 4db8dce | 2015-03-18 13:57:24 -0700 | [diff] [blame] | 398 | setUpToolbar(); |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 399 | setUpDefs(); |
Simon Hunt | cacce34 | 2015-01-07 16:13:05 -0800 | [diff] [blame] | 400 | setUpZoom(); |
Simon Hunt | 7c8ab8d | 2015-02-03 15:05:15 -0800 | [diff] [blame] | 401 | setUpNoDevs(); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 402 | setUpMap().then( |
| 403 | function (proj) { |
| 404 | projection = proj; |
| 405 | $log.debug('** We installed the projection: ', proj); |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame^] | 406 | toggleMap(cookieState.bg); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 407 | } |
| 408 | ); |
Simon Hunt | fd1231a | 2015-01-26 22:14:51 -0800 | [diff] [blame] | 409 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 410 | forceG = zoomLayer.append('g').attr('id', 'topo-force'); |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 411 | tfs.initForce(svg, forceG, uplink, dim); |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 412 | tis.initInst({ showMastership: tfs.showMastership }); |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 413 | tps.initPanels(); |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 414 | tes.start(); |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 415 | |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame^] | 416 | // temporary solution for persisting user settings |
| 417 | restoreConfigFromCookies(); |
| 418 | |
Simon Hunt | 6cc5369 | 2015-01-07 11:33:45 -0800 | [diff] [blame] | 419 | $log.log('OvTopoCtrl has been created'); |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 420 | }]); |
| 421 | }()); |