blob: 0d0d6917d5ea725f458bc75ef6f32986a2097505 [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) {
Steven Burrows1c5c8612016-10-05 13:45:13 -050037 // var order = region.get('layerOrder'),
38 // aLayer = a.get('id'),
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
57 angular.module('ovTopo2')
58 .factory('Topo2DeviceService',
Steven Burrows1c5c8612016-10-05 13:45:13 -050059 ['Topo2Collection', 'Topo2NodeModel', 'Topo2DeviceDetailsPanel',
60 function (_c_, _nm_, detailsPanel) {
Steven Burrows57e24e92016-08-04 18:38:24 +010061
Steven Burrowsdfa52b02016-09-02 13:50:43 +010062 Collection = _c_;
Steven Burrowsec1f45c2016-08-08 16:14:41 +010063
Steven Burrowsdfa52b02016-09-02 13:50:43 +010064 Model = _nm_.extend({
Steven Burrowsec1f45c2016-08-08 16:14:41 +010065 initialize: function () {
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070066 this.super = this.constructor.__super__;
67 this.super.initialize.apply(this, arguments);
Steven Burrowsec1f45c2016-08-08 16:14:41 +010068 },
Steven Burrows1c5c8612016-10-05 13:45:13 -050069 events: {
70 'click': 'onClick'
71 },
Steven Burrowsec1f45c2016-08-08 16:14:41 +010072 nodeType: 'device',
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070073 icon: function () {
74 var type = this.get('type');
75 return remappedDeviceTypes[type] || type || 'unknown';
Steven Burrowsec1f45c2016-08-08 16:14:41 +010076 },
Steven Burrows1c5c8612016-10-05 13:45:13 -050077 onClick: function () {
78
79 if (this.get('selected')) {
80 this.set('selected', false);
81 detailsPanel.hide();
82 } else {
83 this.set('selected', true);
84 detailsPanel.updateDetails(this.get('id'), this.get('nodeType'));
85 detailsPanel.show();
86 }
87
88 this.el.attr('class', this.svgClassName());
89 },
Steven Burrowsdfa52b02016-09-02 13:50:43 +010090 onExit: function () {
91 var node = this.el;
92 node.select('use')
93 .style('opacity', 0.5)
94 .transition()
95 .duration(800)
96 .style('opacity', 0);
97
98 node.selectAll('rect')
99 .style('stroke-fill', '#555')
100 .style('fill', '#888')
101 .style('opacity', 0.5);
Steven Burrowsec1f45c2016-08-08 16:14:41 +0100102 }
103 });
Steven Burrows57e24e92016-08-04 18:38:24 +0100104
105 return {
106 createDeviceCollection: createDeviceCollection
107 };
108 }
109 ]);
110
111})();