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 | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 26 | var Panel, gs, wss, flash, ls; |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 27 | |
| 28 | // Internal State |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 29 | var summaryPanel, summaryData, detailsPanel; |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 30 | |
| 31 | // configuration |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 32 | var id = 'topo2-p-summary', |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 33 | className = 'topo2-p', |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 34 | panelOpts = { |
| 35 | show: true, |
Steven Burrows | 46c5f10 | 2017-07-14 16:52:46 +0100 | [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 = { |
Steven Burrows | 46c5f10 | 2017-07-14 16:52:46 +0100 | [diff] [blame^] | 39 | showSummary: handleSummaryData, |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 42 | function init(_detailsPanel_) { |
| 43 | |
| 44 | detailsPanel = _detailsPanel_; |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 45 | |
| 46 | bindHandlers(); |
| 47 | wss.sendEvent('requestSummary'); |
| 48 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 49 | var options = angular.extend({}, panelOpts, { |
Steven Burrows | 46c5f10 | 2017-07-14 16:52:46 +0100 | [diff] [blame^] | 50 | class: className, |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 51 | }); |
| 52 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 53 | summaryPanel = new Panel(id, options); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 54 | summaryPanel.el.classed(className, true); |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | function render() { |
| 58 | summaryPanel.emptyRegions(); |
| 59 | |
| 60 | var svg = summaryPanel.appendToHeader('div') |
| 61 | .classed('icon', true) |
| 62 | .append('svg'), |
| 63 | title = summaryPanel.appendToHeader('h2'), |
| 64 | table = summaryPanel.appendToBody('table'), |
| 65 | tbody = table.append('tbody'); |
| 66 | |
| 67 | title.text(summaryData.title); |
| 68 | gs.addGlyph(svg, 'bird', 24, 0, [1, 1]); |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 69 | ls.listProps(tbody, summaryData); |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | function handleSummaryData(data) { |
| 73 | summaryData = data; |
| 74 | render(); |
| 75 | } |
| 76 | |
| 77 | function bindHandlers() { |
| 78 | wss.bindHandlers(handlerMap); |
| 79 | } |
| 80 | |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 81 | function hide() { |
| 82 | summaryPanel.el.hide(detailsPanel.getInstance().up); |
| 83 | } |
| 84 | |
| 85 | function show() { |
| 86 | |
| 87 | var _show = function () { |
| 88 | summaryPanel.el.show(); |
| 89 | }; |
| 90 | |
| 91 | var summaryHeight = summaryPanel.el.bbox().height; |
| 92 | if (detailsPanel.isVisible()) { |
| 93 | detailsPanel.getInstance().down(summaryHeight, _show); |
| 94 | } else { |
| 95 | _show(); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 100 | function toggle() { |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 101 | var on = summaryPanel.isVisible(), |
| 102 | verb = on ? 'Hide' : 'Show'; |
Steven Burrows | 0b5e2f7 | 2016-12-19 12:02:22 -0500 | [diff] [blame] | 103 | |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 104 | flash.flash(verb + ' Summary Panel'); |
Simon Hunt | 8043876 | 2016-12-20 13:26:36 -0800 | [diff] [blame] | 105 | wss.sendEvent(on ? 'requestSummary' : 'cancelSummary'); |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 106 | on ? hide(): show(); |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 109 | function destroy() { |
| 110 | wss.unbindHandlers(handlerMap); |
Steven Burrows | 0b5e2f7 | 2016-12-19 12:02:22 -0500 | [diff] [blame] | 111 | wss.sendEvent('cancelSummary'); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 112 | summaryPanel.destroy(); |
| 113 | } |
| 114 | |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 115 | angular.module('ovTopo2') |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 116 | .factory('Topo2SummaryPanelService', [ |
| 117 | 'Topo2PanelService', 'GlyphService', 'WebSocketService', 'FlashService', 'ListService', |
| 118 | function (_ps_, _gs_, _wss_, _flash_, _ls_) { |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 119 | |
| 120 | Panel = _ps_; |
| 121 | gs = _gs_; |
| 122 | wss = _wss_; |
| 123 | flash = _flash_; |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 124 | ls = _ls_; |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 125 | |
| 126 | return { |
| 127 | init: init, |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 128 | toggle: toggle, |
Steven Burrows | c0efbf0 | 2016-11-16 11:30:47 -0600 | [diff] [blame] | 129 | destroy: destroy, |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 130 | isVisible: function () { return summaryPanel.isVisible(); }, |
Steven Burrows | 46c5f10 | 2017-07-14 16:52:46 +0100 | [diff] [blame^] | 131 | getInstance: function () { return summaryPanel; }, |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 132 | }; |
Steven Burrows | 46c5f10 | 2017-07-14 16:52:46 +0100 | [diff] [blame^] | 133 | }, |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 134 | ]); |
| 135 | |
| 136 | })(); |