blob: 0025a75853ac69194d8862ea79707bce6770f44b [file] [log] [blame]
Simon Huntb0ec1e52015-01-28 18:13:49 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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 = {
Simon Hunte8c54db2016-06-15 12:56:50 -070033 width: 290 // summary and detail panel width
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -070034 },
Simon Hunte8c54db2016-06-15 12:56:50 -070035 sumMax = 262, // summary panel max height
36 padTop = 16, // summary panel padding below masthead
37 padFudge = padTop + 6,
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -070038 devPath = 'device';
Simon Hunt626d2102015-01-29 11:54:50 -080039
Simon Hunt0c6b2d32015-03-26 17:46:29 -070040 // internal state
41 var useDetails = true, // should we show details if we have 'em?
Bri Prebilic Coled8745462015-06-01 16:08:57 -070042 haveDetails = false, // do we have details that we could show?
Bri Prebilic Cole0a6ffb62015-06-04 09:32:12 -070043 sumFromTop, // summary panel distance from top of screen
44 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 Hunte8c54db2016-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 Hunte8c54db2016-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 Hunte8c54db2016-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 Hunte8c54db2016-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 Hunte8c54db2016-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,
143 adjustHeight: adjustHeight
144 };
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 Hunta36f03b2015-04-01 15:22:49 -0700169 tr.append('td').attr('class', cls).html(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) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700176 data.propOrder.forEach(function (p) {
Simon Hunt08f841d02015-02-10 14:39:20 -0800177 if (p === '-') {
178 addSep(tbody);
179 } else {
180 addProp(tbody, p, data.props[p]);
181 }
182 });
183 }
184
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700185 function watchWindow() {
Bri Prebilic Cole0a6ffb62015-06-04 09:32:12 -0700186 unbindWatch = $rootScope.$watchCollection(
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700187 function () {
188 return {
189 h: $window.innerHeight,
190 w: $window.innerWidth
191 };
192 }, function () {
Simon Hunte8c54db2016-06-15 12:56:50 -0700193 var h = summary.adjustHeight(sumFromTop, sumMax),
194 ss = summary.panel().isVisible(),
195 dtop = h && ss ? sumFromTop + h + padFudge : 0,
196 dy = dtop || ss ? detail.ypos.current : sumFromTop;
197 detail.adjustHeight(dy);
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700198 }
199 );
200 }
201
Simon Hunt08f841d02015-02-10 14:39:20 -0800202 // === -----------------------------------------------------
203 // Functions for populating the summary panel
204
205 function populateSummary(data) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700206 summary.setup();
Simon Hunt08f841d02015-02-10 14:39:20 -0800207
Bri Prebilic Cole8d3de3d2015-05-15 16:02:59 -0700208 var svg = summary.appendHeader('div')
209 .classed('icon', true)
210 .append('svg'),
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700211 title = summary.appendHeader('h2'),
212 table = summary.appendBody('table'),
Simon Hunt629b99e2015-07-27 17:38:33 -0700213 tbody = table.append('tbody'),
214 glyphId = data.type || 'node';
Simon Hunt08f841d02015-02-10 14:39:20 -0800215
Simon Hunt629b99e2015-07-27 17:38:33 -0700216 gs.addGlyph(svg, glyphId, 40);
217
218 if (glyphId === 'node') {
219 gs.addGlyph(svg, 'bird', 24, true, [8,12]);
220 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800221
Simon Hunt0af1ec32015-07-24 12:17:55 -0700222 title.text(data.title);
Simon Hunt08f841d02015-02-10 14:39:20 -0800223 listProps(tbody, data);
224 }
225
226 // === -----------------------------------------------------
227 // Functions for populating the detail panel
228
Simon Huntb745ca62015-07-28 15:37:11 -0700229 var isDevice = {
230 switch: 1,
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +0200231 roadm: 1,
232 otn:1
Simon Huntb745ca62015-07-28 15:37:11 -0700233 };
234
Simon Hunt08f841d02015-02-10 14:39:20 -0800235 function displaySingle(data) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700236 detail.setup();
Simon Hunt08f841d02015-02-10 14:39:20 -0800237
Bri Prebilic Cole8d3de3d2015-05-15 16:02:59 -0700238 var svg = detail.appendHeader('div')
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700239 .classed('icon clickable', true)
Bri Prebilic Cole8d3de3d2015-05-15 16:02:59 -0700240 .append('svg'),
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700241 title = detail.appendHeader('h2')
242 .classed('clickable', true),
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700243 table = detail.appendBody('table'),
Simon Huntb745ca62015-07-28 15:37:11 -0700244 tbody = table.append('tbody'),
245 navFn;
Simon Hunt08f841d02015-02-10 14:39:20 -0800246
247 gs.addGlyph(svg, (data.type || 'unknown'), 40);
Simon Huntb745ca62015-07-28 15:37:11 -0700248 title.text(data.title);
249
250 // only add navigation when displaying a device
251 if (isDevice[data.type]) {
252 navFn = function () {
253 ns.navTo(devPath, { devId: data.id });
254 };
255
256 svg.on('click', navFn);
257 title.on('click', navFn);
258 }
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700259
Simon Hunt08f841d02015-02-10 14:39:20 -0800260 listProps(tbody, data);
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700261 addBtnFooter();
Simon Hunt08f841d02015-02-10 14:39:20 -0800262 }
263
264 function displayMulti(ids) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700265 detail.setup();
Simon Hunt08f841d02015-02-10 14:39:20 -0800266
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700267 var title = detail.appendHeader('h3'),
268 table = detail.appendBody('table'),
Simon Hunt08f841d02015-02-10 14:39:20 -0800269 tbody = table.append('tbody');
270
271 title.text('Selected Nodes');
272 ids.forEach(function (d, i) {
273 addProp(tbody, i+1, d);
274 });
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700275 addBtnFooter();
Simon Hunt08f841d02015-02-10 14:39:20 -0800276 }
277
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -0700278 function addAction(o) {
279 var btnDiv = d3.select('#' + idDet)
280 .select('.actionBtns')
281 .append('div')
282 .classed('actionBtn', true);
Simon Hunt3a0598f2015-08-04 19:59:04 -0700283 bns.button(btnDiv, idDet + '-' + o.id, o.gid, o.cb, o.tt);
Simon Hunt08f841d02015-02-10 14:39:20 -0800284 }
285
Simon Hunta36f03b2015-04-01 15:22:49 -0700286 var friendlyIndex = {
287 device: 1,
288 host: 0
289 };
290
291 function friendly(d) {
292 var i = friendlyIndex[d.class] || 0;
293 return (d.labels && d.labels[i]) || '';
294 }
295
296 function linkSummary(d) {
297 var o = d && d.online ? 'online' : 'offline';
298 return d ? d.type + ' / ' + o : '-';
299 }
300
Simon Hunte25c5a22015-04-02 14:37:12 -0700301 // provided to change presentation of internal type name
302 var linkTypePres = {
303 hostLink: 'edge link'
304 };
305
306 function linkType(d) {
307 return linkTypePres[d.type()] || d.type();
308 }
309
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800310 function linkExpected(d) {
311 return d.expected();
312 }
313
Simon Hunte25c5a22015-04-02 14:37:12 -0700314 var coreOrder = [
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800315 'Type', 'Expected', '-',
Simon Hunte25c5a22015-04-02 14:37:12 -0700316 'A_type', 'A_id', 'A_label', 'A_port', '-',
Simon Hunt4f732d22016-06-01 19:35:35 -0700317 'B_type', 'B_id', 'B_label', 'B_port'
Simon Hunte25c5a22015-04-02 14:37:12 -0700318 ],
319 edgeOrder = [
320 'Type', '-',
321 'A_type', 'A_id', 'A_label', '-',
322 'B_type', 'B_id', 'B_label', 'B_port'
323 ];
324
Simon Hunt4f732d22016-06-01 19:35:35 -0700325 function displayLink(data, modifyCb) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700326 detail.setup();
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700327
Bri Prebilic Cole8d3de3d2015-05-15 16:02:59 -0700328 var svg = detail.appendHeader('div')
329 .classed('icon', true)
330 .append('svg'),
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700331 title = detail.appendHeader('h2'),
332 table = detail.appendBody('table'),
Simon Hunte25c5a22015-04-02 14:37:12 -0700333 tbody = table.append('tbody'),
334 edgeLink = data.type() === 'hostLink',
335 order = edgeLink ? edgeOrder : coreOrder;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700336
337 gs.addGlyph(svg, 'ports', 40);
338 title.text('Link');
Simon Hunta36f03b2015-04-01 15:22:49 -0700339
Simon Hunt4f732d22016-06-01 19:35:35 -0700340 var linkData = {
341 propOrder: order.slice(0), // makes a copy of the array
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700342 props: {
Simon Hunte25c5a22015-04-02 14:37:12 -0700343 Type: linkType(data),
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800344 Expected: linkExpected(data),
Simon Hunta36f03b2015-04-01 15:22:49 -0700345
346 A_type: data.source.class,
347 A_id: data.source.id,
348 A_label: friendly(data.source),
349 A_port: data.srcPort,
350
351 B_type: data.target.class,
352 B_id: data.target.id,
353 B_label: friendly(data.target),
354 B_port: data.tgtPort
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700355 }
Simon Hunt4f732d22016-06-01 19:35:35 -0700356 };
357 listProps(tbody, modifyCb(linkData, data.extra));
Simon Hunta36f03b2015-04-01 15:22:49 -0700358
Simon Hunte25c5a22015-04-02 14:37:12 -0700359 if (!edgeLink) {
Simon Hunt4f732d22016-06-01 19:35:35 -0700360 addSep(tbody);
Simon Hunte25c5a22015-04-02 14:37:12 -0700361 addProp(tbody, 'A &rarr; B', linkSummary(data.fromSource));
362 addProp(tbody, 'B &rarr; A', linkSummary(data.fromTarget));
363 }
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700364 }
365
366 function displayNothing() {
367 haveDetails = false;
368 hideDetailPanel();
369 }
370
371 function displaySomething() {
372 haveDetails = true;
373 if (useDetails) {
374 showDetailPanel();
375 }
376 }
377
Simon Hunt08f841d02015-02-10 14:39:20 -0800378 // === -----------------------------------------------------
379 // Event Handlers
380
381 function showSummary(data) {
382 populateSummary(data);
383 showSummaryPanel();
384 }
385
Simon Hunt36a58c62015-04-08 11:00:07 -0700386 function toggleSummary(x) {
Simon Huntee7a3ce2015-04-09 13:28:37 -0700387 var kev = (x === 'keyev'),
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700388 on = kev ? !summary.panel().isVisible() : !!x,
Simon Huntee7a3ce2015-04-09 13:28:37 -0700389 verb = on ? 'Show' : 'Hide';
Simon Hunt36a58c62015-04-08 11:00:07 -0700390
391 if (on) {
Simon Hunta0eb0a82015-02-11 12:30:06 -0800392 // ask server to start sending summary data.
Simon Hunt237676b52015-03-10 19:04:26 -0700393 wss.sendEvent('requestSummary');
Simon Hunta0eb0a82015-02-11 12:30:06 -0800394 // note: the summary panel will appear, once data arrives
Simon Hunt36a58c62015-04-08 11:00:07 -0700395 } else {
396 hideSummaryPanel();
Simon Hunt6036b192015-02-11 11:20:26 -0800397 }
Simon Huntee7a3ce2015-04-09 13:28:37 -0700398 flash.flash(verb + ' summary panel');
399 return on;
Simon Hunt6036b192015-02-11 11:20:26 -0800400 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800401
402 // === -----------------------------------------------------
403 // === LOGIC For showing/hiding summary and detail panels...
404
Simon Hunt626d2102015-01-29 11:54:50 -0800405 function showSummaryPanel() {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700406 function _show() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700407 summary.panel().show();
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700408 summary.adjustHeight(sumFromTop, sumMax);
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700409 }
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700410 if (detail.panel().isVisible()) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700411 detail.down(_show);
Simon Hunt6036b192015-02-11 11:20:26 -0800412 } else {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700413 _show();
Simon Hunt6036b192015-02-11 11:20:26 -0800414 }
Simon Huntc252aa62015-02-10 16:45:39 -0800415 }
416
417 function hideSummaryPanel() {
Simon Hunta0eb0a82015-02-11 12:30:06 -0800418 // instruct server to stop sending summary data
Simon Hunt237676b52015-03-10 19:04:26 -0700419 wss.sendEvent("cancelSummary");
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700420 summary.panel().hide(detail.up);
Simon Hunt4b668592015-01-29 17:33:53 -0800421 }
Simon Hunt626d2102015-01-29 11:54:50 -0800422
Simon Hunt08f841d02015-02-10 14:39:20 -0800423 function showDetailPanel() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700424 if (summary.panel().isVisible()) {
425 detail.down(detail.panel().show);
Simon Hunt6036b192015-02-11 11:20:26 -0800426 } else {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700427 detail.up(detail.panel().show);
Simon Hunt6036b192015-02-11 11:20:26 -0800428 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800429 }
430
431 function hideDetailPanel() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700432 detail.panel().hide();
Simon Hunt08f841d02015-02-10 14:39:20 -0800433 }
434
Simon Hunt6036b192015-02-11 11:20:26 -0800435 // ==========================
Simon Hunt08f841d02015-02-10 14:39:20 -0800436
Simon Hunt6036b192015-02-11 11:20:26 -0800437 function augmentDetailPanel() {
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700438 var d = detail,
Simon Hunte8c54db2016-06-15 12:56:50 -0700439 downPos = sumFromTop + sumMax + padFudge;
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700440 d.ypos = { up: sumFromTop, down: downPos, current: downPos};
Simon Hunt6036b192015-02-11 11:20:26 -0800441
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700442 d._move = function (y, cb) {
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700443 var yp = d.ypos,
444 endCb;
445
446 if (fs.isF(cb)) {
447 endCb = function () {
448 cb();
449 d.adjustHeight(d.ypos.current);
450 }
451 } else {
452 endCb = function () {
453 d.adjustHeight(d.ypos.current);
454 }
455 }
Simon Hunt6036b192015-02-11 11:20:26 -0800456 if (yp.current !== y) {
457 yp.current = y;
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700458 d.panel().el().transition().duration(300)
Simon Hunt6036b192015-02-11 11:20:26 -0800459 .each('end', endCb)
460 .style('top', yp.current + 'px');
461 } else {
462 endCb();
463 }
464 };
465
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700466 d.down = function (cb) { d._move(d.ypos.down, cb); };
467 d.up = function (cb) { d._move(d.ypos.up, cb); };
Simon Hunt6036b192015-02-11 11:20:26 -0800468 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800469
Simon Hunt239e5882015-04-23 15:07:04 -0700470 function toggleUseDetailsFlag(x) {
Simon Huntee7a3ce2015-04-09 13:28:37 -0700471 var kev = (x === 'keyev'),
472 verb;
473
474 useDetails = kev ? !useDetails : !!x;
475 verb = useDetails ? 'Enable' : 'Disable';
476
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700477 if (useDetails) {
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700478 if (haveDetails) {
479 showDetailPanel();
480 }
481 } else {
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700482 hideDetailPanel();
483 }
Simon Huntee7a3ce2015-04-09 13:28:37 -0700484 flash.flash(verb + ' details panel');
485 return useDetails;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700486 }
487
Simon Hunt4b668592015-01-29 17:33:53 -0800488 // ==========================
489
Simon Hunt237676b52015-03-10 19:04:26 -0700490 function initPanels() {
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700491 sumFromTop = mast.mastHeight() + padTop;
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700492 summary = createTopoPanel(idSum, panelOpts);
493 detail = createTopoPanel(idDet, panelOpts);
Simon Hunt6036b192015-02-11 11:20:26 -0800494
495 augmentDetailPanel();
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700496 watchWindow();
Simon Hunt4b668592015-01-29 17:33:53 -0800497 }
498
499 function destroyPanels() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700500 summary.destroy();
501 summary = null;
502
503 detail.destroy();
504 detail = null;
Simon Hunt239e5882015-04-23 15:07:04 -0700505 haveDetails = false;
Bri Prebilic Cole0a6ffb62015-06-04 09:32:12 -0700506 unbindWatch();
Simon Hunt626d2102015-01-29 11:54:50 -0800507 }
508
509 // ==========================
510
Simon Huntb0ec1e52015-01-28 18:13:49 -0800511 angular.module('ovTopo')
512 .factory('TopoPanelService',
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700513 ['$log', '$window', '$rootScope', 'FnService', 'PanelService', 'GlyphService',
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700514 'FlashService', 'WebSocketService', 'ButtonService', 'MastService',
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700515 'NavService',
Simon Huntb0ec1e52015-01-28 18:13:49 -0800516
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700517 function (_$log_, _$window_, _$rootScope_,
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700518 _fs_, _ps_, _gs_, _flash_, _wss_, _bns_, _mast_, _ns_) {
Simon Huntb0ec1e52015-01-28 18:13:49 -0800519 $log = _$log_;
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700520 $window = _$window_;
521 $rootScope = _$rootScope_;
Simon Hunt6036b192015-02-11 11:20:26 -0800522 fs = _fs_;
Simon Huntb0ec1e52015-01-28 18:13:49 -0800523 ps = _ps_;
Simon Huntc9b73162015-01-29 14:02:15 -0800524 gs = _gs_;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700525 flash = _flash_;
Simon Hunt237676b52015-03-10 19:04:26 -0700526 wss = _wss_;
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -0700527 bns = _bns_;
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700528 mast = _mast_;
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700529 ns = _ns_;
Simon Huntb0ec1e52015-01-28 18:13:49 -0800530
Simon Huntb0ec1e52015-01-28 18:13:49 -0800531 return {
532 initPanels: initPanels,
Simon Hunt626d2102015-01-29 11:54:50 -0800533 destroyPanels: destroyPanels,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700534 createTopoPanel: createTopoPanel,
Simon Hunt08f841d02015-02-10 14:39:20 -0800535
536 showSummary: showSummary,
Simon Hunt6036b192015-02-11 11:20:26 -0800537 toggleSummary: toggleSummary,
Thomas Vachuska0af26912016-03-21 21:37:30 -0700538 hideSummary: hideSummaryPanel,
Simon Hunt08f841d02015-02-10 14:39:20 -0800539
Simon Hunt239e5882015-04-23 15:07:04 -0700540 toggleUseDetailsFlag: toggleUseDetailsFlag,
Simon Hunt08f841d02015-02-10 14:39:20 -0800541 displaySingle: displaySingle,
542 displayMulti: displayMulti,
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700543 displayLink: displayLink,
544 displayNothing: displayNothing,
545 displaySomething: displaySomething,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700546 addAction: addAction,
Simon Hunt08f841d02015-02-10 14:39:20 -0800547
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700548 detailVisible: function () { return detail.panel().isVisible(); },
549 summaryVisible: function () { return summary.panel().isVisible(); }
Simon Huntb0ec1e52015-01-28 18:13:49 -0800550 };
551 }]);
552}());