blob: f30f157c5848d1c0aa8f65ed9a8305798ddf7ca4 [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) {
35 $log.debug('LION service: uber-lion bundle received:', data);
36 ubercache = data.lion;
37 }
Simon Hunte556e942017-06-19 15:35:44 -070038
Simon Huntc1656ed2017-06-21 16:47:04 -070039 function init() {
40 wss.bindHandlers(handlers);
41 }
Simon Hunte556e942017-06-19 15:35:44 -070042
Simon Huntc1656ed2017-06-21 16:47:04 -070043 // returns a lion bundle (function) for the given bundle ID
44 function bundle(bundleId) {
45 var bundle = ubercache[bundleId];
Simon Hunte556e942017-06-19 15:35:44 -070046
Simon Huntc1656ed2017-06-21 16:47:04 -070047 if (!bundle) {
48 $log.warn('No lion bundle registered:', bundleId);
49 bundle = {};
Simon Hunt083e6fb2017-06-16 16:51:41 -070050 }
51
Simon Hunt083e6fb2017-06-16 16:51:41 -070052 return function (key) {
53 return bundle[key] || '%' + key + '%';
54 };
Simon Hunt94104e72017-06-13 11:38:55 -070055 }
56
57 angular.module('onosUtil')
Simon Huntc1656ed2017-06-21 16:47:04 -070058 .factory('LionService', ['$log', 'FnService', 'WebSocketService',
Simon Hunt94104e72017-06-13 11:38:55 -070059
Simon Huntc1656ed2017-06-21 16:47:04 -070060 function (_$log_, _fs_, _wss_) {
Simon Hunt94104e72017-06-13 11:38:55 -070061 $log = _$log_;
62 fs = _fs_;
Simon Huntc1656ed2017-06-21 16:47:04 -070063 wss = _wss_;
Simon Hunt94104e72017-06-13 11:38:55 -070064
65 return {
Simon Huntc1656ed2017-06-21 16:47:04 -070066 init: init,
Simon Hunt94104e72017-06-13 11:38:55 -070067 bundle: bundle
68 };
69 }]);
70}());