blob: 0720d0ed1e5faef6f464adad353c68cd32ad4fa3 [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 Condon021f0fa2018-12-06 23:31:11 -080024import {Host, HostLabelToggle, Node} from '../../models';
Sean Condon0c577f62018-11-18 22:40:05 +000025import {LogService} from 'gui2-fw-lib';
Sean Condon021f0fa2018-12-06 23:31:11 -080026import {NodeVisual} 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;
42 @Input() labelToggle: HostLabelToggle = HostLabelToggle.IP;
43 @Output() selectedEvent = new EventEmitter<Node>();
Sean Condon0c577f62018-11-18 22:40:05 +000044
45 constructor(
46 protected log: LogService
47 ) {
Sean Condon021f0fa2018-12-06 23:31:11 -080048 super();
Sean Condon0c577f62018-11-18 22:40:05 +000049 }
50
51 ngOnChanges(changes: SimpleChanges) {
52 if (!this.host.x) {
53 this.host.x = 0;
54 this.host.y = 0;
55 }
Sean Condon021f0fa2018-12-06 23:31:11 -080056
57 if (changes['labelToggle']) {
58 this.labelToggle = changes['labelToggle'].currentValue;
59 }
60 // this.ref.markForCheck();
61 }
62
63 hostName(): string {
64 if (this.host === undefined) {
65 return undefined;
66 } else if (this.labelToggle === HostLabelToggle.IP) {
67 return this.host.ips.join(',');
68 } else if (this.labelToggle === HostLabelToggle.MAC) {
69 return this.host.id;
70 } else {
71 return this.host.id; // Todo - replace with a friendly name
72 }
73
Sean Condon0c577f62018-11-18 22:40:05 +000074 }
75}