2018-05-29 06:16:06 +00:00
|
|
|
import { Component, Input, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core';
|
2018-05-28 09:58:13 +00:00
|
|
|
import { ProbeHost, Probe } from '@overflow/commons-typescript/model/probe';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'of-probe-selector',
|
|
|
|
templateUrl: './selector.component.html',
|
|
|
|
})
|
2018-05-29 06:16:06 +00:00
|
|
|
export class ProbeSelectorComponent implements OnChanges {
|
2018-05-28 09:58:13 +00:00
|
|
|
|
|
|
|
@Output() select = new EventEmitter<ProbeHost>();
|
|
|
|
@Input() probeHosts: ProbeHost[];
|
|
|
|
@Input() probeHostID: number;
|
|
|
|
|
|
|
|
options: Probe[];
|
2018-05-29 12:18:43 +00:00
|
|
|
selected: Probe;
|
2018-05-28 09:58:13 +00:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
2018-05-29 06:16:06 +00:00
|
|
|
this.checkPreselected();
|
2018-05-28 09:58:13 +00:00
|
|
|
this.options = [];
|
|
|
|
for (const ph of this.probeHosts) {
|
|
|
|
this.options.push(ph.probe);
|
|
|
|
}
|
2018-05-28 12:12:11 +00:00
|
|
|
}
|
|
|
|
|
2018-05-29 04:13:28 +00:00
|
|
|
checkPreselected() {
|
2018-05-29 06:16:06 +00:00
|
|
|
if (!this.probeHosts || !this.probeHostID) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setTimeout(() => {
|
|
|
|
const preselected = this.probeHosts.find(probeHost => probeHost.id === Number(this.probeHostID));
|
|
|
|
this.select.emit(preselected);
|
|
|
|
});
|
2018-05-29 04:13:28 +00:00
|
|
|
}
|
|
|
|
|
2018-05-29 12:18:43 +00:00
|
|
|
onSelect() {
|
|
|
|
const optionselected = this.probeHosts.find(probeHost => probeHost.probe.id === this.selected.id);
|
2018-05-28 12:12:11 +00:00
|
|
|
this.select.emit(optionselected);
|
2018-05-28 09:58:13 +00:00
|
|
|
}
|
2018-05-28 12:12:11 +00:00
|
|
|
|
2018-05-28 09:58:13 +00:00
|
|
|
}
|