Merge remote-tracking branch 'origin/master'

This commit is contained in:
geek 2018-05-29 18:32:26 +09:00
commit 60d2775dfa

View File

@ -1,11 +1,11 @@
import { Component, Input, Output, EventEmitter, OnChanges, SimpleChanges, OnInit } from '@angular/core'; import { Component, Input, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core';
import { ProbeHost, Probe } from '@overflow/commons-typescript/model/probe'; import { ProbeHost, Probe } from '@overflow/commons-typescript/model/probe';
@Component({ @Component({
selector: 'of-probe-selector', selector: 'of-probe-selector',
templateUrl: './selector.component.html', templateUrl: './selector.component.html',
}) })
export class ProbeSelectorComponent implements OnInit, OnChanges { export class ProbeSelectorComponent implements OnChanges {
@Output() select = new EventEmitter<ProbeHost>(); @Output() select = new EventEmitter<ProbeHost>();
@Input() probeHosts: ProbeHost[]; @Input() probeHosts: ProbeHost[];
@ -16,24 +16,22 @@ export class ProbeSelectorComponent implements OnInit, OnChanges {
constructor() { constructor() {
} }
ngOnInit() {
}
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
this.checkPreselected();
this.options = []; this.options = [];
for (const ph of this.probeHosts) { for (const ph of this.probeHosts) {
this.options.push(ph.probe); this.options.push(ph.probe);
} }
if (changes['probeHosts'] !== null && changes['probeHosts'].currentValue.length > 0) {
this.checkPreselected();
}
} }
checkPreselected() { checkPreselected() {
alert(this.probeHosts.length); if (!this.probeHosts || !this.probeHostID) {
const preselected: ProbeHost = this.probeHosts.find(probeHost => probeHost.id === this.probeHostID); return;
}
setTimeout(() => {
const preselected = this.probeHosts.find(probeHost => probeHost.id === Number(this.probeHostID));
this.select.emit(preselected); this.select.emit(preselected);
});
} }
onSelect(probe: Probe) { onSelect(probe: Probe) {