Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [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 | 86af435 | 2016-11-16 18:19:12 -0600 | [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 View Module. |
| 19 | Module that displays the details panel for selected nodes |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 25 | // TODO: Topo2Panel - A view that draws the container for Summary and Details Panels |
| 26 | // TODO: as well as the show/hide/toggle methods. |
| 27 | |
| 28 | // TODO: Topo2DetailsPanel should extend Topo2Panel and add methods to controller position |
| 29 | // TODO: based on the visibility of Topo2Summary |
| 30 | |
| 31 | // TODO: Topo2<Device|Link|Host>Panel should only be concerned with the content displayed |
| 32 | |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 33 | // Injected Services |
Steven Burrows | b8ebd40 | 2017-11-01 15:31:31 +0000 | [diff] [blame] | 34 | var Panel, flash; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 35 | |
| 36 | // Internal State |
Steven Burrows | b8ebd40 | 2017-11-01 15:31:31 +0000 | [diff] [blame] | 37 | var useDetails = true, |
| 38 | detailsPanel, |
| 39 | summaryPanel; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 40 | |
| 41 | // configuration |
| 42 | var id = 'topo2-p-detail', |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 43 | className = 'topo2-p', |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 44 | transTime = 750, |
| 45 | panelPadding = 64, |
| 46 | panelSpacing = 20, |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 47 | panelOpts = { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 48 | width: 260, // summary and detail panel width |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 49 | }; |
| 50 | |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 51 | function getInstance(_summaryPanel_) { |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 52 | if (detailsPanel) { |
| 53 | return detailsPanel; |
| 54 | } |
| 55 | |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 56 | summaryPanel = _summaryPanel_; |
| 57 | |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 58 | var options = angular.extend({}, panelOpts, { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 59 | class: className, |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 60 | }); |
| 61 | |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 62 | Panel = Panel.extend({ |
| 63 | up: function () { |
| 64 | detailsPanel.el.el() |
| 65 | .transition() |
| 66 | .duration(transTime) |
| 67 | .style('top', panelPadding + 'px'); |
| 68 | }, |
| 69 | down: function (position, callback) { |
| 70 | detailsPanel.el.el() |
| 71 | .transition() |
| 72 | .duration(transTime) |
| 73 | .style('top', position + (panelPadding + panelSpacing) + 'px') |
| 74 | .each('end', callback); |
| 75 | }, |
| 76 | show: function () { |
| 77 | |
Steven Burrows | b8ebd40 | 2017-11-01 15:31:31 +0000 | [diff] [blame] | 78 | if (!useDetails) { |
| 79 | return; |
| 80 | } |
| 81 | |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 82 | var summaryInstance = summaryPanel.getInstance(), |
| 83 | position = 0; |
| 84 | |
| 85 | if (summaryInstance.isVisible()) { |
| 86 | position = summaryInstance.el.bbox().height; |
| 87 | position = position + panelSpacing; |
| 88 | } |
| 89 | |
| 90 | detailsPanel.el.el() |
| 91 | .style('top', panelPadding + position + 'px'); |
| 92 | detailsPanel.el.show(); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 93 | }, |
Steven Burrows | b8ebd40 | 2017-11-01 15:31:31 +0000 | [diff] [blame] | 94 | hide: function () { |
| 95 | detailsPanel.el.hide(); |
| 96 | }, |
| 97 | toggleUseDetailsFlag: function (x) { |
| 98 | var kev = (x === 'keyev'), |
| 99 | verb; |
| 100 | |
| 101 | useDetails = kev ? !useDetails : !!x; |
| 102 | verb = useDetails ? 'Enable' : 'Disable'; |
| 103 | |
| 104 | if (useDetails) { |
| 105 | this.show(); |
| 106 | } else { |
| 107 | this.hide(); |
| 108 | } |
| 109 | |
| 110 | flash.flash(verb + ' details panel'); |
| 111 | return useDetails; |
| 112 | }, |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 113 | }); |
| 114 | |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 115 | detailsPanel = new Panel(id, options); |
| 116 | detailsPanel.el.classed(className, true); |
| 117 | |
| 118 | return detailsPanel; |
| 119 | } |
| 120 | |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 121 | |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 122 | angular.module('ovTopo2') |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 123 | .factory('Topo2DetailsPanelService', [ |
Steven Burrows | b8ebd40 | 2017-11-01 15:31:31 +0000 | [diff] [blame] | 124 | 'Topo2PanelService', 'FlashService', |
| 125 | function (_ps_, _flash_) { |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 126 | Panel = _ps_; |
Steven Burrows | b8ebd40 | 2017-11-01 15:31:31 +0000 | [diff] [blame] | 127 | flash = _flash_; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 128 | |
| 129 | return getInstance; |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 130 | }, |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 131 | ]); |
| 132 | })(); |