blob: 12b0a13c86feac2f002e997026120dcf41cff6af [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 Devices Module.
19 Module that holds the devices for a region
20 */
21
22(function () {
23 'use strict';
24
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070025 var Collection, Model;
Steven Burrowsec1f45c2016-08-08 16:14:41 +010026
27 var remappedDeviceTypes = {
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070028 switch: 'm_switch',
Steven Burrowsec1f45c2016-08-08 16:14:41 +010029 virtual: 'cord'
30 };
31
Steven Burrows57e24e92016-08-04 18:38:24 +010032 function createDeviceCollection(data, region) {
33
34 var DeviceCollection = Collection.extend({
35 model: Model,
Steven Burrowsdfa52b02016-09-02 13:50:43 +010036 comparator: function (a, b) {
37 var order = region.get('layerOrder'),
38 aLayer = a.get('layer'),
39 bLayer = b.get('layer');
40 return order.indexOf(aLayer - order.indexOf(bLayer));
Steven Burrows57e24e92016-08-04 18:38:24 +010041 }
42 });
43
44 var devices = [];
45 data.forEach(function (deviceLayer) {
46 deviceLayer.forEach(function (device) {
47 devices.push(device);
48 });
49 });
50
51 var deviceCollection = new DeviceCollection(devices);
52 deviceCollection.sort();
53
54 return deviceCollection;
55 }
56
Steven Burrowsec1f45c2016-08-08 16:14:41 +010057
Steven Burrows57e24e92016-08-04 18:38:24 +010058 angular.module('ovTopo2')
59 .factory('Topo2DeviceService',
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070060 ['Topo2Collection', 'Topo2NodeModel',
61 function (_c_, _nm_) {
Steven Burrows57e24e92016-08-04 18:38:24 +010062
Steven Burrowsdfa52b02016-09-02 13:50:43 +010063 Collection = _c_;
Steven Burrowsec1f45c2016-08-08 16:14:41 +010064
Steven Burrowsdfa52b02016-09-02 13:50:43 +010065 Model = _nm_.extend({
Steven Burrowsec1f45c2016-08-08 16:14:41 +010066 initialize: function () {
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070067 this.super = this.constructor.__super__;
68 this.super.initialize.apply(this, arguments);
Steven Burrowsec1f45c2016-08-08 16:14:41 +010069 },
70 nodeType: 'device',
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070071 icon: function () {
72 var type = this.get('type');
73 return remappedDeviceTypes[type] || type || 'unknown';
Steven Burrowsec1f45c2016-08-08 16:14:41 +010074 },
Steven Burrowsdfa52b02016-09-02 13:50:43 +010075 onExit: function () {
76 var node = this.el;
77 node.select('use')
78 .style('opacity', 0.5)
79 .transition()
80 .duration(800)
81 .style('opacity', 0);
82
83 node.selectAll('rect')
84 .style('stroke-fill', '#555')
85 .style('fill', '#888')
86 .style('opacity', 0.5);
Steven Burrowsec1f45c2016-08-08 16:14:41 +010087 }
88 });
Steven Burrows57e24e92016-08-04 18:38:24 +010089
90 return {
91 createDeviceCollection: createDeviceCollection
92 };
93 }
94 ]);
95
96})();