blob: 67de6cb8e350790ee30500978d97b8279067b836 [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 Burrows9edc7e02016-08-29 11:52:07 +010025 var wss, is, sus, ts, t2vs;
26 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,
34 labelPad = 10,
35 hostRadius = 14,
36 badgeConfig = {
37 radius: 12,
38 yoff: 5,
39 gdelta: 10
40 },
41 halfDevIcon = devIconDim / 2,
42 devBadgeOff = { dx: -halfDevIcon, dy: -halfDevIcon },
43 hostBadgeOff = { dx: -hostRadius, dy: -hostRadius },
44 status = {
45 i: 'badgeInfo',
46 w: 'badgeWarn',
47 e: 'badgeError'
48 },
49 deviceLabelIndex = 0;
Steven Burrows57e24e92016-08-04 18:38:24 +010050
51 function createSubRegionCollection(data, region) {
52
53 var SubRegionCollection = Collection.extend({
54 model: Model
55 });
56
57 return new SubRegionCollection(data);
58 }
59
Steven Burrows6deb4ce2016-08-26 16:06:23 +010060 function mapDeviceTypeToGlyph(type) {
61 return remappedDeviceTypes[type] || type || 'switch';
62 }
63
64 function iconBox(dim, labelWidth) {
65 return {
66 x: -dim / 2,
67 y: -dim / 2,
68 width: dim + labelWidth,
69 height: dim
70 }
71 }
72
Steven Burrows57e24e92016-08-04 18:38:24 +010073 angular.module('ovTopo2')
74 .factory('Topo2SubRegionService',
Steven Burrows9edc7e02016-08-29 11:52:07 +010075 ['WebSocketService', 'Topo2Collection', 'Topo2NodeModel', 'IconService', 'SvgUtilService',
Steven Burrows6deb4ce2016-08-26 16:06:23 +010076 'ThemeService', 'Topo2ViewService',
Steven Burrows57e24e92016-08-04 18:38:24 +010077
Steven Burrows9edc7e02016-08-29 11:52:07 +010078 function (_wss_, _Collection_, _NodeModel_, _is_, _sus_, _ts_, classnames, _t2vs_) {
Steven Burrows57e24e92016-08-04 18:38:24 +010079
Steven Burrows9edc7e02016-08-29 11:52:07 +010080 wss = _wss_;
Steven Burrows6deb4ce2016-08-26 16:06:23 +010081 t2vs = _t2vs_;
82 is = _is_;
83 sus = _sus_;
84 ts = _ts_;
Steven Burrows57e24e92016-08-04 18:38:24 +010085 Collection = _Collection_;
Steven Burrows6deb4ce2016-08-26 16:06:23 +010086
87 Model = _NodeModel_.extend({
88 initialize: function () {
89 this.set('weight', 0);
90 this.constructor.__super__.initialize.apply(this, arguments);
91 },
92 nodeType: 'sub-region',
93 mapDeviceTypeToGlyph: mapDeviceTypeToGlyph,
Steven Burrows9edc7e02016-08-29 11:52:07 +010094 onClick: function () {
95 wss.sendEvent('topo2navRegion', {
96 dir: 'down',
97 rid: this.get('id')
98 });
99 },
Steven Burrows6deb4ce2016-08-26 16:06:23 +0100100 onEnter: function (el) {
101
102 var node = d3.select(el),
103 glyphId = mapDeviceTypeToGlyph(this.get('type')),
104 label = this.trimLabel(this.label()),
105 glyph, labelWidth;
106
107 this.el = node;
Steven Burrows9edc7e02016-08-29 11:52:07 +0100108 this.el.on('click', this.onClick.bind(this));
Steven Burrows6deb4ce2016-08-26 16:06:23 +0100109
110 // Label
111 var labelElements = this.addLabelElements(label);
112 labelWidth = label ? this.computeLabelWidth(node) : 0;
113 labelElements.rect.attr(iconBox(devIconDim, labelWidth));
114
115 // Icon
116 glyph = is.addDeviceIcon(node, glyphId, devIconDim);
117 glyph.attr(iconBox(devIconDim, 0));
118
119 node.attr('transform', sus.translate(-halfDevIcon, -halfDevIcon));
120 this.render();
121 },
122 onExit: function () {},
123 render: function () {}
124 });
Steven Burrows57e24e92016-08-04 18:38:24 +0100125
126 return {
127 createSubRegionCollection: createSubRegionCollection
128 };
129 }
130 ]);
131
132})();