Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 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 Burrows | bbe3dda | 2016-09-26 14:41:59 -0700 | [diff] [blame] | 25 | var Collection, Model; |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 26 | |
| 27 | var remappedDeviceTypes = { |
Steven Burrows | bbe3dda | 2016-09-26 14:41:59 -0700 | [diff] [blame] | 28 | switch: 'm_switch', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 29 | virtual: 'cord', |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 30 | }; |
| 31 | |
Steven Burrows | 448468c | 2017-04-13 16:09:30 -0700 | [diff] [blame] | 32 | function createDeviceCollection(data) { |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 33 | |
| 34 | var DeviceCollection = Collection.extend({ |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 35 | model: Model, |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 36 | }); |
| 37 | |
| 38 | var devices = []; |
| 39 | data.forEach(function (deviceLayer) { |
| 40 | deviceLayer.forEach(function (device) { |
| 41 | devices.push(device); |
| 42 | }); |
| 43 | }); |
| 44 | |
Steven Burrows | aa57d93 | 2016-10-21 10:01:48 -0500 | [diff] [blame] | 45 | return new DeviceCollection(devices); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | angular.module('ovTopo2') |
Steven Burrows | 02e67f4 | 2017-04-13 13:59:43 -0700 | [diff] [blame] | 49 | .factory('Topo2DeviceService', [ |
| 50 | 'Topo2Collection', 'Topo2NodeModel', 'Topo2DeviceDetailsPanel', |
| 51 | 'PrefsService', |
| 52 | function (_c_, _nm_, detailsPanel, ps) { |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 53 | |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 54 | Collection = _c_; |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 55 | |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 56 | Model = _nm_.extend({ |
Steven Burrows | 5fa057e | 2017-03-15 17:07:56 +0000 | [diff] [blame] | 57 | |
| 58 | nodeType: 'device', |
| 59 | multiSelectEnabled: true, |
| 60 | events: { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 61 | 'click': 'onClick', |
Steven Burrows | 5fa057e | 2017-03-15 17:07:56 +0000 | [diff] [blame] | 62 | }, |
| 63 | |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 64 | initialize: function () { |
Steven Burrows | bbe3dda | 2016-09-26 14:41:59 -0700 | [diff] [blame] | 65 | this.super = this.constructor.__super__; |
| 66 | this.super.initialize.apply(this, arguments); |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 67 | }, |
Steven Burrows | 448468c | 2017-04-13 16:09:30 -0700 | [diff] [blame] | 68 | onChange: function () { |
Steven Burrows | e2d77d6 | 2016-10-21 12:35:58 -0500 | [diff] [blame] | 69 | if (this.el) { |
| 70 | this.el.attr('class', this.svgClassName()); |
Steven Burrows | 42eb9e2 | 2017-02-06 14:20:24 +0000 | [diff] [blame] | 71 | var rect = this.el.select('.icon-rect'); |
| 72 | rect.style('fill', this.devGlyphColor()); |
Steven Burrows | 02e67f4 | 2017-04-13 13:59:43 -0700 | [diff] [blame] | 73 | |
| 74 | this.setOfflineVisibility(); |
Steven Burrows | e2d77d6 | 2016-10-21 12:35:58 -0500 | [diff] [blame] | 75 | } |
| 76 | }, |
Steven Burrows | bbe3dda | 2016-09-26 14:41:59 -0700 | [diff] [blame] | 77 | icon: function () { |
| 78 | var type = this.get('type'); |
| 79 | return remappedDeviceTypes[type] || type || 'unknown'; |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 80 | }, |
Steven Burrows | 5fa057e | 2017-03-15 17:07:56 +0000 | [diff] [blame] | 81 | showDetails: function () { |
| 82 | var id = this.get('id'), |
| 83 | nodeType = this.get('nodeType'); |
| 84 | detailsPanel.updateDetails(id, nodeType); |
| 85 | detailsPanel.show(); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 86 | }, |
Steven Burrows | c515e60 | 2017-04-13 11:17:40 -0700 | [diff] [blame] | 87 | displayMastership: function () { |
| 88 | var id = this.mastershipService.mastership(), |
| 89 | suppress = id ? this.get('master') !== id : false; |
| 90 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 91 | this.set({ mastership: suppress }); |
Steven Burrows | 02e67f4 | 2017-04-13 13:59:43 -0700 | [diff] [blame] | 92 | }, |
| 93 | setOfflineVisibility: function () { |
| 94 | var showOffline = ps.getPrefs('topo2_prefs')['offline_devices'], |
| 95 | display = this.get('online') || showOffline; |
Steven Burrows | 8ba9e6d | 2017-11-01 16:01:23 +0000 | [diff] [blame] | 96 | |
Steven Burrows | 02e67f4 | 2017-04-13 13:59:43 -0700 | [diff] [blame] | 97 | this.el.style('visibility', display ? 'visible' : 'hidden'); |
Steven Burrows | c515e60 | 2017-04-13 11:17:40 -0700 | [diff] [blame] | 98 | }, |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 99 | 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 Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 111 | }, |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 112 | }); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 113 | |
| 114 | return { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 115 | createDeviceCollection: createDeviceCollection, |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 116 | }; |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 117 | }, |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 118 | ]); |
| 119 | |
| 120 | })(); |