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

68 lines
1.7 KiB
TypeScript
Raw Normal View History

2018-09-09 10:20:21 +00:00
import { Component, Input, OnInit, EventEmitter, Output } 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-09 10:20:21 +00:00
import { MenuItem } from 'primeng/primeng';
import { Zone } from '@overflow/model/discovery';
import { toMetaIPType, MetaIPTypeEnum } from '@overflow/model/meta';
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-08-17 10:53:40 +00:00
2018-09-09 10:20:21 +00:00
addresses: MenuItem[];
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-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,
2018-09-09 10:20:21 +00:00
command: () => {
this.makeZone(iface, address.address);
}
2018-08-27 01:41:27 +00:00
});
});
});
2018-08-26 11:09:12 +00:00
}),
catchError(error => {
console.log(error);
return of();
}),
take(1),
).subscribe();
}
2018-09-09 10:20:21 +00:00
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);
}
2018-08-17 10:53:40 +00:00
}