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