blob: 741f942af45f8610388213c83be0a8c2f2bb72f9 [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 Burrows86af4352016-11-16 18:19:12 -060026 var Panel, gs, wss, flash, bs, fs, ns, listProps;
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 Burrows86af4352016-11-16 18:19:12 -060068 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 Burrows1c5c8612016-10-05 13:45:13 -0500117 listProps(tbody, data);
118 addBtnFooter();
119 }
120
Steven Burrowse2d77d62016-10-21 12:35:58 -0500121 function renderMulti(nodes) {
122 detailsPanel.emptyRegions();
123
124 var title = detailsPanel.appendToHeader('h3'),
125 table = detailsPanel.appendToBody('table'),
126 tbody = table.append('tbody');
127
128 title.text('Selected Items');
129 nodes.forEach(function (n, i) {
130 addProp(tbody, i + 1, n.get('id'));
131 });
132
133 // addBtnFooter();
134 show();
135 }
Steven Burrows1c5c8612016-10-05 13:45:13 -0500136
137 function bindHandlers() {
138 wss.bindHandlers(handlerMap);
139 }
140
141 function updateDetails(id, nodeType) {
142 wss.sendEvent('requestDetails', {
143 id: id,
144 class: nodeType
145 });
146 }
147
148 function showDetails(data) {
149 var buttons = fs.isA(data.buttons) || [];
150 renderSingle(data);
151 installButtons(buttons, data, data.id);
152 }
153
154 function toggle() {
Steven Burrows86af4352016-11-16 18:19:12 -0600155 var on = detailsPanel.el.toggle(),
Steven Burrows1c5c8612016-10-05 13:45:13 -0500156 verb = on ? 'Show' : 'Hide';
Steven Burrowsc0efbf02016-11-16 11:30:47 -0600157 flash.flash(verb + ' Details Panel');
Steven Burrows1c5c8612016-10-05 13:45:13 -0500158 }
159
160 function show() {
Steven Burrows86af4352016-11-16 18:19:12 -0600161 detailsPanel.el.show();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500162 }
163
164 function hide() {
Steven Burrows86af4352016-11-16 18:19:12 -0600165 detailsPanel.el.hide();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500166 }
167
168 function destroy() {
169 wss.unbindHandlers(handlerMap);
170 detailsPanel.destroy();
171 }
172
173 angular.module('ovTopo2')
174 .factory('Topo2DeviceDetailsPanel',
Steven Burrows86af4352016-11-16 18:19:12 -0600175 ['Topo2DetailsPanelService', 'GlyphService', 'WebSocketService', 'FlashService',
176 'ButtonService', 'FnService', 'NavService', 'ListService',
177 function (_ps_, _gs_, _wss_, _flash_, _bs_, _fs_, _ns_, _listService_) {
Steven Burrows1c5c8612016-10-05 13:45:13 -0500178
179 Panel = _ps_;
180 gs = _gs_;
181 wss = _wss_;
182 flash = _flash_;
183 bs = _bs_;
184 fs = _fs_;
185 ns = _ns_;
Steven Burrows86af4352016-11-16 18:19:12 -0600186 listProps = _listService_;
Steven Burrows1c5c8612016-10-05 13:45:13 -0500187
188 return {
189 init: init,
190 updateDetails: updateDetails,
Steven Burrowse2d77d62016-10-21 12:35:58 -0500191 showMulti: renderMulti,
Steven Burrows1c5c8612016-10-05 13:45:13 -0500192
193 toggle: toggle,
194 show: show,
195 hide: hide,
Steven Burrowsc0efbf02016-11-16 11:30:47 -0600196 destroy: destroy,
197 isVisible: function () { return detailsPanel.isVisible(); }
Steven Burrows1c5c8612016-10-05 13:45:13 -0500198 };
199 }
200 ]);
201})();