blob: 682daac0f47314fcdd8780ac71f5bd8d033ca035 [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 Burrows86af4352016-11-16 18:19:12 -060026 var Panel, gs, wss, flash, listProps;
Steven Burrows5570d1b2016-09-28 14:21:00 -070027
28 // Internal State
29 var summaryPanel, summaryData;
30
31 // configuration
Steven Burrows1c5c8612016-10-05 13:45:13 -050032 var id = 'topo2-p-summary',
Steven Burrows5570d1b2016-09-28 14:21:00 -070033 className = 'topo-p',
Steven Burrows1c5c8612016-10-05 13:45:13 -050034 panelOpts = {
35 show: true,
Steven Burrows86af4352016-11-16 18:19:12 -060036 width: 260 // summary and detail panel width
Steven Burrows1c5c8612016-10-05 13:45:13 -050037 },
Steven Burrows5570d1b2016-09-28 14:21:00 -070038 handlerMap = {
39 showSummary: handleSummaryData
40 };
41
42 function init() {
43
44 bindHandlers();
45 wss.sendEvent('requestSummary');
46
Steven Burrows1c5c8612016-10-05 13:45:13 -050047 var options = angular.extend({}, panelOpts, {
Steven Burrows5570d1b2016-09-28 14:21:00 -070048 class: className
49 });
50
Steven Burrows1c5c8612016-10-05 13:45:13 -050051 summaryPanel = new Panel(id, options);
Steven Burrows86af4352016-11-16 18:19:12 -060052 summaryPanel.el.classed(className, true);
Steven Burrows5570d1b2016-09-28 14:21:00 -070053 }
54
55 function render() {
56 summaryPanel.emptyRegions();
57
58 var svg = summaryPanel.appendToHeader('div')
59 .classed('icon', true)
60 .append('svg'),
61 title = summaryPanel.appendToHeader('h2'),
62 table = summaryPanel.appendToBody('table'),
63 tbody = table.append('tbody');
64
65 title.text(summaryData.title);
66 gs.addGlyph(svg, 'bird', 24, 0, [1, 1]);
Steven Burrows86af4352016-11-16 18:19:12 -060067 listProps(tbody, summaryData);
Steven Burrows5570d1b2016-09-28 14:21:00 -070068 }
69
70 function handleSummaryData(data) {
71 summaryData = data;
72 render();
73 }
74
75 function bindHandlers() {
76 wss.bindHandlers(handlerMap);
77 }
78
79 function toggle() {
Steven Burrows86af4352016-11-16 18:19:12 -060080 var on = summaryPanel.el.toggle(),
Steven Burrows5570d1b2016-09-28 14:21:00 -070081 verb = on ? 'Show' : 'Hide';
Steven Burrows0b5e2f72016-12-19 12:02:22 -050082
Steven Burrows5570d1b2016-09-28 14:21:00 -070083 flash.flash(verb + ' Summary Panel');
Simon Hunt80438762016-12-20 13:26:36 -080084 wss.sendEvent(on ? 'requestSummary' : 'cancelSummary');
Steven Burrows5570d1b2016-09-28 14:21:00 -070085 }
86
Steven Burrows1c5c8612016-10-05 13:45:13 -050087 function destroy() {
88 wss.unbindHandlers(handlerMap);
Steven Burrows0b5e2f72016-12-19 12:02:22 -050089 wss.sendEvent('cancelSummary');
Steven Burrows1c5c8612016-10-05 13:45:13 -050090 summaryPanel.destroy();
91 }
92
Steven Burrows5570d1b2016-09-28 14:21:00 -070093 angular.module('ovTopo2')
94 .factory('Topo2SummaryPanelService',
Steven Burrows86af4352016-11-16 18:19:12 -060095 ['Topo2PanelService', 'GlyphService', 'WebSocketService', 'FlashService', 'ListService',
96 function (_ps_, _gs_, _wss_, _flash_, _listService_) {
Steven Burrows5570d1b2016-09-28 14:21:00 -070097
98 Panel = _ps_;
99 gs = _gs_;
100 wss = _wss_;
101 flash = _flash_;
Steven Burrows86af4352016-11-16 18:19:12 -0600102 listProps = _listService_;
Steven Burrows5570d1b2016-09-28 14:21:00 -0700103
104 return {
105 init: init,
Steven Burrows1c5c8612016-10-05 13:45:13 -0500106 toggle: toggle,
Steven Burrowsc0efbf02016-11-16 11:30:47 -0600107 destroy: destroy,
108 isVisible: function () { return summaryPanel.isVisible(); }
Steven Burrows5570d1b2016-09-28 14:21:00 -0700109 };
110 }
111 ]);
112
113})();