blob: 5e88295d87ad22f8b630a5852bfa03550a837fef [file] [log] [blame]
Steven Burrows86af4352016-11-16 18:19:12 -06001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Steven Burrows86af4352016-11-16 18:19:12 -06003 *
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 Burrowsc59481f2017-04-13 10:01:15 -070025 // 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 Burrows86af4352016-11-16 18:19:12 -060033 // Injected Services
Steven Burrowsb8ebd402017-11-01 15:31:31 +000034 var Panel, flash;
Steven Burrows86af4352016-11-16 18:19:12 -060035
36 // Internal State
Steven Burrowsb8ebd402017-11-01 15:31:31 +000037 var useDetails = true,
38 detailsPanel,
39 summaryPanel;
Steven Burrows86af4352016-11-16 18:19:12 -060040
41 // configuration
42 var id = 'topo2-p-detail',
Simon Hunt95f4b422017-03-03 13:49:05 -080043 className = 'topo2-p',
Steven Burrowsc59481f2017-04-13 10:01:15 -070044 transTime = 750,
45 panelPadding = 64,
46 panelSpacing = 20,
Steven Burrows86af4352016-11-16 18:19:12 -060047 panelOpts = {
Steven Burrows1c2a9682017-07-14 16:52:46 +010048 width: 260, // summary and detail panel width
Steven Burrows86af4352016-11-16 18:19:12 -060049 };
50
Steven Burrowsc59481f2017-04-13 10:01:15 -070051 function getInstance(_summaryPanel_) {
Steven Burrows86af4352016-11-16 18:19:12 -060052 if (detailsPanel) {
53 return detailsPanel;
54 }
55
Steven Burrowsc59481f2017-04-13 10:01:15 -070056 summaryPanel = _summaryPanel_;
57
Steven Burrows86af4352016-11-16 18:19:12 -060058 var options = angular.extend({}, panelOpts, {
Steven Burrows1c2a9682017-07-14 16:52:46 +010059 class: className,
Steven Burrows86af4352016-11-16 18:19:12 -060060 });
61
Steven Burrowsc59481f2017-04-13 10:01:15 -070062 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 Burrowsb8ebd402017-11-01 15:31:31 +000078 if (!useDetails) {
79 return;
80 }
81
Steven Burrowsc59481f2017-04-13 10:01:15 -070082 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 Burrows1c2a9682017-07-14 16:52:46 +010093 },
Steven Burrowsb8ebd402017-11-01 15:31:31 +000094 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 Burrowsc59481f2017-04-13 10:01:15 -0700113 });
114
Steven Burrows86af4352016-11-16 18:19:12 -0600115 detailsPanel = new Panel(id, options);
116 detailsPanel.el.classed(className, true);
117
118 return detailsPanel;
119 }
120
Steven Burrowsc59481f2017-04-13 10:01:15 -0700121
Steven Burrows86af4352016-11-16 18:19:12 -0600122 angular.module('ovTopo2')
Steven Burrowsaf96a212016-12-28 12:57:02 +0000123 .factory('Topo2DetailsPanelService', [
Steven Burrowsb8ebd402017-11-01 15:31:31 +0000124 'Topo2PanelService', 'FlashService',
125 function (_ps_, _flash_) {
Steven Burrows86af4352016-11-16 18:19:12 -0600126 Panel = _ps_;
Steven Burrowsb8ebd402017-11-01 15:31:31 +0000127 flash = _flash_;
Steven Burrows86af4352016-11-16 18:19:12 -0600128
129 return getInstance;
Steven Burrows1c2a9682017-07-14 16:52:46 +0100130 },
Steven Burrows86af4352016-11-16 18:19:12 -0600131 ]);
132})();