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