blob: ec3531bdd3f6925318c434998f53b1a475d79667 [file] [log] [blame]
Simon Hunt94104e72017-06-13 11:38:55 -07001/*
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 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
25 var $log, fs, wss;
Simon Hunt94104e72017-06-13 11:38:55 -070026
Simon Huntc1656ed2017-06-21 16:47:04 -070027 // private state
28 var handlers = {
29 uberlion: uberlion
30 },
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')
Simon Huntc1656ed2017-06-21 16:47:04 -070068 .factory('LionService', ['$log', 'FnService', 'WebSocketService',
Simon Hunt94104e72017-06-13 11:38:55 -070069
Simon Huntc1656ed2017-06-21 16:47:04 -070070 function (_$log_, _fs_, _wss_) {
Simon Hunt94104e72017-06-13 11:38:55 -070071 $log = _$log_;
72 fs = _fs_;
Simon Huntc1656ed2017-06-21 16:47:04 -070073 wss = _wss_;
Simon Hunt94104e72017-06-13 11:38:55 -070074
75 return {
Simon Huntc1656ed2017-06-21 16:47:04 -070076 init: init,
Simon Hunt94104e72017-06-13 11:38:55 -070077 bundle: bundle
78 };
79 }]);
80}());