Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 1 | /* |
| 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 Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 26 | var panel, gs, wss, flash, bs, fs, ns, ls; |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 27 | |
| 28 | // Internal State |
| 29 | var detailsPanel; |
| 30 | |
| 31 | // configuration |
| 32 | var id = 'topo2-p-detail', |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 33 | 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 Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 68 | detailsPanel = panel(); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 69 | } |
| 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 Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 99 | }); |
| 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 Burrows | e2d77d6 | 2016-10-21 12:35:58 -0500 | [diff] [blame] | 112 | tbody = table.append('tbody'); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 113 | |
| 114 | gs.addGlyph(svg, (data.type || 'unknown'), 26); |
| 115 | title.text(data.title); |
| 116 | |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 117 | ls.listProps(tbody, data); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 118 | addBtnFooter(); |
| 119 | } |
| 120 | |
Steven Burrows | 2d1f5ea | 2016-12-14 10:57:46 -0500 | [diff] [blame] | 121 | 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 Burrows | e2d77d6 | 2016-10-21 12:35:58 -0500 | [diff] [blame] | 137 | 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 Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 152 | |
| 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 Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 171 | var on = detailsPanel.el.toggle(), |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 172 | verb = on ? 'Show' : 'Hide'; |
Steven Burrows | c0efbf0 | 2016-11-16 11:30:47 -0600 | [diff] [blame] | 173 | flash.flash(verb + ' Details Panel'); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | function show() { |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 177 | detailsPanel.el.show(); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | function hide() { |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 181 | detailsPanel.el.hide(); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | function destroy() { |
| 185 | wss.unbindHandlers(handlerMap); |
| 186 | detailsPanel.destroy(); |
| 187 | } |
| 188 | |
| 189 | angular.module('ovTopo2') |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 190 | .factory('Topo2DeviceDetailsPanel', [ |
| 191 | 'Topo2DetailsPanelService', 'GlyphService', 'WebSocketService', 'FlashService', |
| 192 | 'ButtonService', 'FnService', 'NavService', 'ListService', |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 193 | |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 194 | function (_ps_, _gs_, _wss_, _flash_, _bs_, _fs_, _ns_, _ls_) { |
| 195 | |
| 196 | panel = _ps_; |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 197 | gs = _gs_; |
| 198 | wss = _wss_; |
| 199 | flash = _flash_; |
| 200 | bs = _bs_; |
| 201 | fs = _fs_; |
| 202 | ns = _ns_; |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 203 | ls = _ls_; |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 204 | |
| 205 | return { |
| 206 | init: init, |
| 207 | updateDetails: updateDetails, |
Steven Burrows | e2d77d6 | 2016-10-21 12:35:58 -0500 | [diff] [blame] | 208 | showMulti: renderMulti, |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 209 | |
| 210 | toggle: toggle, |
| 211 | show: show, |
| 212 | hide: hide, |
Steven Burrows | c0efbf0 | 2016-11-16 11:30:47 -0600 | [diff] [blame] | 213 | destroy: destroy, |
| 214 | isVisible: function () { return detailsPanel.isVisible(); } |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 215 | }; |
| 216 | } |
| 217 | ]); |
| 218 | })(); |