Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 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 | c59481f | 2017-04-13 10:01:15 -0700 | [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 | 6bc6786 | 2017-04-12 13:20:00 -0700 | [diff] [blame] | 33 | devicePath = 'device', |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 34 | handlerMap = { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 35 | 'showDetails': showDetails, |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | var coreButtons = { |
| 39 | showDeviceView: { |
| 40 | gid: 'switch', |
| 41 | tt: 'Show Device View', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 42 | path: 'device', |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 43 | }, |
| 44 | showFlowView: { |
| 45 | gid: 'flowTable', |
| 46 | tt: 'Show Flow View for this Device', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 47 | path: 'flow', |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 48 | }, |
| 49 | showPortView: { |
| 50 | gid: 'portTable', |
| 51 | tt: 'Show Port View for this Device', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 52 | path: 'port', |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 53 | }, |
| 54 | showGroupView: { |
| 55 | gid: 'groupTable', |
| 56 | tt: 'Show Group View for this Device', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 57 | path: 'group', |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 58 | }, |
| 59 | showMeterView: { |
| 60 | gid: 'meterTable', |
| 61 | tt: 'Show Meter View for this Device', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 62 | path: 'meter', |
| 63 | }, |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 64 | }; |
| 65 | |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 66 | function init(summaryPanel) { |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 67 | |
| 68 | bindHandlers(); |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 69 | detailsPanel = panel(summaryPanel); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 70 | } |
| 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, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 97 | cb: function () { ns.navTo(path, { devId: devId }); }, |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 98 | }); |
| 99 | } |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 100 | }); |
| 101 | } |
| 102 | |
| 103 | function renderSingle(data) { |
Simon Hunt | 3d875ec | 2017-09-07 16:52:59 -0700 | [diff] [blame] | 104 | var endedWithSeparator; |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 105 | |
| 106 | detailsPanel.emptyRegions(); |
| 107 | |
Steven Burrows | 6bc6786 | 2017-04-12 13:20:00 -0700 | [diff] [blame] | 108 | var navFn = function () { |
| 109 | ns.navTo(devicePath, { devId: data.id }); |
| 110 | }; |
| 111 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 112 | var svg = detailsPanel.appendToHeader('div') |
| 113 | .classed('icon clickable', true) |
| 114 | .append('svg'), |
| 115 | title = detailsPanel.appendToHeader('h2') |
Steven Burrows | 6bc6786 | 2017-04-12 13:20:00 -0700 | [diff] [blame] | 116 | .on('click', navFn) |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 117 | .classed('clickable', true), |
| 118 | table = detailsPanel.appendToBody('table'), |
Steven Burrows | e2d77d6 | 2016-10-21 12:35:58 -0500 | [diff] [blame] | 119 | tbody = table.append('tbody'); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 120 | |
Simon Hunt | de40032 | 2017-09-08 10:59:35 -0700 | [diff] [blame] | 121 | gs.addGlyph(svg, (data.glyphId || 'm_unknown'), 26); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 122 | title.text(data.title); |
| 123 | |
Simon Hunt | 3d875ec | 2017-09-07 16:52:59 -0700 | [diff] [blame] | 124 | // TODO: add navigation hot-link if defined |
| 125 | // See topoPanel.js for equivalent code in "classic" topo |
Steven Burrows | 9aeab92 | 2017-04-12 16:17:10 -0700 | [diff] [blame] | 126 | |
Simon Hunt | 3d875ec | 2017-09-07 16:52:59 -0700 | [diff] [blame] | 127 | endedWithSeparator = ls.listProps(tbody, data); |
| 128 | // TODO : review whether we need to use/store end-with-sep state |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 129 | addBtnFooter(); |
| 130 | } |
| 131 | |
Steven Burrows | 2d1f5ea | 2016-12-14 10:57:46 -0500 | [diff] [blame] | 132 | 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 Hunt | 239f09e | 2017-05-18 13:10:09 -0700 | [diff] [blame] | 142 | tr.append('td').attr('class', cls).text(txt); |
Steven Burrows | 2d1f5ea | 2016-12-14 10:57:46 -0500 | [diff] [blame] | 143 | } |
| 144 | addCell('label', lab + ' :'); |
| 145 | addCell('value', value); |
| 146 | } |
| 147 | |
Steven Burrows | e2d77d6 | 2016-10-21 12:35:58 -0500 | [diff] [blame] | 148 | 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 Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 163 | |
| 164 | function bindHandlers() { |
| 165 | wss.bindHandlers(handlerMap); |
| 166 | } |
| 167 | |
| 168 | function updateDetails(id, nodeType) { |
| 169 | wss.sendEvent('requestDetails', { |
| 170 | id: id, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 171 | class: nodeType, |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 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 Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 182 | var on = detailsPanel.el.toggle(), |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 183 | verb = on ? 'Show' : 'Hide'; |
Steven Burrows | c0efbf0 | 2016-11-16 11:30:47 -0600 | [diff] [blame] | 184 | flash.flash(verb + ' Details Panel'); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | function show() { |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 188 | detailsPanel.show(); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | function hide() { |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 192 | detailsPanel.el.hide(); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | function destroy() { |
| 196 | wss.unbindHandlers(handlerMap); |
| 197 | detailsPanel.destroy(); |
| 198 | } |
| 199 | |
| 200 | angular.module('ovTopo2') |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 201 | .factory('Topo2DeviceDetailsPanel', [ |
| 202 | 'Topo2DetailsPanelService', 'GlyphService', 'WebSocketService', 'FlashService', |
| 203 | 'ButtonService', 'FnService', 'NavService', 'ListService', |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 204 | |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 205 | function (_ps_, _gs_, _wss_, _flash_, _bs_, _fs_, _ns_, _ls_) { |
| 206 | |
| 207 | panel = _ps_; |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 208 | gs = _gs_; |
| 209 | wss = _wss_; |
| 210 | flash = _flash_; |
| 211 | bs = _bs_; |
| 212 | fs = _fs_; |
| 213 | ns = _ns_; |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 214 | ls = _ls_; |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 215 | |
| 216 | return { |
| 217 | init: init, |
| 218 | updateDetails: updateDetails, |
Steven Burrows | e2d77d6 | 2016-10-21 12:35:58 -0500 | [diff] [blame] | 219 | showMulti: renderMulti, |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 220 | |
| 221 | toggle: toggle, |
| 222 | show: show, |
| 223 | hide: hide, |
Steven Burrows | c0efbf0 | 2016-11-16 11:30:47 -0600 | [diff] [blame] | 224 | destroy: destroy, |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 225 | isVisible: function () { return detailsPanel.isVisible(); }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 226 | getInstance: function () { return detailsPanel; }, |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 227 | }; |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 228 | }, |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 229 | ]); |
| 230 | })(); |