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 |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 26 | var Panel, gs, wss, flash, listProps; |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 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, |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 36 | width: 260 // summary and detail panel width |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 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 | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 52 | summaryPanel.el.classed(className, true); |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | function render() { |
| 56 | summaryPanel.emptyRegions(); |
| 57 | |
| 58 | var svg = summaryPanel.appendToHeader('div') |
| 59 | .classed('icon', true) |
| 60 | .append('svg'), |
| 61 | title = summaryPanel.appendToHeader('h2'), |
| 62 | table = summaryPanel.appendToBody('table'), |
| 63 | tbody = table.append('tbody'); |
| 64 | |
| 65 | title.text(summaryData.title); |
| 66 | gs.addGlyph(svg, 'bird', 24, 0, [1, 1]); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 67 | listProps(tbody, summaryData); |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | function handleSummaryData(data) { |
| 71 | summaryData = data; |
| 72 | render(); |
| 73 | } |
| 74 | |
| 75 | function bindHandlers() { |
| 76 | wss.bindHandlers(handlerMap); |
| 77 | } |
| 78 | |
| 79 | function toggle() { |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 80 | var on = summaryPanel.el.toggle(), |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 81 | verb = on ? 'Show' : 'Hide'; |
| 82 | flash.flash(verb + ' Summary Panel'); |
| 83 | } |
| 84 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 85 | function destroy() { |
| 86 | wss.unbindHandlers(handlerMap); |
| 87 | summaryPanel.destroy(); |
| 88 | } |
| 89 | |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 90 | angular.module('ovTopo2') |
| 91 | .factory('Topo2SummaryPanelService', |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 92 | ['Topo2PanelService', 'GlyphService', 'WebSocketService', 'FlashService', 'ListService', |
| 93 | function (_ps_, _gs_, _wss_, _flash_, _listService_) { |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 94 | |
| 95 | Panel = _ps_; |
| 96 | gs = _gs_; |
| 97 | wss = _wss_; |
| 98 | flash = _flash_; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 99 | listProps = _listService_; |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 100 | |
| 101 | return { |
| 102 | init: init, |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 103 | toggle: toggle, |
Steven Burrows | c0efbf0 | 2016-11-16 11:30:47 -0600 | [diff] [blame] | 104 | destroy: destroy, |
| 105 | isVisible: function () { return summaryPanel.isVisible(); } |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 106 | }; |
| 107 | } |
| 108 | ]); |
| 109 | |
| 110 | })(); |