blob: 387c95b39f644c4dd68202cd8bc86e7d777771e9 [file] [log] [blame]
Simon Hunt94104e72017-06-13 11:38:55 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Simon Hunt94104e72017-06-13 11:38:55 -07003 *
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 Hunt94104e72017-06-13 11:38:55 -070019 ONOS GUI -- Lion -- Localization Utilities
20 */
21(function () {
22 'use strict';
23
Simon Huntc1656ed2017-06-21 16:47:04 -070024 // injected services
Steven Burrows1c2a9682017-07-14 16:52:46 +010025 var $log, wss;
Simon Hunt94104e72017-06-13 11:38:55 -070026
Simon Huntc1656ed2017-06-21 16:47:04 -070027 // private state
28 var handlers = {
Steven Burrows1c2a9682017-07-14 16:52:46 +010029 uberlion: uberlion,
Simon Huntc1656ed2017-06-21 16:47:04 -070030 },
31 ubercache = {};
Simon Hunt94104e72017-06-13 11:38:55 -070032
Simon Huntc1656ed2017-06-21 16:47:04 -070033 // handler for uberlion event..
34 function uberlion(data) {
Simon Huntc1656ed2017-06-21 16:47:04 -070035 ubercache = data.lion;
Simon Hunt1f4365d2017-06-21 17:25:09 -070036
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 Huntc1656ed2017-06-21 16:47:04 -070047 }
Simon Hunte556e942017-06-19 15:35:44 -070048
Simon Huntc1656ed2017-06-21 16:47:04 -070049 function init() {
50 wss.bindHandlers(handlers);
51 }
Simon Hunte556e942017-06-19 15:35:44 -070052
Simon Huntc1656ed2017-06-21 16:47:04 -070053 // returns a lion bundle (function) for the given bundle ID
54 function bundle(bundleId) {
55 var bundle = ubercache[bundleId];
Simon Hunte556e942017-06-19 15:35:44 -070056
Simon Huntc1656ed2017-06-21 16:47:04 -070057 if (!bundle) {
58 $log.warn('No lion bundle registered:', bundleId);
59 bundle = {};
Simon Hunt083e6fb2017-06-16 16:51:41 -070060 }
61
Simon Hunt083e6fb2017-06-16 16:51:41 -070062 return function (key) {
63 return bundle[key] || '%' + key + '%';
64 };
Simon Hunt94104e72017-06-13 11:38:55 -070065 }
66
67 angular.module('onosUtil')
Steven Burrows1c2a9682017-07-14 16:52:46 +010068 .factory('LionService', ['$log', 'WebSocketService',
Simon Hunt94104e72017-06-13 11:38:55 -070069
Steven Burrows1c2a9682017-07-14 16:52:46 +010070 function (_$log_, _wss_) {
Simon Hunt94104e72017-06-13 11:38:55 -070071 $log = _$log_;
Simon Huntc1656ed2017-06-21 16:47:04 -070072 wss = _wss_;
Simon Hunt94104e72017-06-13 11:38:55 -070073
74 return {
Simon Huntc1656ed2017-06-21 16:47:04 -070075 init: init,
Steven Burrows1c2a9682017-07-14 16:52:46 +010076 bundle: bundle,
Simon Hunt94104e72017-06-13 11:38:55 -070077 };
78 }]);
79}());