app/src/commons/component/nic-dropdown.component.ts

55 lines
1.2 KiB
TypeScript
Raw Normal View History

2018-08-26 11:09:12 +00:00
import { Component, Input, OnInit } from '@angular/core';
import { Observable, Subscription, of } from 'rxjs';
import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators';
import { ProbeService } from '../service/probe.service';
2018-08-26 15:15:10 +00:00
import { Interface } from '@overflow/model/net/nic';
2018-08-17 10:53:40 +00:00
2018-08-27 01:41:27 +00:00
export interface Address {
label: string;
value: string;
}
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-08-17 10:53:40 +00:00
2018-08-27 01:41:27 +00:00
addresses: Address[];
selectedAddress: Address;
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-26 11:09:12 +00:00
console.log(ifaces);
2018-08-27 01:41:27 +00:00
this.addresses = [];
ifaces.forEach(iface => {
iface.addresses.forEach(address => {
this.addresses.push({
label: address.address,
value: address.address,
});
});
});
2018-08-26 11:09:12 +00:00
}),
catchError(error => {
console.log(error);
return of();
}),
take(1),
).subscribe();
}
2018-08-17 10:53:40 +00:00
}