blob: 2ead7c2ccd1aabc30e4fb0255819a64997acbd09 [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',
Simon Hunt5c3ed732017-07-20 19:03:28 +000040 'hwdoc'
Simon Huntb8d37982016-08-22 21:29:55 -070041 // Add more beans...
Simon Huntf4ef6dd2016-02-03 17:05:14 -080042 ];
43
44 function pickBean() {
45 return beans[Math.floor(Math.random() * beans.length)] + '.foo';
46 }
47
Simon Huntf0eb2172016-01-26 18:54:21 -080048 function computeTransform(x) {
49 var m = x.split(':'),
50 h = Number(m[0]),
51 d = m[1],
52 n = d.length,
53 w = [],
54 i;
55
56 for (i = 0; i<n; i+=2)
Simon Hunt5c3ed732017-07-20 19:03:28 +000057 w.push(fcc(Number(d.slice(i, i+2))));
Simon Huntf0eb2172016-01-26 18:54:21 -080058
59 return fs.eecode(h, w.join(''));
60 }
61
62 function genMap(data) {
63 var map = {};
64
65 data.forEach(function (x) {
66 var r = computeTransform(x);
Simon Huntf4ef6dd2016-02-03 17:05:14 -080067 map[r.e] = r.o.toLowerCase() + '.foo';
Simon Huntf0eb2172016-01-26 18:54:21 -080068 });
69 return map;
70 }
71
Simon Huntf4ef6dd2016-02-03 17:05:14 -080072 function cluck(foo) {
73 var f = fs.isF(foo),
74 s = fs.isS(foo);
Simon Huntf0eb2172016-01-26 18:54:21 -080075
Simon Huntf4ef6dd2016-02-03 17:05:14 -080076 $log.debug('>>> CLUCK! <<<', foo);
77
78 if (s === 'fgfb.foo') {
79 s = pickBean();
80 $log.debug('bean picked:', s);
Simon Huntf0eb2172016-01-26 18:54:21 -080081 }
Simon Huntf4ef6dd2016-02-03 17:05:14 -080082
83 if (s && fs.endsWith(s, '.foo')) {
84 flash.tempDiv().append('img').attr('src', 'raw/'+s);
85 }
86
87 f && f();
88 }
89
90 angular.module('onosUtil')
91 .factory('EeService', ['$log', 'FnService', 'FlashService',
92 function (_$log_, _fs_, _flash_) {
93 $log = _$log_;
94 fs = _fs_;
95 flash = _flash_;
96
97 return {
98 genMap: genMap,
Simon Hunt5c3ed732017-07-20 19:03:28 +000099 cluck: cluck
100 }
Simon Huntf4ef6dd2016-02-03 17:05:14 -0800101 }]);
Simon Huntf0eb2172016-01-26 18:54:21 -0800102}());