blob: 6cdf3fe08c32466000a3ab95b2298d90fe4d73d4 [file] [log] [blame]
Steven Burrows5570d1b2016-09-28 14:21:00 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Steven Burrows5570d1b2016-09-28 14:21:00 -07003 *
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 Layout Module.
19 Module that contains the d3.force.layout logic
20 */
21
22(function () {
23 'use strict';
24
25 // Injected Services
Steven Burrowsaf96a212016-12-28 12:57:02 +000026 var Panel, gs, wss, flash, ls;
Steven Burrows5570d1b2016-09-28 14:21:00 -070027
28 // Internal State
Steven Burrowsc59481f2017-04-13 10:01:15 -070029 var summaryPanel, summaryData, detailsPanel;
Steven Burrows5570d1b2016-09-28 14:21:00 -070030
31 // configuration
Steven Burrows1c5c8612016-10-05 13:45:13 -050032 var id = 'topo2-p-summary',
Simon Hunt95f4b422017-03-03 13:49:05 -080033 className = 'topo2-p',
Steven Burrows1c5c8612016-10-05 13:45:13 -050034 panelOpts = {
35 show: true,
Steven Burrows1c2a9682017-07-14 16:52:46 +010036 width: 260, // summary and detail panel width
Steven Burrows1c5c8612016-10-05 13:45:13 -050037 },
Steven Burrows5570d1b2016-09-28 14:21:00 -070038 handlerMap = {
Steven Burrows1c2a9682017-07-14 16:52:46 +010039 showSummary: handleSummaryData,
Steven Burrows5570d1b2016-09-28 14:21:00 -070040 };
41
Steven Burrowsc59481f2017-04-13 10:01:15 -070042 function init(_detailsPanel_) {
43
44 detailsPanel = _detailsPanel_;
Steven Burrows5570d1b2016-09-28 14:21:00 -070045
46 bindHandlers();
47 wss.sendEvent('requestSummary');
48
Steven Burrows1c5c8612016-10-05 13:45:13 -050049 var options = angular.extend({}, panelOpts, {
Steven Burrows1c2a9682017-07-14 16:52:46 +010050 class: className,
Steven Burrows5570d1b2016-09-28 14:21:00 -070051 });
52
Steven Burrows1c5c8612016-10-05 13:45:13 -050053 summaryPanel = new Panel(id, options);
Steven Burrows86af4352016-11-16 18:19:12 -060054 summaryPanel.el.classed(className, true);
Steven Burrows5570d1b2016-09-28 14:21:00 -070055 }
56
57 function render() {
Simon Hunt3d875ec2017-09-07 16:52:59 -070058 var endedWithSeparator;
59
Steven Burrows5570d1b2016-09-28 14:21:00 -070060 summaryPanel.emptyRegions();
61
62 var svg = summaryPanel.appendToHeader('div')
63 .classed('icon', true)
64 .append('svg'),
65 title = summaryPanel.appendToHeader('h2'),
66 table = summaryPanel.appendToBody('table'),
67 tbody = table.append('tbody');
68
69 title.text(summaryData.title);
70 gs.addGlyph(svg, 'bird', 24, 0, [1, 1]);
Simon Hunt3d875ec2017-09-07 16:52:59 -070071 endedWithSeparator = ls.listProps(tbody, summaryData);
72 // TODO : review whether we need to use/store end-with-sep state
Steven Burrows5570d1b2016-09-28 14:21:00 -070073 }
74
75 function handleSummaryData(data) {
76 summaryData = data;
77 render();
78 }
79
80 function bindHandlers() {
81 wss.bindHandlers(handlerMap);
82 }
83
Steven Burrowsc59481f2017-04-13 10:01:15 -070084 function hide() {
85 summaryPanel.el.hide(detailsPanel.getInstance().up);
86 }
87
88 function show() {
89
90 var _show = function () {
91 summaryPanel.el.show();
92 };
93
94 var summaryHeight = summaryPanel.el.bbox().height;
95 if (detailsPanel.isVisible()) {
96 detailsPanel.getInstance().down(summaryHeight, _show);
97 } else {
98 _show();
99 }
100 }
101
102
Steven Burrows5570d1b2016-09-28 14:21:00 -0700103 function toggle() {
Steven Burrowsc59481f2017-04-13 10:01:15 -0700104 var on = summaryPanel.isVisible(),
105 verb = on ? 'Hide' : 'Show';
Steven Burrows0b5e2f72016-12-19 12:02:22 -0500106
Steven Burrows5570d1b2016-09-28 14:21:00 -0700107 flash.flash(verb + ' Summary Panel');
Simon Hunt80438762016-12-20 13:26:36 -0800108 wss.sendEvent(on ? 'requestSummary' : 'cancelSummary');
Steven Burrowsc59481f2017-04-13 10:01:15 -0700109 on ? hide(): show();
Steven Burrows5570d1b2016-09-28 14:21:00 -0700110 }
111
Steven Burrows1c5c8612016-10-05 13:45:13 -0500112 function destroy() {
113 wss.unbindHandlers(handlerMap);
Steven Burrows0b5e2f72016-12-19 12:02:22 -0500114 wss.sendEvent('cancelSummary');
Steven Burrows1c5c8612016-10-05 13:45:13 -0500115 summaryPanel.destroy();
116 }
117
Steven Burrows5570d1b2016-09-28 14:21:00 -0700118 angular.module('ovTopo2')
Steven Burrowsaf96a212016-12-28 12:57:02 +0000119 .factory('Topo2SummaryPanelService', [
120 'Topo2PanelService', 'GlyphService', 'WebSocketService', 'FlashService', 'ListService',
121 function (_ps_, _gs_, _wss_, _flash_, _ls_) {
Steven Burrows5570d1b2016-09-28 14:21:00 -0700122
123 Panel = _ps_;
124 gs = _gs_;
125 wss = _wss_;
126 flash = _flash_;
Steven Burrowsaf96a212016-12-28 12:57:02 +0000127 ls = _ls_;
Steven Burrows5570d1b2016-09-28 14:21:00 -0700128
129 return {
130 init: init,
Steven Burrows1c5c8612016-10-05 13:45:13 -0500131 toggle: toggle,
Steven Burrowsc0efbf02016-11-16 11:30:47 -0600132 destroy: destroy,
Steven Burrowsc59481f2017-04-13 10:01:15 -0700133 isVisible: function () { return summaryPanel.isVisible(); },
Steven Burrows1c2a9682017-07-14 16:52:46 +0100134 getInstance: function () { return summaryPanel; },
Steven Burrows5570d1b2016-09-28 14:21:00 -0700135 };
Steven Burrows1c2a9682017-07-14 16:52:46 +0100136 },
Steven Burrows5570d1b2016-09-28 14:21:00 -0700137 ]);
138
139})();