Simon Hunt

GUI -- Added TopoPanelService to encapsulate summary, detail and instance panels.

- Rudimentary handling of 'showSummary' event implemented.
- Fixed resize behavior of topo SVG.
- Created 'migrate' mock-server scenario.
- Added 'restart' command to mock-server.

Change-Id: I90ac93dbc9efb8f17ef95825d3159030145267a2
...@@ -76,6 +76,7 @@ ...@@ -76,6 +76,7 @@
76 <script src="view/topo/topo.js"></script> 76 <script src="view/topo/topo.js"></script>
77 <script src="view/topo/topoEvent.js"></script> 77 <script src="view/topo/topoEvent.js"></script>
78 <script src="view/topo/topoForce.js"></script> 78 <script src="view/topo/topoForce.js"></script>
79 + <script src="view/topo/topoPanel.js"></script>
79 <script src="view/device/device.js"></script> 80 <script src="view/device/device.js"></script>
80 <!-- TODO: inject javascript refs server-side --> 81 <!-- TODO: inject javascript refs server-side -->
81 82
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
28 ]; 28 ];
29 29
30 // references to injected services etc. 30 // references to injected services etc.
31 - var $log, fs, ks, zs, gs, ms, ps, tes, tfs; 31 + var $log, fs, ks, zs, gs, ms, tes, tfs, tps;
32 32
33 // DOM elements 33 // DOM elements
34 var ovtopo, svg, defs, zoomLayer, mapG, forceG; 34 var ovtopo, svg, defs, zoomLayer, mapG, forceG;
...@@ -101,9 +101,9 @@ ...@@ -101,9 +101,9 @@
101 101
102 102
103 // callback invoked when the SVG view has been resized.. 103 // callback invoked when the SVG view has been resized..
104 - function svgResized(w, h) { 104 + function svgResized(dim) {
105 - $log.debug('TopoView just resized... ' + w + 'x' + h); 105 + //$log.debug('TopoView just resized... ', dim);
106 - tfs.resize(w, h); 106 + tfs.resize(dim);
107 } 107 }
108 108
109 // --- Background Map ------------------------------------------------ 109 // --- Background Map ------------------------------------------------
...@@ -137,6 +137,10 @@ ...@@ -137,6 +137,10 @@
137 tfs.initForce(forceG, svg.attr('width'), svg.attr('height')); 137 tfs.initForce(forceG, svg.attr('width'), svg.attr('height'));
138 } 138 }
139 139
140 + function setUpPanels() {
141 + tps.initPanels();
142 + }
143 +
140 144
141 // --- Controller Definition ----------------------------------------- 145 // --- Controller Definition -----------------------------------------
142 146
...@@ -146,10 +150,10 @@ ...@@ -146,10 +150,10 @@
146 '$scope', '$log', '$location', '$timeout', 150 '$scope', '$log', '$location', '$timeout',
147 'FnService', 'MastService', 151 'FnService', 'MastService',
148 'KeyService', 'ZoomService', 'GlyphService', 'MapService', 152 'KeyService', 'ZoomService', 'GlyphService', 'MapService',
149 - 'PanelService', 'TopoEventService', 'TopoForceService', 153 + 'TopoEventService', 'TopoForceService', 'TopoPanelService',
150 154
151 function ($scope, _$log_, $loc, $timeout, _fs_, mast, 155 function ($scope, _$log_, $loc, $timeout, _fs_, mast,
152 - _ks_, _zs_, _gs_, _ms_, _ps_, _tes_, _tfs_) { 156 + _ks_, _zs_, _gs_, _ms_, _tes_, _tfs_, _tps_) {
153 var self = this; 157 var self = this;
154 $log = _$log_; 158 $log = _$log_;
155 fs = _fs_; 159 fs = _fs_;
...@@ -157,12 +161,12 @@ ...@@ -157,12 +161,12 @@
157 zs = _zs_; 161 zs = _zs_;
158 gs = _gs_; 162 gs = _gs_;
159 ms = _ms_; 163 ms = _ms_;
160 - ps = _ps_;
161 tes = _tes_; 164 tes = _tes_;
162 tfs = _tfs_; 165 tfs = _tfs_;
166 + tps = _tps_;
163 167
164 self.notifyResize = function () { 168 self.notifyResize = function () {
165 - svgResized(svg.attr('width'), svg.attr('height')); 169 + svgResized(fs.windowSize(mast.mastHeight()));
166 }; 170 };
167 171
168 // Cleanup on destroyed scope.. 172 // Cleanup on destroyed scope..
...@@ -186,16 +190,11 @@ ...@@ -186,16 +190,11 @@
186 setUpZoom(); 190 setUpZoom();
187 setUpMap(); 191 setUpMap();
188 setUpForce(); 192 setUpForce();
193 + setUpPanels();
189 194
190 // open up a connection to the server... 195 // open up a connection to the server...
191 tes.openSock(); 196 tes.openSock();
192 197
193 - // TODO: remove this temporary code....
194 - var p = ps.createPanel('topo-p-summary');
195 - p.append('h1').text('Hello World');
196 - p.show();
197 - $timeout(function () { p.hide(); }, 2000);
198 -
199 $log.log('OvTopoCtrl has been created'); 198 $log.log('OvTopoCtrl has been created');
200 }]); 199 }]);
201 }()); 200 }());
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
23 'use strict'; 23 'use strict';
24 24
25 // injected refs 25 // injected refs
26 - var $log, wss, wes; 26 + var $log, wss, wes, tps;
27 27
28 // internal state 28 // internal state
29 var wsock; 29 var wsock;
...@@ -42,11 +42,12 @@ ...@@ -42,11 +42,12 @@
42 // === Event Handlers === 42 // === Event Handlers ===
43 43
44 function showSummary(ev) { 44 function showSummary(ev) {
45 - $log.log(' **** Show Summary **** ', ev.payload); 45 + $log.debug(' **** Show Summary **** ', ev.payload);
46 + tps.showSummary(ev.payload);
46 } 47 }
47 48
48 function addInstance(ev) { 49 function addInstance(ev) {
49 - $log.log(' *** We got an ADD INSTANCE event: ', ev); 50 + $log.debug(' *** We got an ADD INSTANCE event: ', ev);
50 } 51 }
51 52
52 // ========================== 53 // ==========================
...@@ -86,11 +87,13 @@ ...@@ -86,11 +87,13 @@
86 angular.module('ovTopo') 87 angular.module('ovTopo')
87 .factory('TopoEventService', 88 .factory('TopoEventService',
88 ['$log', '$location', 'WebSocketService', 'WsEventService', 89 ['$log', '$location', 'WebSocketService', 'WsEventService',
90 + 'TopoPanelService',
89 91
90 - function (_$log_, $loc, _wss_, _wes_) { 92 + function (_$log_, $loc, _wss_, _wes_, _tps_) {
91 $log = _$log_; 93 $log = _$log_;
92 wss = _wss_; 94 wss = _wss_;
93 wes = _wes_; 95 wes = _wes_;
96 + tps = _tps_;
94 97
95 function bindDispatcher(TopoDomElementsPassedHere) { 98 function bindDispatcher(TopoDomElementsPassedHere) {
96 // TODO: store refs to topo DOM elements... 99 // TODO: store refs to topo DOM elements...
......
...@@ -124,8 +124,8 @@ ...@@ -124,8 +124,8 @@
124 selectCb, atDragEnd, dragEnabled, clickEnabled); 124 selectCb, atDragEnd, dragEnabled, clickEnabled);
125 } 125 }
126 126
127 - function resize(w, h) { 127 + function resize(dim) {
128 - force.size([w, h]); 128 + force.size([dim.width, dim.height]);
129 // Review -- do we need to nudge the layout ? 129 // Review -- do we need to nudge the layout ?
130 130
131 } 131 }
......
1 +/*
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 +
28 + // internal state
29 + var settings;
30 +
31 +
32 + // SVG elements;
33 + var fooPane;
34 +
35 + // D3 selections;
36 + var summaryPanel,
37 + detailPanel,
38 + instancePanel;
39 +
40 + // default settings for force layout
41 + var defaultSettings = {
42 + foo: 2
43 + };
44 +
45 +
46 + // ==========================
47 +
48 + angular.module('ovTopo')
49 + .factory('TopoPanelService',
50 + ['$log', 'PanelService',
51 +
52 + function (_$log_, _ps_) {
53 + $log = _$log_;
54 + ps = _ps_;
55 +
56 + function initPanels() {
57 + summaryPanel = ps.createPanel('topo-p-summary');
58 + // TODO: set up detail and instance panels..
59 + }
60 +
61 + function showSummary(payload) {
62 + summaryPanel.empty();
63 + summaryPanel.append('h2').text(payload.id);
64 + // TODO: complete the formatting...
65 +
66 + summaryPanel.show();
67 + }
68 +
69 + return {
70 + initPanels: initPanels,
71 + showSummary: showSummary
72 + };
73 + }]);
74 +}());
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
20 describe('factory: view/topo/topoEvent.js', function() { 20 describe('factory: view/topo/topoEvent.js', function() {
21 var $log, fs, tes; 21 var $log, fs, tes;
22 22
23 - beforeEach(module('ovTopo', 'onosUtil')); 23 + beforeEach(module('ovTopo', 'onosUtil', 'onosLayer'));
24 24
25 beforeEach(inject(function (_$log_, FnService, TopoEventService) { 25 beforeEach(inject(function (_$log_, FnService, TopoEventService) {
26 $log = _$log_; 26 $log = _$log_;
......
1 +/*
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 -- Topo View -- Topo Panel Service - Unit Tests
19 + */
20 +describe('factory: view/topo/topoPanel.js', function() {
21 + var $log, fs, tps;
22 +
23 + beforeEach(module('ovTopo', 'onosUtil', 'onosLayer'));
24 +
25 + beforeEach(inject(function (_$log_, FnService, TopoPanelService) {
26 + $log = _$log_;
27 + fs = FnService;
28 + tps = TopoPanelService;
29 + }));
30 +
31 + it('should define TopoPanelService', function () {
32 + expect(tps).toBeDefined();
33 + });
34 +
35 + it('should define api functions', function () {
36 + expect(fs.areFunctions(tps, [
37 + 'initPanels'
38 + ])).toBeTruthy();
39 + });
40 +
41 + // TODO: more tests...
42 +});
1 +{
2 + "event": "showSummary",
3 + "sid": 1,
4 + "payload": {
5 + "id": "ONOS Summary",
6 + "type": "node",
7 + "propOrder": [
8 + "Devices",
9 + "Links",
10 + "Hosts",
11 + "Topology SCCs",
12 + "-",
13 + "Intents",
14 + "Flows",
15 + "Version"
16 + ],
17 + "props": {
18 + "Devices": "25",
19 + "Links": "112",
20 + "Hosts": "0",
21 + "Topology SCCs": "1",
22 + "-": "",
23 + "Intents": "0",
24 + "Flows": "125",
25 + "Version": "1.0.0*"
26 + }
27 + }
28 +}
1 +{
2 + "comments": [
3 + "Used during the migration of old GUI (topo.js==3.1KLOC) to Angular"
4 + ],
5 + "title": "Migration Helper",
6 + "params": {
7 + "lastAuto": 0
8 + },
9 + "description": [
10 + "Do what you need to..."
11 + ]
12 +}
...@@ -34,7 +34,7 @@ server.listen(port, function() { ...@@ -34,7 +34,7 @@ server.listen(port, function() {
34 }); 34 });
35 35
36 server.on('listening', function () { 36 server.on('listening', function () {
37 - console.log('ok, server is running'); 37 + console.log('OK, server is running');
38 }); 38 });
39 39
40 var wsServer = new WebSocketServer({ 40 var wsServer = new WebSocketServer({
...@@ -110,6 +110,7 @@ function doCli() { ...@@ -110,6 +110,7 @@ function doCli() {
110 case 'm': customMessage(str); break; 110 case 'm': customMessage(str); break;
111 case 's': setScenario(str); break; 111 case 's': setScenario(str); break;
112 case 'n': nextEvent(); break; 112 case 'n': nextEvent(); break;
113 + case 'r': restartScenario(); break;
113 case 'q': quit(); break; 114 case 'q': quit(); break;
114 case '?': showHelp(); break; 115 case '?': showHelp(); break;
115 default: console.log('Say what?! (? for help)'); break; 116 default: console.log('Say what?! (? for help)'); break;
...@@ -126,10 +127,11 @@ function doCli() { ...@@ -126,10 +127,11 @@ function doCli() {
126 var helptext = '\n' + 127 var helptext = '\n' +
127 'c - show connection status\n' + 128 'c - show connection status\n' +
128 'm {text} - send custom message to client\n' + 129 'm {text} - send custom message to client\n' +
129 - 's {id} - set scenario\n' + 130 + 's {id} - load scenario {id}\n' +
130 's - show scenario staus\n' + 131 's - show scenario staus\n' +
131 //'a - auto-send events\n' + 132 //'a - auto-send events\n' +
132 'n - send next event\n' + 133 'n - send next event\n' +
134 + 'r - restart the scenario\n' +
133 'q - exit the server\n' + 135 'q - exit the server\n' +
134 '? - display this help text\n'; 136 '? - display this help text\n';
135 137
...@@ -146,13 +148,13 @@ function connStatus() { ...@@ -146,13 +148,13 @@ function connStatus() {
146 } 148 }
147 149
148 function quit() { 150 function quit() {
149 - console.log('quitting...'); 151 + console.log('Quitting...');
150 process.exit(0); 152 process.exit(0);
151 } 153 }
152 154
153 function customMessage(m) { 155 function customMessage(m) {
154 if (connection) { 156 if (connection) {
155 - console.log('sending message: ' + m); 157 + console.log('Sending message: ' + m);
156 connection.sendUTF(m); 158 connection.sendUTF(m);
157 } else { 159 } else {
158 console.warn('No current connection.'); 160 console.warn('No current connection.');
...@@ -162,7 +164,7 @@ function customMessage(m) { ...@@ -162,7 +164,7 @@ function customMessage(m) {
162 function showScenarioStatus() { 164 function showScenarioStatus() {
163 var msg; 165 var msg;
164 if (!scenario) { 166 if (!scenario) {
165 - console.log('No scenario selected.'); 167 + console.log('No scenario loaded.');
166 } else { 168 } else {
167 msg = 'Scenario: "' + scenario + '", ' + 169 msg = 'Scenario: "' + scenario + '", ' +
168 (scdone ? 'DONE' : 'next event: ' + evno); 170 (scdone ? 'DONE' : 'next event: ' + evno);
...@@ -189,7 +191,7 @@ function setScenario(id) { ...@@ -189,7 +191,7 @@ function setScenario(id) {
189 } else { 191 } else {
190 evdata = JSON.parse(data); 192 evdata = JSON.parse(data);
191 console.log(); // get past prompt 193 console.log(); // get past prompt
192 - console.log('setting scenario to "' + id + '"'); 194 + console.log('Loading scenario "' + id + '"');
193 console.log(evdata.title); 195 console.log(evdata.title);
194 evdata.description.forEach(function (d) { 196 evdata.description.forEach(function (d) {
195 console.log(' ' + d); 197 console.log(' ' + d);
...@@ -201,11 +203,27 @@ function setScenario(id) { ...@@ -201,11 +203,27 @@ function setScenario(id) {
201 }); 203 });
202 } 204 }
203 205
206 +function restartScenario() {
207 + if (!scenario) {
208 + console.log('No scenario loaded.');
209 + } else {
210 + console.log();
211 + console.log('Restarting scenario "' + scenario + '"');
212 + console.log(evdata.title);
213 + evdata.description.forEach(function (d) {
214 + console.log(' ' + d);
215 + });
216 + evno = 1;
217 + scdone = false;
218 + }
219 + rl.prompt();
220 +}
221 +
204 function nextEvent() { 222 function nextEvent() {
205 var path; 223 var path;
206 224
207 if (!scenario) { 225 if (!scenario) {
208 - console.log('No scenario selected.'); 226 + console.log('No scenario loaded.');
209 rl.prompt(); 227 rl.prompt();
210 } else if (!connection) { 228 } else if (!connection) {
211 console.warn('No current connection.'); 229 console.warn('No current connection.');
...@@ -220,7 +238,7 @@ function nextEvent() { ...@@ -220,7 +238,7 @@ function nextEvent() {
220 } else { 238 } else {
221 evdata = JSON.parse(data); 239 evdata = JSON.parse(data);
222 console.log(); // get past prompt 240 console.log(); // get past prompt
223 - console.log('sending event #' + evno + ' [' + evdata.event + ']'); 241 + console.log('Sending event #' + evno + ' [' + evdata.event + ']');
224 connection.sendUTF(data); 242 connection.sendUTF(data);
225 evno++; 243 evno++;
226 } 244 }
......