blob: e8778ed2874743bc074d007078c0b374718894ae [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 Burrowsaf96a212016-12-28 12:57:02 +000026 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 Burrows1c5c8612016-10-05 13:45:13 -050033 handlerMap = {
34 'showDetails': showDetails
35 };
36
37 var coreButtons = {
38 showDeviceView: {
39 gid: 'switch',
40 tt: 'Show Device View',
41 path: 'device'
42 },
43 showFlowView: {
44 gid: 'flowTable',
45 tt: 'Show Flow View for this Device',
46 path: 'flow'
47 },
48 showPortView: {
49 gid: 'portTable',
50 tt: 'Show Port View for this Device',
51 path: 'port'
52 },
53 showGroupView: {
54 gid: 'groupTable',
55 tt: 'Show Group View for this Device',
56 path: 'group'
57 },
58 showMeterView: {
59 gid: 'meterTable',
60 tt: 'Show Meter View for this Device',
61 path: 'meter'
62 }
63 };
64
65 function init() {
66
67 bindHandlers();
Steven Burrowsaf96a212016-12-28 12:57:02 +000068 detailsPanel = panel();
Steven Burrows1c5c8612016-10-05 13:45:13 -050069 }
70
71 function addBtnFooter() {
72 detailsPanel.appendToFooter('hr');
73 detailsPanel.appendToFooter('div').classed('actionBtns', true);
74 }
75
76 function addAction(o) {
77 var btnDiv = d3.select('#' + id)
78 .select('.actionBtns')
79 .append('div')
80 .classed('actionBtn', true);
81 bs.button(btnDiv, id + '-' + o.id, o.gid, o.cb, o.tt);
82 }
83
84 function installButtons(buttons, data, devId) {
85 buttons.forEach(function (id) {
86 var btn = coreButtons[id],
87 gid = btn && btn.gid,
88 tt = btn && btn.tt,
89 path = btn && btn.path;
90
91 if (btn) {
92 addAction({
93 id: 'core-' + id,
94 gid: gid,
95 tt: tt,
96 cb: function () { ns.navTo(path, { devId: devId }); }
97 });
98 }
Steven Burrows1c5c8612016-10-05 13:45:13 -050099 });
100 }
101
102 function renderSingle(data) {
103
104 detailsPanel.emptyRegions();
105
106 var svg = detailsPanel.appendToHeader('div')
107 .classed('icon clickable', true)
108 .append('svg'),
109 title = detailsPanel.appendToHeader('h2')
110 .classed('clickable', true),
111 table = detailsPanel.appendToBody('table'),
Steven Burrowse2d77d62016-10-21 12:35:58 -0500112 tbody = table.append('tbody');
Steven Burrows1c5c8612016-10-05 13:45:13 -0500113
114 gs.addGlyph(svg, (data.type || 'unknown'), 26);
115 title.text(data.title);
116
Steven Burrowsaf96a212016-12-28 12:57:02 +0000117 ls.listProps(tbody, data);
Steven Burrows1c5c8612016-10-05 13:45:13 -0500118 addBtnFooter();
119 }
120
Steven Burrows2d1f5ea2016-12-14 10:57:46 -0500121 function addProp(tbody, label, value) {
122 var tr = tbody.append('tr'),
123 lab;
124 if (typeof label === 'string') {
125 lab = label.replace(/_/g, ' ');
126 } else {
127 lab = label;
128 }
129
130 function addCell(cls, txt) {
131 tr.append('td').attr('class', cls).html(txt);
132 }
133 addCell('label', lab + ' :');
134 addCell('value', value);
135 }
136
Steven Burrowse2d77d62016-10-21 12:35:58 -0500137 function renderMulti(nodes) {
138 detailsPanel.emptyRegions();
139
140 var title = detailsPanel.appendToHeader('h3'),
141 table = detailsPanel.appendToBody('table'),
142 tbody = table.append('tbody');
143
144 title.text('Selected Items');
145 nodes.forEach(function (n, i) {
146 addProp(tbody, i + 1, n.get('id'));
147 });
148
149 // addBtnFooter();
150 show();
151 }
Steven Burrows1c5c8612016-10-05 13:45:13 -0500152
153 function bindHandlers() {
154 wss.bindHandlers(handlerMap);
155 }
156
157 function updateDetails(id, nodeType) {
158 wss.sendEvent('requestDetails', {
159 id: id,
160 class: nodeType
161 });
162 }
163
164 function showDetails(data) {
165 var buttons = fs.isA(data.buttons) || [];
166 renderSingle(data);
167 installButtons(buttons, data, data.id);
168 }
169
170 function toggle() {
Steven Burrows86af4352016-11-16 18:19:12 -0600171 var on = detailsPanel.el.toggle(),
Steven Burrows1c5c8612016-10-05 13:45:13 -0500172 verb = on ? 'Show' : 'Hide';
Steven Burrowsc0efbf02016-11-16 11:30:47 -0600173 flash.flash(verb + ' Details Panel');
Steven Burrows1c5c8612016-10-05 13:45:13 -0500174 }
175
176 function show() {
Steven Burrows86af4352016-11-16 18:19:12 -0600177 detailsPanel.el.show();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500178 }
179
180 function hide() {
Steven Burrows86af4352016-11-16 18:19:12 -0600181 detailsPanel.el.hide();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500182 }
183
184 function destroy() {
185 wss.unbindHandlers(handlerMap);
186 detailsPanel.destroy();
187 }
188
189 angular.module('ovTopo2')
Steven Burrowsaf96a212016-12-28 12:57:02 +0000190 .factory('Topo2DeviceDetailsPanel', [
191 'Topo2DetailsPanelService', 'GlyphService', 'WebSocketService', 'FlashService',
192 'ButtonService', 'FnService', 'NavService', 'ListService',
Steven Burrows1c5c8612016-10-05 13:45:13 -0500193
Steven Burrowsaf96a212016-12-28 12:57:02 +0000194 function (_ps_, _gs_, _wss_, _flash_, _bs_, _fs_, _ns_, _ls_) {
195
196 panel = _ps_;
Steven Burrows1c5c8612016-10-05 13:45:13 -0500197 gs = _gs_;
198 wss = _wss_;
199 flash = _flash_;
200 bs = _bs_;
201 fs = _fs_;
202 ns = _ns_;
Steven Burrowsaf96a212016-12-28 12:57:02 +0000203 ls = _ls_;
Steven Burrows1c5c8612016-10-05 13:45:13 -0500204
205 return {
206 init: init,
207 updateDetails: updateDetails,
Steven Burrowse2d77d62016-10-21 12:35:58 -0500208 showMulti: renderMulti,
Steven Burrows1c5c8612016-10-05 13:45:13 -0500209
210 toggle: toggle,
211 show: show,
212 hide: hide,
Steven Burrowsc0efbf02016-11-16 11:30:47 -0600213 destroy: destroy,
214 isVisible: function () { return detailsPanel.isVisible(); }
Steven Burrows1c5c8612016-10-05 13:45:13 -0500215 };
216 }
217 ]);
218})();