blob: 45c26521b4abd1b3d476e8fb2d2f83ab7674ae93 [file] [log] [blame]
Steven Burrows57e24e92016-08-04 18:38:24 +01001/*
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 Burrowsec1f45c2016-08-08 16:14:41 +010027 Model,
Steven Burrows57e24e92016-08-04 18:38:24 +010028 t2sr,
29 t2ds,
30 t2hs,
31 t2ls;
32
Steven Burrowsec1f45c2016-08-08 16:14:41 +010033 var region;
Steven Burrows57e24e92016-08-04 18:38:24 +010034
35 function init() {
36 regions = {};
37 }
38
39 function addRegion(data) {
40
Steven Burrowsec1f45c2016-08-08 16:14:41 +010041 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 Burrows57e24e92016-08-04 18:38:24 +010058
59 $log.debug('Region: ', region);
60 }
61
Steven Burrowsec1f45c2016-08-08 16:14:41 +010062 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 Burrows57e24e92016-08-04 18:38:24 +010071 angular.module('ovTopo2')
72 .factory('Topo2RegionService',
Steven Burrowsec1f45c2016-08-08 16:14:41 +010073 ['$log', 'WebSocketService', 'Topo2Model', 'Topo2SubRegionService', 'Topo2DeviceService',
Steven Burrows57e24e92016-08-04 18:38:24 +010074 'Topo2HostService', 'Topo2LinkService',
75
Steven Burrowsec1f45c2016-08-08 16:14:41 +010076 function (_$log_, _wss_, _Model_, _t2sr_, _t2ds_, _t2hs_, _t2ls_) {
Steven Burrows57e24e92016-08-04 18:38:24 +010077
78 $log = _$log_;
79 wss = _wss_;
Steven Burrowsec1f45c2016-08-08 16:14:41 +010080 Model = _Model_
Steven Burrows57e24e92016-08-04 18:38:24 +010081 t2sr = _t2sr_;
82 t2ds = _t2ds_;
83 t2hs = _t2hs_;
84 t2ls = _t2ls_;
85
86 return {
87 init: init,
88
89 addRegion: addRegion,
Steven Burrowsec1f45c2016-08-08 16:14:41 +010090 regionNodes: regionNodes,
91 regionLinks: regionLinks,
92
Steven Burrows57e24e92016-08-04 18:38:24 +010093 getSubRegions: t2sr.getSubRegions
94 };
95 }]);
96
97})();