blob: 3cacf8b03e5a981479d27727e665d97cf020b39d [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
Steven Burrowsc59481f2017-04-13 10:01:15 -070026 var panel, gs, wss, flash, bs, fs, ns, ls;
Steven Burrows1c5c8612016-10-05 13:45:13 -050027
28 // Internal State
29 var detailsPanel;
30
31 // configuration
32 var id = 'topo2-p-detail',
Steven Burrows6bc67862017-04-12 13:20:00 -070033 devicePath = 'device',
Steven Burrows1c5c8612016-10-05 13:45:13 -050034 handlerMap = {
35 'showDetails': showDetails
36 };
37
38 var coreButtons = {
39 showDeviceView: {
40 gid: 'switch',
41 tt: 'Show Device View',
42 path: 'device'
43 },
44 showFlowView: {
45 gid: 'flowTable',
46 tt: 'Show Flow View for this Device',
47 path: 'flow'
48 },
49 showPortView: {
50 gid: 'portTable',
51 tt: 'Show Port View for this Device',
52 path: 'port'
53 },
54 showGroupView: {
55 gid: 'groupTable',
56 tt: 'Show Group View for this Device',
57 path: 'group'
58 },
59 showMeterView: {
60 gid: 'meterTable',
61 tt: 'Show Meter View for this Device',
62 path: 'meter'
63 }
64 };
65
Steven Burrowsc59481f2017-04-13 10:01:15 -070066 function init(summaryPanel) {
Steven Burrows1c5c8612016-10-05 13:45:13 -050067
68 bindHandlers();
Steven Burrowsc59481f2017-04-13 10:01:15 -070069 detailsPanel = panel(summaryPanel);
Steven Burrows1c5c8612016-10-05 13:45:13 -050070 }
71
72 function addBtnFooter() {
73 detailsPanel.appendToFooter('hr');
74 detailsPanel.appendToFooter('div').classed('actionBtns', true);
75 }
76
77 function addAction(o) {
78 var btnDiv = d3.select('#' + id)
79 .select('.actionBtns')
80 .append('div')
81 .classed('actionBtn', true);
82 bs.button(btnDiv, id + '-' + o.id, o.gid, o.cb, o.tt);
83 }
84
85 function installButtons(buttons, data, devId) {
86 buttons.forEach(function (id) {
87 var btn = coreButtons[id],
88 gid = btn && btn.gid,
89 tt = btn && btn.tt,
90 path = btn && btn.path;
91
92 if (btn) {
93 addAction({
94 id: 'core-' + id,
95 gid: gid,
96 tt: tt,
97 cb: function () { ns.navTo(path, { devId: devId }); }
98 });
99 }
Steven Burrows1c5c8612016-10-05 13:45:13 -0500100 });
101 }
102
103 function renderSingle(data) {
104
105 detailsPanel.emptyRegions();
106
Steven Burrows6bc67862017-04-12 13:20:00 -0700107 var navFn = function () {
108 ns.navTo(devicePath, { devId: data.id });
109 };
110
Steven Burrows1c5c8612016-10-05 13:45:13 -0500111 var svg = detailsPanel.appendToHeader('div')
112 .classed('icon clickable', true)
113 .append('svg'),
114 title = detailsPanel.appendToHeader('h2')
Steven Burrows6bc67862017-04-12 13:20:00 -0700115 .on('click', navFn)
Steven Burrows1c5c8612016-10-05 13:45:13 -0500116 .classed('clickable', true),
117 table = detailsPanel.appendToBody('table'),
Steven Burrowse2d77d62016-10-21 12:35:58 -0500118 tbody = table.append('tbody');
Steven Burrows1c5c8612016-10-05 13:45:13 -0500119
120 gs.addGlyph(svg, (data.type || 'unknown'), 26);
121 title.text(data.title);
122
Steven Burrows9aeab922017-04-12 16:17:10 -0700123 if (!data.props.Latitude) {
124 var locationIndex = data.propOrder.indexOf('Latitude');
125 data.propOrder.splice(locationIndex - 1, 3);
126 }
127
Steven Burrowsaf96a212016-12-28 12:57:02 +0000128 ls.listProps(tbody, data);
Steven Burrows1c5c8612016-10-05 13:45:13 -0500129 addBtnFooter();
130 }
131
Steven Burrows2d1f5ea2016-12-14 10:57:46 -0500132 function addProp(tbody, label, value) {
133 var tr = tbody.append('tr'),
134 lab;
135 if (typeof label === 'string') {
136 lab = label.replace(/_/g, ' ');
137 } else {
138 lab = label;
139 }
140
141 function addCell(cls, txt) {
Simon Hunt239f09e2017-05-18 13:10:09 -0700142 tr.append('td').attr('class', cls).text(txt);
Steven Burrows2d1f5ea2016-12-14 10:57:46 -0500143 }
144 addCell('label', lab + ' :');
145 addCell('value', value);
146 }
147
Steven Burrowse2d77d62016-10-21 12:35:58 -0500148 function renderMulti(nodes) {
149 detailsPanel.emptyRegions();
150
151 var title = detailsPanel.appendToHeader('h3'),
152 table = detailsPanel.appendToBody('table'),
153 tbody = table.append('tbody');
154
155 title.text('Selected Items');
156 nodes.forEach(function (n, i) {
157 addProp(tbody, i + 1, n.get('id'));
158 });
159
160 // addBtnFooter();
161 show();
162 }
Steven Burrows1c5c8612016-10-05 13:45:13 -0500163
164 function bindHandlers() {
165 wss.bindHandlers(handlerMap);
166 }
167
168 function updateDetails(id, nodeType) {
169 wss.sendEvent('requestDetails', {
170 id: id,
171 class: nodeType
172 });
173 }
174
175 function showDetails(data) {
176 var buttons = fs.isA(data.buttons) || [];
177 renderSingle(data);
178 installButtons(buttons, data, data.id);
179 }
180
181 function toggle() {
Steven Burrows86af4352016-11-16 18:19:12 -0600182 var on = detailsPanel.el.toggle(),
Steven Burrows1c5c8612016-10-05 13:45:13 -0500183 verb = on ? 'Show' : 'Hide';
Steven Burrowsc0efbf02016-11-16 11:30:47 -0600184 flash.flash(verb + ' Details Panel');
Steven Burrows1c5c8612016-10-05 13:45:13 -0500185 }
186
187 function show() {
Steven Burrowsc59481f2017-04-13 10:01:15 -0700188 detailsPanel.show();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500189 }
190
191 function hide() {
Steven Burrows86af4352016-11-16 18:19:12 -0600192 detailsPanel.el.hide();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500193 }
194
195 function destroy() {
196 wss.unbindHandlers(handlerMap);
197 detailsPanel.destroy();
198 }
199
200 angular.module('ovTopo2')
Steven Burrowsaf96a212016-12-28 12:57:02 +0000201 .factory('Topo2DeviceDetailsPanel', [
202 'Topo2DetailsPanelService', 'GlyphService', 'WebSocketService', 'FlashService',
203 'ButtonService', 'FnService', 'NavService', 'ListService',
Steven Burrows1c5c8612016-10-05 13:45:13 -0500204
Steven Burrowsaf96a212016-12-28 12:57:02 +0000205 function (_ps_, _gs_, _wss_, _flash_, _bs_, _fs_, _ns_, _ls_) {
206
207 panel = _ps_;
Steven Burrows1c5c8612016-10-05 13:45:13 -0500208 gs = _gs_;
209 wss = _wss_;
210 flash = _flash_;
211 bs = _bs_;
212 fs = _fs_;
213 ns = _ns_;
Steven Burrowsaf96a212016-12-28 12:57:02 +0000214 ls = _ls_;
Steven Burrows1c5c8612016-10-05 13:45:13 -0500215
216 return {
217 init: init,
218 updateDetails: updateDetails,
Steven Burrowse2d77d62016-10-21 12:35:58 -0500219 showMulti: renderMulti,
Steven Burrows1c5c8612016-10-05 13:45:13 -0500220
221 toggle: toggle,
222 show: show,
223 hide: hide,
Steven Burrowsc0efbf02016-11-16 11:30:47 -0600224 destroy: destroy,
Steven Burrowsc59481f2017-04-13 10:01:15 -0700225 isVisible: function () { return detailsPanel.isVisible(); },
226 getInstance: function () { return detailsPanel; }
Steven Burrows1c5c8612016-10-05 13:45:13 -0500227 };
228 }
229 ]);
230})();