43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
import { Component, Input, Output, EventEmitter, OnChanges, SimpleChanges, OnInit } from '@angular/core';
|
|
import { ProbeHost, Probe } from '@overflow/commons-typescript/model/probe';
|
|
|
|
@Component({
|
|
selector: 'of-probe-selector',
|
|
templateUrl: './selector.component.html',
|
|
})
|
|
export class ProbeSelectorComponent implements OnInit, OnChanges {
|
|
|
|
@Output() select = new EventEmitter<ProbeHost>();
|
|
@Input() probeHosts: ProbeHost[];
|
|
@Input() probeHostID: number;
|
|
|
|
options: Probe[];
|
|
|
|
constructor() {
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.onPreselected();
|
|
}
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
this.options = [];
|
|
for (const ph of this.probeHosts) {
|
|
this.options.push(ph.probe);
|
|
}
|
|
}
|
|
|
|
onPreselected() {
|
|
if (this.probeHostID) {
|
|
const preselected: ProbeHost = this.probeHosts.find(probeHost => probeHost.id === this.probeHostID);
|
|
this.select.emit(preselected);
|
|
}
|
|
}
|
|
|
|
onSelect(probe: Probe) {
|
|
const optionselected = this.probeHosts.find(probeHost => probeHost.id === probe.id);
|
|
this.select.emit(optionselected);
|
|
}
|
|
|
|
}
|