Steven Burrows | c515e60 | 2017-04-13 11:17:40 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Steven Burrows | c515e60 | 2017-04-13 11:17:40 -0700 | [diff] [blame] | 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 Mastership controller. |
| 19 | Controller that handles the state of the selected mastership |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | |
| 24 | var instance; |
| 25 | |
| 26 | angular.module('ovTopo2') |
| 27 | .factory('Topo2MastershipService', [ |
| 28 | |
| 29 | function () { |
| 30 | |
| 31 | var MastershipController = function () { |
| 32 | instance = this; |
| 33 | this.region = null; |
| 34 | this.currentMastership = null; |
| 35 | }; |
| 36 | |
| 37 | MastershipController.prototype = { |
| 38 | displayMastership: function () { |
| 39 | var nodes = this.region.regionNodes(), |
| 40 | links = this.region.regionLinks(); |
| 41 | |
| 42 | _.each(nodes.concat(links), function (n) { |
| 43 | n.displayMastership(this.currentMastership); |
| 44 | }); |
| 45 | }, |
| 46 | mastership: function () { |
| 47 | return this.currentMastership; |
| 48 | }, |
| 49 | setMastership: function (id) { |
| 50 | this.currentMastership = id; |
| 51 | this.displayMastership(); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 52 | }, |
| 53 | }; |
Steven Burrows | c515e60 | 2017-04-13 11:17:40 -0700 | [diff] [blame] | 54 | |
| 55 | return instance || new MastershipController(); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 56 | }, |
Steven Burrows | c515e60 | 2017-04-13 11:17:40 -0700 | [diff] [blame] | 57 | ]); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 58 | })(); |