Simon Hunt
Committed by Gerrit Code Review

GUI: Javascript cleanup and additional utility functions.

Change-Id: Ia16dd7eecedfd116e9d0a65d60d724657e87b8d3
......@@ -143,6 +143,13 @@
enabled = !!b;
}
function tempDiv(ms) {
var div = d3.select('body').append('div').classed('centered', true),
delay = (ms === undefined || ms < 100) ? 3000 : ms;
$timeout(function () { div.remove(); }, delay);
return div;
}
angular.module('onosLayer')
.factory('FlashService', ['$log', '$timeout',
function (_$log_, _$timeout_) {
......@@ -158,7 +165,8 @@
return {
initFlash: initFlash,
flash: flash,
enable: enable
enable: enable,
tempDiv: tempDiv
};
}]);
......
This diff is collapsed. Click to expand it.
......@@ -21,11 +21,26 @@
'use strict';
// injected services
var fs;
var $log, fs, flash;
// function references
var fcc = String.fromCharCode;
// magic beans
var beans = [
//'umpxwnwcw'
//'eufdvexoc',
//'egpdytgv',
//'xcjvte',
//'bgvest',
//'sevlr',
'ias'
];
function pickBean() {
return beans[Math.floor(Math.random() * beans.length)] + '.foo';
}
function computeTransform(x) {
var m = x.split(':'),
h = Number(m[0]),
......@@ -45,18 +60,39 @@
data.forEach(function (x) {
var r = computeTransform(x);
map['shift' + r.e] = r.o.toLowerCase() + '.bin';
map[r.e] = r.o.toLowerCase() + '.foo';
});
return map;
}
angular.module('onosUtil')
.factory('EeService',
['FnService', function (_fs_) {
fs = _fs_;
function cluck(foo) {
var f = fs.isF(foo),
s = fs.isS(foo);
$log.debug('>>> CLUCK! <<<', foo);
if (s === 'fgfb.foo') {
s = pickBean();
$log.debug('bean picked:', s);
}
return {
genMap: genMap
if (s && fs.endsWith(s, '.foo')) {
flash.tempDiv().append('img').attr('src', 'raw/'+s);
}
}]);
f && f();
}
angular.module('onosUtil')
.factory('EeService', ['$log', 'FnService', 'FlashService',
function (_$log_, _fs_, _flash_) {
$log = _$log_;
fs = _fs_;
flash = _flash_;
return {
genMap: genMap,
cluck: cluck
}
}]);
}());
......
......@@ -21,11 +21,7 @@
'use strict';
// references to injected services
var $log, $timeout, fs, ts, ns, qhs;
// constants
var eeggMin = 'shiftO',
eeggMax = 'shiftONOS';
var $log, $timeout, fs, ts, ns, ee, qhs;
// internal state
var enabled = true,
......@@ -37,23 +33,30 @@
viewFn: null,
viewGestures: []
},
eegg = '';
seq = {},
matching = false,
matched = '',
lookup;
function layEgg(key) {
eegg += key;
if (eeggMax.indexOf(eegg) === 0) {
if (eegg === eeggMax) {
d3.select('body').append('div').attr('id', 'eegg')
.append('img').attr('src', 'raw/ewo.foo');
$timeout(function () { d3.select('#eegg').remove(); }, 3000);
eegg = '';
}
function matchSeq(key) {
if (!matching && key === 'shift') {
matching = true;
return true;
}
if (eegg !== eeggMin) {
eegg = '';
if (matching) {
matched += key;
lookup = fs.trieLookup(seq, matched);
if (lookup === -1) {
return true;
}
matching = false;
matched = '';
if (!lookup) {
return;
}
ee.cluck(lookup);
return true;
}
return false;
}
function whatKey(code) {
......@@ -109,7 +112,7 @@
d3.event.stopPropagation();
if (enabled) {
if (layEgg(key)) return;
if (matchSeq(key)) return;
// global callback?
if (gcb && gcb(token, key, keyCode, event)) {
......@@ -230,13 +233,15 @@
angular.module('onosUtil')
.factory('KeyService',
['$log', '$timeout', 'FnService', 'ThemeService', 'NavService',
'EeService',
function (_$log_, _$timeout_, _fs_, _ts_, _ns_) {
function (_$log_, _$timeout_, _fs_, _ts_, _ns_, _ee_) {
$log = _$log_;
$timeout = _$timeout_;
fs = _fs_;
ts = _ts_;
ns = _ns_;
ee = _ee_;
return {
bindQhs: function (_qhs_) {
......@@ -254,6 +259,12 @@
}
},
unbindKeys: unbindKeys,
addSeq: function (word, data) {
fs.addToTrie(seq, word, data);
},
remSeq: function (word) {
fs.removeFromTrie(seq, word);
},
gestureNotes: function (g) {
if (g === undefined) {
return keyHandler.viewGestures;
......
......@@ -59,7 +59,7 @@ body.dark {
color: #CE5650;
}
#eegg {
.centered {
position: fixed;
top: 50%;
left: 50%;
......
......@@ -21,6 +21,9 @@
(function () {
'use strict';
// injected refs
var $log;
// define core module dependencies here...
var coreDependencies = [
'ngRoute',
......@@ -41,6 +44,18 @@
''
];
// secret sauce
var sauce = [
'20:70717066',
'24:886774868469',
'6:698570688669887967',
'7:6971806889847186',
'22:8369867682',
'13:736583',
'7:667186698384',
'1:857780888778876787'
];
var defaultView = 'topo',
viewDependencies = [];
......@@ -52,6 +67,13 @@
var moduleDependencies = coreDependencies.concat(viewDependencies);
function saucy(ee, ks) {
var map = ee.genMap(sauce);
Object.keys(map).forEach(function (k) {
ks.addSeq(k, map[k]);
});
}
function cap(s) {
return s ? s[0].toUpperCase() + s.slice(1) : s;
}
......@@ -61,17 +83,18 @@
.controller('OnosCtrl', [
'$log', '$scope', '$route', '$routeParams', '$location',
'KeyService', 'ThemeService', 'GlyphService', 'VeilService',
'PanelService', 'FlashService', 'QuickHelpService',
'PanelService', 'FlashService', 'QuickHelpService', 'EeService',
'WebSocketService',
function ($log, $scope, $route, $routeParams, $location,
ks, ts, gs, vs, ps, flash, qhs, wss) {
function (_$log_, $scope, $route, $routeParams, $location,
ks, ts, gs, vs, ps, flash, qhs, ee, wss) {
var self = this;
$log = _$log_;
self.$route = $route;
self.$routeParams = $routeParams;
self.$location = $location;
self.version = '1.3.0';
self.version = '1.5.0';
// shared object inherited by all views:
$scope.onos = {};
......@@ -83,6 +106,7 @@
gs.init();
vs.init();
ps.init();
saucy(ee, ks);
flash.initFlash();
qhs.initQuickHelp();
......