blob: 092ec2c583fc2b74192ef6eeb509d62726dd1c91 [file] [log] [blame]
Steven Burrows6a4febe2017-04-20 11:45:33 -04001/*
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 ONOS GUI -- Topology Region Navigation Service
19 */
20
21(function () {
22
23 var $loc, wss;
24 var instance;
25
26 var RegionNavigationService = function () {
27 this.listeners = {};
28 instance = this;
29 };
30
31 RegionNavigationService.prototype = {
32
33 addListener: function (event, sub) {
34 if (!this.listeners[event]) {
35 this.listeners[event] = [];
36 }
37 this.listeners[event].push(sub);
38 },
39 removeListener: function (sub) {
40 // TODO: This will be needed when we re-implement the overlays
41 // An overlay might want to add a listener when activated and will
42 // need to remove the listener when deactivated.
43 },
44 notifyListeners: function (event, payload) {
45 _.each(this.listeners[event], function (cb) {
46 cb(payload);
47 });
48 },
49
50 navigateToRegion: function (id) {
51 $loc.search('regionId', id);
52 wss.sendEvent('topo2navRegion', {
53 rid: id
54 });
55 this.notifyListeners('region:navigation-start', id);
56 },
57 navigateToRegionComplete: function () {
58 this.notifyListeners('region:navigation-complete');
59 },
60
61 destory: function () {
62 this.listeners = {};
63 }
64 };
65
66 angular.module('ovTopo2')
67 .factory('Topo2RegionNavigationService', [
68 '$location', 'WebSocketService',
69 function (_$loc_, _wss_) {
70
71 $loc = _$loc_;
72 wss = _wss_;
73
74 return instance || new RegionNavigationService();
75 }
76 ]);
77})();