blob: 149e7ccafff4f2fee05dea7d454fa14a4e6ec1bf [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
32 var id = 'topo-p-summary',
33 className = 'topo-p',
34 handlerMap = {
35 showSummary: handleSummaryData
36 };
37
38 function init() {
39
40 bindHandlers();
41 wss.sendEvent('requestSummary');
42
43 summaryPanel = new Panel(id, {
44 class: className
45 });
46
47 summaryPanel.p.classed(className, true);
48 }
49
50 function addProp(tbody, label, value) {
51 var tr = tbody.append('tr'),
52 lab;
53 if (typeof label === 'string') {
54 lab = label.replace(/_/g, ' ');
55 } else {
56 lab = label;
57 }
58
59 function addCell(cls, txt) {
60 tr.append('td').attr('class', cls).html(txt);
61 }
62 addCell('label', lab + ' :');
63 addCell('value', value);
64 }
65
66 function addSep(tbody) {
67 tbody.append('tr').append('td').attr('colspan', 2).append('hr');
68 }
69
70 function listProps(tbody, data) {
71 summaryData.propOrder.forEach(function (p) {
72 if (p === '-') {
73 addSep(tbody);
74 } else {
75 addProp(tbody, p, summaryData.props[p]);
76 }
77 });
78 }
79
80 function render() {
81 summaryPanel.emptyRegions();
82
83 var svg = summaryPanel.appendToHeader('div')
84 .classed('icon', true)
85 .append('svg'),
86 title = summaryPanel.appendToHeader('h2'),
87 table = summaryPanel.appendToBody('table'),
88 tbody = table.append('tbody');
89
90 title.text(summaryData.title);
91 gs.addGlyph(svg, 'bird', 24, 0, [1, 1]);
92 listProps(tbody);
93 }
94
95 function handleSummaryData(data) {
96 summaryData = data;
97 render();
98 }
99
100 function bindHandlers() {
101 wss.bindHandlers(handlerMap);
102 }
103
104 function toggle() {
105 var on = summaryPanel.p.toggle(),
106 verb = on ? 'Show' : 'Hide';
107 flash.flash(verb + ' Summary Panel');
108 }
109
110 angular.module('ovTopo2')
111 .factory('Topo2SummaryPanelService',
112 ['Topo2PanelService', 'GlyphService', 'WebSocketService', 'FlashService',
113 function (_ps_, _gs_, _wss_, _flash_) {
114
115 Panel = _ps_;
116 gs = _gs_;
117 wss = _wss_;
118 flash = _flash_;
119
120 return {
121 init: init,
122
123 toggle: toggle
124 };
125 }
126 ]);
127
128})();