Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 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 | /* |
Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [diff] [blame] | 19 | ONOS GUI -- Lion -- Localization Utilities |
| 20 | */ |
| 21 | (function () { |
| 22 | 'use strict'; |
| 23 | |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame^] | 24 | // injected services |
| 25 | var $log, fs, wss; |
Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [diff] [blame] | 26 | |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame^] | 27 | // private state |
| 28 | var handlers = { |
| 29 | uberlion: uberlion |
| 30 | }, |
| 31 | ubercache = {}; |
Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [diff] [blame] | 32 | |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame^] | 33 | // handler for uberlion event.. |
| 34 | function uberlion(data) { |
| 35 | $log.debug('LION service: uber-lion bundle received:', data); |
| 36 | ubercache = data.lion; |
| 37 | } |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 38 | |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame^] | 39 | function init() { |
| 40 | wss.bindHandlers(handlers); |
| 41 | } |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 42 | |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame^] | 43 | // returns a lion bundle (function) for the given bundle ID |
| 44 | function bundle(bundleId) { |
| 45 | var bundle = ubercache[bundleId]; |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 46 | |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame^] | 47 | if (!bundle) { |
| 48 | $log.warn('No lion bundle registered:', bundleId); |
| 49 | bundle = {}; |
Simon Hunt | 083e6fb | 2017-06-16 16:51:41 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Simon Hunt | 083e6fb | 2017-06-16 16:51:41 -0700 | [diff] [blame] | 52 | return function (key) { |
| 53 | return bundle[key] || '%' + key + '%'; |
| 54 | }; |
Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | angular.module('onosUtil') |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame^] | 58 | .factory('LionService', ['$log', 'FnService', 'WebSocketService', |
Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [diff] [blame] | 59 | |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame^] | 60 | function (_$log_, _fs_, _wss_) { |
Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [diff] [blame] | 61 | $log = _$log_; |
| 62 | fs = _fs_; |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame^] | 63 | wss = _wss_; |
Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [diff] [blame] | 64 | |
| 65 | return { |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame^] | 66 | init: init, |
Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [diff] [blame] | 67 | bundle: bundle |
| 68 | }; |
| 69 | }]); |
| 70 | }()); |