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 | 590b34b | 2019-12-04 18:44:37 +0000 | [diff] [blame] | 24 | import {Badge, Host, HostLabelToggle, Node} from '../../models'; |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame^] | 25 | import {LogService} from 'gui2-fw-lib/public_api'; |
Sean Condon | d88f366 | 2019-04-03 16:35:30 +0100 | [diff] [blame] | 26 | import {NodeVisual, SelectedEvent} 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; |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 42 | @Input() labelToggle: HostLabelToggle.Enum = HostLabelToggle.Enum.IP; |
Sean Condon | 590b34b | 2019-12-04 18:44:37 +0000 | [diff] [blame] | 43 | @Input() badge: Badge; |
Sean Condon | d88f366 | 2019-04-03 16:35:30 +0100 | [diff] [blame] | 44 | @Output() selectedEvent = new EventEmitter<SelectedEvent>(); |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 45 | |
| 46 | constructor( |
| 47 | protected log: LogService |
| 48 | ) { |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 49 | super(); |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | ngOnChanges(changes: SimpleChanges) { |
Sean Condon | 590b34b | 2019-12-04 18:44:37 +0000 | [diff] [blame] | 53 | if (changes['host']) { |
| 54 | if (!this.host.x) { |
| 55 | this.host.x = 0; |
| 56 | this.host.y = 0; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if (changes['badge']) { |
| 61 | this.badge = changes['badge'].currentValue; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 62 | } |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | hostName(): string { |
| 66 | if (this.host === undefined) { |
| 67 | return undefined; |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 68 | } else if (this.labelToggle === HostLabelToggle.Enum.IP) { |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 69 | return this.host.ips.join(','); |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 70 | } else if (this.labelToggle === HostLabelToggle.Enum.MAC) { |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 71 | return this.host.id; |
| 72 | } else { |
| 73 | return this.host.id; // Todo - replace with a friendly name |
| 74 | } |
| 75 | |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 76 | } |
| 77 | } |