Simon Hunt

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

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

Change-Id: I3d9f50b9a91468140845e862aff3fdb518948774
# Framework related code
- Masthead
- Float Panels
- Alerts
- Flash (transient messages)
- Quick Help (key bindings, mouse gestures)
- Death Mask (server connection lost)
- Util
- General Functions
- Key Handler
- Theme Service
- Alert Service
- Mast
- Masthead
- Svg
- Glyph Service
- Icon Service
- Map Service
- Zoom Service
- Layers
- Flash Service (transient messages)
- Panel Service (floating panels)
- Quick Help Service (key bindings, mouse gestures)
- Death Mask Service (loss of server connection)
- Remote
- Login Service
- Web Socket Service
......
......@@ -15,7 +15,7 @@
*/
/*
ONOS GUI -- Masthead
ONOS GUI -- Masthead Module
@author Simon Hunt
*/
......@@ -23,9 +23,14 @@
'use strict';
angular.module('onosMast', [])
.controller('MastCtrl', [function () {
// controller logic here
console.log('MastCtrl has been created');
.controller('MastCtrl', ['$log', function (_$log_) {
var $log = _$log_,
self = this;
// initialize mast controller here...
self.radio = null;
$log.log('MastCtrl has been created');
}]);
}());
......
......@@ -15,11 +15,11 @@
*/
/*
ONOS GUI -- General Purpose Functions
ONOS GUI -- Util -- General Purpose Functions
@author Simon Hunt
*/
(function (onos) {
(function () {
'use strict';
function isF(f) {
......@@ -42,14 +42,15 @@
return isA(a) && a.indexOf(x) > -1;
}
onos.factory('FnService', [function () {
return {
isF: isF,
isA: isA,
isS: isS,
isO: isO,
contains: contains
};
angular.module('onosUtil')
.factory('FnService', [function () {
return {
isF: isF,
isA: isA,
isS: isS,
isO: isO,
contains: contains
};
}]);
}(ONOS));
}());
......
......@@ -15,11 +15,11 @@
*/
/*
ONOS GUI -- Key Handler Service
ONOS GUI -- Util -- Key Handler Service
@author Simon Hunt
*/
(function (onos) {
(function () {
'use strict';
// references to injected services
......@@ -81,6 +81,8 @@
vcb = f.isF(vk) || (f.isA(vk) && f.isF(vk[0])) || f.isF(kh.viewFn),
token = getViewToken();
d3.event.stopPropagation();
// global callback?
if (gcb && gcb(token, key, keyCode, event)) {
// if the event was 'handled', we are done
......@@ -181,32 +183,33 @@
};
}
onos.factory('KeyService', ['$log', 'FnService', function ($l, fs) {
$log = $l;
f = fs;
return {
installOn: function (elem) {
elem.on('keydown', keyIn);
setupGlobalKeys();
},
theme: function () {
return theme;
},
keyBindings: function (x) {
if (x === undefined) {
return getKeyBindings();
} else {
setKeyBindings(x);
angular.module('onosUtil')
.factory('KeyService', ['$log', 'FnService', function ($l, fs) {
$log = $l;
f = fs;
return {
installOn: function (elem) {
elem.on('keydown', keyIn);
setupGlobalKeys();
},
theme: function () {
return theme;
},
keyBindings: function (x) {
if (x === undefined) {
return getKeyBindings();
} else {
setKeyBindings(x);
}
},
gestureNotes: function (g) {
if (g === undefined) {
return keyHandler.viewGestures;
} else {
keyHandler.viewGestures = f.isA(g) || [];
}
}
},
gestureNotes: function (g) {
if (g === undefined) {
return keyHandler.viewGestures;
} else {
keyHandler.viewGestures = f.isA(g) || [];
}
}
};
};
}]);
}(ONOS));
}());
......
/*
* Copyright 2014 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
ONOS GUI -- Utilities Module
@author Simon Hunt
*/
(function () {
'use strict';
angular.module('onosUtil', []);
}());
......@@ -32,8 +32,11 @@
<!-- ONOS UI Framework included here -->
<!-- TODO: use a single catenated-minified file here -->
<script src="onos.js"></script>
<script src="fw/lib/fn.js"></script>
<script src="fw/lib/keys.js"></script>
<script src="fw/util/util.js"></script>
<script src="fw/util/fn.js"></script>
<script src="fw/util/keys.js"></script>
<script src="fw/mast/mast.js"></script>
<!-- Framework and library stylesheets included here -->
......
......@@ -15,21 +15,25 @@
*/
/*
ONOS GUI -- Base Framework
ONOS GUI -- Main Application Module
@author Simon Hunt
*/
// our one global variable
var ONOS;
(function () {
'use strict';
ONOS = angular.module('onosApp', ['onosMast'])
.controller('OnosCtrl', ['KeyService', function (ks) {
console.log('OnosCtrl has been created');
angular.module('onosApp', ['onosUtil', 'onosMast'])
.controller('OnosCtrl', ['$log', 'KeyService', function (_$log_, ks) {
var $log = _$log_,
self = this;
self.version = '1.1.0';
// initialize onos (main app) controller here...
ks.installOn(d3.select('body'));
$log.log('OnosCtrl has been created');
}]);
}());
......
......@@ -15,7 +15,7 @@
*/
/*
ONOS GUI -- General Purpose Functions - Unit Tests
ONOS GUI -- Util -- General Purpose Functions - Unit Tests
@author Simon Hunt
*/
......@@ -29,20 +29,12 @@ describe('factory: fw/lib/fn.js', function() {
someDate = new Date(),
stringArray = ['foo', 'bar'];
beforeEach(module('onosApp'));
beforeEach(module('onosUtil'));
beforeEach(inject(function (FnService) {
fs = FnService;
}));
it('should have ONOS defined', function () {
expect(ONOS).toBeDefined();
});
it('should have FnService defined', function () {
expect(fs).toBeDefined();
});
// === Tests for isF()
it('isF(): null for undefined', function () {
......@@ -158,11 +150,11 @@ describe('factory: fw/lib/fn.js', function() {
it('contains(): false for non-array', function () {
expect(fs.contains(null, 1)).toBeFalsy();
});
it ('contains(): true for contained item', function () {
it('contains(): true for contained item', function () {
expect(fs.contains(someArray, 1)).toBeTruthy();
expect(fs.contains(stringArray, 'bar')).toBeTruthy();
});
it ('contains(): false for non-contained item', function () {
it('contains(): false for non-contained item', function () {
expect(fs.contains(someArray, 109)).toBeFalsy();
expect(fs.contains(stringArray, 'zonko')).toBeFalsy();
});
......
......@@ -20,12 +20,13 @@
@author Simon Hunt
*/
describe('factory: fw/lib/keys.js', function() {
var ks, fs, $log,
var $log, ks, fs,
d3Elem, elem, last;
beforeEach(module('onosApp'));
beforeEach(module('onosUtil'));
beforeEach(inject(function (KeyService, FnService, _$log_) {
beforeEach(inject(function (_$log_, KeyService, FnService) {
$log = _$log_;
ks = KeyService;
fs = FnService;
......@@ -44,12 +45,7 @@ describe('factory: fw/lib/keys.js', function() {
d3.select('#ptest').remove();
});
it('should have injected stuff defined', function () {
expect(ONOS).toBeDefined();
expect(ks).toBeDefined();
expect(fs).toBeDefined();
});
// Code to emulate key presses....
// NOTE: kinda messy, but it seems to get the job done.
function jsKeyDown(element, code) {
var ev = document.createEvent('KeyboardEvent');
......@@ -82,6 +78,8 @@ describe('factory: fw/lib/keys.js', function() {
}
// === Theme related tests
// TODO: fix these tests once we have ThemeService
/*
it('should start in light theme', function () {
expect(ks.theme()).toEqual('light');
});
......@@ -89,6 +87,7 @@ describe('factory: fw/lib/keys.js', function() {
jsKeyDown(elem, 84); // 'T'
expect(ks.theme()).toEqual('dark');
});
*/
// === Key binding related tests
it('should start with default key bindings', function () {
......@@ -201,7 +200,10 @@ describe('factory: fw/lib/keys.js', function() {
var k = {'space': cb, 'T': cb},
count = 0;
function cb() { count++; }
function cb(token, key, code, ev) {
count++;
//console.debug('count = ' + count, token, key, code);
}
spyOn($log, 'warn');
......
/*
* Copyright 2014 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
ONOS GUI -- Masthead Controller - Unit Tests
@author Simon Hunt
*/
describe('Controller: MastCtrl', function () {
// instantiate the masthead module
beforeEach(module('onosMast'));
var $log, ctrl;
// we need an instance of the controller
beforeEach(inject(function(_$log_, $controller) {
$log = _$log_;
ctrl = $controller('MastCtrl');
}));
it('should start with no radio buttons', function () {
expect(ctrl.radio).toBeNull();
});
});
\ No newline at end of file
/*
* Copyright 2014 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
ONOS GUI -- Main App Controller - Unit Tests
@author Simon Hunt
*/
describe('Controller: OnosCtrl', function () {
// instantiate the main module
beforeEach(module('onosApp'));
var $log, ctrl;
// we need an instance of the controller
beforeEach(inject(function(_$log_, $controller) {
$log = _$log_;
ctrl = $controller('OnosCtrl');
}));
it('should report version 1.1.0', function () {
expect(ctrl.version).toEqual('1.1.0');
});
});
\ No newline at end of file
......@@ -22,12 +22,15 @@ module.exports = function(config) {
'../tp/jquery-2.1.1.min.js',
// production code...
// make sure modules are defined first...
'../app/onos.js',
'../app/fw/lib/*.js',
'../app/fw/mast/*.js',
'../app/fw/util/util.js',
// now load services etc. that augment the modules
'../app/**/*.js',
// unit test code...
'fw/lib/*.js'
'app/*-spec.js',
'app/**/*-spec.js'
],
......