blob: df670612fceade22212ea06f3f34aab2666cb1df [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 Burrows6bc67862017-04-12 13:20:00 -070026 var panel, gs, wss, flash, bs, fs, ns, ls, ns;
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
66 function init() {
67
68 bindHandlers();
Steven Burrowsaf96a212016-12-28 12:57:02 +000069 detailsPanel = panel();
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
108 var navFn = function () {
109 ns.navTo(devicePath, { devId: data.id });
110 };
111
Steven Burrows1c5c8612016-10-05 13:45:13 -0500112 var svg = detailsPanel.appendToHeader('div')
113 .classed('icon clickable', true)
114 .append('svg'),
115 title = detailsPanel.appendToHeader('h2')
Steven Burrows6bc67862017-04-12 13:20:00 -0700116 .on('click', navFn)
Steven Burrows1c5c8612016-10-05 13:45:13 -0500117 .classed('clickable', true),
118 table = detailsPanel.appendToBody('table'),
Steven Burrowse2d77d62016-10-21 12:35:58 -0500119 tbody = table.append('tbody');
Steven Burrows1c5c8612016-10-05 13:45:13 -0500120
121 gs.addGlyph(svg, (data.type || 'unknown'), 26);
122 title.text(data.title);
123
Steven Burrowsaf96a212016-12-28 12:57:02 +0000124 ls.listProps(tbody, data);
Steven Burrows1c5c8612016-10-05 13:45:13 -0500125 addBtnFooter();
126 }
127
Steven Burrows2d1f5ea2016-12-14 10:57:46 -0500128 function addProp(tbody, label, value) {
129 var tr = tbody.append('tr'),
130 lab;
131 if (typeof label === 'string') {
132 lab = label.replace(/_/g, ' ');
133 } else {
134 lab = label;
135 }
136
137 function addCell(cls, txt) {
138 tr.append('td').attr('class', cls).html(txt);
139 }
140 addCell('label', lab + ' :');
141 addCell('value', value);
142 }
143
Steven Burrowse2d77d62016-10-21 12:35:58 -0500144 function renderMulti(nodes) {
145 detailsPanel.emptyRegions();
146
147 var title = detailsPanel.appendToHeader('h3'),
148 table = detailsPanel.appendToBody('table'),
149 tbody = table.append('tbody');
150
151 title.text('Selected Items');
152 nodes.forEach(function (n, i) {
153 addProp(tbody, i + 1, n.get('id'));
154 });
155
156 // addBtnFooter();
157 show();
158 }
Steven Burrows1c5c8612016-10-05 13:45:13 -0500159
160 function bindHandlers() {
161 wss.bindHandlers(handlerMap);
162 }
163
164 function updateDetails(id, nodeType) {
165 wss.sendEvent('requestDetails', {
166 id: id,
167 class: nodeType
168 });
169 }
170
171 function showDetails(data) {
172 var buttons = fs.isA(data.buttons) || [];
173 renderSingle(data);
174 installButtons(buttons, data, data.id);
175 }
176
177 function toggle() {
Steven Burrows86af4352016-11-16 18:19:12 -0600178 var on = detailsPanel.el.toggle(),
Steven Burrows1c5c8612016-10-05 13:45:13 -0500179 verb = on ? 'Show' : 'Hide';
Steven Burrowsc0efbf02016-11-16 11:30:47 -0600180 flash.flash(verb + ' Details Panel');
Steven Burrows1c5c8612016-10-05 13:45:13 -0500181 }
182
183 function show() {
Steven Burrows86af4352016-11-16 18:19:12 -0600184 detailsPanel.el.show();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500185 }
186
187 function hide() {
Steven Burrows86af4352016-11-16 18:19:12 -0600188 detailsPanel.el.hide();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500189 }
190
191 function destroy() {
192 wss.unbindHandlers(handlerMap);
193 detailsPanel.destroy();
194 }
195
196 angular.module('ovTopo2')
Steven Burrowsaf96a212016-12-28 12:57:02 +0000197 .factory('Topo2DeviceDetailsPanel', [
198 'Topo2DetailsPanelService', 'GlyphService', 'WebSocketService', 'FlashService',
199 'ButtonService', 'FnService', 'NavService', 'ListService',
Steven Burrows1c5c8612016-10-05 13:45:13 -0500200
Steven Burrowsaf96a212016-12-28 12:57:02 +0000201 function (_ps_, _gs_, _wss_, _flash_, _bs_, _fs_, _ns_, _ls_) {
202
203 panel = _ps_;
Steven Burrows1c5c8612016-10-05 13:45:13 -0500204 gs = _gs_;
205 wss = _wss_;
206 flash = _flash_;
207 bs = _bs_;
208 fs = _fs_;
209 ns = _ns_;
Steven Burrowsaf96a212016-12-28 12:57:02 +0000210 ls = _ls_;
Steven Burrows1c5c8612016-10-05 13:45:13 -0500211
212 return {
213 init: init,
214 updateDetails: updateDetails,
Steven Burrowse2d77d62016-10-21 12:35:58 -0500215 showMulti: renderMulti,
Steven Burrows1c5c8612016-10-05 13:45:13 -0500216
217 toggle: toggle,
218 show: show,
219 hide: hide,
Steven Burrowsc0efbf02016-11-16 11:30:47 -0600220 destroy: destroy,
221 isVisible: function () { return detailsPanel.isVisible(); }
Steven Burrows1c5c8612016-10-05 13:45:13 -0500222 };
223 }
224 ]);
225})();