blob: ac12c2b8bd76e3cd76feb1460f0f37bcf1bef7bd [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
26 var Panel, gs, wss, flash;
27
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,
36 width: 260 // summary and detail panel width
37 },
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);
52
Steven Burrows5570d1b2016-09-28 14:21:00 -070053 summaryPanel.p.classed(className, true);
54 }
55
56 function addProp(tbody, label, value) {
57 var tr = tbody.append('tr'),
58 lab;
59 if (typeof label === 'string') {
60 lab = label.replace(/_/g, ' ');
61 } else {
62 lab = label;
63 }
64
65 function addCell(cls, txt) {
66 tr.append('td').attr('class', cls).html(txt);
67 }
68 addCell('label', lab + ' :');
69 addCell('value', value);
70 }
71
72 function addSep(tbody) {
73 tbody.append('tr').append('td').attr('colspan', 2).append('hr');
74 }
75
76 function listProps(tbody, data) {
77 summaryData.propOrder.forEach(function (p) {
78 if (p === '-') {
79 addSep(tbody);
80 } else {
81 addProp(tbody, p, summaryData.props[p]);
82 }
83 });
84 }
85
86 function render() {
87 summaryPanel.emptyRegions();
88
89 var svg = summaryPanel.appendToHeader('div')
90 .classed('icon', true)
91 .append('svg'),
92 title = summaryPanel.appendToHeader('h2'),
93 table = summaryPanel.appendToBody('table'),
94 tbody = table.append('tbody');
95
96 title.text(summaryData.title);
97 gs.addGlyph(svg, 'bird', 24, 0, [1, 1]);
98 listProps(tbody);
99 }
100
101 function handleSummaryData(data) {
102 summaryData = data;
103 render();
104 }
105
106 function bindHandlers() {
107 wss.bindHandlers(handlerMap);
108 }
109
110 function toggle() {
111 var on = summaryPanel.p.toggle(),
112 verb = on ? 'Show' : 'Hide';
113 flash.flash(verb + ' Summary Panel');
114 }
115
Steven Burrows1c5c8612016-10-05 13:45:13 -0500116 function destroy() {
117 wss.unbindHandlers(handlerMap);
118 summaryPanel.destroy();
119 }
120
Steven Burrows5570d1b2016-09-28 14:21:00 -0700121 angular.module('ovTopo2')
122 .factory('Topo2SummaryPanelService',
123 ['Topo2PanelService', 'GlyphService', 'WebSocketService', 'FlashService',
124 function (_ps_, _gs_, _wss_, _flash_) {
125
126 Panel = _ps_;
127 gs = _gs_;
128 wss = _wss_;
129 flash = _flash_;
130
131 return {
132 init: init,
133
Steven Burrows1c5c8612016-10-05 13:45:13 -0500134 toggle: toggle,
135 destroy: destroy
Steven Burrows5570d1b2016-09-28 14:21:00 -0700136 };
137 }
138 ]);
139
140})();