blob: dc132d73e63f70d462ed0a28ee1c7df06ad50db3 [file] [log] [blame]
Sean Condon0c577f62018-11-18 22:40:05 +00001/*
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 */
16import {
17 Component,
Sean Condon021f0fa2018-12-06 23:31:11 -080018 EventEmitter,
Sean Condon0c577f62018-11-18 22:40:05 +000019 Input,
20 OnChanges,
Sean Condon021f0fa2018-12-06 23:31:11 -080021 Output,
Sean Condon0c577f62018-11-18 22:40:05 +000022 SimpleChanges
23} from '@angular/core';
Sean Condon590b34b2019-12-04 18:44:37 +000024import {Badge, Host, HostLabelToggle, Node} from '../../models';
Sean Condona3ad7792020-01-04 19:26:34 +000025import {LogService} from 'gui2-fw-lib/public_api';
Sean Condond88f3662019-04-03 16:35:30 +010026import {NodeVisual, SelectedEvent} from '../nodevisual';
Sean Condon0c577f62018-11-18 22:40:05 +000027
28/**
29 * The Host node in the force graph
30 *
Sean Condon021f0fa2018-12-06 23:31:11 -080031 * Note: here the selector is given square brackets [] so that it can be
Sean Condon0c577f62018-11-18 22:40:05 +000032 * inserted in SVG element like a directive
Sean Condon0c577f62018-11-18 22:40:05 +000033 */
34@Component({
35 selector: '[onos-hostnodesvg]',
36 templateUrl: './hostnodesvg.component.html',
37 styleUrls: ['./hostnodesvg.component.css']
38})
Sean Condon021f0fa2018-12-06 23:31:11 -080039export class HostNodeSvgComponent extends NodeVisual implements OnChanges {
Sean Condon0c577f62018-11-18 22:40:05 +000040 @Input() host: Host;
Sean Condon021f0fa2018-12-06 23:31:11 -080041 @Input() scale: number = 1.0;
Sean Condonff85fbe2019-03-16 14:28:46 +000042 @Input() labelToggle: HostLabelToggle.Enum = HostLabelToggle.Enum.IP;
Sean Condon590b34b2019-12-04 18:44:37 +000043 @Input() badge: Badge;
Sean Condond88f3662019-04-03 16:35:30 +010044 @Output() selectedEvent = new EventEmitter<SelectedEvent>();
Sean Condon0c577f62018-11-18 22:40:05 +000045
46 constructor(
47 protected log: LogService
48 ) {
Sean Condon021f0fa2018-12-06 23:31:11 -080049 super();
Sean Condon0c577f62018-11-18 22:40:05 +000050 }
51
52 ngOnChanges(changes: SimpleChanges) {
Sean Condon590b34b2019-12-04 18:44:37 +000053 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 Condon0c577f62018-11-18 22:40:05 +000062 }
Sean Condon021f0fa2018-12-06 23:31:11 -080063 }
64
65 hostName(): string {
66 if (this.host === undefined) {
67 return undefined;
Sean Condonff85fbe2019-03-16 14:28:46 +000068 } else if (this.labelToggle === HostLabelToggle.Enum.IP) {
Sean Condon021f0fa2018-12-06 23:31:11 -080069 return this.host.ips.join(',');
Sean Condonff85fbe2019-03-16 14:28:46 +000070 } else if (this.labelToggle === HostLabelToggle.Enum.MAC) {
Sean Condon021f0fa2018-12-06 23:31:11 -080071 return this.host.id;
Sean Condonf9ff66a2020-03-23 08:40:55 +000072 } else if (this.labelToggle === HostLabelToggle.Enum.NAME) {
73 return this.host.props.name;
Sean Condon021f0fa2018-12-06 23:31:11 -080074 } else {
Sean Condonf9ff66a2020-03-23 08:40:55 +000075 return this.host.id;
Sean Condon021f0fa2018-12-06 23:31:11 -080076 }
77
Sean Condon0c577f62018-11-18 22:40:05 +000078 }
79}