blob: 6710a872218431a595617722a3e91a6326fc7afd [file] [log] [blame]
Steven Burrows57e24e92016-08-04 18:38:24 +01001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Steven Burrows57e24e92016-08-04 18:38:24 +01003 *
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 Burrows1c2a9682017-07-14 16:52:46 +010029 virtual: 'cord',
Steven Burrowsec1f45c2016-08-08 16:14:41 +010030 };
31
Steven Burrows448468c2017-04-13 16:09:30 -070032 function createDeviceCollection(data) {
Steven Burrows57e24e92016-08-04 18:38:24 +010033
34 var DeviceCollection = Collection.extend({
Steven Burrows1c2a9682017-07-14 16:52:46 +010035 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')
Steven Burrows02e67f42017-04-13 13:59:43 -070049 .factory('Topo2DeviceService', [
50 'Topo2Collection', 'Topo2NodeModel', 'Topo2DeviceDetailsPanel',
51 'PrefsService',
52 function (_c_, _nm_, detailsPanel, ps) {
Steven Burrows57e24e92016-08-04 18:38:24 +010053
Steven Burrowsdfa52b02016-09-02 13:50:43 +010054 Collection = _c_;
Steven Burrowsec1f45c2016-08-08 16:14:41 +010055
Steven Burrowsdfa52b02016-09-02 13:50:43 +010056 Model = _nm_.extend({
Steven Burrows5fa057e2017-03-15 17:07:56 +000057
58 nodeType: 'device',
59 multiSelectEnabled: true,
60 events: {
Steven Burrows1c2a9682017-07-14 16:52:46 +010061 'click': 'onClick',
Steven Burrows5fa057e2017-03-15 17:07:56 +000062 },
63
Steven Burrowsec1f45c2016-08-08 16:14:41 +010064 initialize: function () {
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070065 this.super = this.constructor.__super__;
66 this.super.initialize.apply(this, arguments);
Steven Burrowsec1f45c2016-08-08 16:14:41 +010067 },
Steven Burrows448468c2017-04-13 16:09:30 -070068 onChange: function () {
Steven Burrowse2d77d62016-10-21 12:35:58 -050069 if (this.el) {
70 this.el.attr('class', this.svgClassName());
Steven Burrows42eb9e22017-02-06 14:20:24 +000071 var rect = this.el.select('.icon-rect');
72 rect.style('fill', this.devGlyphColor());
Steven Burrows02e67f42017-04-13 13:59:43 -070073
74 this.setOfflineVisibility();
Steven Burrowse2d77d62016-10-21 12:35:58 -050075 }
76 },
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070077 icon: function () {
78 var type = this.get('type');
79 return remappedDeviceTypes[type] || type || 'unknown';
Steven Burrowsec1f45c2016-08-08 16:14:41 +010080 },
Steven Burrows5fa057e2017-03-15 17:07:56 +000081 showDetails: function () {
82 var id = this.get('id'),
83 nodeType = this.get('nodeType');
84 detailsPanel.updateDetails(id, nodeType);
85 detailsPanel.show();
Steven Burrows1c5c8612016-10-05 13:45:13 -050086 },
Steven Burrowsc515e602017-04-13 11:17:40 -070087 displayMastership: function () {
88 var id = this.mastershipService.mastership(),
89 suppress = id ? this.get('master') !== id : false;
90
Steven Burrows1c2a9682017-07-14 16:52:46 +010091 this.set({ mastership: suppress });
Steven Burrows02e67f42017-04-13 13:59:43 -070092 },
93 setOfflineVisibility: function () {
94 var showOffline = ps.getPrefs('topo2_prefs')['offline_devices'],
95 display = this.get('online') || showOffline;
Steven Burrows8ba9e6d2017-11-01 16:01:23 +000096
Steven Burrows02e67f42017-04-13 13:59:43 -070097 this.el.style('visibility', display ? 'visible' : 'hidden');
Steven Burrowsc515e602017-04-13 11:17:40 -070098 },
Steven Burrowsdfa52b02016-09-02 13:50:43 +010099 onExit: function () {
100 var node = this.el;
101 node.select('use')
102 .style('opacity', 0.5)
103 .transition()
104 .duration(800)
105 .style('opacity', 0);
106
107 node.selectAll('rect')
108 .style('stroke-fill', '#555')
109 .style('fill', '#888')
110 .style('opacity', 0.5);
Steven Burrows1c2a9682017-07-14 16:52:46 +0100111 },
Steven Burrowsec1f45c2016-08-08 16:14:41 +0100112 });
Steven Burrows57e24e92016-08-04 18:38:24 +0100113
114 return {
Steven Burrows1c2a9682017-07-14 16:52:46 +0100115 createDeviceCollection: createDeviceCollection,
Steven Burrows57e24e92016-08-04 18:38:24 +0100116 };
Steven Burrows1c2a9682017-07-14 16:52:46 +0100117 },
Steven Burrows57e24e92016-08-04 18:38:24 +0100118 ]);
119
120})();