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 |
| 29 | var idSum = 'topo-p-summary', |
| 30 | idDet = 'topo-p-detail', |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 31 | panelOpts = { |
| 32 | width: 260 |
| 33 | }; |
| 34 | |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame^] | 35 | // panels |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 36 | var summaryPanel, |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame^] | 37 | detailPanel; |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 38 | |
| 39 | // ========================== |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame^] | 40 | // *** SHOW SUMMARY *** |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 41 | |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame^] | 42 | function showSummary(data) { |
| 43 | populateSummary(data); |
| 44 | showSummaryPanel(); |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | function populateSummary(data) { |
| 48 | summaryPanel.empty(); |
| 49 | |
Simon Hunt | edf5c0e | 2015-01-29 15:00:53 -0800 | [diff] [blame] | 50 | var svg = summaryPanel.append('svg'), |
| 51 | title = summaryPanel.append('h2'), |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 52 | table = summaryPanel.append('table'), |
| 53 | tbody = table.append('tbody'); |
| 54 | |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 55 | gs.addGlyph(svg, 'node', 40); |
| 56 | gs.addGlyph(svg, 'bird', 24, true, [8,12]); |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 57 | |
| 58 | title.text(data.id); |
| 59 | |
| 60 | data.propOrder.forEach(function(p) { |
| 61 | if (p === '-') { |
| 62 | addSep(tbody); |
| 63 | } else { |
| 64 | addProp(tbody, p, data.props[p]); |
| 65 | } |
| 66 | }); |
| 67 | } |
| 68 | |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame^] | 69 | function addSep(tbody) { |
| 70 | tbody.append('tr').append('td').attr('colspan', 2).append('hr'); |
| 71 | } |
| 72 | |
| 73 | function addProp(tbody, label, value) { |
| 74 | var tr = tbody.append('tr'); |
| 75 | |
| 76 | function addCell(cls, txt) { |
| 77 | tr.append('td').attr('class', cls).text(txt); |
| 78 | } |
| 79 | addCell('label', label + ' :'); |
| 80 | addCell('value', value); |
| 81 | } |
| 82 | |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 83 | function showSummaryPanel() { |
| 84 | summaryPanel.show(); |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame^] | 85 | // TODO: augment, once we have the details pane also |
| 86 | } |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 87 | |
Simon Hunt | 4b66859 | 2015-01-29 17:33:53 -0800 | [diff] [blame^] | 88 | // ========================== |
| 89 | |
| 90 | function initPanels() { |
| 91 | summaryPanel = ps.createPanel(idSum, panelOpts); |
| 92 | detailPanel = ps.createPanel(idDet, panelOpts); |
| 93 | } |
| 94 | |
| 95 | function destroyPanels() { |
| 96 | ps.destroyPanel(idSum); |
| 97 | ps.destroyPanel(idDet); |
| 98 | summaryPanel = detailPanel = null; |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | // ========================== |
| 102 | |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 103 | angular.module('ovTopo') |
| 104 | .factory('TopoPanelService', |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 105 | ['$log', 'PanelService', 'GlyphService', |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 106 | |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 107 | function (_$log_, _ps_, _gs_) { |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 108 | $log = _$log_; |
| 109 | ps = _ps_; |
Simon Hunt | c9b7316 | 2015-01-29 14:02:15 -0800 | [diff] [blame] | 110 | gs = _gs_; |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 111 | |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 112 | return { |
| 113 | initPanels: initPanels, |
Simon Hunt | 626d210 | 2015-01-29 11:54:50 -0800 | [diff] [blame] | 114 | destroyPanels: destroyPanels, |
Simon Hunt | b0ec1e5 | 2015-01-28 18:13:49 -0800 | [diff] [blame] | 115 | showSummary: showSummary |
| 116 | }; |
| 117 | }]); |
| 118 | }()); |