blob: 30536431ea2b7841923a6e7c44a4c52ad228c65d [file] [log] [blame]
Simon Huntb0ec1e52015-01-28 18:13:49 -08001/*
2 * Copyright 2015 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 Panel Module.
19 Defines functions for manipulating the summary, detail, and instance panels.
20 */
21
22(function () {
23 'use strict';
24
25 // injected refs
Simon Huntc9b73162015-01-29 14:02:15 -080026 var $log, ps, gs;
Simon Huntb0ec1e52015-01-28 18:13:49 -080027
Simon Hunt626d2102015-01-29 11:54:50 -080028 // constants
Simon Hunt08f841d02015-02-10 14:39:20 -080029 var pCls = 'topo-p',
30 idSum = 'topo-p-summary',
Simon Hunt626d2102015-01-29 11:54:50 -080031 idDet = 'topo-p-detail',
Simon Hunt626d2102015-01-29 11:54:50 -080032 panelOpts = {
33 width: 260
34 };
35
Simon Hunt4b668592015-01-29 17:33:53 -080036 // panels
Simon Huntb0ec1e52015-01-28 18:13:49 -080037 var summaryPanel,
Simon Hunt4b668592015-01-29 17:33:53 -080038 detailPanel;
Simon Huntb0ec1e52015-01-28 18:13:49 -080039
Simon Huntb0ec1e52015-01-28 18:13:49 -080040
Simon Hunt08f841d02015-02-10 14:39:20 -080041 // === -----------------------------------------------------
42 // Utility functions
Simon Hunt626d2102015-01-29 11:54:50 -080043
Simon Hunt4b668592015-01-29 17:33:53 -080044 function addSep(tbody) {
45 tbody.append('tr').append('td').attr('colspan', 2).append('hr');
46 }
47
48 function addProp(tbody, label, value) {
49 var tr = tbody.append('tr');
50
51 function addCell(cls, txt) {
52 tr.append('td').attr('class', cls).text(txt);
53 }
54 addCell('label', label + ' :');
55 addCell('value', value);
56 }
57
Simon Hunt08f841d02015-02-10 14:39:20 -080058 function listProps(tbody, data) {
59 data.propOrder.forEach(function(p) {
60 if (p === '-') {
61 addSep(tbody);
62 } else {
63 addProp(tbody, p, data.props[p]);
64 }
65 });
66 }
67
68 function dpa(x) {
69 return detailPanel.append(x);
70 }
71
72 function spa(x) {
73 return summaryPanel.append(x);
74 }
75
76 // === -----------------------------------------------------
77 // Functions for populating the summary panel
78
79 function populateSummary(data) {
80 summaryPanel.empty();
81
82 var svg = spa('svg'),
83 title = spa('h2'),
84 table = spa('table'),
85 tbody = table.append('tbody');
86
87 gs.addGlyph(svg, 'node', 40);
88 gs.addGlyph(svg, 'bird', 24, true, [8,12]);
89
90 title.text(data.id);
91 listProps(tbody, data);
92 }
93
94 // === -----------------------------------------------------
95 // Functions for populating the detail panel
96
97 function displaySingle(data) {
98 detailPanel.empty();
99
100 var svg = dpa('svg'),
101 title = dpa('h2'),
102 table = dpa('table'),
103 tbody = table.append('tbody');
104
105 gs.addGlyph(svg, (data.type || 'unknown'), 40);
106 title.text(data.id);
107 listProps(tbody, data);
108 dpa('hr');
109 }
110
111 function displayMulti(ids) {
112 detailPanel.empty();
113
114 var title = dpa('h3'),
115 table = dpa('table'),
116 tbody = table.append('tbody');
117
118 title.text('Selected Nodes');
119 ids.forEach(function (d, i) {
120 addProp(tbody, i+1, d);
121 });
122 dpa('hr');
123 }
124
125 function addAction(text, cb) {
126 dpa('div')
127 .classed('actionBtn', true)
128 .text(text)
129 .on('click', cb);
130 }
131
132 // === -----------------------------------------------------
133 // Event Handlers
134
135 function showSummary(data) {
136 populateSummary(data);
137 showSummaryPanel();
138 }
139
140
141 // === -----------------------------------------------------
142 // === LOGIC For showing/hiding summary and detail panels...
143
Simon Hunt626d2102015-01-29 11:54:50 -0800144 function showSummaryPanel() {
145 summaryPanel.show();
Simon Hunt4b668592015-01-29 17:33:53 -0800146 // TODO: augment, once we have the details pane also
147 }
Simon Hunt626d2102015-01-29 11:54:50 -0800148
Simon Hunt08f841d02015-02-10 14:39:20 -0800149 function showDetailPanel() {
150 // TODO: augment with summary-accomodation-logic
151 detailPanel.show();
152 }
153
154 function hideDetailPanel() {
155 detailPanel.hide();
156 }
157
158
159
Simon Hunt4b668592015-01-29 17:33:53 -0800160 // ==========================
161
162 function initPanels() {
163 summaryPanel = ps.createPanel(idSum, panelOpts);
164 detailPanel = ps.createPanel(idDet, panelOpts);
Simon Hunt08f841d02015-02-10 14:39:20 -0800165
166 summaryPanel.classed(pCls, true);
167 detailPanel.classed(pCls, true);
Simon Hunt4b668592015-01-29 17:33:53 -0800168 }
169
170 function destroyPanels() {
171 ps.destroyPanel(idSum);
172 ps.destroyPanel(idDet);
173 summaryPanel = detailPanel = null;
Simon Hunt626d2102015-01-29 11:54:50 -0800174 }
175
176 // ==========================
177
Simon Huntb0ec1e52015-01-28 18:13:49 -0800178 angular.module('ovTopo')
179 .factory('TopoPanelService',
Simon Huntc9b73162015-01-29 14:02:15 -0800180 ['$log', 'PanelService', 'GlyphService',
Simon Huntb0ec1e52015-01-28 18:13:49 -0800181
Simon Huntc9b73162015-01-29 14:02:15 -0800182 function (_$log_, _ps_, _gs_) {
Simon Huntb0ec1e52015-01-28 18:13:49 -0800183 $log = _$log_;
184 ps = _ps_;
Simon Huntc9b73162015-01-29 14:02:15 -0800185 gs = _gs_;
Simon Huntb0ec1e52015-01-28 18:13:49 -0800186
Simon Huntb0ec1e52015-01-28 18:13:49 -0800187 return {
188 initPanels: initPanels,
Simon Hunt626d2102015-01-29 11:54:50 -0800189 destroyPanels: destroyPanels,
Simon Hunt08f841d02015-02-10 14:39:20 -0800190
191 showSummary: showSummary,
192
193 displaySingle: displaySingle,
194 displayMulti: displayMulti,
195 addAction: addAction,
196
197 showDetailPanel: showDetailPanel,
198 hideDetailPanel: hideDetailPanel,
199
200 detailVisible: function () { return detailPanel.isVisible(); },
201 summaryVisible: function () { return summaryPanel.isVisible(); }
Simon Huntb0ec1e52015-01-28 18:13:49 -0800202 };
203 }]);
204}());