blob: d05dc3eb35c0d3140cb43620023a1f997d3e8ae2 [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
26 var $log, ps;
27
Simon Hunt626d2102015-01-29 11:54:50 -080028 // constants
29 var idSum = 'topo-p-summary',
30 idDet = 'topo-p-detail',
31 idIns = 'topo-p-instance',
32 panelOpts = {
33 width: 260
34 };
35
Simon Huntb0ec1e52015-01-28 18:13:49 -080036 // internal state
37 var settings;
38
39
40 // SVG elements;
41 var fooPane;
42
43 // D3 selections;
44 var summaryPanel,
45 detailPanel,
46 instancePanel;
47
48 // default settings for force layout
49 var defaultSettings = {
50 foo: 2
51 };
52
53
54 // ==========================
55
Simon Hunt626d2102015-01-29 11:54:50 -080056 function addSep(tbody) {
57 tbody.append('tr').append('td').attr('colspan', 2).append('hr');
58 }
59
60 function addProp(tbody, label, value) {
61 var tr = tbody.append('tr');
62
63 function addCell(cls, txt) {
64 tr.append('td').attr('class', cls).text(txt);
65 }
66 addCell('label', label + ' :');
67 addCell('value', value);
68 }
69
70 function populateSummary(data) {
71 summaryPanel.empty();
72
73 var svg = summaryPanel.append('svg').attr({
74 width: 40,
75 height: 40
76 }).style('background-color', 'goldenrod'),
77 iid = '#' + (data.type || 'unknown');
78
79 var title = summaryPanel.append('h2'),
80 table = summaryPanel.append('table'),
81 tbody = table.append('tbody');
82
83 // append glyph iid to SVG // black fill
84 // append glyph bird to SVG // white fill
85
86 title.text(data.id);
87
88 data.propOrder.forEach(function(p) {
89 if (p === '-') {
90 addSep(tbody);
91 } else {
92 addProp(tbody, p, data.props[p]);
93 }
94 });
95 }
96
97 function showSummaryPanel() {
98 summaryPanel.show();
99
100 }
101
102 // ==========================
103
Simon Huntb0ec1e52015-01-28 18:13:49 -0800104 angular.module('ovTopo')
105 .factory('TopoPanelService',
106 ['$log', 'PanelService',
107
108 function (_$log_, _ps_) {
109 $log = _$log_;
110 ps = _ps_;
111
112 function initPanels() {
Simon Hunt626d2102015-01-29 11:54:50 -0800113 summaryPanel = ps.createPanel(idSum, panelOpts);
Simon Huntb0ec1e52015-01-28 18:13:49 -0800114 // TODO: set up detail and instance panels..
115 }
116
Simon Hunt626d2102015-01-29 11:54:50 -0800117 function destroyPanels() {
118 ps.destroyPanel(idSum);
119 summaryPanel = null;
120 // TODO: destroy detail and instance panels..
121 }
Simon Huntb0ec1e52015-01-28 18:13:49 -0800122
Simon Hunt626d2102015-01-29 11:54:50 -0800123 function showSummary(payload) {
124 populateSummary(payload);
125 showSummaryPanel();
Simon Huntb0ec1e52015-01-28 18:13:49 -0800126 }
127
128 return {
129 initPanels: initPanels,
Simon Hunt626d2102015-01-29 11:54:50 -0800130 destroyPanels: destroyPanels,
Simon Huntb0ec1e52015-01-28 18:13:49 -0800131 showSummary: showSummary
132 };
133 }]);
134}());