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 | bbe3dda | 2016-09-26 14:41:59 -0700 | [diff] [blame] | 44 | 'ThemeService', 'Topo2ViewService', |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 45 | |
Steven Burrows | bbe3dda | 2016-09-26 14:41:59 -0700 | [diff] [blame] | 46 | function (_wss_, _c_, _NodeModel_, _ts_, _t2vs_) { |
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: { |
| 57 | 'dblclick': 'navigateToRegion' |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame] | 58 | }, |
| 59 | nodeType: 'sub-region', |
Steven Burrows | bbe3dda | 2016-09-26 14:41:59 -0700 | [diff] [blame] | 60 | icon: function () { |
| 61 | var type = this.get('type'); |
| 62 | return remappedDeviceTypes[type] || type || 'm_cloud'; |
| 63 | }, |
| 64 | navigateToRegion: function () { |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 65 | |
| 66 | if (d3.event.defaultPrevented) return; |
| 67 | |
Steven Burrows | 9edc7e0 | 2016-08-29 11:52:07 +0100 | [diff] [blame] | 68 | wss.sendEvent('topo2navRegion', { |
| 69 | dir: 'down', |
| 70 | rid: this.get('id') |
| 71 | }); |
Steven Burrows | bbe3dda | 2016-09-26 14:41:59 -0700 | [diff] [blame] | 72 | } |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame] | 73 | }); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 74 | |
| 75 | return { |
| 76 | createSubRegionCollection: createSubRegionCollection |
| 77 | }; |
| 78 | } |
| 79 | ]); |
| 80 | |
| 81 | })(); |