Simon Hunt | f0eb217 | 2016-01-26 18:54:21 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
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', |
| 38 | 'jweeidkpizn' |
| 39 | // Add more beans... |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 40 | ]; |
| 41 | |
| 42 | function pickBean() { |
| 43 | return beans[Math.floor(Math.random() * beans.length)] + '.foo'; |
| 44 | } |
| 45 | |
Simon Hunt | f0eb217 | 2016-01-26 18:54:21 -0800 | [diff] [blame] | 46 | function computeTransform(x) { |
| 47 | var m = x.split(':'), |
| 48 | h = Number(m[0]), |
| 49 | d = m[1], |
| 50 | n = d.length, |
| 51 | w = [], |
| 52 | i; |
| 53 | |
| 54 | for (i = 0; i<n; i+=2) |
| 55 | w.push(fcc(Number(d.slice(i, i+2)))); |
| 56 | |
| 57 | return fs.eecode(h, w.join('')); |
| 58 | } |
| 59 | |
| 60 | function genMap(data) { |
| 61 | var map = {}; |
| 62 | |
| 63 | data.forEach(function (x) { |
| 64 | var r = computeTransform(x); |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 65 | map[r.e] = r.o.toLowerCase() + '.foo'; |
Simon Hunt | f0eb217 | 2016-01-26 18:54:21 -0800 | [diff] [blame] | 66 | }); |
| 67 | return map; |
| 68 | } |
| 69 | |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 70 | function cluck(foo) { |
| 71 | var f = fs.isF(foo), |
| 72 | s = fs.isS(foo); |
Simon Hunt | f0eb217 | 2016-01-26 18:54:21 -0800 | [diff] [blame] | 73 | |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 74 | $log.debug('>>> CLUCK! <<<', foo); |
| 75 | |
| 76 | if (s === 'fgfb.foo') { |
| 77 | s = pickBean(); |
| 78 | $log.debug('bean picked:', s); |
Simon Hunt | f0eb217 | 2016-01-26 18:54:21 -0800 | [diff] [blame] | 79 | } |
Simon Hunt | f4ef6dd | 2016-02-03 17:05:14 -0800 | [diff] [blame] | 80 | |
| 81 | if (s && fs.endsWith(s, '.foo')) { |
| 82 | flash.tempDiv().append('img').attr('src', 'raw/'+s); |
| 83 | } |
| 84 | |
| 85 | f && f(); |
| 86 | } |
| 87 | |
| 88 | angular.module('onosUtil') |
| 89 | .factory('EeService', ['$log', 'FnService', 'FlashService', |
| 90 | function (_$log_, _fs_, _flash_) { |
| 91 | $log = _$log_; |
| 92 | fs = _fs_; |
| 93 | flash = _flash_; |
| 94 | |
| 95 | return { |
| 96 | genMap: genMap, |
| 97 | cluck: cluck |
| 98 | } |
| 99 | }]); |
Simon Hunt | f0eb217 | 2016-01-26 18:54:21 -0800 | [diff] [blame] | 100 | }()); |