Simon Hunt

GUI -- reworking code to eliminate unnecessary 'ONOS' global.

 - re-package fn and keys factories into util module.

Change-Id: I3d9f50b9a91468140845e862aff3fdb518948774
1 # Framework related code 1 # Framework related code
2 2
3 -- Masthead 3 +- Util
4 -- Float Panels 4 + - General Functions
5 -- Alerts 5 + - Key Handler
6 -- Flash (transient messages) 6 + - Theme Service
7 -- Quick Help (key bindings, mouse gestures) 7 + - Alert Service
8 -- Death Mask (server connection lost)
9 8
9 +- Mast
10 + - Masthead
11 +
12 +- Svg
13 + - Glyph Service
14 + - Icon Service
15 + - Map Service
16 + - Zoom Service
17 +
18 +- Layers
19 + - Flash Service (transient messages)
20 + - Panel Service (floating panels)
21 + - Quick Help Service (key bindings, mouse gestures)
22 + - Death Mask Service (loss of server connection)
23 +
24 +- Remote
25 + - Login Service
26 + - Web Socket Service
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
15 */ 15 */
16 16
17 /* 17 /*
18 - ONOS GUI -- Masthead 18 + ONOS GUI -- Masthead Module
19 19
20 @author Simon Hunt 20 @author Simon Hunt
21 */ 21 */
...@@ -23,9 +23,14 @@ ...@@ -23,9 +23,14 @@
23 'use strict'; 23 'use strict';
24 24
25 angular.module('onosMast', []) 25 angular.module('onosMast', [])
26 - .controller('MastCtrl', [function () { 26 + .controller('MastCtrl', ['$log', function (_$log_) {
27 - // controller logic here 27 + var $log = _$log_,
28 - console.log('MastCtrl has been created'); 28 + self = this;
29 +
30 + // initialize mast controller here...
31 + self.radio = null;
32 +
33 + $log.log('MastCtrl has been created');
29 }]); 34 }]);
30 35
31 }()); 36 }());
......
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
15 */ 15 */
16 16
17 /* 17 /*
18 - ONOS GUI -- General Purpose Functions 18 + ONOS GUI -- Util -- General Purpose Functions
19 19
20 @author Simon Hunt 20 @author Simon Hunt
21 */ 21 */
22 -(function (onos) { 22 +(function () {
23 'use strict'; 23 'use strict';
24 24
25 function isF(f) { 25 function isF(f) {
...@@ -42,14 +42,15 @@ ...@@ -42,14 +42,15 @@
42 return isA(a) && a.indexOf(x) > -1; 42 return isA(a) && a.indexOf(x) > -1;
43 } 43 }
44 44
45 - onos.factory('FnService', [function () { 45 + angular.module('onosUtil')
46 - return { 46 + .factory('FnService', [function () {
47 - isF: isF, 47 + return {
48 - isA: isA, 48 + isF: isF,
49 - isS: isS, 49 + isA: isA,
50 - isO: isO, 50 + isS: isS,
51 - contains: contains 51 + isO: isO,
52 - }; 52 + contains: contains
53 + };
53 }]); 54 }]);
54 55
55 -}(ONOS)); 56 +}());
......
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
15 */ 15 */
16 16
17 /* 17 /*
18 - ONOS GUI -- Key Handler Service 18 + ONOS GUI -- Util -- Key Handler Service
19 19
20 @author Simon Hunt 20 @author Simon Hunt
21 */ 21 */
22 -(function (onos) { 22 +(function () {
23 'use strict'; 23 'use strict';
24 24
25 // references to injected services 25 // references to injected services
...@@ -81,6 +81,8 @@ ...@@ -81,6 +81,8 @@
81 vcb = f.isF(vk) || (f.isA(vk) && f.isF(vk[0])) || f.isF(kh.viewFn), 81 vcb = f.isF(vk) || (f.isA(vk) && f.isF(vk[0])) || f.isF(kh.viewFn),
82 token = getViewToken(); 82 token = getViewToken();
83 83
84 + d3.event.stopPropagation();
85 +
84 // global callback? 86 // global callback?
85 if (gcb && gcb(token, key, keyCode, event)) { 87 if (gcb && gcb(token, key, keyCode, event)) {
86 // if the event was 'handled', we are done 88 // if the event was 'handled', we are done
...@@ -181,32 +183,33 @@ ...@@ -181,32 +183,33 @@
181 }; 183 };
182 } 184 }
183 185
184 - onos.factory('KeyService', ['$log', 'FnService', function ($l, fs) { 186 + angular.module('onosUtil')
185 - $log = $l; 187 + .factory('KeyService', ['$log', 'FnService', function ($l, fs) {
186 - f = fs; 188 + $log = $l;
187 - return { 189 + f = fs;
188 - installOn: function (elem) { 190 + return {
189 - elem.on('keydown', keyIn); 191 + installOn: function (elem) {
190 - setupGlobalKeys(); 192 + elem.on('keydown', keyIn);
191 - }, 193 + setupGlobalKeys();
192 - theme: function () { 194 + },
193 - return theme; 195 + theme: function () {
194 - }, 196 + return theme;
195 - keyBindings: function (x) { 197 + },
196 - if (x === undefined) { 198 + keyBindings: function (x) {
197 - return getKeyBindings(); 199 + if (x === undefined) {
198 - } else { 200 + return getKeyBindings();
199 - setKeyBindings(x); 201 + } else {
202 + setKeyBindings(x);
203 + }
204 + },
205 + gestureNotes: function (g) {
206 + if (g === undefined) {
207 + return keyHandler.viewGestures;
208 + } else {
209 + keyHandler.viewGestures = f.isA(g) || [];
210 + }
200 } 211 }
201 - }, 212 + };
202 - gestureNotes: function (g) {
203 - if (g === undefined) {
204 - return keyHandler.viewGestures;
205 - } else {
206 - keyHandler.viewGestures = f.isA(g) || [];
207 - }
208 - }
209 - };
210 }]); 213 }]);
211 214
212 -}(ONOS)); 215 +}());
......
1 +/*
2 + * Copyright 2014 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 -- Utilities Module
19 +
20 + @author Simon Hunt
21 + */
22 +(function () {
23 + 'use strict';
24 +
25 + angular.module('onosUtil', []);
26 +
27 +}());
...@@ -32,8 +32,11 @@ ...@@ -32,8 +32,11 @@
32 <!-- ONOS UI Framework included here --> 32 <!-- ONOS UI Framework included here -->
33 <!-- TODO: use a single catenated-minified file here --> 33 <!-- TODO: use a single catenated-minified file here -->
34 <script src="onos.js"></script> 34 <script src="onos.js"></script>
35 - <script src="fw/lib/fn.js"></script> 35 +
36 - <script src="fw/lib/keys.js"></script> 36 + <script src="fw/util/util.js"></script>
37 + <script src="fw/util/fn.js"></script>
38 + <script src="fw/util/keys.js"></script>
39 +
37 <script src="fw/mast/mast.js"></script> 40 <script src="fw/mast/mast.js"></script>
38 41
39 <!-- Framework and library stylesheets included here --> 42 <!-- Framework and library stylesheets included here -->
......
...@@ -15,21 +15,25 @@ ...@@ -15,21 +15,25 @@
15 */ 15 */
16 16
17 /* 17 /*
18 - ONOS GUI -- Base Framework 18 + ONOS GUI -- Main Application Module
19 19
20 @author Simon Hunt 20 @author Simon Hunt
21 */ 21 */
22 22
23 -// our one global variable
24 -var ONOS;
25 -
26 (function () { 23 (function () {
27 'use strict'; 24 'use strict';
28 25
29 - ONOS = angular.module('onosApp', ['onosMast']) 26 + angular.module('onosApp', ['onosUtil', 'onosMast'])
30 - .controller('OnosCtrl', ['KeyService', function (ks) { 27 + .controller('OnosCtrl', ['$log', 'KeyService', function (_$log_, ks) {
31 - console.log('OnosCtrl has been created'); 28 + var $log = _$log_,
29 + self = this;
30 +
31 + self.version = '1.1.0';
32 +
33 + // initialize onos (main app) controller here...
32 ks.installOn(d3.select('body')); 34 ks.installOn(d3.select('body'));
35 +
36 + $log.log('OnosCtrl has been created');
33 }]); 37 }]);
34 38
35 }()); 39 }());
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
15 */ 15 */
16 16
17 /* 17 /*
18 - ONOS GUI -- General Purpose Functions - Unit Tests 18 + ONOS GUI -- Util -- General Purpose Functions - Unit Tests
19 19
20 @author Simon Hunt 20 @author Simon Hunt
21 */ 21 */
...@@ -29,20 +29,12 @@ describe('factory: fw/lib/fn.js', function() { ...@@ -29,20 +29,12 @@ describe('factory: fw/lib/fn.js', function() {
29 someDate = new Date(), 29 someDate = new Date(),
30 stringArray = ['foo', 'bar']; 30 stringArray = ['foo', 'bar'];
31 31
32 - beforeEach(module('onosApp')); 32 + beforeEach(module('onosUtil'));
33 33
34 beforeEach(inject(function (FnService) { 34 beforeEach(inject(function (FnService) {
35 fs = FnService; 35 fs = FnService;
36 })); 36 }));
37 37
38 - it('should have ONOS defined', function () {
39 - expect(ONOS).toBeDefined();
40 - });
41 -
42 - it('should have FnService defined', function () {
43 - expect(fs).toBeDefined();
44 - });
45 -
46 38
47 // === Tests for isF() 39 // === Tests for isF()
48 it('isF(): null for undefined', function () { 40 it('isF(): null for undefined', function () {
...@@ -158,11 +150,11 @@ describe('factory: fw/lib/fn.js', function() { ...@@ -158,11 +150,11 @@ describe('factory: fw/lib/fn.js', function() {
158 it('contains(): false for non-array', function () { 150 it('contains(): false for non-array', function () {
159 expect(fs.contains(null, 1)).toBeFalsy(); 151 expect(fs.contains(null, 1)).toBeFalsy();
160 }); 152 });
161 - it ('contains(): true for contained item', function () { 153 + it('contains(): true for contained item', function () {
162 expect(fs.contains(someArray, 1)).toBeTruthy(); 154 expect(fs.contains(someArray, 1)).toBeTruthy();
163 expect(fs.contains(stringArray, 'bar')).toBeTruthy(); 155 expect(fs.contains(stringArray, 'bar')).toBeTruthy();
164 }); 156 });
165 - it ('contains(): false for non-contained item', function () { 157 + it('contains(): false for non-contained item', function () {
166 expect(fs.contains(someArray, 109)).toBeFalsy(); 158 expect(fs.contains(someArray, 109)).toBeFalsy();
167 expect(fs.contains(stringArray, 'zonko')).toBeFalsy(); 159 expect(fs.contains(stringArray, 'zonko')).toBeFalsy();
168 }); 160 });
......
...@@ -20,12 +20,13 @@ ...@@ -20,12 +20,13 @@
20 @author Simon Hunt 20 @author Simon Hunt
21 */ 21 */
22 describe('factory: fw/lib/keys.js', function() { 22 describe('factory: fw/lib/keys.js', function() {
23 - var ks, fs, $log, 23 + var $log, ks, fs,
24 d3Elem, elem, last; 24 d3Elem, elem, last;
25 +
25 26
26 - beforeEach(module('onosApp')); 27 + beforeEach(module('onosUtil'));
27 28
28 - beforeEach(inject(function (KeyService, FnService, _$log_) { 29 + beforeEach(inject(function (_$log_, KeyService, FnService) {
29 $log = _$log_; 30 $log = _$log_;
30 ks = KeyService; 31 ks = KeyService;
31 fs = FnService; 32 fs = FnService;
...@@ -44,12 +45,7 @@ describe('factory: fw/lib/keys.js', function() { ...@@ -44,12 +45,7 @@ describe('factory: fw/lib/keys.js', function() {
44 d3.select('#ptest').remove(); 45 d3.select('#ptest').remove();
45 }); 46 });
46 47
47 - it('should have injected stuff defined', function () { 48 + // Code to emulate key presses....
48 - expect(ONOS).toBeDefined();
49 - expect(ks).toBeDefined();
50 - expect(fs).toBeDefined();
51 - });
52 -
53 // NOTE: kinda messy, but it seems to get the job done. 49 // NOTE: kinda messy, but it seems to get the job done.
54 function jsKeyDown(element, code) { 50 function jsKeyDown(element, code) {
55 var ev = document.createEvent('KeyboardEvent'); 51 var ev = document.createEvent('KeyboardEvent');
...@@ -82,6 +78,8 @@ describe('factory: fw/lib/keys.js', function() { ...@@ -82,6 +78,8 @@ describe('factory: fw/lib/keys.js', function() {
82 } 78 }
83 79
84 // === Theme related tests 80 // === Theme related tests
81 + // TODO: fix these tests once we have ThemeService
82 +/*
85 it('should start in light theme', function () { 83 it('should start in light theme', function () {
86 expect(ks.theme()).toEqual('light'); 84 expect(ks.theme()).toEqual('light');
87 }); 85 });
...@@ -89,6 +87,7 @@ describe('factory: fw/lib/keys.js', function() { ...@@ -89,6 +87,7 @@ describe('factory: fw/lib/keys.js', function() {
89 jsKeyDown(elem, 84); // 'T' 87 jsKeyDown(elem, 84); // 'T'
90 expect(ks.theme()).toEqual('dark'); 88 expect(ks.theme()).toEqual('dark');
91 }); 89 });
90 +*/
92 91
93 // === Key binding related tests 92 // === Key binding related tests
94 it('should start with default key bindings', function () { 93 it('should start with default key bindings', function () {
...@@ -201,7 +200,10 @@ describe('factory: fw/lib/keys.js', function() { ...@@ -201,7 +200,10 @@ describe('factory: fw/lib/keys.js', function() {
201 var k = {'space': cb, 'T': cb}, 200 var k = {'space': cb, 'T': cb},
202 count = 0; 201 count = 0;
203 202
204 - function cb() { count++; } 203 + function cb(token, key, code, ev) {
204 + count++;
205 + //console.debug('count = ' + count, token, key, code);
206 + }
205 207
206 spyOn($log, 'warn'); 208 spyOn($log, 'warn');
207 209
......
1 +/*
2 + * Copyright 2014 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 -- Masthead Controller - Unit Tests
19 +
20 + @author Simon Hunt
21 + */
22 +describe('Controller: MastCtrl', function () {
23 + // instantiate the masthead module
24 + beforeEach(module('onosMast'));
25 +
26 + var $log, ctrl;
27 +
28 + // we need an instance of the controller
29 + beforeEach(inject(function(_$log_, $controller) {
30 + $log = _$log_;
31 + ctrl = $controller('MastCtrl');
32 + }));
33 +
34 + it('should start with no radio buttons', function () {
35 + expect(ctrl.radio).toBeNull();
36 + });
37 +});
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2014 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 -- Main App Controller - Unit Tests
19 +
20 + @author Simon Hunt
21 + */
22 +describe('Controller: OnosCtrl', function () {
23 + // instantiate the main module
24 + beforeEach(module('onosApp'));
25 +
26 + var $log, ctrl;
27 +
28 + // we need an instance of the controller
29 + beforeEach(inject(function(_$log_, $controller) {
30 + $log = _$log_;
31 + ctrl = $controller('OnosCtrl');
32 + }));
33 +
34 + it('should report version 1.1.0', function () {
35 + expect(ctrl.version).toEqual('1.1.0');
36 + });
37 +});
...\ No newline at end of file ...\ No newline at end of file
...@@ -22,12 +22,15 @@ module.exports = function(config) { ...@@ -22,12 +22,15 @@ module.exports = function(config) {
22 '../tp/jquery-2.1.1.min.js', 22 '../tp/jquery-2.1.1.min.js',
23 23
24 // production code... 24 // production code...
25 + // make sure modules are defined first...
25 '../app/onos.js', 26 '../app/onos.js',
26 - '../app/fw/lib/*.js', 27 + '../app/fw/util/util.js',
27 - '../app/fw/mast/*.js', 28 + // now load services etc. that augment the modules
29 + '../app/**/*.js',
28 30
29 // unit test code... 31 // unit test code...
30 - 'fw/lib/*.js' 32 + 'app/*-spec.js',
33 + 'app/**/*-spec.js'
31 ], 34 ],
32 35
33 36
......