blob: 72e3f6711e4750c3b57d1969e384cae7275a15bf [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);
Steven Burrows4b4d2b42017-08-16 14:11:23 +0100234
235 augmentDetailPanel();
Simon Hunt08f841d02015-02-10 14:39:20 -0800236 }
237
238 // === -----------------------------------------------------
239 // Functions for populating the detail panel
240
Simon Hunt10618f62017-06-15 19:30:52 -0700241 var navPathIdKey = {
242 device: 'devId',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100243 host: 'hostId',
Simon Huntb745ca62015-07-28 15:37:11 -0700244 };
245
Simon Hunt08f841d02015-02-10 14:39:20 -0800246 function displaySingle(data) {
Simon Hunta58d8942017-08-11 12:51:14 -0700247 var sepLast;
248
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700249 detail.setup();
Simon Hunt08f841d02015-02-10 14:39:20 -0800250
Bri Prebilic Cole8d3de3d2015-05-15 16:02:59 -0700251 var svg = detail.appendHeader('div')
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700252 .classed('icon clickable', true)
Bri Prebilic Cole8d3de3d2015-05-15 16:02:59 -0700253 .append('svg'),
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700254 title = detail.appendHeader('h2')
255 .classed('clickable', true),
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700256 table = detail.appendBody('table'),
Simon Huntb745ca62015-07-28 15:37:11 -0700257 tbody = table.append('tbody'),
Simon Hunt10618f62017-06-15 19:30:52 -0700258 navFn,
259 navPath;
Simon Hunt08f841d02015-02-10 14:39:20 -0800260
Simon Hunta58d8942017-08-11 12:51:14 -0700261 gs.addGlyph(svg, (data.glyphId || 'm_unknown'), 26);
Simon Huntb745ca62015-07-28 15:37:11 -0700262 title.text(data.title);
263
Simon Hunt10618f62017-06-15 19:30:52 -0700264 // add navigation hot-link if defined
265 navPath = data.navPath;
266 if (navPath) {
Simon Huntb745ca62015-07-28 15:37:11 -0700267 navFn = function () {
Simon Hunt10618f62017-06-15 19:30:52 -0700268 var arg = {};
269 arg[navPathIdKey[navPath]] = data.id;
270 ns.navTo(navPath, arg);
Simon Huntb745ca62015-07-28 15:37:11 -0700271 };
272
273 svg.on('click', navFn);
274 title.on('click', navFn);
275 }
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700276
Simon Hunta58d8942017-08-11 12:51:14 -0700277 sepLast = listProps(tbody, data);
278 addBtnFooter(sepLast);
Simon Hunt08f841d02015-02-10 14:39:20 -0800279 }
280
281 function displayMulti(ids) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700282 detail.setup();
Simon Hunt08f841d02015-02-10 14:39:20 -0800283
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700284 var title = detail.appendHeader('h3'),
285 table = detail.appendBody('table'),
Simon Hunt08f841d02015-02-10 14:39:20 -0800286 tbody = table.append('tbody');
287
Simon Hunta58d8942017-08-11 12:51:14 -0700288 title.text(topoLion('title_selected_items'));
Simon Hunt08f841d02015-02-10 14:39:20 -0800289 ids.forEach(function (d, i) {
Simon Hunta58d8942017-08-11 12:51:14 -0700290 addProp(tbody, i + 1, d);
Simon Hunt08f841d02015-02-10 14:39:20 -0800291 });
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700292 addBtnFooter();
Simon Hunt08f841d02015-02-10 14:39:20 -0800293 }
294
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -0700295 function addAction(o) {
296 var btnDiv = d3.select('#' + idDet)
297 .select('.actionBtns')
298 .append('div')
299 .classed('actionBtn', true);
Simon Hunt3a0598f2015-08-04 19:59:04 -0700300 bns.button(btnDiv, idDet + '-' + o.id, o.gid, o.cb, o.tt);
Simon Hunt08f841d02015-02-10 14:39:20 -0800301 }
302
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700303 function displayNothing() {
304 haveDetails = false;
305 hideDetailPanel();
306 }
307
308 function displaySomething() {
309 haveDetails = true;
310 if (useDetails) {
311 showDetailPanel();
312 }
313 }
314
Simon Hunt08f841d02015-02-10 14:39:20 -0800315 // === -----------------------------------------------------
316 // Event Handlers
317
318 function showSummary(data) {
319 populateSummary(data);
320 showSummaryPanel();
321 }
322
Simon Hunt36a58c62015-04-08 11:00:07 -0700323 function toggleSummary(x) {
Simon Huntee7a3ce2015-04-09 13:28:37 -0700324 var kev = (x === 'keyev'),
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700325 on = kev ? !summary.panel().isVisible() : !!x,
Simon Hunt879ce452017-08-10 23:32:00 -0700326 verb = on ? topoLion('show') : topoLion('hide'),
327 sumpan = topoLion('fl_panel_summary');
Simon Hunt36a58c62015-04-08 11:00:07 -0700328
329 if (on) {
Simon Hunta0eb0a82015-02-11 12:30:06 -0800330 // ask server to start sending summary data.
Simon Hunt237676b52015-03-10 19:04:26 -0700331 wss.sendEvent('requestSummary');
Simon Hunta0eb0a82015-02-11 12:30:06 -0800332 // note: the summary panel will appear, once data arrives
Simon Hunt36a58c62015-04-08 11:00:07 -0700333 } else {
334 hideSummaryPanel();
Simon Hunt6036b192015-02-11 11:20:26 -0800335 }
Simon Hunt879ce452017-08-10 23:32:00 -0700336 flash.flash(verb + ' ' + sumpan);
Simon Huntee7a3ce2015-04-09 13:28:37 -0700337 return on;
Simon Hunt6036b192015-02-11 11:20:26 -0800338 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800339
340 // === -----------------------------------------------------
341 // === LOGIC For showing/hiding summary and detail panels...
342
Simon Hunt626d2102015-01-29 11:54:50 -0800343 function showSummaryPanel() {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700344 function _show() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700345 summary.panel().show();
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700346 summary.adjustHeight(sumFromTop, sumMax);
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700347 }
Simon Hunta58d8942017-08-11 12:51:14 -0700348
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700349 if (detail.panel().isVisible()) {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700350 detail.down(_show);
Simon Hunt6036b192015-02-11 11:20:26 -0800351 } else {
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700352 _show();
Simon Hunt6036b192015-02-11 11:20:26 -0800353 }
Simon Huntc252aa62015-02-10 16:45:39 -0800354 }
355
356 function hideSummaryPanel() {
Simon Hunta0eb0a82015-02-11 12:30:06 -0800357 // instruct server to stop sending summary data
Steven Burrows1c2a9682017-07-14 16:52:46 +0100358 wss.sendEvent('cancelSummary');
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700359 summary.panel().hide(detail.up);
Simon Hunt4b668592015-01-29 17:33:53 -0800360 }
Simon Hunt626d2102015-01-29 11:54:50 -0800361
Simon Hunt08f841d02015-02-10 14:39:20 -0800362 function showDetailPanel() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700363 if (summary.panel().isVisible()) {
364 detail.down(detail.panel().show);
Simon Hunt6036b192015-02-11 11:20:26 -0800365 } else {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700366 detail.up(detail.panel().show);
Simon Hunt6036b192015-02-11 11:20:26 -0800367 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800368 }
369
Steven Burrows4b4d2b42017-08-16 14:11:23 +0100370 function summaryBBox() {
371 return d3.select('#' + idSum).node().getBoundingClientRect();
372 }
373
Simon Hunt08f841d02015-02-10 14:39:20 -0800374 function hideDetailPanel() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700375 detail.panel().hide();
Simon Hunt08f841d02015-02-10 14:39:20 -0800376 }
377
Simon Hunt6036b192015-02-11 11:20:26 -0800378 // ==========================
Simon Hunt08f841d02015-02-10 14:39:20 -0800379
Simon Hunt6036b192015-02-11 11:20:26 -0800380 function augmentDetailPanel() {
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700381 var d = detail,
Steven Burrows4b4d2b42017-08-16 14:11:23 +0100382 downPos = summaryBBox().bottom + padTop;
383
Steven Burrows1c2a9682017-07-14 16:52:46 +0100384 d.ypos = { up: sumFromTop, down: downPos, current: downPos };
Simon Hunt6036b192015-02-11 11:20:26 -0800385
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700386 d._move = function (y, cb) {
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700387 var yp = d.ypos,
388 endCb;
389
390 if (fs.isF(cb)) {
391 endCb = function () {
392 cb();
393 d.adjustHeight(d.ypos.current);
Steven Burrows1c2a9682017-07-14 16:52:46 +0100394 };
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700395 } else {
396 endCb = function () {
397 d.adjustHeight(d.ypos.current);
Steven Burrows1c2a9682017-07-14 16:52:46 +0100398 };
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700399 }
Simon Hunt6036b192015-02-11 11:20:26 -0800400 if (yp.current !== y) {
401 yp.current = y;
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700402 d.panel().el().transition().duration(300)
Simon Hunt6036b192015-02-11 11:20:26 -0800403 .each('end', endCb)
404 .style('top', yp.current + 'px');
405 } else {
406 endCb();
407 }
408 };
409
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700410 d.down = function (cb) { d._move(d.ypos.down, cb); };
411 d.up = function (cb) { d._move(d.ypos.up, cb); };
Simon Hunt6036b192015-02-11 11:20:26 -0800412 }
Simon Hunt08f841d02015-02-10 14:39:20 -0800413
Simon Hunt239e5882015-04-23 15:07:04 -0700414 function toggleUseDetailsFlag(x) {
Simon Huntee7a3ce2015-04-09 13:28:37 -0700415 var kev = (x === 'keyev'),
416 verb;
417
418 useDetails = kev ? !useDetails : !!x;
Simon Hunt8032d8b2017-08-11 19:46:48 -0700419 verb = topoLion(useDetails ? 'enable' : 'disable');
Simon Huntee7a3ce2015-04-09 13:28:37 -0700420
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700421 if (useDetails) {
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700422 if (haveDetails) {
423 showDetailPanel();
424 }
425 } else {
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700426 hideDetailPanel();
427 }
Simon Hunt8032d8b2017-08-11 19:46:48 -0700428 flash.flash(verb + ' ' + topoLion('fl_panel_details'));
Simon Huntee7a3ce2015-04-09 13:28:37 -0700429 return useDetails;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700430 }
431
Simon Hunt4b668592015-01-29 17:33:53 -0800432 // ==========================
433
Simon Hunt237676b52015-03-10 19:04:26 -0700434 function initPanels() {
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700435 sumFromTop = mast.mastHeight() + padTop;
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700436 summary = createTopoPanel(idSum, panelOpts);
437 detail = createTopoPanel(idDet, panelOpts);
Simon Hunt6036b192015-02-11 11:20:26 -0800438
439 augmentDetailPanel();
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700440 watchWindow();
Simon Hunt4b668592015-01-29 17:33:53 -0800441 }
442
443 function destroyPanels() {
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700444 summary.destroy();
445 summary = null;
446
447 detail.destroy();
448 detail = null;
Simon Hunt239e5882015-04-23 15:07:04 -0700449 haveDetails = false;
Bri Prebilic Cole0a6ffb62015-06-04 09:32:12 -0700450 unbindWatch();
Simon Hunt626d2102015-01-29 11:54:50 -0800451 }
452
453 // ==========================
454
Simon Huntb0ec1e52015-01-28 18:13:49 -0800455 angular.module('ovTopo')
456 .factory('TopoPanelService',
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700457 ['$log', '$window', '$rootScope', 'FnService', 'PanelService', 'GlyphService',
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700458 'FlashService', 'WebSocketService', 'ButtonService', 'MastService',
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700459 'NavService',
Simon Huntb0ec1e52015-01-28 18:13:49 -0800460
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700461 function (_$log_, _$window_, _$rootScope_,
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700462 _fs_, _ps_, _gs_, _flash_, _wss_, _bns_, _mast_, _ns_) {
Simon Huntb0ec1e52015-01-28 18:13:49 -0800463 $log = _$log_;
Bri Prebilic Cole69d5f4e2015-05-19 15:59:55 -0700464 $window = _$window_;
465 $rootScope = _$rootScope_;
Simon Hunt6036b192015-02-11 11:20:26 -0800466 fs = _fs_;
Simon Huntb0ec1e52015-01-28 18:13:49 -0800467 ps = _ps_;
Simon Huntc9b73162015-01-29 14:02:15 -0800468 gs = _gs_;
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700469 flash = _flash_;
Simon Hunt237676b52015-03-10 19:04:26 -0700470 wss = _wss_;
Bri Prebilic Colef5e48b12015-04-21 14:52:36 -0700471 bns = _bns_;
Bri Prebilic Coled8745462015-06-01 16:08:57 -0700472 mast = _mast_;
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700473 ns = _ns_;
Simon Huntb0ec1e52015-01-28 18:13:49 -0800474
Simon Huntb0ec1e52015-01-28 18:13:49 -0800475 return {
476 initPanels: initPanels,
Simon Hunt626d2102015-01-29 11:54:50 -0800477 destroyPanels: destroyPanels,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700478 createTopoPanel: createTopoPanel,
Simon Hunt08f841d02015-02-10 14:39:20 -0800479
480 showSummary: showSummary,
Simon Hunt6036b192015-02-11 11:20:26 -0800481 toggleSummary: toggleSummary,
Thomas Vachuska0af26912016-03-21 21:37:30 -0700482 hideSummary: hideSummaryPanel,
Simon Hunt08f841d02015-02-10 14:39:20 -0800483
Simon Hunt239e5882015-04-23 15:07:04 -0700484 toggleUseDetailsFlag: toggleUseDetailsFlag,
Simon Hunt08f841d02015-02-10 14:39:20 -0800485 displaySingle: displaySingle,
486 displayMulti: displayMulti,
Simon Hunt0c6b2d32015-03-26 17:46:29 -0700487 displayNothing: displayNothing,
488 displaySomething: displaySomething,
Bri Prebilic Cole684bcb72015-05-11 12:00:24 -0700489 addAction: addAction,
Simon Hunt08f841d02015-02-10 14:39:20 -0800490
Bri Prebilic Cole35d29712015-05-11 16:01:32 -0700491 detailVisible: function () { return detail.panel().isVisible(); },
Steven Burrows1c2a9682017-07-14 16:52:46 +0100492 summaryVisible: function () { return summary.panel().isVisible(); },
Simon Hunt879ce452017-08-10 23:32:00 -0700493
494 setLionBundle: function (bundle) { topoLion = bundle; },
Simon Huntb0ec1e52015-01-28 18:13:49 -0800495 };
496 }]);
497}());