Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [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 | b0ec1e5 | 2015-01-28 18:13:49 -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 Panel Module. |
| 19 | Defines functions for manipulating the summary, detail, and instance panels. |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
| 25 | // injected refs |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 26 | var $log, $window, $rootScope, fs, ps, gs, flash, wss, bns, mast, ns; |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 27 | |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 28 | // constants |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 29 | var pCls = 'topo-p', |
| 30 | idSum = 'topo-p-summary', |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 31 | idDet = 'topo-p-detail', |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 32 | panelOpts = { |
Simon Hunt | 8f907cc | 2016-06-15 18:04:01 -0700 | [diff] [blame] | 33 | width: 260 // summary and detail panel width |
Bri Prebilic Cole | 69d5f4e | 2015-05-19 15:59:55 -0700 | [diff] [blame] | 34 | }, |
Simon Hunt | 8f907cc | 2016-06-15 18:04:01 -0700 | [diff] [blame] | 35 | sumMax = 226, // summary panel max height |
Simon Hunt | 8d47a5c | 2016-06-15 12:56:50 -0700 | [diff] [blame] | 36 | padTop = 16, // summary panel padding below masthead |
Simon Hunt | 8f907cc | 2016-06-15 18:04:01 -0700 | [diff] [blame] | 37 | padding = 16, // panel internal padding |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 38 | padFudge = padTop + 2 * padding; |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 39 | |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 40 | // internal state |
| 41 | var useDetails = true, // should we show details if we have 'em? |
Bri Prebilic Cole | d874546 | 2015-06-01 16:08:57 -0700 | [diff] [blame] | 42 | haveDetails = false, // do we have details that we could show? |
Bri Prebilic Cole | 0a6ffb6 | 2015-06-04 09:32:12 -0700 | [diff] [blame] | 43 | sumFromTop, // summary panel distance from top of screen |
| 44 | unbindWatch; |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 45 | |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 46 | // panels |
| 47 | var summary, detail; |
| 48 | |
| 49 | // === ----------------------------------------------------- |
| 50 | // Panel API |
| 51 | function createTopoPanel(id, opts) { |
| 52 | var p = ps.createPanel(id, opts), |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 53 | pid = id, |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 54 | header, body, footer; |
| 55 | p.classed(pCls, true); |
| 56 | |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 57 | function panel() { |
| 58 | return p; |
| 59 | } |
| 60 | |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 61 | function hAppend(x) { |
| 62 | return header.append(x); |
| 63 | } |
| 64 | |
| 65 | function bAppend(x) { |
| 66 | return body.append(x); |
| 67 | } |
| 68 | |
| 69 | function fAppend(x) { |
| 70 | return footer.append(x); |
| 71 | } |
| 72 | |
| 73 | function setup() { |
| 74 | p.empty(); |
| 75 | |
| 76 | p.append('div').classed('header', true); |
| 77 | p.append('div').classed('body', true); |
| 78 | p.append('div').classed('footer', true); |
| 79 | |
| 80 | header = p.el().select('.header'); |
| 81 | body = p.el().select('.body'); |
| 82 | footer = p.el().select('.footer'); |
| 83 | } |
| 84 | |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 85 | function destroy() { |
| 86 | ps.destroyPanel(pid); |
| 87 | } |
| 88 | |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 89 | // fromTop is how many pixels from the top of the page the panel is |
| 90 | // max is the max height of the panel in pixels |
| 91 | // only adjusts if the body content would be 10px or larger |
| 92 | function adjustHeight(fromTop, max) { |
| 93 | var totalPHeight, avSpace, |
Simon Hunt | 8d47a5c | 2016-06-15 12:56:50 -0700 | [diff] [blame] | 94 | overflow = 0; |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 95 | |
| 96 | if (!fromTop) { |
| 97 | $log.warn('adjustHeight: height from top of page not given'); |
| 98 | return null; |
| 99 | } else if (!body || !p) { |
Simon Hunt | 5b024d7 | 2016-01-29 11:02:43 -0800 | [diff] [blame] | 100 | // panel contents are not defined |
| 101 | // this may happen when window is resizing but panel has |
| 102 | // been cleared or removed |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 103 | return null; |
| 104 | } |
| 105 | |
Simon Hunt | 8d47a5c | 2016-06-15 12:56:50 -0700 | [diff] [blame] | 106 | p.el().style('top', fromTop + 'px'); |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 107 | p.el().style('height', null); |
| 108 | body.style('height', null); |
| 109 | |
| 110 | totalPHeight = fromTop + p.height(); |
Simon Hunt | 8d47a5c | 2016-06-15 12:56:50 -0700 | [diff] [blame] | 111 | avSpace = fs.windowSize(padFudge).height; |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 112 | |
| 113 | if (totalPHeight >= avSpace) { |
| 114 | overflow = totalPHeight - avSpace; |
| 115 | } |
| 116 | |
| 117 | function _adjustBody(height) { |
| 118 | if (height < 10) { |
| 119 | return false; |
| 120 | } else { |
| 121 | body.style('height', height + 'px'); |
| 122 | } |
| 123 | return true; |
| 124 | } |
| 125 | |
| 126 | if (!_adjustBody(fs.noPxStyle(body, 'height') - overflow)) { |
Simon Hunt | 8d47a5c | 2016-06-15 12:56:50 -0700 | [diff] [blame] | 127 | return p.height(); |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | if (max && p.height() > max) { |
| 131 | _adjustBody(fs.noPxStyle(body, 'height') - (p.height() - max)); |
| 132 | } |
Simon Hunt | 8d47a5c | 2016-06-15 12:56:50 -0700 | [diff] [blame] | 133 | return p.height(); |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | return { |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 137 | panel: panel, |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 138 | setup: setup, |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 139 | destroy: destroy, |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 140 | appendHeader: hAppend, |
| 141 | appendBody: bAppend, |
| 142 | appendFooter: fAppend, |
| 143 | adjustHeight: adjustHeight |
| 144 | }; |
| 145 | } |
| 146 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 147 | // === ----------------------------------------------------- |
| 148 | // Utility functions |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 149 | |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 150 | function addSep(tbody) { |
| 151 | tbody.append('tr').append('td').attr('colspan', 2).append('hr'); |
| 152 | } |
| 153 | |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 154 | function addBtnFooter() { |
| 155 | detail.appendFooter('hr'); |
| 156 | detail.appendFooter('div').classed('actionBtns', true); |
| 157 | } |
| 158 | |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 159 | function addProp(tbody, label, value) { |
Simon Hunt | e25c5a2 | 2015-04-02 14:37:12 -0700 | [diff] [blame] | 160 | var tr = tbody.append('tr'), |
Bri Prebilic Cole | f5e48b1 | 2015-04-21 14:52:36 -0700 | [diff] [blame] | 161 | lab; |
| 162 | if (typeof label === 'string') { |
Simon Hunt | e25c5a2 | 2015-04-02 14:37:12 -0700 | [diff] [blame] | 163 | lab = label.replace(/_/g, ' '); |
Bri Prebilic Cole | f5e48b1 | 2015-04-21 14:52:36 -0700 | [diff] [blame] | 164 | } else { |
| 165 | lab = label; |
| 166 | } |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 167 | |
| 168 | function addCell(cls, txt) { |
Simon Hunt | 239f09e | 2017-05-18 13:10:09 -0700 | [diff] [blame] | 169 | tr.append('td').attr('class', cls).text(txt); |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 170 | } |
Simon Hunt | e25c5a2 | 2015-04-02 14:37:12 -0700 | [diff] [blame] | 171 | addCell('label', lab + ' :'); |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 172 | addCell('value', value); |
| 173 | } |
| 174 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 175 | function listProps(tbody, data) { |
Steven Burrows | cdf6b33 | 2017-05-05 11:29:29 -0400 | [diff] [blame] | 176 | |
| 177 | // Suppress Lat Long in details panel if null |
| 178 | if (data.props.Latitude === null || |
| 179 | data.props.Longitude === null) { |
| 180 | var idx = data.propOrder.indexOf('Latitude'); |
| 181 | data.propOrder.splice(idx, 3); |
| 182 | } |
| 183 | |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 184 | data.propOrder.forEach(function (p) { |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 185 | if (p === '-') { |
| 186 | addSep(tbody); |
| 187 | } else { |
| 188 | addProp(tbody, p, data.props[p]); |
| 189 | } |
| 190 | }); |
| 191 | } |
| 192 | |
Bri Prebilic Cole | 69d5f4e | 2015-05-19 15:59:55 -0700 | [diff] [blame] | 193 | function watchWindow() { |
Bri Prebilic Cole | 0a6ffb6 | 2015-06-04 09:32:12 -0700 | [diff] [blame] | 194 | unbindWatch = $rootScope.$watchCollection( |
Bri Prebilic Cole | 69d5f4e | 2015-05-19 15:59:55 -0700 | [diff] [blame] | 195 | function () { |
| 196 | return { |
| 197 | h: $window.innerHeight, |
| 198 | w: $window.innerWidth |
| 199 | }; |
| 200 | }, function () { |
Simon Hunt | 8d47a5c | 2016-06-15 12:56:50 -0700 | [diff] [blame] | 201 | var h = summary.adjustHeight(sumFromTop, sumMax), |
| 202 | ss = summary.panel().isVisible(), |
| 203 | dtop = h && ss ? sumFromTop + h + padFudge : 0, |
| 204 | dy = dtop || ss ? detail.ypos.current : sumFromTop; |
| 205 | detail.adjustHeight(dy); |
Bri Prebilic Cole | 69d5f4e | 2015-05-19 15:59:55 -0700 | [diff] [blame] | 206 | } |
| 207 | ); |
| 208 | } |
| 209 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 210 | // === ----------------------------------------------------- |
| 211 | // Functions for populating the summary panel |
| 212 | |
| 213 | function populateSummary(data) { |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 214 | summary.setup(); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 215 | |
Bri Prebilic Cole | 8d3de3d | 2015-05-15 16:02:59 -0700 | [diff] [blame] | 216 | var svg = summary.appendHeader('div') |
| 217 | .classed('icon', true) |
| 218 | .append('svg'), |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 219 | title = summary.appendHeader('h2'), |
| 220 | table = summary.appendBody('table'), |
Simon Hunt | 8f907cc | 2016-06-15 18:04:01 -0700 | [diff] [blame] | 221 | tbody = table.append('tbody'); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 222 | |
Simon Hunt | 8f907cc | 2016-06-15 18:04:01 -0700 | [diff] [blame] | 223 | gs.addGlyph(svg, 'bird', 24, 0, [1,1]); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 224 | |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 225 | title.text(data.title); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 226 | listProps(tbody, data); |
| 227 | } |
| 228 | |
| 229 | // === ----------------------------------------------------- |
| 230 | // Functions for populating the detail panel |
| 231 | |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 232 | var navPathIdKey = { |
| 233 | device: 'devId', |
| 234 | host: 'hostId' |
Simon Hunt | b745ca6 | 2015-07-28 15:37:11 -0700 | [diff] [blame] | 235 | }; |
| 236 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 237 | function displaySingle(data) { |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 238 | detail.setup(); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 239 | |
Bri Prebilic Cole | 8d3de3d | 2015-05-15 16:02:59 -0700 | [diff] [blame] | 240 | var svg = detail.appendHeader('div') |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 241 | .classed('icon clickable', true) |
Bri Prebilic Cole | 8d3de3d | 2015-05-15 16:02:59 -0700 | [diff] [blame] | 242 | .append('svg'), |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 243 | title = detail.appendHeader('h2') |
| 244 | .classed('clickable', true), |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 245 | table = detail.appendBody('table'), |
Simon Hunt | b745ca6 | 2015-07-28 15:37:11 -0700 | [diff] [blame] | 246 | tbody = table.append('tbody'), |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 247 | navFn, |
| 248 | navPath; |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 249 | |
Simon Hunt | 8f907cc | 2016-06-15 18:04:01 -0700 | [diff] [blame] | 250 | gs.addGlyph(svg, (data.type || 'unknown'), 26); |
Simon Hunt | b745ca6 | 2015-07-28 15:37:11 -0700 | [diff] [blame] | 251 | title.text(data.title); |
| 252 | |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 253 | // add navigation hot-link if defined |
| 254 | navPath = data.navPath; |
| 255 | if (navPath) { |
Simon Hunt | b745ca6 | 2015-07-28 15:37:11 -0700 | [diff] [blame] | 256 | navFn = function () { |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 257 | var arg = {}; |
| 258 | arg[navPathIdKey[navPath]] = data.id; |
| 259 | ns.navTo(navPath, arg); |
Simon Hunt | b745ca6 | 2015-07-28 15:37:11 -0700 | [diff] [blame] | 260 | }; |
| 261 | |
| 262 | svg.on('click', navFn); |
| 263 | title.on('click', navFn); |
| 264 | } |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 265 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 266 | listProps(tbody, data); |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 267 | addBtnFooter(); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | function displayMulti(ids) { |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 271 | detail.setup(); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 272 | |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 273 | var title = detail.appendHeader('h3'), |
| 274 | table = detail.appendBody('table'), |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 275 | tbody = table.append('tbody'); |
| 276 | |
Prince Pereira | 46c82d4 | 2016-09-19 13:30:50 +0530 | [diff] [blame] | 277 | title.text('Selected Items'); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 278 | ids.forEach(function (d, i) { |
| 279 | addProp(tbody, i+1, d); |
| 280 | }); |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 281 | addBtnFooter(); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 282 | } |
| 283 | |
Bri Prebilic Cole | f5e48b1 | 2015-04-21 14:52:36 -0700 | [diff] [blame] | 284 | function addAction(o) { |
| 285 | var btnDiv = d3.select('#' + idDet) |
| 286 | .select('.actionBtns') |
| 287 | .append('div') |
| 288 | .classed('actionBtn', true); |
Simon Hunt | 3a0598f | 2015-08-04 19:59:04 -0700 | [diff] [blame] | 289 | bns.button(btnDiv, idDet + '-' + o.id, o.gid, o.cb, o.tt); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 290 | } |
| 291 | |
Simon Hunt | a36f03b | 2015-04-01 15:22:49 -0700 | [diff] [blame] | 292 | var friendlyIndex = { |
| 293 | device: 1, |
| 294 | host: 0 |
| 295 | }; |
| 296 | |
| 297 | function friendly(d) { |
| 298 | var i = friendlyIndex[d.class] || 0; |
| 299 | return (d.labels && d.labels[i]) || ''; |
| 300 | } |
| 301 | |
| 302 | function linkSummary(d) { |
| 303 | var o = d && d.online ? 'online' : 'offline'; |
| 304 | return d ? d.type + ' / ' + o : '-'; |
| 305 | } |
| 306 | |
Simon Hunt | e25c5a2 | 2015-04-02 14:37:12 -0700 | [diff] [blame] | 307 | // provided to change presentation of internal type name |
| 308 | var linkTypePres = { |
| 309 | hostLink: 'edge link' |
| 310 | }; |
| 311 | |
| 312 | function linkType(d) { |
| 313 | return linkTypePres[d.type()] || d.type(); |
| 314 | } |
| 315 | |
Ray Milkey | b7f0f64 | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 316 | function linkExpected(d) { |
| 317 | return d.expected(); |
| 318 | } |
| 319 | |
Simon Hunt | e25c5a2 | 2015-04-02 14:37:12 -0700 | [diff] [blame] | 320 | var coreOrder = [ |
Ray Milkey | b7f0f64 | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 321 | 'Type', 'Expected', '-', |
Simon Hunt | e25c5a2 | 2015-04-02 14:37:12 -0700 | [diff] [blame] | 322 | 'A_type', 'A_id', 'A_label', 'A_port', '-', |
Simon Hunt | 5c1a938 | 2016-06-01 19:35:35 -0700 | [diff] [blame] | 323 | 'B_type', 'B_id', 'B_label', 'B_port' |
Simon Hunt | e25c5a2 | 2015-04-02 14:37:12 -0700 | [diff] [blame] | 324 | ], |
| 325 | edgeOrder = [ |
| 326 | 'Type', '-', |
| 327 | 'A_type', 'A_id', 'A_label', '-', |
| 328 | 'B_type', 'B_id', 'B_label', 'B_port' |
| 329 | ]; |
| 330 | |
Simon Hunt | 5c1a938 | 2016-06-01 19:35:35 -0700 | [diff] [blame] | 331 | function displayLink(data, modifyCb) { |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 332 | detail.setup(); |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 333 | |
Bri Prebilic Cole | 8d3de3d | 2015-05-15 16:02:59 -0700 | [diff] [blame] | 334 | var svg = detail.appendHeader('div') |
| 335 | .classed('icon', true) |
| 336 | .append('svg'), |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 337 | title = detail.appendHeader('h2'), |
| 338 | table = detail.appendBody('table'), |
Simon Hunt | e25c5a2 | 2015-04-02 14:37:12 -0700 | [diff] [blame] | 339 | tbody = table.append('tbody'), |
| 340 | edgeLink = data.type() === 'hostLink', |
| 341 | order = edgeLink ? edgeOrder : coreOrder; |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 342 | |
Simon Hunt | f29d8e6 | 2016-06-20 11:09:25 -0700 | [diff] [blame] | 343 | gs.addGlyph(svg, 'ports', 26); |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 344 | title.text('Link'); |
Simon Hunt | a36f03b | 2015-04-01 15:22:49 -0700 | [diff] [blame] | 345 | |
Simon Hunt | 5c1a938 | 2016-06-01 19:35:35 -0700 | [diff] [blame] | 346 | var linkData = { |
| 347 | propOrder: order.slice(0), // makes a copy of the array |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 348 | props: { |
Simon Hunt | e25c5a2 | 2015-04-02 14:37:12 -0700 | [diff] [blame] | 349 | Type: linkType(data), |
Ray Milkey | b7f0f64 | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 350 | Expected: linkExpected(data), |
Simon Hunt | a36f03b | 2015-04-01 15:22:49 -0700 | [diff] [blame] | 351 | |
| 352 | A_type: data.source.class, |
| 353 | A_id: data.source.id, |
| 354 | A_label: friendly(data.source), |
| 355 | A_port: data.srcPort, |
| 356 | |
| 357 | B_type: data.target.class, |
| 358 | B_id: data.target.id, |
| 359 | B_label: friendly(data.target), |
| 360 | B_port: data.tgtPort |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 361 | } |
Simon Hunt | 5c1a938 | 2016-06-01 19:35:35 -0700 | [diff] [blame] | 362 | }; |
| 363 | listProps(tbody, modifyCb(linkData, data.extra)); |
Simon Hunt | a36f03b | 2015-04-01 15:22:49 -0700 | [diff] [blame] | 364 | |
Simon Hunt | e25c5a2 | 2015-04-02 14:37:12 -0700 | [diff] [blame] | 365 | if (!edgeLink) { |
Simon Hunt | 5c1a938 | 2016-06-01 19:35:35 -0700 | [diff] [blame] | 366 | addSep(tbody); |
Simon Hunt | e25c5a2 | 2015-04-02 14:37:12 -0700 | [diff] [blame] | 367 | addProp(tbody, 'A → B', linkSummary(data.fromSource)); |
| 368 | addProp(tbody, 'B → A', linkSummary(data.fromTarget)); |
| 369 | } |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | function displayNothing() { |
| 373 | haveDetails = false; |
| 374 | hideDetailPanel(); |
| 375 | } |
| 376 | |
| 377 | function displaySomething() { |
| 378 | haveDetails = true; |
| 379 | if (useDetails) { |
| 380 | showDetailPanel(); |
| 381 | } |
| 382 | } |
| 383 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 384 | // === ----------------------------------------------------- |
| 385 | // Event Handlers |
| 386 | |
| 387 | function showSummary(data) { |
| 388 | populateSummary(data); |
| 389 | showSummaryPanel(); |
| 390 | } |
| 391 | |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame] | 392 | function toggleSummary(x) { |
Simon Hunt | ee7a3ce | 2015-04-09 13:28:37 -0700 | [diff] [blame] | 393 | var kev = (x === 'keyev'), |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 394 | on = kev ? !summary.panel().isVisible() : !!x, |
Simon Hunt | ee7a3ce | 2015-04-09 13:28:37 -0700 | [diff] [blame] | 395 | verb = on ? 'Show' : 'Hide'; |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame] | 396 | |
| 397 | if (on) { |
Simon Hunt | a0eb0a8 | 2015-02-11 12:30:06 -0800 | [diff] [blame] | 398 | // ask server to start sending summary data. |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 399 | wss.sendEvent('requestSummary'); |
Simon Hunt | a0eb0a8 | 2015-02-11 12:30:06 -0800 | [diff] [blame] | 400 | // note: the summary panel will appear, once data arrives |
Simon Hunt | 36a58c6 | 2015-04-08 11:00:07 -0700 | [diff] [blame] | 401 | } else { |
| 402 | hideSummaryPanel(); |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 403 | } |
Simon Hunt | ee7a3ce | 2015-04-09 13:28:37 -0700 | [diff] [blame] | 404 | flash.flash(verb + ' summary panel'); |
| 405 | return on; |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 406 | } |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 407 | |
| 408 | // === ----------------------------------------------------- |
| 409 | // === LOGIC For showing/hiding summary and detail panels... |
| 410 | |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 411 | function showSummaryPanel() { |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 412 | function _show() { |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 413 | summary.panel().show(); |
Bri Prebilic Cole | 69d5f4e | 2015-05-19 15:59:55 -0700 | [diff] [blame] | 414 | summary.adjustHeight(sumFromTop, sumMax); |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 415 | } |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 416 | if (detail.panel().isVisible()) { |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 417 | detail.down(_show); |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 418 | } else { |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 419 | _show(); |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 420 | } |
Simon Hunt | c252aa6 | 2015-02-10 16:45:39 -0800 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | function hideSummaryPanel() { |
Simon Hunt | a0eb0a8 | 2015-02-11 12:30:06 -0800 | [diff] [blame] | 424 | // instruct server to stop sending summary data |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 425 | wss.sendEvent("cancelSummary"); |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 426 | summary.panel().hide(detail.up); |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 427 | } |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 428 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 429 | function showDetailPanel() { |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 430 | if (summary.panel().isVisible()) { |
| 431 | detail.down(detail.panel().show); |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 432 | } else { |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 433 | detail.up(detail.panel().show); |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 434 | } |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | function hideDetailPanel() { |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 438 | detail.panel().hide(); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 439 | } |
| 440 | |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 441 | // ========================== |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 442 | |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 443 | function augmentDetailPanel() { |
Bri Prebilic Cole | d874546 | 2015-06-01 16:08:57 -0700 | [diff] [blame] | 444 | var d = detail, |
Simon Hunt | 8d47a5c | 2016-06-15 12:56:50 -0700 | [diff] [blame] | 445 | downPos = sumFromTop + sumMax + padFudge; |
Bri Prebilic Cole | d874546 | 2015-06-01 16:08:57 -0700 | [diff] [blame] | 446 | d.ypos = { up: sumFromTop, down: downPos, current: downPos}; |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 447 | |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 448 | d._move = function (y, cb) { |
Bri Prebilic Cole | 69d5f4e | 2015-05-19 15:59:55 -0700 | [diff] [blame] | 449 | var yp = d.ypos, |
| 450 | endCb; |
| 451 | |
| 452 | if (fs.isF(cb)) { |
| 453 | endCb = function () { |
| 454 | cb(); |
| 455 | d.adjustHeight(d.ypos.current); |
| 456 | } |
| 457 | } else { |
| 458 | endCb = function () { |
| 459 | d.adjustHeight(d.ypos.current); |
| 460 | } |
| 461 | } |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 462 | if (yp.current !== y) { |
| 463 | yp.current = y; |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 464 | d.panel().el().transition().duration(300) |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 465 | .each('end', endCb) |
| 466 | .style('top', yp.current + 'px'); |
| 467 | } else { |
| 468 | endCb(); |
| 469 | } |
| 470 | }; |
| 471 | |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 472 | d.down = function (cb) { d._move(d.ypos.down, cb); }; |
| 473 | d.up = function (cb) { d._move(d.ypos.up, cb); }; |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 474 | } |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 475 | |
Simon Hunt | 239e588 | 2015-04-23 15:07:04 -0700 | [diff] [blame] | 476 | function toggleUseDetailsFlag(x) { |
Simon Hunt | ee7a3ce | 2015-04-09 13:28:37 -0700 | [diff] [blame] | 477 | var kev = (x === 'keyev'), |
| 478 | verb; |
| 479 | |
| 480 | useDetails = kev ? !useDetails : !!x; |
| 481 | verb = useDetails ? 'Enable' : 'Disable'; |
| 482 | |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 483 | if (useDetails) { |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 484 | if (haveDetails) { |
| 485 | showDetailPanel(); |
| 486 | } |
| 487 | } else { |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 488 | hideDetailPanel(); |
| 489 | } |
Simon Hunt | ee7a3ce | 2015-04-09 13:28:37 -0700 | [diff] [blame] | 490 | flash.flash(verb + ' details panel'); |
| 491 | return useDetails; |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 494 | // ========================== |
| 495 | |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 496 | function initPanels() { |
Bri Prebilic Cole | d874546 | 2015-06-01 16:08:57 -0700 | [diff] [blame] | 497 | sumFromTop = mast.mastHeight() + padTop; |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 498 | summary = createTopoPanel(idSum, panelOpts); |
| 499 | detail = createTopoPanel(idDet, panelOpts); |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 500 | |
| 501 | augmentDetailPanel(); |
Bri Prebilic Cole | 69d5f4e | 2015-05-19 15:59:55 -0700 | [diff] [blame] | 502 | watchWindow(); |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | function destroyPanels() { |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 506 | summary.destroy(); |
| 507 | summary = null; |
| 508 | |
| 509 | detail.destroy(); |
| 510 | detail = null; |
Simon Hunt | 239e588 | 2015-04-23 15:07:04 -0700 | [diff] [blame] | 511 | haveDetails = false; |
Bri Prebilic Cole | 0a6ffb6 | 2015-06-04 09:32:12 -0700 | [diff] [blame] | 512 | unbindWatch(); |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | // ========================== |
| 516 | |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 517 | angular.module('ovTopo') |
| 518 | .factory('TopoPanelService', |
Bri Prebilic Cole | 69d5f4e | 2015-05-19 15:59:55 -0700 | [diff] [blame] | 519 | ['$log', '$window', '$rootScope', 'FnService', 'PanelService', 'GlyphService', |
Bri Prebilic Cole | d874546 | 2015-06-01 16:08:57 -0700 | [diff] [blame] | 520 | 'FlashService', 'WebSocketService', 'ButtonService', 'MastService', |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 521 | 'NavService', |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 522 | |
Bri Prebilic Cole | 69d5f4e | 2015-05-19 15:59:55 -0700 | [diff] [blame] | 523 | function (_$log_, _$window_, _$rootScope_, |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 524 | _fs_, _ps_, _gs_, _flash_, _wss_, _bns_, _mast_, _ns_) { |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 525 | $log = _$log_; |
Bri Prebilic Cole | 69d5f4e | 2015-05-19 15:59:55 -0700 | [diff] [blame] | 526 | $window = _$window_; |
| 527 | $rootScope = _$rootScope_; |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 528 | fs = _fs_; |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 529 | ps = _ps_; |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 530 | gs = _gs_; |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 531 | flash = _flash_; |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 532 | wss = _wss_; |
Bri Prebilic Cole | f5e48b1 | 2015-04-21 14:52:36 -0700 | [diff] [blame] | 533 | bns = _bns_; |
Bri Prebilic Cole | d874546 | 2015-06-01 16:08:57 -0700 | [diff] [blame] | 534 | mast = _mast_; |
Bri Prebilic Cole | 17c6d0a | 2015-07-16 14:56:40 -0700 | [diff] [blame] | 535 | ns = _ns_; |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 536 | |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 537 | return { |
| 538 | initPanels: initPanels, |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 539 | destroyPanels: destroyPanels, |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 540 | createTopoPanel: createTopoPanel, |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 541 | |
| 542 | showSummary: showSummary, |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 543 | toggleSummary: toggleSummary, |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 544 | hideSummary: hideSummaryPanel, |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 545 | |
Simon Hunt | 239e588 | 2015-04-23 15:07:04 -0700 | [diff] [blame] | 546 | toggleUseDetailsFlag: toggleUseDetailsFlag, |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 547 | displaySingle: displaySingle, |
| 548 | displayMulti: displayMulti, |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 549 | displayLink: displayLink, |
| 550 | displayNothing: displayNothing, |
| 551 | displaySomething: displaySomething, |
Bri Prebilic Cole | 684bcb7 | 2015-05-11 12:00:24 -0700 | [diff] [blame] | 552 | addAction: addAction, |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 553 | |
Bri Prebilic Cole | 35d2971 | 2015-05-11 16:01:32 -0700 | [diff] [blame] | 554 | detailVisible: function () { return detail.panel().isVisible(); }, |
| 555 | summaryVisible: function () { return summary.panel().isVisible(); } |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 556 | }; |
| 557 | }]); |
| 558 | }()); |