Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 Panel Module. |
| 19 | Defines functions for manipulating the summary, detail, and instance panels. |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
| 25 | // injected refs |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame^] | 26 | var $log, fs, ps, gs, wss; |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 27 | |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 28 | // constants |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 29 | var pCls = 'topo-p', |
| 30 | idSum = 'topo-p-summary', |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 31 | idDet = 'topo-p-detail', |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 32 | panelOpts = { |
| 33 | width: 260 |
| 34 | }; |
| 35 | |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 36 | // panels |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 37 | var summaryPanel, |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 38 | detailPanel; |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 39 | |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 40 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 41 | // === ----------------------------------------------------- |
| 42 | // Utility functions |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 43 | |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 44 | function addSep(tbody) { |
| 45 | tbody.append('tr').append('td').attr('colspan', 2).append('hr'); |
| 46 | } |
| 47 | |
| 48 | function addProp(tbody, label, value) { |
| 49 | var tr = tbody.append('tr'); |
| 50 | |
| 51 | function addCell(cls, txt) { |
| 52 | tr.append('td').attr('class', cls).text(txt); |
| 53 | } |
| 54 | addCell('label', label + ' :'); |
| 55 | addCell('value', value); |
| 56 | } |
| 57 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 58 | function listProps(tbody, data) { |
| 59 | data.propOrder.forEach(function(p) { |
| 60 | if (p === '-') { |
| 61 | addSep(tbody); |
| 62 | } else { |
| 63 | addProp(tbody, p, data.props[p]); |
| 64 | } |
| 65 | }); |
| 66 | } |
| 67 | |
| 68 | function dpa(x) { |
| 69 | return detailPanel.append(x); |
| 70 | } |
| 71 | |
| 72 | function spa(x) { |
| 73 | return summaryPanel.append(x); |
| 74 | } |
| 75 | |
| 76 | // === ----------------------------------------------------- |
| 77 | // Functions for populating the summary panel |
| 78 | |
| 79 | function populateSummary(data) { |
| 80 | summaryPanel.empty(); |
| 81 | |
| 82 | var svg = spa('svg'), |
| 83 | title = spa('h2'), |
| 84 | table = spa('table'), |
| 85 | tbody = table.append('tbody'); |
| 86 | |
| 87 | gs.addGlyph(svg, 'node', 40); |
| 88 | gs.addGlyph(svg, 'bird', 24, true, [8,12]); |
| 89 | |
| 90 | title.text(data.id); |
| 91 | listProps(tbody, data); |
| 92 | } |
| 93 | |
| 94 | // === ----------------------------------------------------- |
| 95 | // Functions for populating the detail panel |
| 96 | |
| 97 | function displaySingle(data) { |
| 98 | detailPanel.empty(); |
| 99 | |
| 100 | var svg = dpa('svg'), |
| 101 | title = dpa('h2'), |
| 102 | table = dpa('table'), |
| 103 | tbody = table.append('tbody'); |
| 104 | |
| 105 | gs.addGlyph(svg, (data.type || 'unknown'), 40); |
| 106 | title.text(data.id); |
| 107 | listProps(tbody, data); |
| 108 | dpa('hr'); |
| 109 | } |
| 110 | |
| 111 | function displayMulti(ids) { |
| 112 | detailPanel.empty(); |
| 113 | |
| 114 | var title = dpa('h3'), |
| 115 | table = dpa('table'), |
| 116 | tbody = table.append('tbody'); |
| 117 | |
| 118 | title.text('Selected Nodes'); |
| 119 | ids.forEach(function (d, i) { |
| 120 | addProp(tbody, i+1, d); |
| 121 | }); |
| 122 | dpa('hr'); |
| 123 | } |
| 124 | |
| 125 | function addAction(text, cb) { |
| 126 | dpa('div') |
| 127 | .classed('actionBtn', true) |
| 128 | .text(text) |
| 129 | .on('click', cb); |
| 130 | } |
| 131 | |
| 132 | // === ----------------------------------------------------- |
| 133 | // Event Handlers |
| 134 | |
| 135 | function showSummary(data) { |
| 136 | populateSummary(data); |
| 137 | showSummaryPanel(); |
| 138 | } |
| 139 | |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 140 | function toggleSummary() { |
| 141 | if (summaryPanel.isVisible()) { |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 142 | hideSummaryPanel(); |
| 143 | } else { |
Simon Hunt | a0eb0a8 | 2015-02-11 12:30:06 -0800 | [diff] [blame] | 144 | // ask server to start sending summary data. |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame^] | 145 | wss.sendEvent('requestSummary'); |
Simon Hunt | a0eb0a8 | 2015-02-11 12:30:06 -0800 | [diff] [blame] | 146 | // note: the summary panel will appear, once data arrives |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 147 | } |
| 148 | } |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 149 | |
| 150 | // === ----------------------------------------------------- |
| 151 | // === LOGIC For showing/hiding summary and detail panels... |
| 152 | |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 153 | function showSummaryPanel() { |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 154 | if (detailPanel.isVisible()) { |
| 155 | detailPanel.down(summaryPanel.show); |
| 156 | } else { |
| 157 | summaryPanel.show(); |
| 158 | } |
Simon Hunt | c252aa6 | 2015-02-10 16:45:39 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | function hideSummaryPanel() { |
Simon Hunt | a0eb0a8 | 2015-02-11 12:30:06 -0800 | [diff] [blame] | 162 | // instruct server to stop sending summary data |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame^] | 163 | wss.sendEvent("cancelSummary"); |
Simon Hunt | a0eb0a8 | 2015-02-11 12:30:06 -0800 | [diff] [blame] | 164 | summaryPanel.hide(detailPanel.up); |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 165 | } |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 166 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 167 | function showDetailPanel() { |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 168 | if (summaryPanel.isVisible()) { |
| 169 | detailPanel.down(detailPanel.show); |
| 170 | } else { |
| 171 | detailPanel.up(detailPanel.show); |
| 172 | } |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | function hideDetailPanel() { |
| 176 | detailPanel.hide(); |
| 177 | } |
| 178 | |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 179 | // ========================== |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 180 | |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 181 | function noop () {} |
| 182 | |
| 183 | function augmentDetailPanel() { |
| 184 | var dp = detailPanel; |
| 185 | dp.ypos = { up: 64, down: 320, current: 320}; |
| 186 | |
| 187 | dp._move = function (y, cb) { |
| 188 | var endCb = fs.isF(cb) || noop, |
| 189 | yp = dp.ypos; |
| 190 | if (yp.current !== y) { |
| 191 | yp.current = y; |
| 192 | dp.el().transition().duration(300) |
| 193 | .each('end', endCb) |
| 194 | .style('top', yp.current + 'px'); |
| 195 | } else { |
| 196 | endCb(); |
| 197 | } |
| 198 | }; |
| 199 | |
| 200 | dp.down = function (cb) { dp._move(dp.ypos.down, cb); }; |
| 201 | dp.up = function (cb) { dp._move(dp.ypos.up, cb); }; |
| 202 | } |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 203 | |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 204 | // ========================== |
| 205 | |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame^] | 206 | function initPanels() { |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 207 | summaryPanel = ps.createPanel(idSum, panelOpts); |
| 208 | detailPanel = ps.createPanel(idDet, panelOpts); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 209 | |
| 210 | summaryPanel.classed(pCls, true); |
| 211 | detailPanel.classed(pCls, true); |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 212 | |
| 213 | augmentDetailPanel(); |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | function destroyPanels() { |
| 217 | ps.destroyPanel(idSum); |
| 218 | ps.destroyPanel(idDet); |
| 219 | summaryPanel = detailPanel = null; |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | // ========================== |
| 223 | |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 224 | angular.module('ovTopo') |
| 225 | .factory('TopoPanelService', |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame^] | 226 | ['$log', 'FnService', 'PanelService', 'GlyphService', 'WebSocketService', |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 227 | |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame^] | 228 | function (_$log_, _fs_, _ps_, _gs_, _wss_) { |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 229 | $log = _$log_; |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 230 | fs = _fs_; |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 231 | ps = _ps_; |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 232 | gs = _gs_; |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame^] | 233 | wss = _wss_; |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 234 | |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 235 | return { |
| 236 | initPanels: initPanels, |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 237 | destroyPanels: destroyPanels, |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 238 | |
| 239 | showSummary: showSummary, |
Simon Hunt | 6036b19 | 2015-02-11 11:20:26 -0800 | [diff] [blame] | 240 | toggleSummary: toggleSummary, |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 241 | |
| 242 | displaySingle: displaySingle, |
| 243 | displayMulti: displayMulti, |
| 244 | addAction: addAction, |
| 245 | |
Simon Hunt | c252aa6 | 2015-02-10 16:45:39 -0800 | [diff] [blame] | 246 | hideSummaryPanel: hideSummaryPanel, |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 247 | showDetailPanel: showDetailPanel, |
| 248 | hideDetailPanel: hideDetailPanel, |
| 249 | |
| 250 | detailVisible: function () { return detailPanel.isVisible(); }, |
| 251 | summaryVisible: function () { return summaryPanel.isVisible(); } |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 252 | }; |
| 253 | }]); |
| 254 | }()); |