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 | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 26 | var $log, ps, gs; |
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 | |
| 140 | |
| 141 | // === ----------------------------------------------------- |
| 142 | // === LOGIC For showing/hiding summary and detail panels... |
| 143 | |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 144 | function showSummaryPanel() { |
| 145 | summaryPanel.show(); |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 146 | // TODO: augment, once we have the details pane also |
| 147 | } |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 148 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 149 | function showDetailPanel() { |
| 150 | // TODO: augment with summary-accomodation-logic |
| 151 | detailPanel.show(); |
| 152 | } |
| 153 | |
| 154 | function hideDetailPanel() { |
| 155 | detailPanel.hide(); |
| 156 | } |
| 157 | |
| 158 | |
| 159 | |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 160 | // ========================== |
| 161 | |
| 162 | function initPanels() { |
| 163 | summaryPanel = ps.createPanel(idSum, panelOpts); |
| 164 | detailPanel = ps.createPanel(idDet, panelOpts); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 165 | |
| 166 | summaryPanel.classed(pCls, true); |
| 167 | detailPanel.classed(pCls, true); |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | function destroyPanels() { |
| 171 | ps.destroyPanel(idSum); |
| 172 | ps.destroyPanel(idDet); |
| 173 | summaryPanel = detailPanel = null; |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | // ========================== |
| 177 | |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 178 | angular.module('ovTopo') |
| 179 | .factory('TopoPanelService', |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 180 | ['$log', 'PanelService', 'GlyphService', |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 181 | |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 182 | function (_$log_, _ps_, _gs_) { |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 183 | $log = _$log_; |
| 184 | ps = _ps_; |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 185 | gs = _gs_; |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 186 | |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 187 | return { |
| 188 | initPanels: initPanels, |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 189 | destroyPanels: destroyPanels, |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 190 | |
| 191 | showSummary: showSummary, |
| 192 | |
| 193 | displaySingle: displaySingle, |
| 194 | displayMulti: displayMulti, |
| 195 | addAction: addAction, |
| 196 | |
| 197 | showDetailPanel: showDetailPanel, |
| 198 | hideDetailPanel: hideDetailPanel, |
| 199 | |
| 200 | detailVisible: function () { return detailPanel.isVisible(); }, |
| 201 | summaryVisible: function () { return summaryPanel.isVisible(); } |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 202 | }; |
| 203 | }]); |
| 204 | }()); |