member_webapp/@overflow/probe/component/selector/selector.component.ts

45 lines
1.2 KiB
TypeScript
Raw Normal View History

2018-05-28 12:12:11 +00:00
import { Component, Input, Output, EventEmitter, OnChanges, SimpleChanges, OnInit } 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-28 12:12:11 +00:00
export class ProbeSelectorComponent implements OnInit, OnChanges {
2018-05-28 09:58:13 +00:00
@Output() select = new EventEmitter<ProbeHost>();
@Input() probeHosts: ProbeHost[];
@Input() probeHostID: number;
options: Probe[];
constructor() {
}
2018-05-28 12:12:11 +00:00
ngOnInit() {
}
2018-05-28 09:58:13 +00:00
ngOnChanges(changes: SimpleChanges): void {
this.options = [];
for (const ph of this.probeHosts) {
this.options.push(ph.probe);
}
2018-05-29 04:13:28 +00:00
if (changes['probeHosts'] !== null && changes['probeHosts'].currentValue.length > 0) {
this.checkPreselected();
2018-05-28 12:12:11 +00:00
}
}
2018-05-29 04:13:28 +00:00
checkPreselected() {
alert(this.probeHosts.length);
const preselected: ProbeHost = this.probeHosts.find(probeHost => probeHost.id === this.probeHostID);
this.select.emit(preselected);
}
2018-05-28 12:12:11 +00:00
onSelect(probe: Probe) {
const optionselected = this.probeHosts.find(probeHost => probeHost.id === probe.id);
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
}