Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [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 Layout Module. |
| 19 | Module that contains the d3.force.layout logic |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
| 25 | // Injected Services |
| 26 | var Panel, gs, wss, flash; |
| 27 | |
| 28 | // Internal State |
| 29 | var summaryPanel, summaryData; |
| 30 | |
| 31 | // configuration |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 32 | var id = 'topo2-p-summary', |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 33 | className = 'topo-p', |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 34 | panelOpts = { |
| 35 | show: true, |
| 36 | width: 260 // summary and detail panel width |
| 37 | }, |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 38 | handlerMap = { |
| 39 | showSummary: handleSummaryData |
| 40 | }; |
| 41 | |
| 42 | function init() { |
| 43 | |
| 44 | bindHandlers(); |
| 45 | wss.sendEvent('requestSummary'); |
| 46 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 47 | var options = angular.extend({}, panelOpts, { |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 48 | class: className |
| 49 | }); |
| 50 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 51 | summaryPanel = new Panel(id, options); |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 52 | summaryPanel.p.classed(className, true); |
| 53 | } |
| 54 | |
| 55 | function addProp(tbody, label, value) { |
| 56 | var tr = tbody.append('tr'), |
| 57 | lab; |
| 58 | if (typeof label === 'string') { |
| 59 | lab = label.replace(/_/g, ' '); |
| 60 | } else { |
| 61 | lab = label; |
| 62 | } |
| 63 | |
| 64 | function addCell(cls, txt) { |
| 65 | tr.append('td').attr('class', cls).html(txt); |
| 66 | } |
| 67 | addCell('label', lab + ' :'); |
| 68 | addCell('value', value); |
| 69 | } |
| 70 | |
| 71 | function addSep(tbody) { |
| 72 | tbody.append('tr').append('td').attr('colspan', 2).append('hr'); |
| 73 | } |
| 74 | |
| 75 | function listProps(tbody, data) { |
| 76 | summaryData.propOrder.forEach(function (p) { |
| 77 | if (p === '-') { |
| 78 | addSep(tbody); |
| 79 | } else { |
| 80 | addProp(tbody, p, summaryData.props[p]); |
| 81 | } |
| 82 | }); |
| 83 | } |
| 84 | |
| 85 | function render() { |
| 86 | summaryPanel.emptyRegions(); |
| 87 | |
| 88 | var svg = summaryPanel.appendToHeader('div') |
| 89 | .classed('icon', true) |
| 90 | .append('svg'), |
| 91 | title = summaryPanel.appendToHeader('h2'), |
| 92 | table = summaryPanel.appendToBody('table'), |
| 93 | tbody = table.append('tbody'); |
| 94 | |
| 95 | title.text(summaryData.title); |
| 96 | gs.addGlyph(svg, 'bird', 24, 0, [1, 1]); |
| 97 | listProps(tbody); |
| 98 | } |
| 99 | |
| 100 | function handleSummaryData(data) { |
| 101 | summaryData = data; |
| 102 | render(); |
| 103 | } |
| 104 | |
| 105 | function bindHandlers() { |
| 106 | wss.bindHandlers(handlerMap); |
| 107 | } |
| 108 | |
| 109 | function toggle() { |
| 110 | var on = summaryPanel.p.toggle(), |
| 111 | verb = on ? 'Show' : 'Hide'; |
| 112 | flash.flash(verb + ' Summary Panel'); |
| 113 | } |
| 114 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 115 | function destroy() { |
| 116 | wss.unbindHandlers(handlerMap); |
| 117 | summaryPanel.destroy(); |
| 118 | } |
| 119 | |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 120 | angular.module('ovTopo2') |
| 121 | .factory('Topo2SummaryPanelService', |
| 122 | ['Topo2PanelService', 'GlyphService', 'WebSocketService', 'FlashService', |
| 123 | function (_ps_, _gs_, _wss_, _flash_) { |
| 124 | |
| 125 | Panel = _ps_; |
| 126 | gs = _gs_; |
| 127 | wss = _wss_; |
| 128 | flash = _flash_; |
| 129 | |
| 130 | return { |
| 131 | init: init, |
| 132 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 133 | toggle: toggle, |
Steven Burrows | c0efbf0 | 2016-11-16 11:30:47 -0600 | [diff] [blame] | 134 | destroy: destroy, |
| 135 | isVisible: function () { return summaryPanel.isVisible(); } |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 136 | }; |
| 137 | } |
| 138 | ]); |
| 139 | |
| 140 | })(); |