import { Component, Input, OnInit, EventEmitter, Output } from '@angular/core'; import { of } from 'rxjs'; import { catchError, map, take } from 'rxjs/operators'; import { ProbeService } from '../service/probe.service'; import { Interface } from '@overflow/model/net/nic'; import { MenuItem } from 'primeng/primeng'; import { Zone } from '@overflow/model/discovery'; import { toMetaIPType, MetaIPTypeEnum } from '@overflow/model/meta'; @Component({ selector: 'app-nic-dropdown', templateUrl: './nic-dropdown.component.html', styleUrls: ['./nic-dropdown.component.scss'], }) export class NicDropdownComponent implements OnInit { @Input() blockTarget: any; @Output() select = new EventEmitter(); addresses: MenuItem[]; constructor( private probeService: ProbeService, ) { } ngOnInit(): void { this.probeService.call('MachineService.Interfaces').pipe( map((ifaces: Interface[]) => { console.log(ifaces); this.addresses = []; ifaces.forEach(iface => { iface.addresses.forEach(address => { this.addresses.push({ label: address.address, command: () => { this.makeZone(iface, address.address); } }); }); }); }), catchError(error => { console.log(error); return of(); }), take(1), ).subscribe(); } makeZone(iface: Interface, address: string) { var zone: Zone = { network: address, iface: iface.iface, metaIPType: toMetaIPType(MetaIPTypeEnum.V4), address: '192.168.1.103', // mac: iface.mac, } this.select.emit(zone); } }