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