Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | import { |
| 17 | Component, |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 18 | EventEmitter, |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 19 | Input, |
| 20 | OnChanges, |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 21 | Output, |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 22 | SimpleChanges |
| 23 | } from '@angular/core'; |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 24 | import {Host, HostLabelToggle, Node} from '../../models'; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 25 | import {LogService} from 'gui2-fw-lib'; |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 26 | import {NodeVisual} from '../nodevisual'; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * The Host node in the force graph |
| 30 | * |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 31 | * Note: here the selector is given square brackets [] so that it can be |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 32 | * inserted in SVG element like a directive |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 33 | */ |
| 34 | @Component({ |
| 35 | selector: '[onos-hostnodesvg]', |
| 36 | templateUrl: './hostnodesvg.component.html', |
| 37 | styleUrls: ['./hostnodesvg.component.css'] |
| 38 | }) |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 39 | export class HostNodeSvgComponent extends NodeVisual implements OnChanges { |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 40 | @Input() host: Host; |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 41 | @Input() scale: number = 1.0; |
| 42 | @Input() labelToggle: HostLabelToggle = HostLabelToggle.IP; |
| 43 | @Output() selectedEvent = new EventEmitter<Node>(); |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 44 | |
| 45 | constructor( |
| 46 | protected log: LogService |
| 47 | ) { |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 48 | super(); |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | ngOnChanges(changes: SimpleChanges) { |
| 52 | if (!this.host.x) { |
| 53 | this.host.x = 0; |
| 54 | this.host.y = 0; |
| 55 | } |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | hostName(): string { |
| 59 | if (this.host === undefined) { |
| 60 | return undefined; |
| 61 | } else if (this.labelToggle === HostLabelToggle.IP) { |
| 62 | return this.host.ips.join(','); |
| 63 | } else if (this.labelToggle === HostLabelToggle.MAC) { |
| 64 | return this.host.id; |
| 65 | } else { |
| 66 | return this.host.id; // Todo - replace with a friendly name |
| 67 | } |
| 68 | |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 69 | } |
| 70 | } |