blob: b2ffb32b95b7f340e61e45b1c4f14d94ee1efb42 [file] [log] [blame]
Simon Huntf0eb2172016-01-26 18:54:21 -08001/*
Brian O'Connorce2a03d2017-08-03 19:21:03 -07002 * Copyright 2016-present Open Networking Foundation
Simon Huntf0eb2172016-01-26 18:54:21 -08003 *
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 -- Util -- EE functions
19 */
20(function () {
21 'use strict';
22
23 // injected services
Simon Huntf4ef6dd2016-02-03 17:05:14 -080024 var $log, fs, flash;
Simon Huntf0eb2172016-01-26 18:54:21 -080025
26 // function references
27 var fcc = String.fromCharCode;
28
Simon Huntf4ef6dd2016-02-03 17:05:14 -080029 // magic beans
30 var beans = [
Simon Huntc4f320a2016-02-09 18:25:33 -080031 'umpxwnwcw',
32 'eufdvexoc',
33 'egpdytgv',
34 'xcjvte',
35 'bgvest',
36 'sevlr',
Simon Huntb8d37982016-08-22 21:29:55 -070037 'ias',
Viswanath KSP0cf084b2016-11-19 18:17:55 +053038 'jweeidkpizn',
Viswanath KSP539427f2016-12-21 19:08:08 +053039 'fmfv',
Thomas Vachuska146e68f62017-08-01 14:08:04 -070040 'hwdoc',
41 'acxefcsdgt'
Simon Huntb8d37982016-08-22 21:29:55 -070042 // Add more beans...
Simon Huntf4ef6dd2016-02-03 17:05:14 -080043 ];
44
45 function pickBean() {
46 return beans[Math.floor(Math.random() * beans.length)] + '.foo';
47 }
48
Simon Huntf0eb2172016-01-26 18:54:21 -080049 function computeTransform(x) {
50 var m = x.split(':'),
51 h = Number(m[0]),
52 d = m[1],
53 n = d.length,
54 w = [],
55 i;
56
57 for (i = 0; i<n; i+=2)
58 w.push(fcc(Number(d.slice(i, i+2))));
59
60 return fs.eecode(h, w.join(''));
61 }
62
63 function genMap(data) {
64 var map = {};
65
66 data.forEach(function (x) {
67 var r = computeTransform(x);
Simon Huntf4ef6dd2016-02-03 17:05:14 -080068 map[r.e] = r.o.toLowerCase() + '.foo';
Simon Huntf0eb2172016-01-26 18:54:21 -080069 });
70 return map;
71 }
72
Simon Huntf4ef6dd2016-02-03 17:05:14 -080073 function cluck(foo) {
74 var f = fs.isF(foo),
75 s = fs.isS(foo);
Simon Huntf0eb2172016-01-26 18:54:21 -080076
Simon Huntf4ef6dd2016-02-03 17:05:14 -080077 $log.debug('>>> CLUCK! <<<', foo);
78
79 if (s === 'fgfb.foo') {
80 s = pickBean();
81 $log.debug('bean picked:', s);
Simon Huntf0eb2172016-01-26 18:54:21 -080082 }
Simon Huntf4ef6dd2016-02-03 17:05:14 -080083
84 if (s && fs.endsWith(s, '.foo')) {
85 flash.tempDiv().append('img').attr('src', 'raw/'+s);
86 }
87
88 f && f();
89 }
90
91 angular.module('onosUtil')
92 .factory('EeService', ['$log', 'FnService', 'FlashService',
93 function (_$log_, _fs_, _flash_) {
94 $log = _$log_;
95 fs = _fs_;
96 flash = _flash_;
97
98 return {
99 genMap: genMap,
100 cluck: cluck
101 }
102 }]);
Simon Huntf0eb2172016-01-26 18:54:21 -0800103}());