Committed by
Gerrit Code Review
GUI: Javascript cleanup and additional utility functions.
Change-Id: Ia16dd7eecedfd116e9d0a65d60d724657e87b8d3
Showing
7 changed files
with
124 additions
and
43 deletions
... | @@ -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 | ... | ... |
... | @@ -28,12 +28,6 @@ | ... | @@ -28,12 +28,6 @@ |
28 | // injected references | 28 | // injected references |
29 | var $log, fs; | 29 | var $log, fs; |
30 | 30 | ||
31 | - angular.module('onosSvg') | ||
32 | - .factory('SvgUtilService', ['$log', 'FnService', | ||
33 | - function (_$log_, _fs_) { | ||
34 | - $log = _$log_; | ||
35 | - fs = _fs_; | ||
36 | - | ||
37 | // TODO: change 'force' ref to be 'force.alpha' ref. | 31 | // TODO: change 'force' ref to be 'force.alpha' ref. |
38 | function createDragBehavior(force, selectCb, atDragEnd, | 32 | function createDragBehavior(force, selectCb, atDragEnd, |
39 | dragEnabled, clickEnabled) { | 33 | dragEnabled, clickEnabled) { |
... | @@ -289,6 +283,20 @@ | ... | @@ -289,6 +283,20 @@ |
289 | return el.style('visibility') === 'visible'; | 283 | return el.style('visibility') === 'visible'; |
290 | } | 284 | } |
291 | 285 | ||
286 | + function visible(el, x) { | ||
287 | + if (x === undefined) { | ||
288 | + return isVisible(el); | ||
289 | + } else { | ||
290 | + makeVisible(el, x); | ||
291 | + } | ||
292 | + } | ||
293 | + | ||
294 | + angular.module('onosSvg') | ||
295 | + .factory('SvgUtilService', ['$log', 'FnService', | ||
296 | + function (_$log_, _fs_) { | ||
297 | + $log = _$log_; | ||
298 | + fs = _fs_; | ||
299 | + | ||
292 | return { | 300 | return { |
293 | createDragBehavior: createDragBehavior, | 301 | createDragBehavior: createDragBehavior, |
294 | loadGlowDefs: loadGlowDefs, | 302 | loadGlowDefs: loadGlowDefs, |
... | @@ -299,13 +307,7 @@ | ... | @@ -299,13 +307,7 @@ |
299 | rotate: rotate, | 307 | rotate: rotate, |
300 | stripPx: stripPx, | 308 | stripPx: stripPx, |
301 | safeId: safeId, | 309 | safeId: safeId, |
302 | - visible: function (el, x) { | 310 | + visible: visible |
303 | - if (x === undefined) { | ||
304 | - return isVisible(el); | ||
305 | - } else { | ||
306 | - makeVisible(el, x); | ||
307 | - } | ||
308 | - } | ||
309 | }; | 311 | }; |
310 | }]); | 312 | }]); |
311 | }()); | 313 | }()); | ... | ... |
... | @@ -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 | ||
68 | + function cluck(foo) { | ||
69 | + var f = fs.isF(foo), | ||
70 | + s = fs.isS(foo); | ||
71 | + | ||
72 | + $log.debug('>>> CLUCK! <<<', foo); | ||
73 | + | ||
74 | + if (s === 'fgfb.foo') { | ||
75 | + s = pickBean(); | ||
76 | + $log.debug('bean picked:', s); | ||
77 | + } | ||
78 | + | ||
79 | + if (s && fs.endsWith(s, '.foo')) { | ||
80 | + flash.tempDiv().append('img').attr('src', 'raw/'+s); | ||
81 | + } | ||
82 | + | ||
83 | + f && f(); | ||
84 | + } | ||
85 | + | ||
53 | angular.module('onosUtil') | 86 | angular.module('onosUtil') |
54 | - .factory('EeService', | 87 | + .factory('EeService', ['$log', 'FnService', 'FlashService', |
55 | - ['FnService', function (_fs_) { | 88 | + function (_$log_, _fs_, _flash_) { |
89 | + $log = _$log_; | ||
56 | fs = _fs_; | 90 | fs = _fs_; |
91 | + flash = _flash_; | ||
57 | 92 | ||
58 | return { | 93 | return { |
59 | - genMap: genMap | 94 | + genMap: genMap, |
95 | + cluck: cluck | ||
60 | } | 96 | } |
61 | }]); | 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) { | 44 | + return true; |
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 | } | 45 | } |
46 | + if (matching) { | ||
47 | + matched += key; | ||
48 | + lookup = fs.trieLookup(seq, matched); | ||
49 | + if (lookup === -1) { | ||
51 | return true; | 50 | return true; |
52 | } | 51 | } |
53 | - if (eegg !== eeggMin) { | 52 | + matching = false; |
54 | - eegg = ''; | 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; | ... | ... |
... | @@ -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 | ... | ... |
No preview for this file type
-
Please register or login to post a comment