Simon Hunt
Committed by Gerrit Code Review

GUI: Javascript cleanup and additional utility functions.

Change-Id: Ia16dd7eecedfd116e9d0a65d60d724657e87b8d3
...@@ -143,6 +143,13 @@ ...@@ -143,6 +143,13 @@
143 enabled = !!b; 143 enabled = !!b;
144 } 144 }
145 145
146 + function tempDiv(ms) {
147 + var div = d3.select('body').append('div').classed('centered', true),
148 + delay = (ms === undefined || ms < 100) ? 3000 : ms;
149 + $timeout(function () { div.remove(); }, delay);
150 + return div;
151 + }
152 +
146 angular.module('onosLayer') 153 angular.module('onosLayer')
147 .factory('FlashService', ['$log', '$timeout', 154 .factory('FlashService', ['$log', '$timeout',
148 function (_$log_, _$timeout_) { 155 function (_$log_, _$timeout_) {
...@@ -158,7 +165,8 @@ ...@@ -158,7 +165,8 @@
158 return { 165 return {
159 initFlash: initFlash, 166 initFlash: initFlash,
160 flash: flash, 167 flash: flash,
161 - enable: enable 168 + enable: enable,
169 + tempDiv: tempDiv
162 }; 170 };
163 }]); 171 }]);
164 172
......
This diff is collapsed. Click to expand it.
...@@ -21,11 +21,26 @@ ...@@ -21,11 +21,26 @@
21 'use strict'; 21 'use strict';
22 22
23 // injected services 23 // injected services
24 - var fs; 24 + var $log, fs, flash;
25 25
26 // function references 26 // function references
27 var fcc = String.fromCharCode; 27 var fcc = String.fromCharCode;
28 28
29 + // magic beans
30 + var beans = [
31 + //'umpxwnwcw'
32 + //'eufdvexoc',
33 + //'egpdytgv',
34 + //'xcjvte',
35 + //'bgvest',
36 + //'sevlr',
37 + 'ias'
38 + ];
39 +
40 + function pickBean() {
41 + return beans[Math.floor(Math.random() * beans.length)] + '.foo';
42 + }
43 +
29 function computeTransform(x) { 44 function computeTransform(x) {
30 var m = x.split(':'), 45 var m = x.split(':'),
31 h = Number(m[0]), 46 h = Number(m[0]),
...@@ -45,18 +60,39 @@ ...@@ -45,18 +60,39 @@
45 60
46 data.forEach(function (x) { 61 data.forEach(function (x) {
47 var r = computeTransform(x); 62 var r = computeTransform(x);
48 - map['shift' + r.e] = r.o.toLowerCase() + '.bin'; 63 + map[r.e] = r.o.toLowerCase() + '.foo';
49 }); 64 });
50 return map; 65 return map;
51 } 66 }
52 67
53 - angular.module('onosUtil') 68 + function cluck(foo) {
54 - .factory('EeService', 69 + var f = fs.isF(foo),
55 - ['FnService', function (_fs_) { 70 + s = fs.isS(foo);
56 - fs = _fs_; 71 +
72 + $log.debug('>>> CLUCK! <<<', foo);
73 +
74 + if (s === 'fgfb.foo') {
75 + s = pickBean();
76 + $log.debug('bean picked:', s);
77 + }
57 78
58 - return { 79 + if (s && fs.endsWith(s, '.foo')) {
59 - genMap: genMap 80 + flash.tempDiv().append('img').attr('src', 'raw/'+s);
60 } 81 }
61 - }]); 82 +
83 + f && f();
84 + }
85 +
86 + angular.module('onosUtil')
87 + .factory('EeService', ['$log', 'FnService', 'FlashService',
88 + function (_$log_, _fs_, _flash_) {
89 + $log = _$log_;
90 + fs = _fs_;
91 + flash = _flash_;
92 +
93 + return {
94 + genMap: genMap,
95 + cluck: cluck
96 + }
97 + }]);
62 }()); 98 }());
......
...@@ -21,11 +21,7 @@ ...@@ -21,11 +21,7 @@
21 'use strict'; 21 'use strict';
22 22
23 // references to injected services 23 // references to injected services
24 - var $log, $timeout, fs, ts, ns, qhs; 24 + var $log, $timeout, fs, ts, ns, ee, qhs;
25 -
26 - // constants
27 - var eeggMin = 'shiftO',
28 - eeggMax = 'shiftONOS';
29 25
30 // internal state 26 // internal state
31 var enabled = true, 27 var enabled = true,
...@@ -37,23 +33,30 @@ ...@@ -37,23 +33,30 @@
37 viewFn: null, 33 viewFn: null,
38 viewGestures: [] 34 viewGestures: []
39 }, 35 },
40 - eegg = ''; 36 + seq = {},
37 + matching = false,
38 + matched = '',
39 + lookup;
41 40
42 - function layEgg(key) { 41 + function matchSeq(key) {
43 - eegg += key; 42 + if (!matching && key === 'shift') {
44 - if (eeggMax.indexOf(eegg) === 0) { 43 + matching = true;
45 - if (eegg === eeggMax) {
46 - d3.select('body').append('div').attr('id', 'eegg')
47 - .append('img').attr('src', 'raw/ewo.foo');
48 - $timeout(function () { d3.select('#eegg').remove(); }, 3000);
49 - eegg = '';
50 - }
51 return true; 44 return true;
52 } 45 }
53 - if (eegg !== eeggMin) { 46 + if (matching) {
54 - eegg = ''; 47 + matched += key;
48 + lookup = fs.trieLookup(seq, matched);
49 + if (lookup === -1) {
50 + return true;
51 + }
52 + matching = false;
53 + matched = '';
54 + if (!lookup) {
55 + return;
56 + }
57 + ee.cluck(lookup);
58 + return true;
55 } 59 }
56 - return false;
57 } 60 }
58 61
59 function whatKey(code) { 62 function whatKey(code) {
...@@ -109,7 +112,7 @@ ...@@ -109,7 +112,7 @@
109 d3.event.stopPropagation(); 112 d3.event.stopPropagation();
110 113
111 if (enabled) { 114 if (enabled) {
112 - if (layEgg(key)) return; 115 + if (matchSeq(key)) return;
113 116
114 // global callback? 117 // global callback?
115 if (gcb && gcb(token, key, keyCode, event)) { 118 if (gcb && gcb(token, key, keyCode, event)) {
...@@ -230,13 +233,15 @@ ...@@ -230,13 +233,15 @@
230 angular.module('onosUtil') 233 angular.module('onosUtil')
231 .factory('KeyService', 234 .factory('KeyService',
232 ['$log', '$timeout', 'FnService', 'ThemeService', 'NavService', 235 ['$log', '$timeout', 'FnService', 'ThemeService', 'NavService',
236 + 'EeService',
233 237
234 - function (_$log_, _$timeout_, _fs_, _ts_, _ns_) { 238 + function (_$log_, _$timeout_, _fs_, _ts_, _ns_, _ee_) {
235 $log = _$log_; 239 $log = _$log_;
236 $timeout = _$timeout_; 240 $timeout = _$timeout_;
237 fs = _fs_; 241 fs = _fs_;
238 ts = _ts_; 242 ts = _ts_;
239 ns = _ns_; 243 ns = _ns_;
244 + ee = _ee_;
240 245
241 return { 246 return {
242 bindQhs: function (_qhs_) { 247 bindQhs: function (_qhs_) {
...@@ -254,6 +259,12 @@ ...@@ -254,6 +259,12 @@
254 } 259 }
255 }, 260 },
256 unbindKeys: unbindKeys, 261 unbindKeys: unbindKeys,
262 + addSeq: function (word, data) {
263 + fs.addToTrie(seq, word, data);
264 + },
265 + remSeq: function (word) {
266 + fs.removeFromTrie(seq, word);
267 + },
257 gestureNotes: function (g) { 268 gestureNotes: function (g) {
258 if (g === undefined) { 269 if (g === undefined) {
259 return keyHandler.viewGestures; 270 return keyHandler.viewGestures;
......
...@@ -59,7 +59,7 @@ body.dark { ...@@ -59,7 +59,7 @@ body.dark {
59 color: #CE5650; 59 color: #CE5650;
60 } 60 }
61 61
62 -#eegg { 62 +.centered {
63 position: fixed; 63 position: fixed;
64 top: 50%; 64 top: 50%;
65 left: 50%; 65 left: 50%;
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
21 (function () { 21 (function () {
22 'use strict'; 22 'use strict';
23 23
24 + // injected refs
25 + var $log;
26 +
24 // define core module dependencies here... 27 // define core module dependencies here...
25 var coreDependencies = [ 28 var coreDependencies = [
26 'ngRoute', 29 'ngRoute',
...@@ -41,6 +44,18 @@ ...@@ -41,6 +44,18 @@
41 '' 44 ''
42 ]; 45 ];
43 46
47 + // secret sauce
48 + var sauce = [
49 + '20:70717066',
50 + '24:886774868469',
51 + '6:698570688669887967',
52 + '7:6971806889847186',
53 + '22:8369867682',
54 + '13:736583',
55 + '7:667186698384',
56 + '1:857780888778876787'
57 + ];
58 +
44 var defaultView = 'topo', 59 var defaultView = 'topo',
45 viewDependencies = []; 60 viewDependencies = [];
46 61
...@@ -52,6 +67,13 @@ ...@@ -52,6 +67,13 @@
52 67
53 var moduleDependencies = coreDependencies.concat(viewDependencies); 68 var moduleDependencies = coreDependencies.concat(viewDependencies);
54 69
70 + function saucy(ee, ks) {
71 + var map = ee.genMap(sauce);
72 + Object.keys(map).forEach(function (k) {
73 + ks.addSeq(k, map[k]);
74 + });
75 + }
76 +
55 function cap(s) { 77 function cap(s) {
56 return s ? s[0].toUpperCase() + s.slice(1) : s; 78 return s ? s[0].toUpperCase() + s.slice(1) : s;
57 } 79 }
...@@ -61,17 +83,18 @@ ...@@ -61,17 +83,18 @@
61 .controller('OnosCtrl', [ 83 .controller('OnosCtrl', [
62 '$log', '$scope', '$route', '$routeParams', '$location', 84 '$log', '$scope', '$route', '$routeParams', '$location',
63 'KeyService', 'ThemeService', 'GlyphService', 'VeilService', 85 'KeyService', 'ThemeService', 'GlyphService', 'VeilService',
64 - 'PanelService', 'FlashService', 'QuickHelpService', 86 + 'PanelService', 'FlashService', 'QuickHelpService', 'EeService',
65 'WebSocketService', 87 'WebSocketService',
66 88
67 - function ($log, $scope, $route, $routeParams, $location, 89 + function (_$log_, $scope, $route, $routeParams, $location,
68 - ks, ts, gs, vs, ps, flash, qhs, wss) { 90 + ks, ts, gs, vs, ps, flash, qhs, ee, wss) {
69 var self = this; 91 var self = this;
92 + $log = _$log_;
70 93
71 self.$route = $route; 94 self.$route = $route;
72 self.$routeParams = $routeParams; 95 self.$routeParams = $routeParams;
73 self.$location = $location; 96 self.$location = $location;
74 - self.version = '1.3.0'; 97 + self.version = '1.5.0';
75 98
76 // shared object inherited by all views: 99 // shared object inherited by all views:
77 $scope.onos = {}; 100 $scope.onos = {};
...@@ -83,6 +106,7 @@ ...@@ -83,6 +106,7 @@
83 gs.init(); 106 gs.init();
84 vs.init(); 107 vs.init();
85 ps.init(); 108 ps.init();
109 + saucy(ee, ks);
86 flash.initFlash(); 110 flash.initFlash();
87 qhs.initQuickHelp(); 111 qhs.initQuickHelp();
88 112
......