Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-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 Module. |
| 19 | Module that holds the current region in memory |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
| 25 | var $log, |
| 26 | wss, |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame^] | 27 | Model, |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 28 | t2sr, |
| 29 | t2ds, |
| 30 | t2hs, |
| 31 | t2ls; |
| 32 | |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame^] | 33 | var region; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 34 | |
| 35 | function init() { |
| 36 | regions = {}; |
| 37 | } |
| 38 | |
| 39 | function addRegion(data) { |
| 40 | |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame^] | 41 | region = new Model({ |
| 42 | id: data.id, |
| 43 | layerOrder: data.layerOrder |
| 44 | }); |
| 45 | |
| 46 | region.set({ |
| 47 | subregions: t2sr.createSubRegionCollection(data.subregions, region), |
| 48 | devices: t2ds.createDeviceCollection(data.devices, region), |
| 49 | hosts: t2hs.createHostCollection(data.hosts, region), |
| 50 | links: t2ls.createLinkCollection(data.links, region), |
| 51 | }); |
| 52 | |
| 53 | region.set('test', 2); |
| 54 | |
| 55 | angular.forEach(region.get('links').models, function (link) { |
| 56 | link.createLink(); |
| 57 | }); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 58 | |
| 59 | $log.debug('Region: ', region); |
| 60 | } |
| 61 | |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame^] | 62 | function regionNodes() { |
| 63 | return [].concat(region.get('devices').models, region.get('hosts').models); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | function regionLinks() { |
| 68 | return region.get('links').models; |
| 69 | } |
| 70 | |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 71 | angular.module('ovTopo2') |
| 72 | .factory('Topo2RegionService', |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame^] | 73 | ['$log', 'WebSocketService', 'Topo2Model', 'Topo2SubRegionService', 'Topo2DeviceService', |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 74 | 'Topo2HostService', 'Topo2LinkService', |
| 75 | |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame^] | 76 | function (_$log_, _wss_, _Model_, _t2sr_, _t2ds_, _t2hs_, _t2ls_) { |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 77 | |
| 78 | $log = _$log_; |
| 79 | wss = _wss_; |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame^] | 80 | Model = _Model_ |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 81 | t2sr = _t2sr_; |
| 82 | t2ds = _t2ds_; |
| 83 | t2hs = _t2hs_; |
| 84 | t2ls = _t2ls_; |
| 85 | |
| 86 | return { |
| 87 | init: init, |
| 88 | |
| 89 | addRegion: addRegion, |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame^] | 90 | regionNodes: regionNodes, |
| 91 | regionLinks: regionLinks, |
| 92 | |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 93 | getSubRegions: t2sr.getSubRegions |
| 94 | }; |
| 95 | }]); |
| 96 | |
| 97 | })(); |