blob: 823387c5a93a1067065f50051c5e0412fe61dc88 [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({
Steven Burrowsaa57d932016-10-21 10:01:48 -050035 model: Model
Steven Burrows57e24e92016-08-04 18:38:24 +010036 });
37
38 var devices = [];
39 data.forEach(function (deviceLayer) {
40 deviceLayer.forEach(function (device) {
41 devices.push(device);
42 });
43 });
44
Steven Burrowsaa57d932016-10-21 10:01:48 -050045 return new DeviceCollection(devices);
Steven Burrows57e24e92016-08-04 18:38:24 +010046 }
47
48 angular.module('ovTopo2')
49 .factory('Topo2DeviceService',
Steven Burrows1c5c8612016-10-05 13:45:13 -050050 ['Topo2Collection', 'Topo2NodeModel', 'Topo2DeviceDetailsPanel',
51 function (_c_, _nm_, detailsPanel) {
Steven Burrows57e24e92016-08-04 18:38:24 +010052
Steven Burrowsdfa52b02016-09-02 13:50:43 +010053 Collection = _c_;
Steven Burrowsec1f45c2016-08-08 16:14:41 +010054
Steven Burrowsdfa52b02016-09-02 13:50:43 +010055 Model = _nm_.extend({
Steven Burrowsec1f45c2016-08-08 16:14:41 +010056 initialize: function () {
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070057 this.super = this.constructor.__super__;
58 this.super.initialize.apply(this, arguments);
Steven Burrowsec1f45c2016-08-08 16:14:41 +010059 },
Steven Burrows1c5c8612016-10-05 13:45:13 -050060 events: {
61 'click': 'onClick'
62 },
Steven Burrows42eb9e22017-02-06 14:20:24 +000063 onChange: function (change) {
Steven Burrowse2d77d62016-10-21 12:35:58 -050064 if (this.el) {
65 this.el.attr('class', this.svgClassName());
Steven Burrows42eb9e22017-02-06 14:20:24 +000066 var rect = this.el.select('.icon-rect');
67 rect.style('fill', this.devGlyphColor());
Steven Burrowse2d77d62016-10-21 12:35:58 -050068 }
69 },
Steven Burrowsec1f45c2016-08-08 16:14:41 +010070 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 Burrows1c5c8612016-10-05 13:45:13 -050075 onClick: function () {
76
Steven Burrowsb11a8b82017-03-10 16:00:31 +000077 if (d3.event.defaultPrevented) return;
Steven Burrows86af4352016-11-16 18:19:12 -060078 var selected = this.select(d3.event);
Steven Burrowse2d77d62016-10-21 12:35:58 -050079
80 if (_.isArray(selected) && selected.length > 0) {
81 if (selected.length === 1) {
82 var model = selected[0],
83 id = model.get('id'),
84 nodeType = model.get('nodeType');
Steven Burrowsaa57d932016-10-21 10:01:48 -050085 detailsPanel.updateDetails(id, nodeType);
86 detailsPanel.show();
Steven Burrowse2d77d62016-10-21 12:35:58 -050087 } else {
88 // Multi Panel
89 detailsPanel.showMulti(selected);
Steven Burrowsaa57d932016-10-21 10:01:48 -050090 }
Steven Burrowse2d77d62016-10-21 12:35:58 -050091 } else {
92 detailsPanel.hide();
Steven Burrowsaa57d932016-10-21 10:01:48 -050093 }
Steven Burrows1c5c8612016-10-05 13:45:13 -050094 },
Steven Burrowsdfa52b02016-09-02 13:50:43 +010095 onExit: function () {
96 var node = this.el;
97 node.select('use')
98 .style('opacity', 0.5)
99 .transition()
100 .duration(800)
101 .style('opacity', 0);
102
103 node.selectAll('rect')
104 .style('stroke-fill', '#555')
105 .style('fill', '#888')
106 .style('opacity', 0.5);
Steven Burrowsec1f45c2016-08-08 16:14:41 +0100107 }
108 });
Steven Burrows57e24e92016-08-04 18:38:24 +0100109
110 return {
111 createDeviceCollection: createDeviceCollection
112 };
113 }
114 ]);
115
116})();