blob: a3707469295a74ee0cfb7d99eb7c2538932196f6 [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 SubRegion Module.
19 Module that holds the sub-regions for a region
20 */
21
22(function () {
23 'use strict';
24
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070025 var wss;
Steven Burrows9edc7e02016-08-29 11:52:07 +010026 var Collection, Model;
Steven Burrows6deb4ce2016-08-26 16:06:23 +010027
28 var remappedDeviceTypes = {
29 virtual: 'cord'
30 };
31
Steven Burrows57e24e92016-08-04 18:38:24 +010032 function createSubRegionCollection(data, region) {
33
34 var SubRegionCollection = Collection.extend({
35 model: Model
36 });
37
38 return new SubRegionCollection(data);
39 }
40
41 angular.module('ovTopo2')
42 .factory('Topo2SubRegionService',
Steven Burrowsdfa52b02016-09-02 13:50:43 +010043 ['WebSocketService', 'Topo2Collection', 'Topo2NodeModel',
Steven Burrows86af4352016-11-16 18:19:12 -060044 'ThemeService', 'Topo2ViewService', 'Topo2SubRegionPanelService',
Steven Burrows57e24e92016-08-04 18:38:24 +010045
Steven Burrows86af4352016-11-16 18:19:12 -060046 function (_wss_, _c_, _NodeModel_, _ts_, _t2vs_m, _t2srp_) {
Steven Burrows57e24e92016-08-04 18:38:24 +010047
Steven Burrows9edc7e02016-08-29 11:52:07 +010048 wss = _wss_;
Steven Burrowsdfa52b02016-09-02 13:50:43 +010049 Collection = _c_;
Steven Burrows6deb4ce2016-08-26 16:06:23 +010050
51 Model = _NodeModel_.extend({
52 initialize: function () {
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070053 this.super = this.constructor.__super__;
54 this.super.initialize.apply(this, arguments);
55 },
56 events: {
Steven Burrows86af4352016-11-16 18:19:12 -060057 'dblclick': 'navigateToRegion',
58 'click': 'onClick'
59 },
60 onChange: function () {
61 // Update class names when the model changes
62 if (this.el) {
63 this.el.attr('class', this.svgClassName());
64 }
Steven Burrows6deb4ce2016-08-26 16:06:23 +010065 },
66 nodeType: 'sub-region',
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070067 icon: function () {
68 var type = this.get('type');
69 return remappedDeviceTypes[type] || type || 'm_cloud';
70 },
Steven Burrows86af4352016-11-16 18:19:12 -060071 onClick: function () {
72 var selected = this.select(d3.event);
73
74 if (selected.length > 0) {
75 _t2srp_.displayPanel(this);
76 } else {
77 _t2srp_.hide();
78 }
79 },
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070080 navigateToRegion: function () {
Steven Burrowse3a18842016-09-22 15:33:33 +010081
82 if (d3.event.defaultPrevented) return;
83
Steven Burrows9edc7e02016-08-29 11:52:07 +010084 wss.sendEvent('topo2navRegion', {
85 dir: 'down',
86 rid: this.get('id')
87 });
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070088 }
Steven Burrows6deb4ce2016-08-26 16:06:23 +010089 });
Steven Burrows57e24e92016-08-04 18:38:24 +010090
91 return {
92 createSubRegionCollection: createSubRegionCollection
93 };
94 }
95 ]);
96
97})();