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