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

43 lines
1.0 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() {
this.onPreselected();
}
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-28 12:12:11 +00:00
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);
2018-05-28 09:58:13 +00:00
}
2018-05-28 12:12:11 +00:00
2018-05-28 09:58:13 +00:00
}