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 SubRegion Module. |
| 19 | Module that holds the sub-regions for a region |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
Steven Burrows | 9edc7e0 | 2016-08-29 11:52:07 +0100 | [diff] [blame] | 25 | var Collection, Model; |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame] | 26 | |
| 27 | var remappedDeviceTypes = { |
| 28 | virtual: 'cord' |
| 29 | }; |
| 30 | |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 31 | function createSubRegionCollection(data, region) { |
| 32 | |
| 33 | var SubRegionCollection = Collection.extend({ |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame^] | 34 | model: Model, |
| 35 | region: region |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 36 | }); |
| 37 | |
| 38 | return new SubRegionCollection(data); |
| 39 | } |
| 40 | |
| 41 | angular.module('ovTopo2') |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame^] | 42 | .factory('Topo2SubRegionService', [ |
| 43 | 'WebSocketService', 'Topo2Collection', 'Topo2NodeModel', |
| 44 | 'Topo2SubRegionPanelService', |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 45 | |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame^] | 46 | function (wss, _c_, NodeModel, t2srp) { |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 47 | |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame^] | 48 | Collection = _c_; |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame] | 49 | |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame^] | 50 | Model = NodeModel.extend({ |
| 51 | initialize: function () { |
| 52 | this.super = this.constructor.__super__; |
| 53 | this.super.initialize.apply(this, arguments); |
| 54 | }, |
| 55 | events: { |
| 56 | 'dblclick': 'navigateToRegion', |
| 57 | 'click': 'onClick' |
| 58 | }, |
| 59 | onChange: function () { |
| 60 | // Update class names when the model changes |
| 61 | if (this.el) { |
| 62 | this.el.attr('class', this.svgClassName()); |
Steven Burrows | bbe3dda | 2016-09-26 14:41:59 -0700 | [diff] [blame] | 63 | } |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame^] | 64 | }, |
| 65 | nodeType: 'sub-region', |
| 66 | icon: function () { |
| 67 | var type = this.get('type'); |
| 68 | return remappedDeviceTypes[type] || type || 'm_cloud'; |
| 69 | }, |
| 70 | onClick: function () { |
| 71 | var selected = this.select(d3.event); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 72 | |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame^] | 73 | if (selected.length > 0) { |
| 74 | t2srp.displayPanel(this); |
| 75 | } else { |
| 76 | t2srp.hide(); |
| 77 | } |
| 78 | }, |
| 79 | navigateToRegion: function () { |
| 80 | |
| 81 | if (d3.event.defaultPrevented) return; |
| 82 | |
| 83 | wss.sendEvent('topo2navRegion', { |
| 84 | dir: 'down', |
| 85 | rid: this.get('id') |
| 86 | }); |
| 87 | |
| 88 | var layout = this.collection.region.layout; |
| 89 | layout.createForceElements(); |
| 90 | layout.transitionDownRegion(); |
| 91 | |
| 92 | t2srp.hide(); |
| 93 | } |
| 94 | }); |
| 95 | |
| 96 | return { |
| 97 | createSubRegionCollection: createSubRegionCollection |
| 98 | }; |
| 99 | } |
| 100 | ]); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 101 | |
| 102 | })(); |