Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [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 | /* |
| 19 | ONOS GUI -- Topology Overlay Module. |
| 20 | |
| 21 | Provides overlay capabilities, allowing ONOS apps to provide additional |
| 22 | custom data/behavior for the topology view. |
| 23 | |
| 24 | */ |
| 25 | |
| 26 | (function () { |
| 27 | 'use strict'; |
| 28 | |
| 29 | // constants |
| 30 | var tos = 'TopoOverlayService: '; |
| 31 | |
| 32 | // injected refs |
Andrea Campanella | 2dc91dc | 2015-12-07 12:17:02 -0800 | [diff] [blame] | 33 | var $log, $timeout, fs, gs, wss, ns, tss, tps, api; |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 34 | |
| 35 | // internal state |
Simon Hunt | e05cae4 | 2015-07-23 17:35:24 -0700 | [diff] [blame] | 36 | var overlays = {}, |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 37 | current = null, |
| 38 | reset = true; |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 39 | |
Simon Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 40 | // function to be replaced by the localization bundle function |
| 41 | var topoLion = function (x) { |
| 42 | return '#tov#' + x + '#'; |
| 43 | }; |
| 44 | |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 45 | function error(fn, msg) { |
| 46 | $log.error(tos + fn + '(): ' + msg); |
| 47 | } |
| 48 | |
| 49 | function warn(fn, msg) { |
| 50 | $log.warn(tos + fn + '(): ' + msg); |
| 51 | } |
| 52 | |
Simon Hunt | fb94011 | 2015-07-29 18:36:35 -0700 | [diff] [blame] | 53 | function mkGlyphId(oid, gid) { |
| 54 | return (gid[0] === '*') ? oid + '-' + gid.slice(1) : gid; |
| 55 | } |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 56 | |
Simon Hunt | fb94011 | 2015-07-29 18:36:35 -0700 | [diff] [blame] | 57 | function handleGlyphs(o) { |
| 58 | var gdata = fs.isO(o.glyphs), |
| 59 | oid = o.overlayId, |
| 60 | gid = o.glyphId || 'unknown', |
| 61 | data = {}, |
| 62 | note = []; |
| 63 | |
| 64 | o._glyphId = mkGlyphId(oid, gid); |
| 65 | |
| 66 | o.mkGid = function (g) { |
| 67 | return mkGlyphId(oid, g); |
| 68 | }; |
| 69 | o.mkId = function (s) { |
| 70 | return oid + '-' + s; |
| 71 | }; |
| 72 | |
| 73 | // process glyphs if defined |
| 74 | if (gdata) { |
| 75 | angular.forEach(gdata, function (value, key) { |
| 76 | var fullkey = oid + '-' + key; |
| 77 | data['_' + fullkey] = value.vb; |
| 78 | data[fullkey] = value.d; |
| 79 | note.push('*' + key); |
| 80 | }); |
| 81 | gs.registerGlyphs(data); |
| 82 | $log.debug('registered overlay glyphs:', oid, note); |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
| 86 | function register(overlay) { |
| 87 | var r = 'register', |
| 88 | over = fs.isO(overlay), |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 89 | kb = over ? fs.isO(overlay.keyBindings) : null, |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 90 | id = over ? over.overlayId : ''; |
| 91 | |
| 92 | if (!id) { |
| 93 | return error(r, 'not a recognized overlay'); |
| 94 | } |
| 95 | if (overlays[id]) { |
| 96 | return warn(r, 'already registered: "' + id + '"'); |
| 97 | } |
| 98 | overlays[id] = overlay; |
Simon Hunt | fb94011 | 2015-07-29 18:36:35 -0700 | [diff] [blame] | 99 | handleGlyphs(overlay); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 100 | |
| 101 | if (kb) { |
| 102 | if (!fs.isA(kb._keyOrder)) { |
| 103 | warn(r, 'no _keyOrder array defined on keyBindings'); |
| 104 | } else { |
| 105 | kb._keyOrder.forEach(function (k) { |
| 106 | if (k !== '-' && !kb[k]) { |
| 107 | warn(r, 'no "' + k + '" property defined on keyBindings'); |
| 108 | } |
| 109 | }); |
| 110 | } |
| 111 | } |
| 112 | |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 113 | $log.debug(tos + 'registered overlay: ' + id, overlay); |
| 114 | } |
| 115 | |
Simon Hunt | fc5c584 | 2017-02-01 23:32:18 -0800 | [diff] [blame] | 116 | // Returns the list of overlay identifiers. |
| 117 | function list() { |
| 118 | return d3.map(overlays).keys(); |
| 119 | } |
Simon Hunt | c5489c9 | 2017-01-30 17:50:48 -0800 | [diff] [blame] | 120 | |
Simon Hunt | 441c9ae | 2017-02-03 18:22:31 -0800 | [diff] [blame] | 121 | // Returns an array containing overlays that implement the showIntent and |
| 122 | // acceptIntent callbacks, and that accept the given intent type |
| 123 | function overlaysAcceptingIntents(intentType) { |
Simon Hunt | fc5c584 | 2017-02-01 23:32:18 -0800 | [diff] [blame] | 124 | var result = []; |
| 125 | angular.forEach(overlays, function (ov) { |
Simon Hunt | 441c9ae | 2017-02-03 18:22:31 -0800 | [diff] [blame] | 126 | var ovid = ov.overlayId, |
| 127 | hooks = fs.isO(ov.hooks) || {}, |
| 128 | aicb = fs.isF(hooks.acceptIntent), |
| 129 | sicb = fs.isF(hooks.showIntent); |
Simon Hunt | c5489c9 | 2017-01-30 17:50:48 -0800 | [diff] [blame] | 130 | |
Simon Hunt | 441c9ae | 2017-02-03 18:22:31 -0800 | [diff] [blame] | 131 | if (sicb && aicb && aicb(intentType)) { |
Simon Hunt | fc5c584 | 2017-02-01 23:32:18 -0800 | [diff] [blame] | 132 | result.push({ |
Simon Hunt | 441c9ae | 2017-02-03 18:22:31 -0800 | [diff] [blame] | 133 | id: ovid, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 134 | tt: ov.tooltip || '%' + ovid + '%', |
Simon Hunt | fc5c584 | 2017-02-01 23:32:18 -0800 | [diff] [blame] | 135 | }); |
| 136 | } |
Simon Hunt | c5489c9 | 2017-01-30 17:50:48 -0800 | [diff] [blame] | 137 | }); |
Simon Hunt | fc5c584 | 2017-02-01 23:32:18 -0800 | [diff] [blame] | 138 | return result; |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 141 | // add a radio button for each registered overlay |
Simon Hunt | a5b53af | 2015-10-12 15:56:40 -0700 | [diff] [blame] | 142 | // return an overlay id to index map |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 143 | function augmentRbset(rset, switchFn) { |
Simon Hunt | a5b53af | 2015-10-12 15:56:40 -0700 | [diff] [blame] | 144 | var map = {}, |
| 145 | idx = 1; |
| 146 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 147 | angular.forEach(overlays, function (ov) { |
| 148 | rset.push({ |
| 149 | gid: ov._glyphId, |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame^] | 150 | tooltip: (ov.tooltip || ''), |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 151 | cb: function () { |
| 152 | tbSelection(ov.overlayId, switchFn); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 153 | }, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 154 | }); |
Simon Hunt | a5b53af | 2015-10-12 15:56:40 -0700 | [diff] [blame] | 155 | map[ov.overlayId] = idx++; |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 156 | }); |
Simon Hunt | a5b53af | 2015-10-12 15:56:40 -0700 | [diff] [blame] | 157 | return map; |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Simon Hunt | e05cae4 | 2015-07-23 17:35:24 -0700 | [diff] [blame] | 160 | // an overlay was selected via toolbar radio button press from user |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 161 | function tbSelection(id, switchFn) { |
Simon Hunt | e05cae4 | 2015-07-23 17:35:24 -0700 | [diff] [blame] | 162 | var same = current && current.overlayId === id, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 163 | payload = {}, |
| 164 | actions; |
Simon Hunt | e05cae4 | 2015-07-23 17:35:24 -0700 | [diff] [blame] | 165 | |
| 166 | function doop(op) { |
| 167 | var oid = current.overlayId; |
| 168 | $log.debug('Overlay:', op, oid); |
| 169 | current[op](); |
| 170 | payload[op] = oid; |
| 171 | } |
| 172 | |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 173 | if (reset || !same) { |
| 174 | reset = false; |
Simon Hunt | e05cae4 | 2015-07-23 17:35:24 -0700 | [diff] [blame] | 175 | current && doop('deactivate'); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 176 | current = overlays[id]; |
Simon Hunt | e05cae4 | 2015-07-23 17:35:24 -0700 | [diff] [blame] | 177 | current && doop('activate'); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 178 | actions = current && fs.isO(current.keyBindings); |
| 179 | switchFn(id, actions); |
| 180 | |
Simon Hunt | e05cae4 | 2015-07-23 17:35:24 -0700 | [diff] [blame] | 181 | wss.sendEvent('topoSelectOverlay', payload); |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 182 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 183 | // Ensure summary and details panels are updated immediately.. |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 184 | wss.sendEvent('requestSummary'); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 185 | tss.updateDetail(); |
Simon Hunt | e05cae4 | 2015-07-23 17:35:24 -0700 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 189 | var coreButtons = { |
| 190 | showDeviceView: { |
| 191 | gid: 'switch', |
Simon Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 192 | tt: function () { return topoLion('btn_show_view_device'); }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 193 | path: 'device', |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 194 | }, |
| 195 | showFlowView: { |
| 196 | gid: 'flowTable', |
Simon Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 197 | tt: function () { return topoLion('btn_show_view_flow'); }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 198 | path: 'flow', |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 199 | }, |
| 200 | showPortView: { |
| 201 | gid: 'portTable', |
Simon Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 202 | tt: function () { return topoLion('btn_show_view_port'); }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 203 | path: 'port', |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 204 | }, |
| 205 | showGroupView: { |
| 206 | gid: 'groupTable', |
Simon Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 207 | tt: function () { return topoLion('btn_show_view_group'); }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 208 | path: 'group', |
Jian Li | 79f6732 | 2016-01-06 18:22:37 -0800 | [diff] [blame] | 209 | }, |
| 210 | showMeterView: { |
| 211 | gid: 'meterTable', |
Simon Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 212 | tt: function () { return topoLion('btn_show_view_meter'); }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 213 | path: 'meter', |
| 214 | }, |
Simon Hunt | 3a0598f | 2015-08-04 19:59:04 -0700 | [diff] [blame] | 215 | }; |
Simon Hunt | fb94011 | 2015-07-29 18:36:35 -0700 | [diff] [blame] | 216 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 217 | // retrieves a button definition from the current overlay and generates |
| 218 | // a button descriptor to be added to the panel, with the data baked in |
| 219 | function _getButtonDef(id, data) { |
| 220 | var btns = current && current.buttons, |
| 221 | b = btns && btns[id], |
| 222 | cb = fs.isF(b.cb), |
| 223 | f = cb ? function () { cb(data); } : function () {}; |
| 224 | |
| 225 | return b ? { |
| 226 | id: current.mkId(id), |
| 227 | gid: current.mkGid(b.gid), |
| 228 | tt: b.tt, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 229 | cb: f, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 230 | } : null; |
| 231 | } |
| 232 | |
Simon Hunt | 3a0598f | 2015-08-04 19:59:04 -0700 | [diff] [blame] | 233 | // install core buttons, and include any additional from the current overlay |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 234 | function installButtons(buttons, data, devId) { |
| 235 | buttons.forEach(function (id) { |
| 236 | var btn = coreButtons[id], |
| 237 | gid = btn && btn.gid, |
| 238 | tt = btn && btn.tt, |
| 239 | path = btn && btn.path; |
Simon Hunt | 3a0598f | 2015-08-04 19:59:04 -0700 | [diff] [blame] | 240 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 241 | if (btn) { |
| 242 | tps.addAction({ |
| 243 | id: 'core-' + id, |
| 244 | gid: gid, |
| 245 | tt: tt, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 246 | cb: function () { ns.navTo(path, { devId: devId }); }, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 247 | }); |
| 248 | } else if (btn = _getButtonDef(id, data)) { |
| 249 | tps.addAction(btn); |
Simon Hunt | 3a0598f | 2015-08-04 19:59:04 -0700 | [diff] [blame] | 250 | } |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 251 | }); |
| 252 | } |
Simon Hunt | 3a0598f | 2015-08-04 19:59:04 -0700 | [diff] [blame] | 253 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 254 | function addDetailButton(id) { |
| 255 | var b = _getButtonDef(id); |
| 256 | if (b) { |
| 257 | tps.addAction({ |
| 258 | id: current.mkId(id), |
| 259 | gid: current.mkGid(b.gid), |
| 260 | cb: b.cb, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 261 | tt: b.tt, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 262 | }); |
| 263 | } |
| 264 | } |
Simon Hunt | 3a0598f | 2015-08-04 19:59:04 -0700 | [diff] [blame] | 265 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 266 | |
| 267 | // === ----------------------------------------------------- |
| 268 | // Hooks for overlays |
| 269 | |
| 270 | function _hook(x) { |
| 271 | var h = current && current.hooks; |
| 272 | return h && fs.isF(h[x]); |
| 273 | } |
| 274 | |
| 275 | function escapeHook() { |
| 276 | var eh = _hook('escape'); |
| 277 | return eh ? eh() : false; |
| 278 | } |
| 279 | |
| 280 | function emptySelectHook() { |
| 281 | var cb = _hook('empty'); |
| 282 | cb && cb(); |
| 283 | } |
| 284 | |
| 285 | function singleSelectHook(data) { |
| 286 | var cb = _hook('single'); |
| 287 | cb && cb(data); |
| 288 | } |
| 289 | |
| 290 | function multiSelectHook(selectOrder) { |
| 291 | var cb = _hook('multi'); |
| 292 | cb && cb(selectOrder); |
| 293 | } |
| 294 | |
Simon Hunt | 584e92d | 2015-08-24 11:27:22 -0700 | [diff] [blame] | 295 | function mouseOverHook(what) { |
| 296 | var cb = _hook('mouseover'); |
| 297 | cb && cb(what); |
| 298 | } |
| 299 | |
| 300 | function mouseOutHook() { |
| 301 | var cb = _hook('mouseout'); |
| 302 | cb && cb(); |
| 303 | } |
| 304 | |
Simon Hunt | 8419efd | 2017-01-12 12:36:28 -0800 | [diff] [blame] | 305 | // Request from Intent View to visualize an intent on the topo view |
| 306 | function showIntentHook(intentData) { |
Simon Hunt | 441c9ae | 2017-02-03 18:22:31 -0800 | [diff] [blame] | 307 | var cb = _hook('showIntent'); |
Simon Hunt | 8419efd | 2017-01-12 12:36:28 -0800 | [diff] [blame] | 308 | return cb && cb(intentData); |
| 309 | } |
| 310 | |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame^] | 311 | // 'core.view.Topo' lion bundle will be injected here. |
| 312 | // NOTE: if an overlay wants additional bundles, it should use the |
| 313 | // LionService to request them at this time. |
| 314 | function injectLion(topoBundle) { |
| 315 | var cb = _hook('injectLion'); |
| 316 | return cb && cb(topoBundle); |
| 317 | } |
| 318 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 319 | // === ----------------------------------------------------- |
| 320 | // Event (from server) Handlers |
| 321 | |
| 322 | function setApi(_api_, _tss_) { |
| 323 | api = _api_; |
| 324 | tss = _tss_; |
| 325 | } |
| 326 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 327 | // process highlight event with optional delay |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 328 | function showHighlights(data) { |
Andrea Campanella | 2dc91dc | 2015-12-07 12:17:02 -0800 | [diff] [blame] | 329 | function doHighlight() { |
| 330 | _showHighlights(data); |
| 331 | } |
| 332 | |
| 333 | if (data.delay) { |
| 334 | $timeout(doHighlight, data.delay); |
| 335 | } else { |
| 336 | doHighlight(); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | function _showHighlights(data) { |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 341 | var less; |
| 342 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 343 | /* |
| 344 | API to topoForce |
| 345 | clearLinkTrafficStyle() |
| 346 | removeLinkLabels() |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 347 | findLinkById( id ) |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 348 | findNodeById( id ) |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 349 | updateLinks() |
| 350 | updateNodes() |
| 351 | supLayers( bool, [less] ) |
| 352 | unsupNode( id, [less] ) |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 353 | unsupLink( key, [less] ) |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 354 | */ |
| 355 | |
Simon Hunt | e9343f3 | 2015-10-21 18:07:46 -0700 | [diff] [blame] | 356 | api.clearNodeDeco(); |
| 357 | api.removeNodeBadges(); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 358 | api.clearLinkTrafficStyle(); |
| 359 | api.removeLinkLabels(); |
| 360 | |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 361 | // handle element suppression |
| 362 | if (data.subdue) { |
| 363 | less = data.subdue === 'min'; |
| 364 | api.supLayers(true, less); |
| 365 | |
| 366 | } else { |
| 367 | api.supLayers(false); |
| 368 | api.supLayers(false, true); |
| 369 | } |
| 370 | |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 371 | data.hosts.forEach(function (host) { |
Andrea Campanella | 5212541 | 2015-12-03 14:50:40 -0800 | [diff] [blame] | 372 | var hdata = api.findNodeById(host.id), |
| 373 | badgeData = host.badge || null; |
| 374 | |
Simon Hunt | a1f1c02 | 2016-03-03 15:54:57 -0800 | [diff] [blame] | 375 | if (hdata && hdata.el && !hdata.el.empty()) { |
Andrea Campanella | 5212541 | 2015-12-03 14:50:40 -0800 | [diff] [blame] | 376 | hdata.badge = badgeData; |
Simon Hunt | 5b3ff90 | 2015-08-27 09:46:27 -0700 | [diff] [blame] | 377 | if (!host.subdue) { |
| 378 | api.unsupNode(hdata.id, less); |
| 379 | } |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 380 | // TODO: further highlighting? |
Simon Hunt | b344248 | 2016-03-03 17:30:07 -0800 | [diff] [blame] | 381 | } else { |
| 382 | $log.warn('HILITE: no host element:', host.id); |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 383 | } |
| 384 | }); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 385 | |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 386 | data.devices.forEach(function (device) { |
Simon Hunt | e9343f3 | 2015-10-21 18:07:46 -0700 | [diff] [blame] | 387 | var ddata = api.findNodeById(device.id), |
| 388 | badgeData = device.badge || null; |
| 389 | |
Simon Hunt | a1f1c02 | 2016-03-03 15:54:57 -0800 | [diff] [blame] | 390 | if (ddata && ddata.el && !ddata.el.empty()) { |
Simon Hunt | e9343f3 | 2015-10-21 18:07:46 -0700 | [diff] [blame] | 391 | ddata.badge = badgeData; |
Simon Hunt | 5b3ff90 | 2015-08-27 09:46:27 -0700 | [diff] [blame] | 392 | if (!device.subdue) { |
| 393 | api.unsupNode(ddata.id, less); |
| 394 | } |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 395 | // TODO: further highlighting? |
Simon Hunt | b344248 | 2016-03-03 17:30:07 -0800 | [diff] [blame] | 396 | } else { |
| 397 | $log.warn('HILITE: no device element:', device.id); |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 398 | } |
| 399 | }); |
| 400 | |
| 401 | data.links.forEach(function (link) { |
Simon Hunt | 6985517 | 2017-03-31 09:48:25 -0700 | [diff] [blame] | 402 | var ldata = api.findLinkById(link.id); |
Simon Hunt | a1f1c02 | 2016-03-03 15:54:57 -0800 | [diff] [blame] | 403 | |
| 404 | if (ldata && ldata.el && !ldata.el.empty()) { |
Simon Hunt | 5b3ff90 | 2015-08-27 09:46:27 -0700 | [diff] [blame] | 405 | if (!link.subdue) { |
| 406 | api.unsupLink(ldata.key, less); |
| 407 | } |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 408 | ldata.el.classed(link.css, true); |
Simon Hunt | 6985517 | 2017-03-31 09:48:25 -0700 | [diff] [blame] | 409 | ldata.label = link.label; |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 410 | |
Simon Hunt | b344248 | 2016-03-03 17:30:07 -0800 | [diff] [blame] | 411 | } else { |
| 412 | $log.warn('HILITE: no link element:', link.id); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 413 | } |
Simon Hunt | 3a0598f | 2015-08-04 19:59:04 -0700 | [diff] [blame] | 414 | }); |
Simon Hunt | fb94011 | 2015-07-29 18:36:35 -0700 | [diff] [blame] | 415 | |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 416 | api.updateNodes(); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 417 | api.updateLinks(); |
Simon Hunt | fb94011 | 2015-07-29 18:36:35 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Simon Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 420 | // invoked after the localization bundle has been received from the server |
| 421 | function setLionBundle(bundle) { |
| 422 | topoLion = bundle; |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame^] | 423 | // also inject the topo lion bundle to all overlays that request it |
| 424 | angular.forEach(overlays, function (ov) { |
| 425 | var hooks = fs.isO(ov.hooks) || {}, |
| 426 | inj = fs.isF(hooks.injectLion); |
| 427 | inj && inj(bundle); |
| 428 | }); |
Simon Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 431 | // ======================================================================== |
| 432 | |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 433 | angular.module('ovTopo') |
| 434 | .factory('TopoOverlayService', |
Andrea Campanella | 2dc91dc | 2015-12-07 12:17:02 -0800 | [diff] [blame] | 435 | ['$log', '$timeout', 'FnService', 'GlyphService', 'WebSocketService', |
| 436 | 'NavService', 'TopoPanelService', |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 437 | |
Andrea Campanella | 2dc91dc | 2015-12-07 12:17:02 -0800 | [diff] [blame] | 438 | function (_$log_, _$timeout_, _fs_, _gs_, _wss_, _ns_, _tps_) { |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 439 | $log = _$log_; |
Andrea Campanella | 2dc91dc | 2015-12-07 12:17:02 -0800 | [diff] [blame] | 440 | $timeout = _$timeout_; |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 441 | fs = _fs_; |
| 442 | gs = _gs_; |
Simon Hunt | e05cae4 | 2015-07-23 17:35:24 -0700 | [diff] [blame] | 443 | wss = _wss_; |
Simon Hunt | 3a0598f | 2015-08-04 19:59:04 -0700 | [diff] [blame] | 444 | ns = _ns_; |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 445 | tps = _tps_; |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 446 | |
| 447 | return { |
| 448 | register: register, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 449 | setApi: setApi, |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 450 | list: list, |
Simon Hunt | 441c9ae | 2017-02-03 18:22:31 -0800 | [diff] [blame] | 451 | overlaysAcceptingIntents: overlaysAcceptingIntents, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 452 | augmentRbset: augmentRbset, |
| 453 | mkGlyphId: mkGlyphId, |
Simon Hunt | fb94011 | 2015-07-29 18:36:35 -0700 | [diff] [blame] | 454 | tbSelection: tbSelection, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 455 | installButtons: installButtons, |
| 456 | addDetailButton: addDetailButton, |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 457 | resetOnToolbarDestroy: function () { reset = true; }, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 458 | hooks: { |
| 459 | escape: escapeHook, |
| 460 | emptySelect: emptySelectHook, |
| 461 | singleSelect: singleSelectHook, |
Simon Hunt | 584e92d | 2015-08-24 11:27:22 -0700 | [diff] [blame] | 462 | multiSelect: multiSelectHook, |
| 463 | mouseOver: mouseOverHook, |
Simon Hunt | 5c1a938 | 2016-06-01 19:35:35 -0700 | [diff] [blame] | 464 | mouseOut: mouseOutHook, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 465 | showIntent: showIntentHook, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 466 | }, |
| 467 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 468 | showHighlights: showHighlights, |
Simon Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 469 | setLionBundle: setLionBundle, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 470 | }; |
Simon Hunt | 72e44bf | 2015-07-21 21:34:20 -0700 | [diff] [blame] | 471 | }]); |
| 472 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 473 | }()); |