Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 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 | 1c2a968 | 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 | 1c2a968 | 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 | 1c2a968 | 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() { |
Simon Hunt | 3d875ec | 2017-09-07 16:52:59 -0700 | [diff] [blame] | 58 | var endedWithSeparator; |
| 59 | |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 60 | summaryPanel.emptyRegions(); |
| 61 | |
| 62 | var svg = summaryPanel.appendToHeader('div') |
| 63 | .classed('icon', true) |
| 64 | .append('svg'), |
| 65 | title = summaryPanel.appendToHeader('h2'), |
| 66 | table = summaryPanel.appendToBody('table'), |
| 67 | tbody = table.append('tbody'); |
| 68 | |
| 69 | title.text(summaryData.title); |
| 70 | gs.addGlyph(svg, 'bird', 24, 0, [1, 1]); |
Simon Hunt | 3d875ec | 2017-09-07 16:52:59 -0700 | [diff] [blame] | 71 | endedWithSeparator = ls.listProps(tbody, summaryData); |
| 72 | // TODO : review whether we need to use/store end-with-sep state |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | function handleSummaryData(data) { |
| 76 | summaryData = data; |
| 77 | render(); |
| 78 | } |
| 79 | |
| 80 | function bindHandlers() { |
| 81 | wss.bindHandlers(handlerMap); |
| 82 | } |
| 83 | |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 84 | function hide() { |
| 85 | summaryPanel.el.hide(detailsPanel.getInstance().up); |
| 86 | } |
| 87 | |
| 88 | function show() { |
| 89 | |
| 90 | var _show = function () { |
| 91 | summaryPanel.el.show(); |
| 92 | }; |
| 93 | |
| 94 | var summaryHeight = summaryPanel.el.bbox().height; |
| 95 | if (detailsPanel.isVisible()) { |
| 96 | detailsPanel.getInstance().down(summaryHeight, _show); |
| 97 | } else { |
| 98 | _show(); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 103 | function toggle() { |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 104 | var on = summaryPanel.isVisible(), |
| 105 | verb = on ? 'Hide' : 'Show'; |
Steven Burrows | 0b5e2f7 | 2016-12-19 12:02:22 -0500 | [diff] [blame] | 106 | |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 107 | flash.flash(verb + ' Summary Panel'); |
Simon Hunt | 8043876 | 2016-12-20 13:26:36 -0800 | [diff] [blame] | 108 | wss.sendEvent(on ? 'requestSummary' : 'cancelSummary'); |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 109 | on ? hide(): show(); |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 112 | function destroy() { |
| 113 | wss.unbindHandlers(handlerMap); |
Steven Burrows | 0b5e2f7 | 2016-12-19 12:02:22 -0500 | [diff] [blame] | 114 | wss.sendEvent('cancelSummary'); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 115 | summaryPanel.destroy(); |
| 116 | } |
| 117 | |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 118 | angular.module('ovTopo2') |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 119 | .factory('Topo2SummaryPanelService', [ |
| 120 | 'Topo2PanelService', 'GlyphService', 'WebSocketService', 'FlashService', 'ListService', |
| 121 | function (_ps_, _gs_, _wss_, _flash_, _ls_) { |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 122 | |
| 123 | Panel = _ps_; |
| 124 | gs = _gs_; |
| 125 | wss = _wss_; |
| 126 | flash = _flash_; |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 127 | ls = _ls_; |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 128 | |
| 129 | return { |
| 130 | init: init, |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 131 | toggle: toggle, |
Steven Burrows | c0efbf0 | 2016-11-16 11:30:47 -0600 | [diff] [blame] | 132 | destroy: destroy, |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 133 | isVisible: function () { return summaryPanel.isVisible(); }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 134 | getInstance: function () { return summaryPanel; }, |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 135 | }; |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 136 | }, |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 137 | ]); |
| 138 | |
| 139 | })(); |