blob: eac6a89f7e46385bc4d3b1df5316e909a301ab8b [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
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700159 function addBtnFooter() {
160 detail.appendFooter('hr');
161 detail.appendFooter('div').classed('actionBtns', true);
162 }
163
Simon Hunt4b668592015-01-29 17:33:53 -0800164 function addProp(tbody, label, value) {
Simon Hunte25c5a22015-04-02 14:37:12 -0700165 var tr = tbody.append('tr'),
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -0700166 lab;
167 if (typeof label === 'string') {
Simon Hunte25c5a22015-04-02 14:37:12 -0700168 lab = label.replace(/_/g, ' ');
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -0700169 } else {
170 lab = label;
171 }
Simon Hunt4b668592015-01-29 17:33:53 -0800172
173 function addCell(cls, txt) {
Simon Hunt239f09e2017-05-18 13:10:09 -0700174 tr.append('td').attr('class', cls).text(txt);
Simon Hunt4b668592015-01-29 17:33:53 -0800175 }
Simon Hunte25c5a22015-04-02 14:37:12 -0700176 addCell('label', lab + ' :');
Simon Hunt4b668592015-01-29 17:33:53 -0800177 addCell('value', value);
178 }
179
Simon Hunt08f841d02015-02-10 14:39:20 -0800180 function listProps(tbody, data) {
Steven Burrowscdf6b332017-05-05 11:29:29 -0400181
182 // Suppress Lat Long in details panel if null
Simon Hunt879ce452017-08-10 23:32:00 -0700183 if (data.propLabels.latitude === null ||
184 data.propLabels.longitude === null) {
185 var idx = data.propOrder.indexOf('latitude');
Steven Burrowscdf6b332017-05-05 11:29:29 -0400186 data.propOrder.splice(idx, 3);
187 }
188
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700189 data.propOrder.forEach(function (p) {
Simon Hunt879ce452017-08-10 23:32:00 -0700190 // TODO: remove after topo view fully i18n'd
191 var foo = data.props && data.props[p];
192
Simon Hunt08f841d02015-02-10 14:39:20 -0800193 if (p === '-') {
194 addSep(tbody);
Simon Hunt879ce452017-08-10 23:32:00 -0700195
Simon Hunt08f841d02015-02-10 14:39:20 -0800196 } else {
Simon Hunt879ce452017-08-10 23:32:00 -0700197 // TODO: remove this if/else once DETAILS panel fixed for i18n
198 if (foo !== undefined) {
199 addProp(tbody, p, foo);
200 } else {
201 addProp(tbody, data.propLabels[p], data.propValues[p]);
202 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800203 }
204 });
205 }
206
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700207 function watchWindow() {
Bri Prebilic Cole0a6ffb62015-06-04 09:32:12 -0700208 unbindWatch = $rootScope.$watchCollection(
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700209 function () {
210 return {
211 h: $window.innerHeight,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100212 w: $window.innerWidth,
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700213 };
214 }, function () {
Simon Hunt8d47a5c2016-06-15 12:56:50 -0700215 var h = summary.adjustHeight(sumFromTop, sumMax),
216 ss = summary.panel().isVisible(),
217 dtop = h && ss ? sumFromTop + h + padFudge : 0,
218 dy = dtop || ss ? detail.ypos.current : sumFromTop;
219 detail.adjustHeight(dy);
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700220 }
221 );
222 }
223
Simon Hunt08f841d02015-02-10 14:39:20 -0800224 // === -----------------------------------------------------
225 // Functions for populating the summary panel
226
227 function populateSummary(data) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700228 summary.setup();
Simon Hunt08f841d02015-02-10 14:39:20 -0800229
Bri Prebilic Cole8d3de3d2015-05-15 16:02:59 -0700230 var svg = summary.appendHeader('div')
231 .classed('icon', true)
232 .append('svg'),
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700233 title = summary.appendHeader('h2'),
234 table = summary.appendBody('table'),
Simon Hunt8f907cc2016-06-15 18:04:01 -0700235 tbody = table.append('tbody');
Simon Hunt08f841d02015-02-10 14:39:20 -0800236
Steven Burrows1c2a9682017-07-14 16:52:46 +0100237 gs.addGlyph(svg, 'bird', 24, 0, [1, 1]);
Simon Hunt08f841d02015-02-10 14:39:20 -0800238
Simon Hunt0af1ec32015-07-24 12:17:55 -0700239 title.text(data.title);
Simon Hunt08f841d02015-02-10 14:39:20 -0800240 listProps(tbody, data);
241 }
242
243 // === -----------------------------------------------------
244 // Functions for populating the detail panel
245
Simon Hunt10618f62017-06-15 19:30:52 -0700246 var navPathIdKey = {
247 device: 'devId',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100248 host: 'hostId',
Simon Huntb745ca62015-07-28 15:37:11 -0700249 };
250
Simon Hunt08f841d02015-02-10 14:39:20 -0800251 function displaySingle(data) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700252 detail.setup();
Simon Hunt08f841d02015-02-10 14:39:20 -0800253
Bri Prebilic Cole8d3de3d2015-05-15 16:02:59 -0700254 var svg = detail.appendHeader('div')
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700255 .classed('icon clickable', true)
Bri Prebilic Cole8d3de3d2015-05-15 16:02:59 -0700256 .append('svg'),
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700257 title = detail.appendHeader('h2')
258 .classed('clickable', true),
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700259 table = detail.appendBody('table'),
Simon Huntb745ca62015-07-28 15:37:11 -0700260 tbody = table.append('tbody'),
Simon Hunt10618f62017-06-15 19:30:52 -0700261 navFn,
262 navPath;
Simon Hunt08f841d02015-02-10 14:39:20 -0800263
Simon Hunt8f907cc2016-06-15 18:04:01 -0700264 gs.addGlyph(svg, (data.type || 'unknown'), 26);
Simon Huntb745ca62015-07-28 15:37:11 -0700265 title.text(data.title);
266
Simon Hunt10618f62017-06-15 19:30:52 -0700267 // add navigation hot-link if defined
268 navPath = data.navPath;
269 if (navPath) {
Simon Huntb745ca62015-07-28 15:37:11 -0700270 navFn = function () {
Simon Hunt10618f62017-06-15 19:30:52 -0700271 var arg = {};
272 arg[navPathIdKey[navPath]] = data.id;
273 ns.navTo(navPath, arg);
Simon Huntb745ca62015-07-28 15:37:11 -0700274 };
275
276 svg.on('click', navFn);
277 title.on('click', navFn);
278 }
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700279
Simon Hunt08f841d02015-02-10 14:39:20 -0800280 listProps(tbody, data);
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700281 addBtnFooter();
Simon Hunt08f841d02015-02-10 14:39:20 -0800282 }
283
284 function displayMulti(ids) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700285 detail.setup();
Simon Hunt08f841d02015-02-10 14:39:20 -0800286
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700287 var title = detail.appendHeader('h3'),
288 table = detail.appendBody('table'),
Simon Hunt08f841d02015-02-10 14:39:20 -0800289 tbody = table.append('tbody');
290
Prince Pereira46c82d42016-09-19 13:30:50 +0530291 title.text('Selected Items');
Simon Hunt08f841d02015-02-10 14:39:20 -0800292 ids.forEach(function (d, i) {
293 addProp(tbody, i+1, d);
294 });
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700295 addBtnFooter();
Simon Hunt08f841d02015-02-10 14:39:20 -0800296 }
297
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -0700298 function addAction(o) {
299 var btnDiv = d3.select('#' + idDet)
300 .select('.actionBtns')
301 .append('div')
302 .classed('actionBtn', true);
Simon Hunt3a0598f2015-08-04 19:59:04 -0700303 bns.button(btnDiv, idDet + '-' + o.id, o.gid, o.cb, o.tt);
Simon Hunt08f841d02015-02-10 14:39:20 -0800304 }
305
Simon Hunta36f03b2015-04-01 15:22:49 -0700306 var friendlyIndex = {
307 device: 1,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100308 host: 0,
Simon Hunta36f03b2015-04-01 15:22:49 -0700309 };
310
311 function friendly(d) {
312 var i = friendlyIndex[d.class] || 0;
313 return (d.labels && d.labels[i]) || '';
314 }
315
316 function linkSummary(d) {
317 var o = d && d.online ? 'online' : 'offline';
318 return d ? d.type + ' / ' + o : '-';
319 }
320
Simon Hunte25c5a22015-04-02 14:37:12 -0700321 // provided to change presentation of internal type name
322 var linkTypePres = {
Steven Burrows1c2a9682017-07-14 16:52:46 +0100323 hostLink: 'edge link',
Simon Hunte25c5a22015-04-02 14:37:12 -0700324 };
325
326 function linkType(d) {
327 return linkTypePres[d.type()] || d.type();
328 }
329
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800330 function linkExpected(d) {
331 return d.expected();
332 }
333
Simon Hunte25c5a22015-04-02 14:37:12 -0700334 var coreOrder = [
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800335 'Type', 'Expected', '-',
Simon Hunte25c5a22015-04-02 14:37:12 -0700336 'A_type', 'A_id', 'A_label', 'A_port', '-',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100337 'B_type', 'B_id', 'B_label', 'B_port',
Simon Hunte25c5a22015-04-02 14:37:12 -0700338 ],
339 edgeOrder = [
340 'Type', '-',
341 'A_type', 'A_id', 'A_label', '-',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100342 'B_type', 'B_id', 'B_label', 'B_port',
Simon Hunte25c5a22015-04-02 14:37:12 -0700343 ];
344
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 }
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700431 if (detail.panel().isVisible()) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700432 detail.down(_show);
Simon Hunt6036b192015-02-11 11:20:26 -0800433 } else {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700434 _show();
Simon Hunt6036b192015-02-11 11:20:26 -0800435 }
Simon Huntc252aa62015-02-10 16:45:39 -0800436 }
437
438 function hideSummaryPanel() {
Simon Hunta0eb0a82015-02-11 12:30:06 -0800439 // instruct server to stop sending summary data
Steven Burrows1c2a9682017-07-14 16:52:46 +0100440 wss.sendEvent('cancelSummary');
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700441 summary.panel().hide(detail.up);
Simon Hunt4b668592015-01-29 17:33:53 -0800442 }
Simon Hunt626d2102015-01-29 11:54:50 -0800443
Simon Hunt08f841d02015-02-10 14:39:20 -0800444 function showDetailPanel() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700445 if (summary.panel().isVisible()) {
446 detail.down(detail.panel().show);
Simon Hunt6036b192015-02-11 11:20:26 -0800447 } else {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700448 detail.up(detail.panel().show);
Simon Hunt6036b192015-02-11 11:20:26 -0800449 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800450 }
451
452 function hideDetailPanel() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700453 detail.panel().hide();
Simon Hunt08f841d02015-02-10 14:39:20 -0800454 }
455
Simon Hunt6036b192015-02-11 11:20:26 -0800456 // ==========================
Simon Hunt08f841d02015-02-10 14:39:20 -0800457
Simon Hunt6036b192015-02-11 11:20:26 -0800458 function augmentDetailPanel() {
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700459 var d = detail,
Simon Hunt8d47a5c2016-06-15 12:56:50 -0700460 downPos = sumFromTop + sumMax + padFudge;
Steven Burrows1c2a9682017-07-14 16:52:46 +0100461 d.ypos = { up: sumFromTop, down: downPos, current: downPos };
Simon Hunt6036b192015-02-11 11:20:26 -0800462
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700463 d._move = function (y, cb) {
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700464 var yp = d.ypos,
465 endCb;
466
467 if (fs.isF(cb)) {
468 endCb = function () {
469 cb();
470 d.adjustHeight(d.ypos.current);
Steven Burrows1c2a9682017-07-14 16:52:46 +0100471 };
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700472 } else {
473 endCb = function () {
474 d.adjustHeight(d.ypos.current);
Steven Burrows1c2a9682017-07-14 16:52:46 +0100475 };
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700476 }
Simon Hunt6036b192015-02-11 11:20:26 -0800477 if (yp.current !== y) {
478 yp.current = y;
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700479 d.panel().el().transition().duration(300)
Simon Hunt6036b192015-02-11 11:20:26 -0800480 .each('end', endCb)
481 .style('top', yp.current + 'px');
482 } else {
483 endCb();
484 }
485 };
486
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700487 d.down = function (cb) { d._move(d.ypos.down, cb); };
488 d.up = function (cb) { d._move(d.ypos.up, cb); };
Simon Hunt6036b192015-02-11 11:20:26 -0800489 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800490
Simon Hunt239e5882015-04-23 15:07:04 -0700491 function toggleUseDetailsFlag(x) {
Simon Huntee7a3ce2015-04-09 13:28:37 -0700492 var kev = (x === 'keyev'),
493 verb;
494
495 useDetails = kev ? !useDetails : !!x;
496 verb = useDetails ? 'Enable' : 'Disable';
497
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700498 if (useDetails) {
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700499 if (haveDetails) {
500 showDetailPanel();
501 }
502 } else {
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700503 hideDetailPanel();
504 }
Simon Huntee7a3ce2015-04-09 13:28:37 -0700505 flash.flash(verb + ' details panel');
506 return useDetails;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700507 }
508
Simon Hunt4b668592015-01-29 17:33:53 -0800509 // ==========================
510
Simon Hunt237676b52015-03-10 19:04:26 -0700511 function initPanels() {
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700512 sumFromTop = mast.mastHeight() + padTop;
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700513 summary = createTopoPanel(idSum, panelOpts);
514 detail = createTopoPanel(idDet, panelOpts);
Simon Hunt6036b192015-02-11 11:20:26 -0800515
516 augmentDetailPanel();
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700517 watchWindow();
Simon Hunt4b668592015-01-29 17:33:53 -0800518 }
519
520 function destroyPanels() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700521 summary.destroy();
522 summary = null;
523
524 detail.destroy();
525 detail = null;
Simon Hunt239e5882015-04-23 15:07:04 -0700526 haveDetails = false;
Bri Prebilic Cole0a6ffb62015-06-04 09:32:12 -0700527 unbindWatch();
Simon Hunt626d2102015-01-29 11:54:50 -0800528 }
529
530 // ==========================
531
Simon Huntb0ec1e52015-01-28 18:13:49 -0800532 angular.module('ovTopo')
533 .factory('TopoPanelService',
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700534 ['$log', '$window', '$rootScope', 'FnService', 'PanelService', 'GlyphService',
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700535 'FlashService', 'WebSocketService', 'ButtonService', 'MastService',
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700536 'NavService',
Simon Huntb0ec1e52015-01-28 18:13:49 -0800537
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700538 function (_$log_, _$window_, _$rootScope_,
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700539 _fs_, _ps_, _gs_, _flash_, _wss_, _bns_, _mast_, _ns_) {
Simon Huntb0ec1e52015-01-28 18:13:49 -0800540 $log = _$log_;
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700541 $window = _$window_;
542 $rootScope = _$rootScope_;
Simon Hunt6036b192015-02-11 11:20:26 -0800543 fs = _fs_;
Simon Huntb0ec1e52015-01-28 18:13:49 -0800544 ps = _ps_;
Simon Huntc9b73162015-01-29 14:02:15 -0800545 gs = _gs_;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700546 flash = _flash_;
Simon Hunt237676b52015-03-10 19:04:26 -0700547 wss = _wss_;
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -0700548 bns = _bns_;
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700549 mast = _mast_;
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700550 ns = _ns_;
Simon Huntb0ec1e52015-01-28 18:13:49 -0800551
Simon Huntb0ec1e52015-01-28 18:13:49 -0800552 return {
553 initPanels: initPanels,
Simon Hunt626d2102015-01-29 11:54:50 -0800554 destroyPanels: destroyPanels,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700555 createTopoPanel: createTopoPanel,
Simon Hunt08f841d02015-02-10 14:39:20 -0800556
557 showSummary: showSummary,
Simon Hunt6036b192015-02-11 11:20:26 -0800558 toggleSummary: toggleSummary,
Thomas Vachuska0af26912016-03-21 21:37:30 -0700559 hideSummary: hideSummaryPanel,
Simon Hunt08f841d02015-02-10 14:39:20 -0800560
Simon Hunt239e5882015-04-23 15:07:04 -0700561 toggleUseDetailsFlag: toggleUseDetailsFlag,
Simon Hunt08f841d02015-02-10 14:39:20 -0800562 displaySingle: displaySingle,
563 displayMulti: displayMulti,
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700564 displayLink: displayLink,
565 displayNothing: displayNothing,
566 displaySomething: displaySomething,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700567 addAction: addAction,
Simon Hunt08f841d02015-02-10 14:39:20 -0800568
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700569 detailVisible: function () { return detail.panel().isVisible(); },
Steven Burrows1c2a9682017-07-14 16:52:46 +0100570 summaryVisible: function () { return summary.panel().isVisible(); },
Simon Hunt879ce452017-08-10 23:32:00 -0700571
572 setLionBundle: function (bundle) { topoLion = bundle; },
Simon Huntb0ec1e52015-01-28 18:13:49 -0800573 };
574 }]);
575}());