Simon Hunt | f0eb217 | 2016-01-26 18:54:21 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Simon Hunt | f0eb217 | 2016-01-26 18:54:21 -0800 | [diff] [blame] | 3 | * |
| 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 Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 24 | var $log, fs, flash; |
Simon Hunt | f0eb217 | 2016-01-26 18:54:21 -0800 | [diff] [blame] | 25 | |
| 26 | // function references |
| 27 | var fcc = String.fromCharCode; |
| 28 | |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 29 | // magic beans |
| 30 | var beans = [ |
Simon Hunt | c4f320a | 2016-02-09 18:25:33 -0800 | [diff] [blame] | 31 | 'umpxwnwcw', |
| 32 | 'eufdvexoc', |
| 33 | 'egpdytgv', |
| 34 | 'xcjvte', |
| 35 | 'bgvest', |
| 36 | 'sevlr', |
Simon Hunt | b8d3798 | 2016-08-22 21:29:55 -0700 | [diff] [blame] | 37 | 'ias', |
Viswanath KSP | 0cf084b | 2016-11-19 18:17:55 +0530 | [diff] [blame] | 38 | 'jweeidkpizn', |
Viswanath KSP | 539427f | 2016-12-21 19:08:08 +0530 | [diff] [blame] | 39 | 'fmfv', |
Thomas Vachuska | 9e4bf03 | 2017-08-01 10:05:09 -0700 | [diff] [blame] | 40 | 'hwdoc', |
| 41 | 'acxefcsdgt', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 42 | 'pmmn', |
Thomas Vachuska | 9ad6260 | 2018-04-04 18:09:20 -0700 | [diff] [blame] | 43 | 'ugaryc', |
Thomas Vachuska | 25ffa03 | 2018-08-08 17:27:33 -0700 | [diff] [blame] | 44 | 'xcedrcxekzg', |
| 45 | 'qit' |
Simon Hunt | b8d3798 | 2016-08-22 21:29:55 -0700 | [diff] [blame] | 46 | // Add more beans... |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 47 | ]; |
| 48 | |
| 49 | function pickBean() { |
| 50 | return beans[Math.floor(Math.random() * beans.length)] + '.foo'; |
| 51 | } |
| 52 | |
Simon Hunt | f0eb217 | 2016-01-26 18:54:21 -0800 | [diff] [blame] | 53 | function computeTransform(x) { |
| 54 | var m = x.split(':'), |
| 55 | h = Number(m[0]), |
| 56 | d = m[1], |
| 57 | n = d.length, |
| 58 | w = [], |
| 59 | i; |
| 60 | |
| 61 | for (i = 0; i<n; i+=2) |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 62 | { w.push(fcc(Number(d.slice(i, i+2)))); } |
Simon Hunt | f0eb217 | 2016-01-26 18:54:21 -0800 | [diff] [blame] | 63 | |
| 64 | return fs.eecode(h, w.join('')); |
| 65 | } |
| 66 | |
| 67 | function genMap(data) { |
| 68 | var map = {}; |
| 69 | |
| 70 | data.forEach(function (x) { |
| 71 | var r = computeTransform(x); |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 72 | map[r.e] = r.o.toLowerCase() + '.foo'; |
Simon Hunt | f0eb217 | 2016-01-26 18:54:21 -0800 | [diff] [blame] | 73 | }); |
| 74 | return map; |
| 75 | } |
| 76 | |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 77 | function cluck(foo) { |
| 78 | var f = fs.isF(foo), |
| 79 | s = fs.isS(foo); |
Simon Hunt | f0eb217 | 2016-01-26 18:54:21 -0800 | [diff] [blame] | 80 | |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 81 | $log.debug('>>> CLUCK! <<<', foo); |
| 82 | |
| 83 | if (s === 'fgfb.foo') { |
| 84 | s = pickBean(); |
| 85 | $log.debug('bean picked:', s); |
Simon Hunt | f0eb217 | 2016-01-26 18:54:21 -0800 | [diff] [blame] | 86 | } |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 87 | |
| 88 | if (s && fs.endsWith(s, '.foo')) { |
| 89 | flash.tempDiv().append('img').attr('src', 'raw/'+s); |
| 90 | } |
| 91 | |
| 92 | f && f(); |
| 93 | } |
| 94 | |
| 95 | angular.module('onosUtil') |
| 96 | .factory('EeService', ['$log', 'FnService', 'FlashService', |
| 97 | function (_$log_, _fs_, _flash_) { |
| 98 | $log = _$log_; |
| 99 | fs = _fs_; |
| 100 | flash = _flash_; |
| 101 | |
| 102 | return { |
| 103 | genMap: genMap, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 104 | cluck: cluck, |
| 105 | }; |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 106 | }]); |
Simon Hunt | f0eb217 | 2016-01-26 18:54:21 -0800 | [diff] [blame] | 107 | }()); |