blob: f57136a1aefe2b05909fc2118540ba0e82818072 [file] [log] [blame]
Simon Huntf0eb2172016-01-26 18:54:21 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -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 Vachuska9e4bf032017-08-01 10:05:09 -070040 'hwdoc',
41 'acxefcsdgt',
Steven Burrows1c2a9682017-07-14 16:52:46 +010042 'pmmn',
Thomas Vachuska9ad62602018-04-04 18:09:20 -070043 'ugaryc',
44 'xcedrcxekzg'
Simon Huntb8d37982016-08-22 21:29:55 -070045 // Add more beans...
Simon Huntf4ef6dd2016-02-03 17:05:14 -080046 ];
47
48 function pickBean() {
49 return beans[Math.floor(Math.random() * beans.length)] + '.foo';
50 }
51
Simon Huntf0eb2172016-01-26 18:54:21 -080052 function computeTransform(x) {
53 var m = x.split(':'),
54 h = Number(m[0]),
55 d = m[1],
56 n = d.length,
57 w = [],
58 i;
59
60 for (i = 0; i<n; i+=2)
Steven Burrows1c2a9682017-07-14 16:52:46 +010061 { w.push(fcc(Number(d.slice(i, i+2)))); }
Simon Huntf0eb2172016-01-26 18:54:21 -080062
63 return fs.eecode(h, w.join(''));
64 }
65
66 function genMap(data) {
67 var map = {};
68
69 data.forEach(function (x) {
70 var r = computeTransform(x);
Simon Huntf4ef6dd2016-02-03 17:05:14 -080071 map[r.e] = r.o.toLowerCase() + '.foo';
Simon Huntf0eb2172016-01-26 18:54:21 -080072 });
73 return map;
74 }
75
Simon Huntf4ef6dd2016-02-03 17:05:14 -080076 function cluck(foo) {
77 var f = fs.isF(foo),
78 s = fs.isS(foo);
Simon Huntf0eb2172016-01-26 18:54:21 -080079
Simon Huntf4ef6dd2016-02-03 17:05:14 -080080 $log.debug('>>> CLUCK! <<<', foo);
81
82 if (s === 'fgfb.foo') {
83 s = pickBean();
84 $log.debug('bean picked:', s);
Simon Huntf0eb2172016-01-26 18:54:21 -080085 }
Simon Huntf4ef6dd2016-02-03 17:05:14 -080086
87 if (s && fs.endsWith(s, '.foo')) {
88 flash.tempDiv().append('img').attr('src', 'raw/'+s);
89 }
90
91 f && f();
92 }
93
94 angular.module('onosUtil')
95 .factory('EeService', ['$log', 'FnService', 'FlashService',
96 function (_$log_, _fs_, _flash_) {
97 $log = _$log_;
98 fs = _fs_;
99 flash = _flash_;
100
101 return {
102 genMap: genMap,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100103 cluck: cluck,
104 };
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800105 }]);
Simon Huntf0eb2172016-01-26 18:54:21 -0800106}());