blob: 6b651f7f827bc174b9f1261fdc604d78d6342978 [file] [log] [blame]
Steven Burrows5570d1b2016-09-28 14:21:00 -07001/*
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 Burrowsaf96a212016-12-28 12:57:02 +000026 var Panel, gs, wss, flash, ls;
Steven Burrows5570d1b2016-09-28 14:21:00 -070027
28 // Internal State
Steven Burrowsc59481f2017-04-13 10:01:15 -070029 var summaryPanel, summaryData, detailsPanel;
Steven Burrows5570d1b2016-09-28 14:21:00 -070030
31 // configuration
Steven Burrows1c5c8612016-10-05 13:45:13 -050032 var id = 'topo2-p-summary',
Simon Hunt95f4b422017-03-03 13:49:05 -080033 className = 'topo2-p',
Steven Burrows1c5c8612016-10-05 13:45:13 -050034 panelOpts = {
35 show: true,
Steven Burrows46c5f102017-07-14 16:52:46 +010036 width: 260, // summary and detail panel width
Steven Burrows1c5c8612016-10-05 13:45:13 -050037 },
Steven Burrows5570d1b2016-09-28 14:21:00 -070038 handlerMap = {
Steven Burrows46c5f102017-07-14 16:52:46 +010039 showSummary: handleSummaryData,
Steven Burrows5570d1b2016-09-28 14:21:00 -070040 };
41
Steven Burrowsc59481f2017-04-13 10:01:15 -070042 function init(_detailsPanel_) {
43
44 detailsPanel = _detailsPanel_;
Steven Burrows5570d1b2016-09-28 14:21:00 -070045
46 bindHandlers();
47 wss.sendEvent('requestSummary');
48
Steven Burrows1c5c8612016-10-05 13:45:13 -050049 var options = angular.extend({}, panelOpts, {
Steven Burrows46c5f102017-07-14 16:52:46 +010050 class: className,
Steven Burrows5570d1b2016-09-28 14:21:00 -070051 });
52
Steven Burrows1c5c8612016-10-05 13:45:13 -050053 summaryPanel = new Panel(id, options);
Steven Burrows86af4352016-11-16 18:19:12 -060054 summaryPanel.el.classed(className, true);
Steven Burrows5570d1b2016-09-28 14:21:00 -070055 }
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 Burrowsaf96a212016-12-28 12:57:02 +000069 ls.listProps(tbody, summaryData);
Steven Burrows5570d1b2016-09-28 14:21:00 -070070 }
71
72 function handleSummaryData(data) {
73 summaryData = data;
74 render();
75 }
76
77 function bindHandlers() {
78 wss.bindHandlers(handlerMap);
79 }
80
Steven Burrowsc59481f2017-04-13 10:01:15 -070081 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 Burrows5570d1b2016-09-28 14:21:00 -0700100 function toggle() {
Steven Burrowsc59481f2017-04-13 10:01:15 -0700101 var on = summaryPanel.isVisible(),
102 verb = on ? 'Hide' : 'Show';
Steven Burrows0b5e2f72016-12-19 12:02:22 -0500103
Steven Burrows5570d1b2016-09-28 14:21:00 -0700104 flash.flash(verb + ' Summary Panel');
Simon Hunt80438762016-12-20 13:26:36 -0800105 wss.sendEvent(on ? 'requestSummary' : 'cancelSummary');
Steven Burrowsc59481f2017-04-13 10:01:15 -0700106 on ? hide(): show();
Steven Burrows5570d1b2016-09-28 14:21:00 -0700107 }
108
Steven Burrows1c5c8612016-10-05 13:45:13 -0500109 function destroy() {
110 wss.unbindHandlers(handlerMap);
Steven Burrows0b5e2f72016-12-19 12:02:22 -0500111 wss.sendEvent('cancelSummary');
Steven Burrows1c5c8612016-10-05 13:45:13 -0500112 summaryPanel.destroy();
113 }
114
Steven Burrows5570d1b2016-09-28 14:21:00 -0700115 angular.module('ovTopo2')
Steven Burrowsaf96a212016-12-28 12:57:02 +0000116 .factory('Topo2SummaryPanelService', [
117 'Topo2PanelService', 'GlyphService', 'WebSocketService', 'FlashService', 'ListService',
118 function (_ps_, _gs_, _wss_, _flash_, _ls_) {
Steven Burrows5570d1b2016-09-28 14:21:00 -0700119
120 Panel = _ps_;
121 gs = _gs_;
122 wss = _wss_;
123 flash = _flash_;
Steven Burrowsaf96a212016-12-28 12:57:02 +0000124 ls = _ls_;
Steven Burrows5570d1b2016-09-28 14:21:00 -0700125
126 return {
127 init: init,
Steven Burrows1c5c8612016-10-05 13:45:13 -0500128 toggle: toggle,
Steven Burrowsc0efbf02016-11-16 11:30:47 -0600129 destroy: destroy,
Steven Burrowsc59481f2017-04-13 10:01:15 -0700130 isVisible: function () { return summaryPanel.isVisible(); },
Steven Burrows46c5f102017-07-14 16:52:46 +0100131 getInstance: function () { return summaryPanel; },
Steven Burrows5570d1b2016-09-28 14:21:00 -0700132 };
Steven Burrows46c5f102017-07-14 16:52:46 +0100133 },
Steven Burrows5570d1b2016-09-28 14:21:00 -0700134 ]);
135
136})();