import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { NzModalSubject } from 'ng-zorro-antd';
import { parseResponse } from '../../../shared/util';
import { PlatformService } from '../../platform.service';
// import { AnalysisService } from '../analysis.service';
@Component({
selector: 'analysis-form',
templateUrl: './analysis-form.component.html',
styleUrls: ['./analysis-form.component.less']
})
export class AnalysisFormComponent implements OnInit {
validateForm: FormGroup;
systems = [];
currentSystem: number;
tables = [];
currentTable: number;
constructor(private fb: FormBuilder,
private platformServ: PlatformService,
// private analysisServ: AnalysisService,
private subject: NzModalSubject) {
}
onSummit() {
// 去掉databaseId属性
const { databaseId, ...submitValue } = this.validateForm.value;
for (const i in this.validateForm.controls) {
this.validateForm.controls[ i ].markAsDirty();
}
if (!this.validateForm.valid) return;
// this.analysisServ.addAnalysis(submitValue).subscribe(data => {
// this.subject.next('success');
// });
}
handleCancel() {
this.subject.destroy();
}
getFormControl(name: string) {
return this.validateForm.get(name);
}
ngOnInit() {
this.validateForm = this.fb.group({
name: [ null, [ Validators.required ] ],
description: [ null ],
databaseId: [],
tableId: [ null, [ Validators.required ] ],
});
this.platformServ.getSystemList().subscribe(data => {
this.systems = parseResponse(data).data;
this.currentSystem = this.systems[0].id;
});
}
private updateTables(systemId: number) {
this.platformServ.getTableList((systemId))
.subscribe(data => {
this.tables = parseResponse(data).data;
this.currentTable = this.tables[0].id;
});
}
}
|