blob: 9f43e8c76e8d295a897fb5f70b37a468b342dc79 [file] [log] [blame]
Simon Huntf0eb2172016-01-26 18:54:21 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
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 Vachuska9e4bf032017-08-01 10:05:09 -070040 'hwdoc',
41 'acxefcsdgt',
42 'pmmn'
Simon Huntb8d37982016-08-22 21:29:55 -070043 // Add more beans...
Simon Huntf4ef6dd2016-02-03 17:05:14 -080044 ];
45
46 function pickBean() {
47 return beans[Math.floor(Math.random() * beans.length)] + '.foo';
48 }
49
Simon Huntf0eb2172016-01-26 18:54:21 -080050 function computeTransform(x) {
51 var m = x.split(':'),
52 h = Number(m[0]),
53 d = m[1],
54 n = d.length,
55 w = [],
56 i;
57
58 for (i = 0; i<n; i+=2)
Simon Hunt5c3ed732017-07-20 19:03:28 +000059 w.push(fcc(Number(d.slice(i, i+2))));
Simon Huntf0eb2172016-01-26 18:54:21 -080060
61 return fs.eecode(h, w.join(''));
62 }
63
64 function genMap(data) {
65 var map = {};
66
67 data.forEach(function (x) {
68 var r = computeTransform(x);
Simon Huntf4ef6dd2016-02-03 17:05:14 -080069 map[r.e] = r.o.toLowerCase() + '.foo';
Simon Huntf0eb2172016-01-26 18:54:21 -080070 });
71 return map;
72 }
73
Simon Huntf4ef6dd2016-02-03 17:05:14 -080074 function cluck(foo) {
75 var f = fs.isF(foo),
76 s = fs.isS(foo);
Simon Huntf0eb2172016-01-26 18:54:21 -080077
Simon Huntf4ef6dd2016-02-03 17:05:14 -080078 $log.debug('>>> CLUCK! <<<', foo);
79
80 if (s === 'fgfb.foo') {
81 s = pickBean();
82 $log.debug('bean picked:', s);
Simon Huntf0eb2172016-01-26 18:54:21 -080083 }
Simon Huntf4ef6dd2016-02-03 17:05:14 -080084
85 if (s && fs.endsWith(s, '.foo')) {
86 flash.tempDiv().append('img').attr('src', 'raw/'+s);
87 }
88
89 f && f();
90 }
91
92 angular.module('onosUtil')
93 .factory('EeService', ['$log', 'FnService', 'FlashService',
94 function (_$log_, _fs_, _flash_) {
95 $log = _$log_;
96 fs = _fs_;
97 flash = _flash_;
98
99 return {
100 genMap: genMap,
Simon Hunt5c3ed732017-07-20 19:03:28 +0000101 cluck: cluck
102 }
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800103 }]);
Simon Huntf0eb2172016-01-26 18:54:21 -0800104}());