blob: fc55271ec9e89a524381bfa066d80286b54b6296 [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
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 Condon0c577f62018-11-18 22:40:05 +000069 }
70}