Steven Burrows | 6a4febe | 2017-04-20 11:45:33 -0400 | [diff] [blame] | 1 | /* |
| 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', { |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 53 | rid: id |
Steven Burrows | 6a4febe | 2017-04-20 11:45:33 -0400 | [diff] [blame] | 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 = {}; |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 63 | } |
Steven Burrows | 6a4febe | 2017-04-20 11:45:33 -0400 | [diff] [blame] | 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(); |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 75 | } |
Steven Burrows | 6a4febe | 2017-04-20 11:45:33 -0400 | [diff] [blame] | 76 | ]); |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 77 | })(); |