2018-09-10 07:37:42 +00:00
|
|
|
import { Component, Input, OnInit, EventEmitter, Output, ViewChild } from '@angular/core';
|
2018-08-26 11:09:12 +00:00
|
|
|
|
2018-09-09 10:20:21 +00:00
|
|
|
import { of } from 'rxjs';
|
|
|
|
import { catchError, map, take } from 'rxjs/operators';
|
2018-08-26 11:09:12 +00:00
|
|
|
|
|
|
|
import { ProbeService } from '../service/probe.service';
|
2018-08-26 15:15:10 +00:00
|
|
|
import { Interface } from '@overflow/model/net/nic';
|
2018-09-10 07:37:42 +00:00
|
|
|
import { SelectItem } from 'primeng/primeng';
|
2018-09-09 10:20:21 +00:00
|
|
|
import { Zone } from '@overflow/model/discovery';
|
|
|
|
import { toMetaIPType, MetaIPTypeEnum } from '@overflow/model/meta';
|
2018-09-10 07:37:42 +00:00
|
|
|
import { DropdownPanelComponent } from '@overflow/commons/ui/component/primeng';
|
2018-08-17 10:53:40 +00:00
|
|
|
|
2018-08-27 01:41:27 +00:00
|
|
|
|
|
|
|
|
2018-08-17 10:53:40 +00:00
|
|
|
@Component({
|
|
|
|
selector: 'app-nic-dropdown',
|
|
|
|
templateUrl: './nic-dropdown.component.html',
|
|
|
|
styleUrls: ['./nic-dropdown.component.scss'],
|
|
|
|
})
|
2018-08-26 11:09:12 +00:00
|
|
|
export class NicDropdownComponent implements OnInit {
|
2018-08-18 01:04:59 +00:00
|
|
|
@Input() blockTarget: any;
|
2018-09-09 10:20:21 +00:00
|
|
|
@Output() select = new EventEmitter<Zone>();
|
2018-09-10 07:37:42 +00:00
|
|
|
@ViewChild('panel') panel: DropdownPanelComponent;
|
2018-08-17 10:53:40 +00:00
|
|
|
|
2018-09-10 07:37:42 +00:00
|
|
|
nics: SelectItem[] = [];
|
|
|
|
selected;
|
2018-08-27 01:41:27 +00:00
|
|
|
|
2018-08-17 10:53:40 +00:00
|
|
|
constructor(
|
2018-08-26 11:09:12 +00:00
|
|
|
private probeService: ProbeService,
|
2018-08-17 10:53:40 +00:00
|
|
|
) {
|
|
|
|
|
|
|
|
}
|
2018-08-26 11:09:12 +00:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
2018-08-26 15:15:10 +00:00
|
|
|
this.probeService.call<Interface>('MachineService.Interfaces').pipe(
|
|
|
|
map((ifaces: Interface[]) => {
|
2018-08-27 01:41:27 +00:00
|
|
|
ifaces.forEach(iface => {
|
2018-09-11 10:33:00 +00:00
|
|
|
console.log(iface);
|
2018-08-27 01:41:27 +00:00
|
|
|
iface.addresses.forEach(address => {
|
2018-09-12 05:25:32 +00:00
|
|
|
if (address.metaIPType.key !== toMetaIPType(MetaIPTypeEnum.V4).key) {
|
2018-09-10 07:37:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.nics.push({
|
|
|
|
label: iface.iface + ' (' + address.address + ')',
|
|
|
|
value: {
|
|
|
|
name: iface.iface,
|
|
|
|
metaIPType: address.metaIPType,
|
|
|
|
mac: iface.mac,
|
|
|
|
address: address.address,
|
|
|
|
},
|
2018-09-12 05:25:32 +00:00
|
|
|
disabled: address.metaIPType.key !== toMetaIPType(MetaIPTypeEnum.V4).key ? true : false,
|
2018-08-27 01:41:27 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-09-10 07:37:42 +00:00
|
|
|
if (this.nics.length > 0) {
|
|
|
|
this.nicSelected(this.nics[0].value);
|
|
|
|
}
|
2018-08-26 11:09:12 +00:00
|
|
|
}),
|
|
|
|
catchError(error => {
|
|
|
|
console.log(error);
|
|
|
|
return of();
|
|
|
|
}),
|
|
|
|
take(1),
|
|
|
|
).subscribe();
|
2018-09-10 07:37:42 +00:00
|
|
|
|
2018-08-26 11:09:12 +00:00
|
|
|
}
|
2018-09-09 10:20:21 +00:00
|
|
|
|
2018-09-10 07:37:42 +00:00
|
|
|
nicSelected(nic: SelectItem) {
|
|
|
|
this.selected = nic;
|
|
|
|
|
2018-09-12 05:25:32 +00:00
|
|
|
const zone: Zone = {
|
|
|
|
network: this.selected.network,
|
2018-09-10 07:37:42 +00:00
|
|
|
iface: this.selected.name,
|
2018-09-09 10:20:21 +00:00
|
|
|
metaIPType: toMetaIPType(MetaIPTypeEnum.V4),
|
2018-09-12 05:25:32 +00:00
|
|
|
address: this.selected.address,
|
2018-09-10 07:37:42 +00:00
|
|
|
mac: this.selected.mac,
|
2018-09-12 05:25:32 +00:00
|
|
|
};
|
2018-09-09 10:20:21 +00:00
|
|
|
this.select.emit(zone);
|
2018-09-10 07:37:42 +00:00
|
|
|
|
|
|
|
this.panel.hide();
|
2018-09-09 10:20:21 +00:00
|
|
|
}
|
|
|
|
|
2018-08-17 10:53:40 +00:00
|
|
|
}
|