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