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) { |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 37 | // var order = region.get('layerOrder'), |
| 38 | // aLayer = a.get('id'), |
| 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 | |
| 57 | angular.module('ovTopo2') |
| 58 | .factory('Topo2DeviceService', |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 59 | ['Topo2Collection', 'Topo2NodeModel', 'Topo2DeviceDetailsPanel', |
| 60 | function (_c_, _nm_, detailsPanel) { |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 61 | |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 62 | Collection = _c_; |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 63 | |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 64 | Model = _nm_.extend({ |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 65 | initialize: function () { |
Steven Burrows | bbe3dda | 2016-09-26 14:41:59 -0700 | [diff] [blame] | 66 | this.super = this.constructor.__super__; |
| 67 | this.super.initialize.apply(this, arguments); |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 68 | }, |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 69 | events: { |
| 70 | 'click': 'onClick' |
| 71 | }, |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 72 | nodeType: 'device', |
Steven Burrows | bbe3dda | 2016-09-26 14:41:59 -0700 | [diff] [blame] | 73 | icon: function () { |
| 74 | var type = this.get('type'); |
| 75 | return remappedDeviceTypes[type] || type || 'unknown'; |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 76 | }, |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 77 | 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 Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 90 | 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 Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 102 | } |
| 103 | }); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 104 | |
| 105 | return { |
| 106 | createDeviceCollection: createDeviceCollection |
| 107 | }; |
| 108 | } |
| 109 | ]); |
| 110 | |
| 111 | })(); |