blob: 50b43d38d4c52cbd63c9e9677104dce93e19cb64 [file] [log] [blame]
Steven Burrows1c5c8612016-10-05 13:45:13 -05001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
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 View Module.
19 Module that displays the details panel for selected nodes
20 */
21
22(function () {
23 'use strict';
24
25 // Injected Services
26 var Panel, gs, wss, flash, bs, fs, ns;
27
28 // Internal State
29 var detailsPanel;
30
31 // configuration
32 var id = 'topo2-p-detail',
33 className = 'topo-p',
34 panelOpts = {
35 width: 260 // summary and detail panel width
36 },
37 handlerMap = {
38 'showDetails': showDetails
39 };
40
41 var coreButtons = {
42 showDeviceView: {
43 gid: 'switch',
44 tt: 'Show Device View',
45 path: 'device'
46 },
47 showFlowView: {
48 gid: 'flowTable',
49 tt: 'Show Flow View for this Device',
50 path: 'flow'
51 },
52 showPortView: {
53 gid: 'portTable',
54 tt: 'Show Port View for this Device',
55 path: 'port'
56 },
57 showGroupView: {
58 gid: 'groupTable',
59 tt: 'Show Group View for this Device',
60 path: 'group'
61 },
62 showMeterView: {
63 gid: 'meterTable',
64 tt: 'Show Meter View for this Device',
65 path: 'meter'
66 }
67 };
68
69 function init() {
70
71 bindHandlers();
72
73 var options = angular.extend({}, panelOpts, {
74 class: className
75 });
76
77 detailsPanel = new Panel(id, options);
78 detailsPanel.p.classed(className, true);
79 }
80
81 function addProp(tbody, label, value) {
82 var tr = tbody.append('tr'),
83 lab;
84 if (typeof label === 'string') {
85 lab = label.replace(/_/g, ' ');
86 } else {
87 lab = label;
88 }
89
90 function addCell(cls, txt) {
91 tr.append('td').attr('class', cls).html(txt);
92 }
93 addCell('label', lab + ' :');
94 addCell('value', value);
95 }
96
97 function addSep(tbody) {
98 tbody.append('tr').append('td').attr('colspan', 2).append('hr');
99 }
100
101 function listProps(tbody, data) {
102 data.propOrder.forEach(function (p) {
103 if (p === '-') {
104 addSep(tbody);
105 } else {
106 addProp(tbody, p, data.props[p]);
107 }
108 });
109 }
110
111 function addBtnFooter() {
112 detailsPanel.appendToFooter('hr');
113 detailsPanel.appendToFooter('div').classed('actionBtns', true);
114 }
115
116 function addAction(o) {
117 var btnDiv = d3.select('#' + id)
118 .select('.actionBtns')
119 .append('div')
120 .classed('actionBtn', true);
121 bs.button(btnDiv, id + '-' + o.id, o.gid, o.cb, o.tt);
122 }
123
124 function installButtons(buttons, data, devId) {
125 buttons.forEach(function (id) {
126 var btn = coreButtons[id],
127 gid = btn && btn.gid,
128 tt = btn && btn.tt,
129 path = btn && btn.path;
130
131 if (btn) {
132 addAction({
133 id: 'core-' + id,
134 gid: gid,
135 tt: tt,
136 cb: function () { ns.navTo(path, { devId: devId }); }
137 });
138 }
Steven Burrowse2d77d62016-10-21 12:35:58 -0500139 // TODO: Implement Overlay service
Steven Burrows1c5c8612016-10-05 13:45:13 -0500140 // else if (btn = _getButtonDef(id, data)) {
141 // addAction(btn);
142 // }
143 });
144 }
145
146 function renderSingle(data) {
147
148 detailsPanel.emptyRegions();
149
150 var svg = detailsPanel.appendToHeader('div')
151 .classed('icon clickable', true)
152 .append('svg'),
153 title = detailsPanel.appendToHeader('h2')
154 .classed('clickable', true),
155 table = detailsPanel.appendToBody('table'),
Steven Burrowse2d77d62016-10-21 12:35:58 -0500156 tbody = table.append('tbody');
Steven Burrows1c5c8612016-10-05 13:45:13 -0500157
158 gs.addGlyph(svg, (data.type || 'unknown'), 26);
159 title.text(data.title);
160
Steven Burrows1c5c8612016-10-05 13:45:13 -0500161 listProps(tbody, data);
162 addBtnFooter();
163 }
164
Steven Burrowse2d77d62016-10-21 12:35:58 -0500165 function renderMulti(nodes) {
166 detailsPanel.emptyRegions();
167
168 var title = detailsPanel.appendToHeader('h3'),
169 table = detailsPanel.appendToBody('table'),
170 tbody = table.append('tbody');
171
172 title.text('Selected Items');
173 nodes.forEach(function (n, i) {
174 addProp(tbody, i + 1, n.get('id'));
175 });
176
177 // addBtnFooter();
178 show();
179 }
Steven Burrows1c5c8612016-10-05 13:45:13 -0500180
181 function bindHandlers() {
182 wss.bindHandlers(handlerMap);
183 }
184
185 function updateDetails(id, nodeType) {
186 wss.sendEvent('requestDetails', {
187 id: id,
188 class: nodeType
189 });
190 }
191
192 function showDetails(data) {
193 var buttons = fs.isA(data.buttons) || [];
194 renderSingle(data);
195 installButtons(buttons, data, data.id);
196 }
197
198 function toggle() {
199 var on = detailsPanel.p.toggle(),
200 verb = on ? 'Show' : 'Hide';
201 flash.flash(verb + ' Summary Panel');
202 }
203
204 function show() {
205 detailsPanel.p.show();
206 }
207
208 function hide() {
209 detailsPanel.p.hide();
210 }
211
212 function destroy() {
213 wss.unbindHandlers(handlerMap);
214 detailsPanel.destroy();
215 }
216
217 angular.module('ovTopo2')
218 .factory('Topo2DeviceDetailsPanel',
219 ['Topo2PanelService', 'GlyphService', 'WebSocketService', 'FlashService',
220 'ButtonService', 'FnService', 'NavService',
221 function (_ps_, _gs_, _wss_, _flash_, _bs_, _fs_, _ns_) {
222
223 Panel = _ps_;
224 gs = _gs_;
225 wss = _wss_;
226 flash = _flash_;
227 bs = _bs_;
228 fs = _fs_;
229 ns = _ns_;
230
231 return {
232 init: init,
233 updateDetails: updateDetails,
Steven Burrowse2d77d62016-10-21 12:35:58 -0500234 showMulti: renderMulti,
Steven Burrows1c5c8612016-10-05 13:45:13 -0500235
236 toggle: toggle,
237 show: show,
238 hide: hide,
239 destroy: destroy
240 };
241 }
242 ]);
243})();