Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [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 | /* |
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 |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 25 | var $log, 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 = { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 29 | uberlion: uberlion, |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame] | 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) { |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame] | 35 | ubercache = data.lion; |
Simon Hunt | 1f4365d | 2017-06-21 17:25:09 -0700 | [diff] [blame] | 36 | |
| 37 | $log.info('LION service: Locale... [' + data.locale + ']'); |
| 38 | $log.info('LION service: Bundles installed...'); |
| 39 | |
| 40 | for (var p in ubercache) { |
| 41 | if (ubercache.hasOwnProperty(p)) { |
| 42 | $log.info(' :=> ', p); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | $log.debug('LION service: uber-lion bundle received:', data); |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame] | 47 | } |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 48 | |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame] | 49 | function init() { |
| 50 | wss.bindHandlers(handlers); |
| 51 | } |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 52 | |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame] | 53 | // returns a lion bundle (function) for the given bundle ID |
| 54 | function bundle(bundleId) { |
| 55 | var bundle = ubercache[bundleId]; |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 56 | |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame] | 57 | if (!bundle) { |
| 58 | $log.warn('No lion bundle registered:', bundleId); |
| 59 | bundle = {}; |
Simon Hunt | 083e6fb | 2017-06-16 16:51:41 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Simon Hunt | 083e6fb | 2017-06-16 16:51:41 -0700 | [diff] [blame] | 62 | return function (key) { |
| 63 | return bundle[key] || '%' + key + '%'; |
| 64 | }; |
Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | angular.module('onosUtil') |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 68 | .factory('LionService', ['$log', 'WebSocketService', |
Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [diff] [blame] | 69 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 70 | function (_$log_, _wss_) { |
Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [diff] [blame] | 71 | $log = _$log_; |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame] | 72 | wss = _wss_; |
Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [diff] [blame] | 73 | |
| 74 | return { |
Simon Hunt | c1656ed | 2017-06-21 16:47:04 -0700 | [diff] [blame] | 75 | init: init, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 76 | bundle: bundle, |
Simon Hunt | 94104e7 | 2017-06-13 11:38:55 -0700 | [diff] [blame] | 77 | }; |
| 78 | }]); |
| 79 | }()); |