blob: 031ab53630d5ff8ec4bad2aba1bdf17975fbd885 [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 Huntc252aa62015-02-10 16:45:39 -0800146 // TODO: augment, for details panel move
147 }
148
149 function hideSummaryPanel() {
150 summaryPanel.hide();
151 // TODO: augment, for details panel move
Simon Hunt4b668592015-01-29 17:33:53 -0800152 }
Simon Hunt626d2102015-01-29 11:54:50 -0800153
Simon Hunt08f841d02015-02-10 14:39:20 -0800154 function showDetailPanel() {
155 // TODO: augment with summary-accomodation-logic
156 detailPanel.show();
157 }
158
159 function hideDetailPanel() {
160 detailPanel.hide();
161 }
162
163
164
Simon Hunt4b668592015-01-29 17:33:53 -0800165 // ==========================
166
167 function initPanels() {
168 summaryPanel = ps.createPanel(idSum, panelOpts);
169 detailPanel = ps.createPanel(idDet, panelOpts);
Simon Hunt08f841d02015-02-10 14:39:20 -0800170
171 summaryPanel.classed(pCls, true);
172 detailPanel.classed(pCls, true);
Simon Hunt4b668592015-01-29 17:33:53 -0800173 }
174
175 function destroyPanels() {
176 ps.destroyPanel(idSum);
177 ps.destroyPanel(idDet);
178 summaryPanel = detailPanel = null;
Simon Hunt626d2102015-01-29 11:54:50 -0800179 }
180
181 // ==========================
182
Simon Huntb0ec1e52015-01-28 18:13:49 -0800183 angular.module('ovTopo')
184 .factory('TopoPanelService',
Simon Huntc9b73162015-01-29 14:02:15 -0800185 ['$log', 'PanelService', 'GlyphService',
Simon Huntb0ec1e52015-01-28 18:13:49 -0800186
Simon Huntc9b73162015-01-29 14:02:15 -0800187 function (_$log_, _ps_, _gs_) {
Simon Huntb0ec1e52015-01-28 18:13:49 -0800188 $log = _$log_;
189 ps = _ps_;
Simon Huntc9b73162015-01-29 14:02:15 -0800190 gs = _gs_;
Simon Huntb0ec1e52015-01-28 18:13:49 -0800191
Simon Huntb0ec1e52015-01-28 18:13:49 -0800192 return {
193 initPanels: initPanels,
Simon Hunt626d2102015-01-29 11:54:50 -0800194 destroyPanels: destroyPanels,
Simon Hunt08f841d02015-02-10 14:39:20 -0800195
196 showSummary: showSummary,
197
198 displaySingle: displaySingle,
199 displayMulti: displayMulti,
200 addAction: addAction,
201
Simon Huntc252aa62015-02-10 16:45:39 -0800202 hideSummaryPanel: hideSummaryPanel,
Simon Hunt08f841d02015-02-10 14:39:20 -0800203 showDetailPanel: showDetailPanel,
204 hideDetailPanel: hideDetailPanel,
205
206 detailVisible: function () { return detailPanel.isVisible(); },
207 summaryVisible: function () { return summaryPanel.isVisible(); }
Simon Huntb0ec1e52015-01-28 18:13:49 -0800208 };
209 }]);
210}());