blob: 469e0a8ff39b9d197e7002c26b50c97b0d041585 [file] [log] [blame]
Steven Burrows68d6f952017-03-10 13:53:35 +00001/*
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 PeerRegion Module.
19 Module that creates a peer region node for the topology
20 */
21
22(function () {
23 'use strict';
24
25 var Collection, Model;
26
27 var remappedDeviceTypes = {
28 virtual: 'cord'
29 };
30
31 function createCollection(data, region) {
32
33 var PeerRegionCollection = Collection.extend({
34 model: Model,
35 region: region
36 });
37
38 return new PeerRegionCollection(data);
39 }
40
41 angular.module('ovTopo2')
42 .factory('Topo2PeerRegionService', [
43 'WebSocketService', 'Topo2Collection', 'Topo2NodeModel',
44 'Topo2SubRegionPanelService',
45
46 function (wss, _c_, NodeModel, t2srp) {
47
48 Collection = _c_;
49
50 Model = NodeModel.extend({
Steven Burrows5fa057e2017-03-15 17:07:56 +000051
52 nodeType: 'peer-region',
Steven Burrows68d6f952017-03-10 13:53:35 +000053 events: {
54 'dblclick': 'navigateToRegion',
55 'click': 'onClick'
56 },
Steven Burrows5fa057e2017-03-15 17:07:56 +000057
58 initialize: function () {
59 this.super = this.constructor.__super__;
60 this.super.initialize.apply(this, arguments);
61 },
Steven Burrows68d6f952017-03-10 13:53:35 +000062 onChange: function () {
63 // Update class names when the model changes
64 if (this.el) {
65 this.el.attr('class', this.svgClassName());
66 }
67 },
Steven Burrows5fa057e2017-03-15 17:07:56 +000068 showDetails: function () {
69 t2srp.displayPanel(this);
70 },
Steven Burrows68d6f952017-03-10 13:53:35 +000071 icon: function () {
72 var type = this.get('type');
73 return remappedDeviceTypes[type] || type || 'm_cloud';
74 },
Steven Burrows68d6f952017-03-10 13:53:35 +000075 navigateToRegion: function () {
76
77 if (d3.event.defaultPrevented) return;
78
79 wss.sendEvent('topo2navRegion', {
Steven Burrows68d6f952017-03-10 13:53:35 +000080 rid: this.get('id')
81 });
82
83 var layout = this.collection.region.layout;
84 layout.createForceElements();
85 layout.transitionDownRegion();
86
87 t2srp.hide();
88 }
89 });
90
91 return {
92 createCollection: createCollection
93 };
94 }
95 ]);
96
97})();