Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 1 | /* |
| 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 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 | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 29 | virtual: 'cord' |
| 30 | }; |
| 31 | |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 32 | function createDeviceCollection(data, region) { |
| 33 | |
| 34 | var DeviceCollection = Collection.extend({ |
| 35 | model: Model, |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 36 | 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 Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 41 | } |
| 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 Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 57 | |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 58 | angular.module('ovTopo2') |
| 59 | .factory('Topo2DeviceService', |
Steven Burrows | bbe3dda | 2016-09-26 14:41:59 -0700 | [diff] [blame] | 60 | ['Topo2Collection', 'Topo2NodeModel', |
| 61 | function (_c_, _nm_) { |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 62 | |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 63 | Collection = _c_; |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 64 | |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 65 | Model = _nm_.extend({ |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 66 | initialize: function () { |
Steven Burrows | bbe3dda | 2016-09-26 14:41:59 -0700 | [diff] [blame] | 67 | this.super = this.constructor.__super__; |
| 68 | this.super.initialize.apply(this, arguments); |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 69 | }, |
| 70 | nodeType: 'device', |
Steven Burrows | bbe3dda | 2016-09-26 14:41:59 -0700 | [diff] [blame] | 71 | icon: function () { |
| 72 | var type = this.get('type'); |
| 73 | return remappedDeviceTypes[type] || type || 'unknown'; |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 74 | }, |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 75 | 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 Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 87 | } |
| 88 | }); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 89 | |
| 90 | return { |
| 91 | createDeviceCollection: createDeviceCollection |
| 92 | }; |
| 93 | } |
| 94 | ]); |
| 95 | |
| 96 | })(); |