blob: 34526141c61817312d0dee385e5af600cb189ccd [file] [log] [blame]
Simon Huntb0ec1e52015-01-28 18:13:49 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Simon Huntb0ec1e52015-01-28 18:13:49 -08003 *
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 Cole17c6d0a2015-07-16 14:56:40 -070026 var $log, $window, $rootScope, fs, ps, gs, flash, wss, bns, mast, ns;
Simon Huntb0ec1e52015-01-28 18:13:49 -080027
Simon Hunt879ce452017-08-10 23:32:00 -070028 // function to be replaced by the localization bundle function
29 var topoLion = function (x) {
30 return '#tps#' + x + '#';
31 };
32
Simon Hunt626d2102015-01-29 11:54:50 -080033 // constants
Simon Hunt08f841d02015-02-10 14:39:20 -080034 var pCls = 'topo-p',
35 idSum = 'topo-p-summary',
Simon Hunt626d2102015-01-29 11:54:50 -080036 idDet = 'topo-p-detail',
Simon Hunt626d2102015-01-29 11:54:50 -080037 panelOpts = {
Steven Burrows1c2a9682017-07-14 16:52:46 +010038 width: 260, // summary and detail panel width
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -070039 },
Steven Burrows1c2a9682017-07-14 16:52:46 +010040 sumMax = 226, // summary panel max height
41 padTop = 16, // summary panel padding below masthead
42 padding = 16, // panel internal padding
Simon Hunt10618f62017-06-15 19:30:52 -070043 padFudge = padTop + 2 * padding;
Simon Hunt626d2102015-01-29 11:54:50 -080044
Simon Hunt0c6b2d32015-03-26 17:46:29 -070045 // internal state
Steven Burrows1c2a9682017-07-14 16:52:46 +010046 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 Cole0a6ffb62015-06-04 09:32:12 -070049 unbindWatch;
Simon Huntb0ec1e52015-01-28 18:13:49 -080050
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -070051 // panels
52 var summary, detail;
53
54 // === -----------------------------------------------------
55 // Panel API
56 function createTopoPanel(id, opts) {
57 var p = ps.createPanel(id, opts),
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070058 pid = id,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -070059 header, body, footer;
60 p.classed(pCls, true);
61
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070062 function panel() {
63 return p;
64 }
65
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -070066 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 Cole35d29712015-05-11 16:01:32 -070090 function destroy() {
91 ps.destroyPanel(pid);
92 }
93
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -070094 // 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 Hunt8d47a5c2016-06-15 12:56:50 -070099 overflow = 0;
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700100
101 if (!fromTop) {
102 $log.warn('adjustHeight: height from top of page not given');
103 return null;
104 } else if (!body || !p) {
Simon Hunt5b024d72016-01-29 11:02:43 -0800105 // panel contents are not defined
106 // this may happen when window is resizing but panel has
107 // been cleared or removed
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700108 return null;
109 }
110
Simon Hunt8d47a5c2016-06-15 12:56:50 -0700111 p.el().style('top', fromTop + 'px');
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700112 p.el().style('height', null);
113 body.style('height', null);
114
115 totalPHeight = fromTop + p.height();
Simon Hunt8d47a5c2016-06-15 12:56:50 -0700116 avSpace = fs.windowSize(padFudge).height;
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700117
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 Hunt8d47a5c2016-06-15 12:56:50 -0700132 return p.height();
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700133 }
134
135 if (max && p.height() > max) {
136 _adjustBody(fs.noPxStyle(body, 'height') - (p.height() - max));
137 }
Simon Hunt8d47a5c2016-06-15 12:56:50 -0700138 return p.height();
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700139 }
140
141 return {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700142 panel: panel,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700143 setup: setup,
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700144 destroy: destroy,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700145 appendHeader: hAppend,
146 appendBody: bAppend,
147 appendFooter: fAppend,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100148 adjustHeight: adjustHeight,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700149 };
150 }
151
Simon Hunt08f841d02015-02-10 14:39:20 -0800152 // === -----------------------------------------------------
153 // Utility functions
Simon Hunt626d2102015-01-29 11:54:50 -0800154
Simon Hunt4b668592015-01-29 17:33:53 -0800155 function addSep(tbody) {
156 tbody.append('tr').append('td').attr('colspan', 2).append('hr');
157 }
158
Simon Hunta58d8942017-08-11 12:51:14 -0700159 function addBtnFooter(sepAlreadyThere) {
160 if (!sepAlreadyThere) {
161 detail.appendFooter('hr');
162 }
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700163 detail.appendFooter('div').classed('actionBtns', true);
164 }
165
Simon Hunt4b668592015-01-29 17:33:53 -0800166 function addProp(tbody, label, value) {
Simon Hunte25c5a22015-04-02 14:37:12 -0700167 var tr = tbody.append('tr'),
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -0700168 lab;
169 if (typeof label === 'string') {
Simon Hunte25c5a22015-04-02 14:37:12 -0700170 lab = label.replace(/_/g, ' ');
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -0700171 } else {
172 lab = label;
173 }
Simon Hunt4b668592015-01-29 17:33:53 -0800174
175 function addCell(cls, txt) {
Simon Hunt239f09e2017-05-18 13:10:09 -0700176 tr.append('td').attr('class', cls).text(txt);
Simon Hunt4b668592015-01-29 17:33:53 -0800177 }
Simon Hunta58d8942017-08-11 12:51:14 -0700178
Simon Hunte25c5a22015-04-02 14:37:12 -0700179 addCell('label', lab + ' :');
Simon Hunt4b668592015-01-29 17:33:53 -0800180 addCell('value', value);
181 }
182
Simon Hunt08f841d02015-02-10 14:39:20 -0800183 function listProps(tbody, data) {
Simon Hunta58d8942017-08-11 12:51:14 -0700184 var sepLast = false;
Steven Burrowscdf6b332017-05-05 11:29:29 -0400185
Simon Hunta58d8942017-08-11 12:51:14 -0700186 // note: track whether we end with a separator or not...
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700187 data.propOrder.forEach(function (p) {
Simon Hunt08f841d02015-02-10 14:39:20 -0800188 if (p === '-') {
189 addSep(tbody);
Simon Hunta58d8942017-08-11 12:51:14 -0700190 sepLast = true;
Simon Hunt08f841d02015-02-10 14:39:20 -0800191 } else {
Simon Hunta58d8942017-08-11 12:51:14 -0700192 addProp(tbody, data.propLabels[p], data.propValues[p]);
193 sepLast = false;
Simon Hunt08f841d02015-02-10 14:39:20 -0800194 }
195 });
Simon Hunta58d8942017-08-11 12:51:14 -0700196 return sepLast;
Simon Hunt08f841d02015-02-10 14:39:20 -0800197 }
198
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700199 function watchWindow() {
Bri Prebilic Cole0a6ffb62015-06-04 09:32:12 -0700200 unbindWatch = $rootScope.$watchCollection(
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700201 function () {
202 return {
203 h: $window.innerHeight,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100204 w: $window.innerWidth,
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700205 };
206 }, function () {
Simon Hunt8d47a5c2016-06-15 12:56:50 -0700207 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 Cole69d5f4e2015-05-19 15:59:55 -0700212 }
213 );
214 }
215
Simon Hunt08f841d02015-02-10 14:39:20 -0800216 // === -----------------------------------------------------
217 // Functions for populating the summary panel
218
219 function populateSummary(data) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700220 summary.setup();
Simon Hunt08f841d02015-02-10 14:39:20 -0800221
Bri Prebilic Cole8d3de3d2015-05-15 16:02:59 -0700222 var svg = summary.appendHeader('div')
223 .classed('icon', true)
224 .append('svg'),
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700225 title = summary.appendHeader('h2'),
226 table = summary.appendBody('table'),
Simon Hunta58d8942017-08-11 12:51:14 -0700227 tbody = table.append('tbody'),
228 glyphId = data.glyphId || 'bird';
Simon Hunt08f841d02015-02-10 14:39:20 -0800229
Simon Hunta58d8942017-08-11 12:51:14 -0700230 gs.addGlyph(svg, glyphId, 24, 0, [1, 1]);
Simon Hunt08f841d02015-02-10 14:39:20 -0800231
Simon Hunt0af1ec32015-07-24 12:17:55 -0700232 title.text(data.title);
Simon Hunt08f841d02015-02-10 14:39:20 -0800233 listProps(tbody, data);
234 }
235
236 // === -----------------------------------------------------
237 // Functions for populating the detail panel
238
Simon Hunt10618f62017-06-15 19:30:52 -0700239 var navPathIdKey = {
240 device: 'devId',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100241 host: 'hostId',
Simon Huntb745ca62015-07-28 15:37:11 -0700242 };
243
Simon Hunt08f841d02015-02-10 14:39:20 -0800244 function displaySingle(data) {
Simon Hunta58d8942017-08-11 12:51:14 -0700245 var sepLast;
246
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700247 detail.setup();
Simon Hunt08f841d02015-02-10 14:39:20 -0800248
Simon Hunta58d8942017-08-11 12:51:14 -0700249 // TODO: remove
250 $log.debug('>> Display Single Item Details', data);
251
Bri Prebilic Cole8d3de3d2015-05-15 16:02:59 -0700252 var svg = detail.appendHeader('div')
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700253 .classed('icon clickable', true)
Bri Prebilic Cole8d3de3d2015-05-15 16:02:59 -0700254 .append('svg'),
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700255 title = detail.appendHeader('h2')
256 .classed('clickable', true),
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700257 table = detail.appendBody('table'),
Simon Huntb745ca62015-07-28 15:37:11 -0700258 tbody = table.append('tbody'),
Simon Hunt10618f62017-06-15 19:30:52 -0700259 navFn,
260 navPath;
Simon Hunt08f841d02015-02-10 14:39:20 -0800261
Simon Hunta58d8942017-08-11 12:51:14 -0700262 gs.addGlyph(svg, (data.glyphId || 'm_unknown'), 26);
Simon Huntb745ca62015-07-28 15:37:11 -0700263 title.text(data.title);
264
Simon Hunt10618f62017-06-15 19:30:52 -0700265 // add navigation hot-link if defined
266 navPath = data.navPath;
267 if (navPath) {
Simon Huntb745ca62015-07-28 15:37:11 -0700268 navFn = function () {
Simon Hunt10618f62017-06-15 19:30:52 -0700269 var arg = {};
270 arg[navPathIdKey[navPath]] = data.id;
271 ns.navTo(navPath, arg);
Simon Huntb745ca62015-07-28 15:37:11 -0700272 };
273
274 svg.on('click', navFn);
275 title.on('click', navFn);
276 }
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700277
Simon Hunta58d8942017-08-11 12:51:14 -0700278 sepLast = listProps(tbody, data);
279 addBtnFooter(sepLast);
Simon Hunt08f841d02015-02-10 14:39:20 -0800280 }
281
282 function displayMulti(ids) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700283 detail.setup();
Simon Hunt08f841d02015-02-10 14:39:20 -0800284
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700285 var title = detail.appendHeader('h3'),
286 table = detail.appendBody('table'),
Simon Hunt08f841d02015-02-10 14:39:20 -0800287 tbody = table.append('tbody');
288
Simon Hunta58d8942017-08-11 12:51:14 -0700289 title.text(topoLion('title_selected_items'));
Simon Hunt08f841d02015-02-10 14:39:20 -0800290 ids.forEach(function (d, i) {
Simon Hunta58d8942017-08-11 12:51:14 -0700291 addProp(tbody, i + 1, d);
Simon Hunt08f841d02015-02-10 14:39:20 -0800292 });
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700293 addBtnFooter();
Simon Hunt08f841d02015-02-10 14:39:20 -0800294 }
295
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -0700296 function addAction(o) {
297 var btnDiv = d3.select('#' + idDet)
298 .select('.actionBtns')
299 .append('div')
300 .classed('actionBtn', true);
Simon Hunt3a0598f2015-08-04 19:59:04 -0700301 bns.button(btnDiv, idDet + '-' + o.id, o.gid, o.cb, o.tt);
Simon Hunt08f841d02015-02-10 14:39:20 -0800302 }
303
Simon Hunta36f03b2015-04-01 15:22:49 -0700304 var friendlyIndex = {
305 device: 1,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100306 host: 0,
Simon Hunta36f03b2015-04-01 15:22:49 -0700307 };
308
309 function friendly(d) {
310 var i = friendlyIndex[d.class] || 0;
311 return (d.labels && d.labels[i]) || '';
312 }
313
314 function linkSummary(d) {
315 var o = d && d.online ? 'online' : 'offline';
316 return d ? d.type + ' / ' + o : '-';
317 }
318
Simon Hunte25c5a22015-04-02 14:37:12 -0700319 // provided to change presentation of internal type name
320 var linkTypePres = {
Steven Burrows1c2a9682017-07-14 16:52:46 +0100321 hostLink: 'edge link',
Simon Hunte25c5a22015-04-02 14:37:12 -0700322 };
323
324 function linkType(d) {
325 return linkTypePres[d.type()] || d.type();
326 }
327
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800328 function linkExpected(d) {
329 return d.expected();
330 }
331
Simon Hunta58d8942017-08-11 12:51:14 -0700332 // TODO: implement server-side processing of link details
Simon Hunte25c5a22015-04-02 14:37:12 -0700333 var coreOrder = [
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800334 'Type', 'Expected', '-',
Simon Hunte25c5a22015-04-02 14:37:12 -0700335 'A_type', 'A_id', 'A_label', 'A_port', '-',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100336 'B_type', 'B_id', 'B_label', 'B_port',
Simon Hunte25c5a22015-04-02 14:37:12 -0700337 ],
338 edgeOrder = [
339 'Type', '-',
340 'A_type', 'A_id', 'A_label', '-',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100341 'B_type', 'B_id', 'B_label', 'B_port',
Simon Hunte25c5a22015-04-02 14:37:12 -0700342 ];
343
Simon Hunta58d8942017-08-11 12:51:14 -0700344 // FIXME: DEPRECATED (no longer called)
Simon Hunt5c1a9382016-06-01 19:35:35 -0700345 function displayLink(data, modifyCb) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700346 detail.setup();
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700347
Bri Prebilic Cole8d3de3d2015-05-15 16:02:59 -0700348 var svg = detail.appendHeader('div')
349 .classed('icon', true)
350 .append('svg'),
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700351 title = detail.appendHeader('h2'),
352 table = detail.appendBody('table'),
Simon Hunte25c5a22015-04-02 14:37:12 -0700353 tbody = table.append('tbody'),
354 edgeLink = data.type() === 'hostLink',
355 order = edgeLink ? edgeOrder : coreOrder;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700356
Simon Huntf29d8e62016-06-20 11:09:25 -0700357 gs.addGlyph(svg, 'ports', 26);
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700358 title.text('Link');
Simon Hunta36f03b2015-04-01 15:22:49 -0700359
Simon Hunt5c1a9382016-06-01 19:35:35 -0700360 var linkData = {
Steven Burrows1c2a9682017-07-14 16:52:46 +0100361 propOrder: order.slice(0), // makes a copy of the array
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700362 props: {
Simon Hunte25c5a22015-04-02 14:37:12 -0700363 Type: linkType(data),
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800364 Expected: linkExpected(data),
Simon Hunta36f03b2015-04-01 15:22:49 -0700365
366 A_type: data.source.class,
367 A_id: data.source.id,
368 A_label: friendly(data.source),
369 A_port: data.srcPort,
370
371 B_type: data.target.class,
372 B_id: data.target.id,
373 B_label: friendly(data.target),
Steven Burrows1c2a9682017-07-14 16:52:46 +0100374 B_port: data.tgtPort,
375 },
Simon Hunt5c1a9382016-06-01 19:35:35 -0700376 };
377 listProps(tbody, modifyCb(linkData, data.extra));
Simon Hunta36f03b2015-04-01 15:22:49 -0700378
Simon Hunte25c5a22015-04-02 14:37:12 -0700379 if (!edgeLink) {
Simon Hunt5c1a9382016-06-01 19:35:35 -0700380 addSep(tbody);
Simon Hunte25c5a22015-04-02 14:37:12 -0700381 addProp(tbody, 'A &rarr; B', linkSummary(data.fromSource));
382 addProp(tbody, 'B &rarr; A', linkSummary(data.fromTarget));
383 }
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700384 }
385
386 function displayNothing() {
387 haveDetails = false;
388 hideDetailPanel();
389 }
390
391 function displaySomething() {
392 haveDetails = true;
393 if (useDetails) {
394 showDetailPanel();
395 }
396 }
397
Simon Hunt08f841d02015-02-10 14:39:20 -0800398 // === -----------------------------------------------------
399 // Event Handlers
400
401 function showSummary(data) {
402 populateSummary(data);
403 showSummaryPanel();
404 }
405
Simon Hunt36a58c62015-04-08 11:00:07 -0700406 function toggleSummary(x) {
Simon Huntee7a3ce2015-04-09 13:28:37 -0700407 var kev = (x === 'keyev'),
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700408 on = kev ? !summary.panel().isVisible() : !!x,
Simon Hunt879ce452017-08-10 23:32:00 -0700409 verb = on ? topoLion('show') : topoLion('hide'),
410 sumpan = topoLion('fl_panel_summary');
Simon Hunt36a58c62015-04-08 11:00:07 -0700411
412 if (on) {
Simon Hunta0eb0a82015-02-11 12:30:06 -0800413 // ask server to start sending summary data.
Simon Hunt237676b52015-03-10 19:04:26 -0700414 wss.sendEvent('requestSummary');
Simon Hunta0eb0a82015-02-11 12:30:06 -0800415 // note: the summary panel will appear, once data arrives
Simon Hunt36a58c62015-04-08 11:00:07 -0700416 } else {
417 hideSummaryPanel();
Simon Hunt6036b192015-02-11 11:20:26 -0800418 }
Simon Hunt879ce452017-08-10 23:32:00 -0700419 flash.flash(verb + ' ' + sumpan);
Simon Huntee7a3ce2015-04-09 13:28:37 -0700420 return on;
Simon Hunt6036b192015-02-11 11:20:26 -0800421 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800422
423 // === -----------------------------------------------------
424 // === LOGIC For showing/hiding summary and detail panels...
425
Simon Hunt626d2102015-01-29 11:54:50 -0800426 function showSummaryPanel() {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700427 function _show() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700428 summary.panel().show();
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700429 summary.adjustHeight(sumFromTop, sumMax);
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700430 }
Simon Hunta58d8942017-08-11 12:51:14 -0700431
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700432 if (detail.panel().isVisible()) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700433 detail.down(_show);
Simon Hunt6036b192015-02-11 11:20:26 -0800434 } else {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700435 _show();
Simon Hunt6036b192015-02-11 11:20:26 -0800436 }
Simon Huntc252aa62015-02-10 16:45:39 -0800437 }
438
439 function hideSummaryPanel() {
Simon Hunta0eb0a82015-02-11 12:30:06 -0800440 // instruct server to stop sending summary data
Steven Burrows1c2a9682017-07-14 16:52:46 +0100441 wss.sendEvent('cancelSummary');
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700442 summary.panel().hide(detail.up);
Simon Hunt4b668592015-01-29 17:33:53 -0800443 }
Simon Hunt626d2102015-01-29 11:54:50 -0800444
Simon Hunt08f841d02015-02-10 14:39:20 -0800445 function showDetailPanel() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700446 if (summary.panel().isVisible()) {
447 detail.down(detail.panel().show);
Simon Hunt6036b192015-02-11 11:20:26 -0800448 } else {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700449 detail.up(detail.panel().show);
Simon Hunt6036b192015-02-11 11:20:26 -0800450 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800451 }
452
453 function hideDetailPanel() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700454 detail.panel().hide();
Simon Hunt08f841d02015-02-10 14:39:20 -0800455 }
456
Simon Hunt6036b192015-02-11 11:20:26 -0800457 // ==========================
Simon Hunt08f841d02015-02-10 14:39:20 -0800458
Simon Hunt6036b192015-02-11 11:20:26 -0800459 function augmentDetailPanel() {
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700460 var d = detail,
Simon Hunt8d47a5c2016-06-15 12:56:50 -0700461 downPos = sumFromTop + sumMax + padFudge;
Steven Burrows1c2a9682017-07-14 16:52:46 +0100462 d.ypos = { up: sumFromTop, down: downPos, current: downPos };
Simon Hunt6036b192015-02-11 11:20:26 -0800463
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700464 d._move = function (y, cb) {
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700465 var yp = d.ypos,
466 endCb;
467
468 if (fs.isF(cb)) {
469 endCb = function () {
470 cb();
471 d.adjustHeight(d.ypos.current);
Steven Burrows1c2a9682017-07-14 16:52:46 +0100472 };
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700473 } else {
474 endCb = function () {
475 d.adjustHeight(d.ypos.current);
Steven Burrows1c2a9682017-07-14 16:52:46 +0100476 };
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700477 }
Simon Hunt6036b192015-02-11 11:20:26 -0800478 if (yp.current !== y) {
479 yp.current = y;
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700480 d.panel().el().transition().duration(300)
Simon Hunt6036b192015-02-11 11:20:26 -0800481 .each('end', endCb)
482 .style('top', yp.current + 'px');
483 } else {
484 endCb();
485 }
486 };
487
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700488 d.down = function (cb) { d._move(d.ypos.down, cb); };
489 d.up = function (cb) { d._move(d.ypos.up, cb); };
Simon Hunt6036b192015-02-11 11:20:26 -0800490 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800491
Simon Hunt239e5882015-04-23 15:07:04 -0700492 function toggleUseDetailsFlag(x) {
Simon Huntee7a3ce2015-04-09 13:28:37 -0700493 var kev = (x === 'keyev'),
494 verb;
495
496 useDetails = kev ? !useDetails : !!x;
Simon Hunta58d8942017-08-11 12:51:14 -0700497 verb = useDetails ? 'Enable' : 'Disable'; // TODO: Lion
Simon Huntee7a3ce2015-04-09 13:28:37 -0700498
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700499 if (useDetails) {
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700500 if (haveDetails) {
501 showDetailPanel();
502 }
503 } else {
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700504 hideDetailPanel();
505 }
Simon Hunta58d8942017-08-11 12:51:14 -0700506 flash.flash(verb + ' details panel'); // TODO: Lion
Simon Huntee7a3ce2015-04-09 13:28:37 -0700507 return useDetails;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700508 }
509
Simon Hunt4b668592015-01-29 17:33:53 -0800510 // ==========================
511
Simon Hunt237676b52015-03-10 19:04:26 -0700512 function initPanels() {
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700513 sumFromTop = mast.mastHeight() + padTop;
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700514 summary = createTopoPanel(idSum, panelOpts);
515 detail = createTopoPanel(idDet, panelOpts);
Simon Hunt6036b192015-02-11 11:20:26 -0800516
517 augmentDetailPanel();
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700518 watchWindow();
Simon Hunt4b668592015-01-29 17:33:53 -0800519 }
520
521 function destroyPanels() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700522 summary.destroy();
523 summary = null;
524
525 detail.destroy();
526 detail = null;
Simon Hunt239e5882015-04-23 15:07:04 -0700527 haveDetails = false;
Bri Prebilic Cole0a6ffb62015-06-04 09:32:12 -0700528 unbindWatch();
Simon Hunt626d2102015-01-29 11:54:50 -0800529 }
530
531 // ==========================
532
Simon Huntb0ec1e52015-01-28 18:13:49 -0800533 angular.module('ovTopo')
534 .factory('TopoPanelService',
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700535 ['$log', '$window', '$rootScope', 'FnService', 'PanelService', 'GlyphService',
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700536 'FlashService', 'WebSocketService', 'ButtonService', 'MastService',
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700537 'NavService',
Simon Huntb0ec1e52015-01-28 18:13:49 -0800538
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700539 function (_$log_, _$window_, _$rootScope_,
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700540 _fs_, _ps_, _gs_, _flash_, _wss_, _bns_, _mast_, _ns_) {
Simon Huntb0ec1e52015-01-28 18:13:49 -0800541 $log = _$log_;
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700542 $window = _$window_;
543 $rootScope = _$rootScope_;
Simon Hunt6036b192015-02-11 11:20:26 -0800544 fs = _fs_;
Simon Huntb0ec1e52015-01-28 18:13:49 -0800545 ps = _ps_;
Simon Huntc9b73162015-01-29 14:02:15 -0800546 gs = _gs_;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700547 flash = _flash_;
Simon Hunt237676b52015-03-10 19:04:26 -0700548 wss = _wss_;
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -0700549 bns = _bns_;
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700550 mast = _mast_;
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700551 ns = _ns_;
Simon Huntb0ec1e52015-01-28 18:13:49 -0800552
Simon Huntb0ec1e52015-01-28 18:13:49 -0800553 return {
554 initPanels: initPanels,
Simon Hunt626d2102015-01-29 11:54:50 -0800555 destroyPanels: destroyPanels,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700556 createTopoPanel: createTopoPanel,
Simon Hunt08f841d02015-02-10 14:39:20 -0800557
558 showSummary: showSummary,
Simon Hunt6036b192015-02-11 11:20:26 -0800559 toggleSummary: toggleSummary,
Thomas Vachuska0af26912016-03-21 21:37:30 -0700560 hideSummary: hideSummaryPanel,
Simon Hunt08f841d02015-02-10 14:39:20 -0800561
Simon Hunt239e5882015-04-23 15:07:04 -0700562 toggleUseDetailsFlag: toggleUseDetailsFlag,
Simon Hunt08f841d02015-02-10 14:39:20 -0800563 displaySingle: displaySingle,
564 displayMulti: displayMulti,
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700565 displayLink: displayLink,
566 displayNothing: displayNothing,
567 displaySomething: displaySomething,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700568 addAction: addAction,
Simon Hunt08f841d02015-02-10 14:39:20 -0800569
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700570 detailVisible: function () { return detail.panel().isVisible(); },
Steven Burrows1c2a9682017-07-14 16:52:46 +0100571 summaryVisible: function () { return summary.panel().isVisible(); },
Simon Hunt879ce452017-08-10 23:32:00 -0700572
573 setLionBundle: function (bundle) { topoLion = bundle; },
Simon Huntb0ec1e52015-01-28 18:13:49 -0800574 };
575 }]);
576}());