GUI -- reworking code to eliminate unnecessary 'ONOS' global.
- re-package fn and keys factories into util module. Change-Id: I3d9f50b9a91468140845e862aff3fdb518948774
Showing
12 changed files
with
183 additions
and
52 deletions
| 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,7 +42,8 @@ | ... | @@ -42,7 +42,8 @@ |
| 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 | + .factory('FnService', [function () { | ||
| 46 | return { | 47 | return { |
| 47 | isF: isF, | 48 | isF: isF, |
| 48 | isA: isA, | 49 | isA: isA, |
| ... | @@ -52,4 +53,4 @@ | ... | @@ -52,4 +53,4 @@ |
| 52 | }; | 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,7 +183,8 @@ | ... | @@ -181,7 +183,8 @@ |
| 181 | }; | 183 | }; |
| 182 | } | 184 | } |
| 183 | 185 | ||
| 184 | - onos.factory('KeyService', ['$log', 'FnService', function ($l, fs) { | 186 | + angular.module('onosUtil') |
| 187 | + .factory('KeyService', ['$log', 'FnService', function ($l, fs) { | ||
| 185 | $log = $l; | 188 | $log = $l; |
| 186 | f = fs; | 189 | f = fs; |
| 187 | return { | 190 | return { |
| ... | @@ -209,4 +212,4 @@ | ... | @@ -209,4 +212,4 @@ |
| 209 | }; | 212 | }; |
| 210 | }]); | 213 | }]); |
| 211 | 214 | ||
| 212 | -}(ONOS)); | 215 | +}()); | ... | ... |
web/gui/src/main/webapp/app/fw/util/util.js
0 → 100644
| 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 | - beforeEach(module('onosApp')); | ||
| 27 | 26 | ||
| 28 | - beforeEach(inject(function (KeyService, FnService, _$log_) { | 27 | + beforeEach(module('onosUtil')); |
| 28 | + | ||
| 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 | ... | ... |
-
Please register or login to post a comment