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 = { |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 28 | virtual: 'cord' |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame] | 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, |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 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', [ |
Simon Hunt | 9edd172 | 2017-03-10 17:43:26 -0800 | [diff] [blame] | 43 | '$location', 'WebSocketService', 'Topo2Collection', 'Topo2NodeModel', |
Steven Burrows | 6a4febe | 2017-04-20 11:45:33 -0400 | [diff] [blame] | 44 | 'Topo2SubRegionPanelService', 'Topo2RegionNavigationService', |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 45 | |
Steven Burrows | 6a4febe | 2017-04-20 11:45:33 -0400 | [diff] [blame] | 46 | function ($loc, wss, _c_, NodeModel, t2srp, t2rns) { |
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({ |
Steven Burrows | 5fa057e | 2017-03-15 17:07:56 +0000 | [diff] [blame] | 51 | |
| 52 | nodeType: 'sub-region', |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 53 | events: { |
| 54 | 'dblclick': 'navigateToRegion', |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 55 | 'click': 'onClick' |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 56 | }, |
Steven Burrows | 5fa057e | 2017-03-15 17:07:56 +0000 | [diff] [blame] | 57 | |
| 58 | initialize: function () { |
| 59 | this.super = this.constructor.__super__; |
| 60 | this.super.initialize.apply(this, arguments); |
| 61 | }, |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 62 | onChange: function () { |
| 63 | // Update class names when the model changes |
| 64 | if (this.el) { |
| 65 | this.el.attr('class', this.svgClassName()); |
Steven Burrows | bbe3dda | 2016-09-26 14:41:59 -0700 | [diff] [blame] | 66 | } |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 67 | }, |
Steven Burrows | 5fa057e | 2017-03-15 17:07:56 +0000 | [diff] [blame] | 68 | showDetails: function () { |
| 69 | t2srp.displayPanel(this); |
| 70 | }, |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 71 | icon: function () { |
| 72 | var type = this.get('type'); |
| 73 | return remappedDeviceTypes[type] || type || 'm_cloud'; |
| 74 | }, |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 75 | navigateToRegion: function () { |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 76 | if (d3.event.defaultPrevented) return; |
Steven Burrows | 6a4febe | 2017-04-20 11:45:33 -0400 | [diff] [blame] | 77 | t2rns.navigateToRegion(this.get('id')); |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 78 | t2srp.hide(); |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 79 | } |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 80 | }); |
| 81 | |
| 82 | return { |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 83 | createSubRegionCollection: createSubRegionCollection |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 84 | }; |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 85 | } |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 86 | ]); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 87 | |
| 88 | })(); |