All files / src/app/platform/analysis/analysis-form analysis-form.component.ts

67.57% Statements 25/37
0% Branches 0/2
55.56% Functions 5/9
73.33% Lines 22/30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 711x 1x 1x   1x 1x               1x   2x   2x     2x 2x   2x       1x                         1x       1x 8x     1x 1x             1x 1x 1x       1x             1x  
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;
    });
  }
}