blob: 627a94e835413ed99b01a1549a20397c4ee3a5a6 [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
29 var idSum = 'topo-p-summary',
30 idDet = 'topo-p-detail',
Simon Hunt626d2102015-01-29 11:54:50 -080031 panelOpts = {
32 width: 260
33 };
34
Simon Hunt4b668592015-01-29 17:33:53 -080035 // panels
Simon Huntb0ec1e52015-01-28 18:13:49 -080036 var summaryPanel,
Simon Hunt4b668592015-01-29 17:33:53 -080037 detailPanel;
Simon Huntb0ec1e52015-01-28 18:13:49 -080038
39 // ==========================
Simon Hunt4b668592015-01-29 17:33:53 -080040 // *** SHOW SUMMARY ***
Simon Huntb0ec1e52015-01-28 18:13:49 -080041
Simon Hunt4b668592015-01-29 17:33:53 -080042 function showSummary(data) {
43 populateSummary(data);
44 showSummaryPanel();
Simon Hunt626d2102015-01-29 11:54:50 -080045 }
46
47 function populateSummary(data) {
48 summaryPanel.empty();
49
Simon Huntedf5c0e2015-01-29 15:00:53 -080050 var svg = summaryPanel.append('svg'),
51 title = summaryPanel.append('h2'),
Simon Hunt626d2102015-01-29 11:54:50 -080052 table = summaryPanel.append('table'),
53 tbody = table.append('tbody');
54
Simon Huntc9b73162015-01-29 14:02:15 -080055 gs.addGlyph(svg, 'node', 40);
56 gs.addGlyph(svg, 'bird', 24, true, [8,12]);
Simon Hunt626d2102015-01-29 11:54:50 -080057
58 title.text(data.id);
59
60 data.propOrder.forEach(function(p) {
61 if (p === '-') {
62 addSep(tbody);
63 } else {
64 addProp(tbody, p, data.props[p]);
65 }
66 });
67 }
68
Simon Hunt4b668592015-01-29 17:33:53 -080069 function addSep(tbody) {
70 tbody.append('tr').append('td').attr('colspan', 2).append('hr');
71 }
72
73 function addProp(tbody, label, value) {
74 var tr = tbody.append('tr');
75
76 function addCell(cls, txt) {
77 tr.append('td').attr('class', cls).text(txt);
78 }
79 addCell('label', label + ' :');
80 addCell('value', value);
81 }
82
Simon Hunt626d2102015-01-29 11:54:50 -080083 function showSummaryPanel() {
84 summaryPanel.show();
Simon Hunt4b668592015-01-29 17:33:53 -080085 // TODO: augment, once we have the details pane also
86 }
Simon Hunt626d2102015-01-29 11:54:50 -080087
Simon Hunt4b668592015-01-29 17:33:53 -080088 // ==========================
89
90 function initPanels() {
91 summaryPanel = ps.createPanel(idSum, panelOpts);
92 detailPanel = ps.createPanel(idDet, panelOpts);
93 }
94
95 function destroyPanels() {
96 ps.destroyPanel(idSum);
97 ps.destroyPanel(idDet);
98 summaryPanel = detailPanel = null;
Simon Hunt626d2102015-01-29 11:54:50 -080099 }
100
101 // ==========================
102
Simon Huntb0ec1e52015-01-28 18:13:49 -0800103 angular.module('ovTopo')
104 .factory('TopoPanelService',
Simon Huntc9b73162015-01-29 14:02:15 -0800105 ['$log', 'PanelService', 'GlyphService',
Simon Huntb0ec1e52015-01-28 18:13:49 -0800106
Simon Huntc9b73162015-01-29 14:02:15 -0800107 function (_$log_, _ps_, _gs_) {
Simon Huntb0ec1e52015-01-28 18:13:49 -0800108 $log = _$log_;
109 ps = _ps_;
Simon Huntc9b73162015-01-29 14:02:15 -0800110 gs = _gs_;
Simon Huntb0ec1e52015-01-28 18:13:49 -0800111
Simon Huntb0ec1e52015-01-28 18:13:49 -0800112 return {
113 initPanels: initPanels,
Simon Hunt626d2102015-01-29 11:54:50 -0800114 destroyPanels: destroyPanels,
Simon Huntb0ec1e52015-01-28 18:13:49 -0800115 showSummary: showSummary
116 };
117 }]);
118}());