blob: dad55f53e4bd153028604c16da60ce42cf49d72b [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 Burrowsdfa52b02016-09-02 13:50:43 +010025 var wss, is, sus;
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
32 // configuration
33 var devIconDim = 36,
Steven Burrowsdfa52b02016-09-02 13:50:43 +010034 halfDevIcon = devIconDim / 2;
Steven Burrows57e24e92016-08-04 18:38:24 +010035
36 function createSubRegionCollection(data, region) {
37
38 var SubRegionCollection = Collection.extend({
39 model: Model
40 });
41
42 return new SubRegionCollection(data);
43 }
44
Steven Burrows6deb4ce2016-08-26 16:06:23 +010045 function mapDeviceTypeToGlyph(type) {
46 return remappedDeviceTypes[type] || type || 'switch';
47 }
48
49 function iconBox(dim, labelWidth) {
50 return {
51 x: -dim / 2,
52 y: -dim / 2,
53 width: dim + labelWidth,
54 height: dim
Steven Burrowsdfa52b02016-09-02 13:50:43 +010055 };
Steven Burrows6deb4ce2016-08-26 16:06:23 +010056 }
57
Steven Burrows57e24e92016-08-04 18:38:24 +010058 angular.module('ovTopo2')
59 .factory('Topo2SubRegionService',
Steven Burrowsdfa52b02016-09-02 13:50:43 +010060 ['WebSocketService', 'Topo2Collection', 'Topo2NodeModel',
61 'IconService', 'SvgUtilService', 'ThemeService', 'Topo2ViewService',
Steven Burrows57e24e92016-08-04 18:38:24 +010062
Steven Burrowsdfa52b02016-09-02 13:50:43 +010063 function (_wss_, _c_, _NodeModel_, _is_, _sus_, _ts_, _t2vs_) {
Steven Burrows57e24e92016-08-04 18:38:24 +010064
Steven Burrows9edc7e02016-08-29 11:52:07 +010065 wss = _wss_;
Steven Burrows6deb4ce2016-08-26 16:06:23 +010066 is = _is_;
67 sus = _sus_;
Steven Burrowsdfa52b02016-09-02 13:50:43 +010068 Collection = _c_;
Steven Burrows6deb4ce2016-08-26 16:06:23 +010069
70 Model = _NodeModel_.extend({
71 initialize: function () {
72 this.set('weight', 0);
73 this.constructor.__super__.initialize.apply(this, arguments);
74 },
75 nodeType: 'sub-region',
76 mapDeviceTypeToGlyph: mapDeviceTypeToGlyph,
Steven Burrows9edc7e02016-08-29 11:52:07 +010077 onClick: function () {
78 wss.sendEvent('topo2navRegion', {
79 dir: 'down',
80 rid: this.get('id')
81 });
82 },
Steven Burrows6deb4ce2016-08-26 16:06:23 +010083 onEnter: function (el) {
84
85 var node = d3.select(el),
86 glyphId = mapDeviceTypeToGlyph(this.get('type')),
87 label = this.trimLabel(this.label()),
88 glyph, labelWidth;
89
90 this.el = node;
Steven Burrows9edc7e02016-08-29 11:52:07 +010091 this.el.on('click', this.onClick.bind(this));
Steven Burrows6deb4ce2016-08-26 16:06:23 +010092
93 // Label
94 var labelElements = this.addLabelElements(label);
95 labelWidth = label ? this.computeLabelWidth(node) : 0;
96 labelElements.rect.attr(iconBox(devIconDim, labelWidth));
97
98 // Icon
99 glyph = is.addDeviceIcon(node, glyphId, devIconDim);
100 glyph.attr(iconBox(devIconDim, 0));
101
102 node.attr('transform', sus.translate(-halfDevIcon, -halfDevIcon));
103 this.render();
104 },
105 onExit: function () {},
106 render: function () {}
107 });
Steven Burrows57e24e92016-08-04 18:38:24 +0100108
109 return {
110 createSubRegionCollection: createSubRegionCollection
111 };
112 }
113 ]);
114
115})();