blob: b25f02e05ae5dfe7a32dea1b818b86b2533c47c7 [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 Hunt626d2102015-01-29 11:54:50 -080028 // constants
Simon Hunt08f841d02015-02-10 14:39:20 -080029 var pCls = 'topo-p',
30 idSum = 'topo-p-summary',
Simon Hunt626d2102015-01-29 11:54:50 -080031 idDet = 'topo-p-detail',
Simon Hunt626d2102015-01-29 11:54:50 -080032 panelOpts = {
Steven Burrows1c2a9682017-07-14 16:52:46 +010033 width: 260, // summary and detail panel width
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -070034 },
Steven Burrows1c2a9682017-07-14 16:52:46 +010035 sumMax = 226, // summary panel max height
36 padTop = 16, // summary panel padding below masthead
37 padding = 16, // panel internal padding
Simon Hunt10618f62017-06-15 19:30:52 -070038 padFudge = padTop + 2 * padding;
Simon Hunt626d2102015-01-29 11:54:50 -080039
Simon Hunt0c6b2d32015-03-26 17:46:29 -070040 // internal state
Steven Burrows1c2a9682017-07-14 16:52:46 +010041 var useDetails = true, // should we show details if we have 'em?
42 haveDetails = false, // do we have details that we could show?
43 sumFromTop, // summary panel distance from top of screen
Bri Prebilic Cole0a6ffb62015-06-04 09:32:12 -070044 unbindWatch;
Simon Huntb0ec1e52015-01-28 18:13:49 -080045
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -070046 // panels
47 var summary, detail;
48
49 // === -----------------------------------------------------
50 // Panel API
51 function createTopoPanel(id, opts) {
52 var p = ps.createPanel(id, opts),
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070053 pid = id,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -070054 header, body, footer;
55 p.classed(pCls, true);
56
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070057 function panel() {
58 return p;
59 }
60
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -070061 function hAppend(x) {
62 return header.append(x);
63 }
64
65 function bAppend(x) {
66 return body.append(x);
67 }
68
69 function fAppend(x) {
70 return footer.append(x);
71 }
72
73 function setup() {
74 p.empty();
75
76 p.append('div').classed('header', true);
77 p.append('div').classed('body', true);
78 p.append('div').classed('footer', true);
79
80 header = p.el().select('.header');
81 body = p.el().select('.body');
82 footer = p.el().select('.footer');
83 }
84
Bri Prebilic Cole35d29712015-05-11 16:01:32 -070085 function destroy() {
86 ps.destroyPanel(pid);
87 }
88
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -070089 // fromTop is how many pixels from the top of the page the panel is
90 // max is the max height of the panel in pixels
91 // only adjusts if the body content would be 10px or larger
92 function adjustHeight(fromTop, max) {
93 var totalPHeight, avSpace,
Simon Hunt8d47a5c2016-06-15 12:56:50 -070094 overflow = 0;
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -070095
96 if (!fromTop) {
97 $log.warn('adjustHeight: height from top of page not given');
98 return null;
99 } else if (!body || !p) {
Simon Hunt5b024d72016-01-29 11:02:43 -0800100 // panel contents are not defined
101 // this may happen when window is resizing but panel has
102 // been cleared or removed
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700103 return null;
104 }
105
Simon Hunt8d47a5c2016-06-15 12:56:50 -0700106 p.el().style('top', fromTop + 'px');
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700107 p.el().style('height', null);
108 body.style('height', null);
109
110 totalPHeight = fromTop + p.height();
Simon Hunt8d47a5c2016-06-15 12:56:50 -0700111 avSpace = fs.windowSize(padFudge).height;
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700112
113 if (totalPHeight >= avSpace) {
114 overflow = totalPHeight - avSpace;
115 }
116
117 function _adjustBody(height) {
118 if (height < 10) {
119 return false;
120 } else {
121 body.style('height', height + 'px');
122 }
123 return true;
124 }
125
126 if (!_adjustBody(fs.noPxStyle(body, 'height') - overflow)) {
Simon Hunt8d47a5c2016-06-15 12:56:50 -0700127 return p.height();
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700128 }
129
130 if (max && p.height() > max) {
131 _adjustBody(fs.noPxStyle(body, 'height') - (p.height() - max));
132 }
Simon Hunt8d47a5c2016-06-15 12:56:50 -0700133 return p.height();
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700134 }
135
136 return {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700137 panel: panel,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700138 setup: setup,
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700139 destroy: destroy,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700140 appendHeader: hAppend,
141 appendBody: bAppend,
142 appendFooter: fAppend,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100143 adjustHeight: adjustHeight,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700144 };
145 }
146
Simon Hunt08f841d02015-02-10 14:39:20 -0800147 // === -----------------------------------------------------
148 // Utility functions
Simon Hunt626d2102015-01-29 11:54:50 -0800149
Simon Hunt4b668592015-01-29 17:33:53 -0800150 function addSep(tbody) {
151 tbody.append('tr').append('td').attr('colspan', 2).append('hr');
152 }
153
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700154 function addBtnFooter() {
155 detail.appendFooter('hr');
156 detail.appendFooter('div').classed('actionBtns', true);
157 }
158
Simon Hunt4b668592015-01-29 17:33:53 -0800159 function addProp(tbody, label, value) {
Simon Hunte25c5a22015-04-02 14:37:12 -0700160 var tr = tbody.append('tr'),
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -0700161 lab;
162 if (typeof label === 'string') {
Simon Hunte25c5a22015-04-02 14:37:12 -0700163 lab = label.replace(/_/g, ' ');
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -0700164 } else {
165 lab = label;
166 }
Simon Hunt4b668592015-01-29 17:33:53 -0800167
168 function addCell(cls, txt) {
Simon Hunt239f09e2017-05-18 13:10:09 -0700169 tr.append('td').attr('class', cls).text(txt);
Simon Hunt4b668592015-01-29 17:33:53 -0800170 }
Simon Hunte25c5a22015-04-02 14:37:12 -0700171 addCell('label', lab + ' :');
Simon Hunt4b668592015-01-29 17:33:53 -0800172 addCell('value', value);
173 }
174
Simon Hunt08f841d02015-02-10 14:39:20 -0800175 function listProps(tbody, data) {
Steven Burrowscdf6b332017-05-05 11:29:29 -0400176
177 // Suppress Lat Long in details panel if null
178 if (data.props.Latitude === null ||
179 data.props.Longitude === null) {
180 var idx = data.propOrder.indexOf('Latitude');
181 data.propOrder.splice(idx, 3);
182 }
183
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700184 data.propOrder.forEach(function (p) {
Simon Hunt08f841d02015-02-10 14:39:20 -0800185 if (p === '-') {
186 addSep(tbody);
187 } else {
188 addProp(tbody, p, data.props[p]);
189 }
190 });
191 }
192
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700193 function watchWindow() {
Bri Prebilic Cole0a6ffb62015-06-04 09:32:12 -0700194 unbindWatch = $rootScope.$watchCollection(
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700195 function () {
196 return {
197 h: $window.innerHeight,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100198 w: $window.innerWidth,
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700199 };
200 }, function () {
Simon Hunt8d47a5c2016-06-15 12:56:50 -0700201 var h = summary.adjustHeight(sumFromTop, sumMax),
202 ss = summary.panel().isVisible(),
203 dtop = h && ss ? sumFromTop + h + padFudge : 0,
204 dy = dtop || ss ? detail.ypos.current : sumFromTop;
205 detail.adjustHeight(dy);
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700206 }
207 );
208 }
209
Simon Hunt08f841d02015-02-10 14:39:20 -0800210 // === -----------------------------------------------------
211 // Functions for populating the summary panel
212
213 function populateSummary(data) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700214 summary.setup();
Simon Hunt08f841d02015-02-10 14:39:20 -0800215
Bri Prebilic Cole8d3de3d2015-05-15 16:02:59 -0700216 var svg = summary.appendHeader('div')
217 .classed('icon', true)
218 .append('svg'),
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700219 title = summary.appendHeader('h2'),
220 table = summary.appendBody('table'),
Simon Hunt8f907cc2016-06-15 18:04:01 -0700221 tbody = table.append('tbody');
Simon Hunt08f841d02015-02-10 14:39:20 -0800222
Steven Burrows1c2a9682017-07-14 16:52:46 +0100223 gs.addGlyph(svg, 'bird', 24, 0, [1, 1]);
Simon Hunt08f841d02015-02-10 14:39:20 -0800224
Simon Hunt0af1ec32015-07-24 12:17:55 -0700225 title.text(data.title);
Simon Hunt08f841d02015-02-10 14:39:20 -0800226 listProps(tbody, data);
227 }
228
229 // === -----------------------------------------------------
230 // Functions for populating the detail panel
231
Simon Hunt10618f62017-06-15 19:30:52 -0700232 var navPathIdKey = {
233 device: 'devId',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100234 host: 'hostId',
Simon Huntb745ca62015-07-28 15:37:11 -0700235 };
236
Simon Hunt08f841d02015-02-10 14:39:20 -0800237 function displaySingle(data) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700238 detail.setup();
Simon Hunt08f841d02015-02-10 14:39:20 -0800239
Bri Prebilic Cole8d3de3d2015-05-15 16:02:59 -0700240 var svg = detail.appendHeader('div')
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700241 .classed('icon clickable', true)
Bri Prebilic Cole8d3de3d2015-05-15 16:02:59 -0700242 .append('svg'),
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700243 title = detail.appendHeader('h2')
244 .classed('clickable', true),
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700245 table = detail.appendBody('table'),
Simon Huntb745ca62015-07-28 15:37:11 -0700246 tbody = table.append('tbody'),
Simon Hunt10618f62017-06-15 19:30:52 -0700247 navFn,
248 navPath;
Simon Hunt08f841d02015-02-10 14:39:20 -0800249
Simon Hunt8f907cc2016-06-15 18:04:01 -0700250 gs.addGlyph(svg, (data.type || 'unknown'), 26);
Simon Huntb745ca62015-07-28 15:37:11 -0700251 title.text(data.title);
252
Simon Hunt10618f62017-06-15 19:30:52 -0700253 // add navigation hot-link if defined
254 navPath = data.navPath;
255 if (navPath) {
Simon Huntb745ca62015-07-28 15:37:11 -0700256 navFn = function () {
Simon Hunt10618f62017-06-15 19:30:52 -0700257 var arg = {};
258 arg[navPathIdKey[navPath]] = data.id;
259 ns.navTo(navPath, arg);
Simon Huntb745ca62015-07-28 15:37:11 -0700260 };
261
262 svg.on('click', navFn);
263 title.on('click', navFn);
264 }
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700265
Simon Hunt08f841d02015-02-10 14:39:20 -0800266 listProps(tbody, data);
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700267 addBtnFooter();
Simon Hunt08f841d02015-02-10 14:39:20 -0800268 }
269
270 function displayMulti(ids) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700271 detail.setup();
Simon Hunt08f841d02015-02-10 14:39:20 -0800272
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700273 var title = detail.appendHeader('h3'),
274 table = detail.appendBody('table'),
Simon Hunt08f841d02015-02-10 14:39:20 -0800275 tbody = table.append('tbody');
276
Prince Pereira46c82d42016-09-19 13:30:50 +0530277 title.text('Selected Items');
Simon Hunt08f841d02015-02-10 14:39:20 -0800278 ids.forEach(function (d, i) {
279 addProp(tbody, i+1, d);
280 });
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700281 addBtnFooter();
Simon Hunt08f841d02015-02-10 14:39:20 -0800282 }
283
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -0700284 function addAction(o) {
285 var btnDiv = d3.select('#' + idDet)
286 .select('.actionBtns')
287 .append('div')
288 .classed('actionBtn', true);
Simon Hunt3a0598f2015-08-04 19:59:04 -0700289 bns.button(btnDiv, idDet + '-' + o.id, o.gid, o.cb, o.tt);
Simon Hunt08f841d02015-02-10 14:39:20 -0800290 }
291
Simon Hunta36f03b2015-04-01 15:22:49 -0700292 var friendlyIndex = {
293 device: 1,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100294 host: 0,
Simon Hunta36f03b2015-04-01 15:22:49 -0700295 };
296
297 function friendly(d) {
298 var i = friendlyIndex[d.class] || 0;
299 return (d.labels && d.labels[i]) || '';
300 }
301
302 function linkSummary(d) {
303 var o = d && d.online ? 'online' : 'offline';
304 return d ? d.type + ' / ' + o : '-';
305 }
306
Simon Hunte25c5a22015-04-02 14:37:12 -0700307 // provided to change presentation of internal type name
308 var linkTypePres = {
Steven Burrows1c2a9682017-07-14 16:52:46 +0100309 hostLink: 'edge link',
Simon Hunte25c5a22015-04-02 14:37:12 -0700310 };
311
312 function linkType(d) {
313 return linkTypePres[d.type()] || d.type();
314 }
315
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800316 function linkExpected(d) {
317 return d.expected();
318 }
319
Simon Hunte25c5a22015-04-02 14:37:12 -0700320 var coreOrder = [
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800321 'Type', 'Expected', '-',
Simon Hunte25c5a22015-04-02 14:37:12 -0700322 'A_type', 'A_id', 'A_label', 'A_port', '-',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100323 'B_type', 'B_id', 'B_label', 'B_port',
Simon Hunte25c5a22015-04-02 14:37:12 -0700324 ],
325 edgeOrder = [
326 'Type', '-',
327 'A_type', 'A_id', 'A_label', '-',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100328 'B_type', 'B_id', 'B_label', 'B_port',
Simon Hunte25c5a22015-04-02 14:37:12 -0700329 ];
330
Simon Hunt5c1a9382016-06-01 19:35:35 -0700331 function displayLink(data, modifyCb) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700332 detail.setup();
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700333
Bri Prebilic Cole8d3de3d2015-05-15 16:02:59 -0700334 var svg = detail.appendHeader('div')
335 .classed('icon', true)
336 .append('svg'),
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700337 title = detail.appendHeader('h2'),
338 table = detail.appendBody('table'),
Simon Hunte25c5a22015-04-02 14:37:12 -0700339 tbody = table.append('tbody'),
340 edgeLink = data.type() === 'hostLink',
341 order = edgeLink ? edgeOrder : coreOrder;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700342
Simon Huntf29d8e62016-06-20 11:09:25 -0700343 gs.addGlyph(svg, 'ports', 26);
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700344 title.text('Link');
Simon Hunta36f03b2015-04-01 15:22:49 -0700345
Simon Hunt5c1a9382016-06-01 19:35:35 -0700346 var linkData = {
Steven Burrows1c2a9682017-07-14 16:52:46 +0100347 propOrder: order.slice(0), // makes a copy of the array
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700348 props: {
Simon Hunte25c5a22015-04-02 14:37:12 -0700349 Type: linkType(data),
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800350 Expected: linkExpected(data),
Simon Hunta36f03b2015-04-01 15:22:49 -0700351
352 A_type: data.source.class,
353 A_id: data.source.id,
354 A_label: friendly(data.source),
355 A_port: data.srcPort,
356
357 B_type: data.target.class,
358 B_id: data.target.id,
359 B_label: friendly(data.target),
Steven Burrows1c2a9682017-07-14 16:52:46 +0100360 B_port: data.tgtPort,
361 },
Simon Hunt5c1a9382016-06-01 19:35:35 -0700362 };
363 listProps(tbody, modifyCb(linkData, data.extra));
Simon Hunta36f03b2015-04-01 15:22:49 -0700364
Simon Hunte25c5a22015-04-02 14:37:12 -0700365 if (!edgeLink) {
Simon Hunt5c1a9382016-06-01 19:35:35 -0700366 addSep(tbody);
Simon Hunte25c5a22015-04-02 14:37:12 -0700367 addProp(tbody, 'A &rarr; B', linkSummary(data.fromSource));
368 addProp(tbody, 'B &rarr; A', linkSummary(data.fromTarget));
369 }
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700370 }
371
372 function displayNothing() {
373 haveDetails = false;
374 hideDetailPanel();
375 }
376
377 function displaySomething() {
378 haveDetails = true;
379 if (useDetails) {
380 showDetailPanel();
381 }
382 }
383
Simon Hunt08f841d02015-02-10 14:39:20 -0800384 // === -----------------------------------------------------
385 // Event Handlers
386
387 function showSummary(data) {
388 populateSummary(data);
389 showSummaryPanel();
390 }
391
Simon Hunt36a58c62015-04-08 11:00:07 -0700392 function toggleSummary(x) {
Simon Huntee7a3ce2015-04-09 13:28:37 -0700393 var kev = (x === 'keyev'),
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700394 on = kev ? !summary.panel().isVisible() : !!x,
Simon Huntee7a3ce2015-04-09 13:28:37 -0700395 verb = on ? 'Show' : 'Hide';
Simon Hunt36a58c62015-04-08 11:00:07 -0700396
397 if (on) {
Simon Hunta0eb0a82015-02-11 12:30:06 -0800398 // ask server to start sending summary data.
Simon Hunt237676b52015-03-10 19:04:26 -0700399 wss.sendEvent('requestSummary');
Simon Hunta0eb0a82015-02-11 12:30:06 -0800400 // note: the summary panel will appear, once data arrives
Simon Hunt36a58c62015-04-08 11:00:07 -0700401 } else {
402 hideSummaryPanel();
Simon Hunt6036b192015-02-11 11:20:26 -0800403 }
Simon Huntee7a3ce2015-04-09 13:28:37 -0700404 flash.flash(verb + ' summary panel');
405 return on;
Simon Hunt6036b192015-02-11 11:20:26 -0800406 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800407
408 // === -----------------------------------------------------
409 // === LOGIC For showing/hiding summary and detail panels...
410
Simon Hunt626d2102015-01-29 11:54:50 -0800411 function showSummaryPanel() {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700412 function _show() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700413 summary.panel().show();
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700414 summary.adjustHeight(sumFromTop, sumMax);
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700415 }
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700416 if (detail.panel().isVisible()) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700417 detail.down(_show);
Simon Hunt6036b192015-02-11 11:20:26 -0800418 } else {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700419 _show();
Simon Hunt6036b192015-02-11 11:20:26 -0800420 }
Simon Huntc252aa62015-02-10 16:45:39 -0800421 }
422
423 function hideSummaryPanel() {
Simon Hunta0eb0a82015-02-11 12:30:06 -0800424 // instruct server to stop sending summary data
Steven Burrows1c2a9682017-07-14 16:52:46 +0100425 wss.sendEvent('cancelSummary');
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700426 summary.panel().hide(detail.up);
Simon Hunt4b668592015-01-29 17:33:53 -0800427 }
Simon Hunt626d2102015-01-29 11:54:50 -0800428
Simon Hunt08f841d02015-02-10 14:39:20 -0800429 function showDetailPanel() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700430 if (summary.panel().isVisible()) {
431 detail.down(detail.panel().show);
Simon Hunt6036b192015-02-11 11:20:26 -0800432 } else {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700433 detail.up(detail.panel().show);
Simon Hunt6036b192015-02-11 11:20:26 -0800434 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800435 }
436
437 function hideDetailPanel() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700438 detail.panel().hide();
Simon Hunt08f841d02015-02-10 14:39:20 -0800439 }
440
Simon Hunt6036b192015-02-11 11:20:26 -0800441 // ==========================
Simon Hunt08f841d02015-02-10 14:39:20 -0800442
Simon Hunt6036b192015-02-11 11:20:26 -0800443 function augmentDetailPanel() {
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700444 var d = detail,
Simon Hunt8d47a5c2016-06-15 12:56:50 -0700445 downPos = sumFromTop + sumMax + padFudge;
Steven Burrows1c2a9682017-07-14 16:52:46 +0100446 d.ypos = { up: sumFromTop, down: downPos, current: downPos };
Simon Hunt6036b192015-02-11 11:20:26 -0800447
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700448 d._move = function (y, cb) {
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700449 var yp = d.ypos,
450 endCb;
451
452 if (fs.isF(cb)) {
453 endCb = function () {
454 cb();
455 d.adjustHeight(d.ypos.current);
Steven Burrows1c2a9682017-07-14 16:52:46 +0100456 };
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700457 } else {
458 endCb = function () {
459 d.adjustHeight(d.ypos.current);
Steven Burrows1c2a9682017-07-14 16:52:46 +0100460 };
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700461 }
Simon Hunt6036b192015-02-11 11:20:26 -0800462 if (yp.current !== y) {
463 yp.current = y;
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700464 d.panel().el().transition().duration(300)
Simon Hunt6036b192015-02-11 11:20:26 -0800465 .each('end', endCb)
466 .style('top', yp.current + 'px');
467 } else {
468 endCb();
469 }
470 };
471
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700472 d.down = function (cb) { d._move(d.ypos.down, cb); };
473 d.up = function (cb) { d._move(d.ypos.up, cb); };
Simon Hunt6036b192015-02-11 11:20:26 -0800474 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800475
Simon Hunt239e5882015-04-23 15:07:04 -0700476 function toggleUseDetailsFlag(x) {
Simon Huntee7a3ce2015-04-09 13:28:37 -0700477 var kev = (x === 'keyev'),
478 verb;
479
480 useDetails = kev ? !useDetails : !!x;
481 verb = useDetails ? 'Enable' : 'Disable';
482
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700483 if (useDetails) {
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700484 if (haveDetails) {
485 showDetailPanel();
486 }
487 } else {
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700488 hideDetailPanel();
489 }
Simon Huntee7a3ce2015-04-09 13:28:37 -0700490 flash.flash(verb + ' details panel');
491 return useDetails;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700492 }
493
Simon Hunt4b668592015-01-29 17:33:53 -0800494 // ==========================
495
Simon Hunt237676b52015-03-10 19:04:26 -0700496 function initPanels() {
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700497 sumFromTop = mast.mastHeight() + padTop;
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700498 summary = createTopoPanel(idSum, panelOpts);
499 detail = createTopoPanel(idDet, panelOpts);
Simon Hunt6036b192015-02-11 11:20:26 -0800500
501 augmentDetailPanel();
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700502 watchWindow();
Simon Hunt4b668592015-01-29 17:33:53 -0800503 }
504
505 function destroyPanels() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700506 summary.destroy();
507 summary = null;
508
509 detail.destroy();
510 detail = null;
Simon Hunt239e5882015-04-23 15:07:04 -0700511 haveDetails = false;
Bri Prebilic Cole0a6ffb62015-06-04 09:32:12 -0700512 unbindWatch();
Simon Hunt626d2102015-01-29 11:54:50 -0800513 }
514
515 // ==========================
516
Simon Huntb0ec1e52015-01-28 18:13:49 -0800517 angular.module('ovTopo')
518 .factory('TopoPanelService',
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700519 ['$log', '$window', '$rootScope', 'FnService', 'PanelService', 'GlyphService',
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700520 'FlashService', 'WebSocketService', 'ButtonService', 'MastService',
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700521 'NavService',
Simon Huntb0ec1e52015-01-28 18:13:49 -0800522
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700523 function (_$log_, _$window_, _$rootScope_,
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700524 _fs_, _ps_, _gs_, _flash_, _wss_, _bns_, _mast_, _ns_) {
Simon Huntb0ec1e52015-01-28 18:13:49 -0800525 $log = _$log_;
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700526 $window = _$window_;
527 $rootScope = _$rootScope_;
Simon Hunt6036b192015-02-11 11:20:26 -0800528 fs = _fs_;
Simon Huntb0ec1e52015-01-28 18:13:49 -0800529 ps = _ps_;
Simon Huntc9b73162015-01-29 14:02:15 -0800530 gs = _gs_;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700531 flash = _flash_;
Simon Hunt237676b52015-03-10 19:04:26 -0700532 wss = _wss_;
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -0700533 bns = _bns_;
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700534 mast = _mast_;
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700535 ns = _ns_;
Simon Huntb0ec1e52015-01-28 18:13:49 -0800536
Simon Huntb0ec1e52015-01-28 18:13:49 -0800537 return {
538 initPanels: initPanels,
Simon Hunt626d2102015-01-29 11:54:50 -0800539 destroyPanels: destroyPanels,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700540 createTopoPanel: createTopoPanel,
Simon Hunt08f841d02015-02-10 14:39:20 -0800541
542 showSummary: showSummary,
Simon Hunt6036b192015-02-11 11:20:26 -0800543 toggleSummary: toggleSummary,
Thomas Vachuska0af26912016-03-21 21:37:30 -0700544 hideSummary: hideSummaryPanel,
Simon Hunt08f841d02015-02-10 14:39:20 -0800545
Simon Hunt239e5882015-04-23 15:07:04 -0700546 toggleUseDetailsFlag: toggleUseDetailsFlag,
Simon Hunt08f841d02015-02-10 14:39:20 -0800547 displaySingle: displaySingle,
548 displayMulti: displayMulti,
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700549 displayLink: displayLink,
550 displayNothing: displayNothing,
551 displaySomething: displaySomething,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700552 addAction: addAction,
Simon Hunt08f841d02015-02-10 14:39:20 -0800553
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700554 detailVisible: function () { return detail.panel().isVisible(); },
Steven Burrows1c2a9682017-07-14 16:52:46 +0100555 summaryVisible: function () { return summary.panel().isVisible(); },
Simon Huntb0ec1e52015-01-28 18:13:49 -0800556 };
557 }]);
558}());