setSpTableRows()

in ui/src/app/components/object-detail/object-detail.component.ts [270:334]


  setSpTableRows() {
    this.spRowArray = this.fb.array([])
    this.localTableData.forEach((row) => {
      if (row.spOrder) {
        let fb = new FormGroup({
          srcOrder: new FormControl(row.srcOrder),
          srcColName: new FormControl(row.srcColName),
          srcDataType: new FormControl(row.srcDataType),
          srcIsPk: new FormControl(row.srcIsPk),
          srcIsNotNull: new FormControl(row.srcIsNotNull),
          srcDefaultValue: new FormControl(row.srcDefaultValue),
          srcColMaxLength: new FormControl(row.srcColMaxLength),
          srcAutoGen: new FormControl(row.srcAutoGen),
          spOrder: new FormControl(row.srcOrder),
          spColName: new FormControl(row.spColName, [
            Validators.required,
            Validators.pattern('^[a-zA-Z]([a-zA-Z0-9/_]*[a-zA-Z0-9])?'),
          ]),
          spDataType: new FormControl(row.spDataType),
          spIsPk: new FormControl(row.spIsPk),
          spIsNotNull: new FormControl(row.spIsNotNull), spId: new FormControl(row.spId),
          srcId: new FormControl(row.srcId),
          spColMaxLength: new FormControl(row.spColMaxLength, [
            Validators.required]),
          spAutoGen: new FormControl(row.spAutoGen),
          spDefaultValue: new FormControl(row.spDefaultValue ? row.spDefaultValue.Value.Statement : ''),
        })
        // Disable spDefaultValue if spAutoGen is set
        if (row.spAutoGen.Name !== '') {
          fb.get('spDefaultValue')?.disable();
        }
        // Subscribe to changes in spAutoGen
        fb.get('spAutoGen')?.valueChanges.subscribe((autoGen: AutoGen | null) => { // Allow null value
          if (autoGen && autoGen.Name !== '') {
            fb.get('spDefaultValue')?.disable();
          } else {
            fb.get('spDefaultValue')?.enable();
          }
        });
        if (this.dataTypesWithColLen.indexOf(row.spDataType.toString()) > -1) {
          fb.get('spColMaxLength')?.setValidators([Validators.required, Validators.pattern('([1-9][0-9]*|MAX)')])
          if (row.spColMaxLength === undefined) {
            fb.get('spColMaxLength')?.setValue('MAX')
          }
          else if (row.spColMaxLength !== 'MAX') {
            if ((row.spDataType === 'STRING' || row.spDataType === 'VARCHAR') && typeof row.spColMaxLength === "number" && row.spColMaxLength > ColLength.StringMaxLength) {
              fb.get('spColMaxLength')?.setValue('MAX')
            } else if (row.spDataType === 'BYTES' && typeof row.spColMaxLength === "number" && row.spColMaxLength > ColLength.ByteMaxLength) {
              fb.get('spColMaxLength')?.setValue('MAX')
            }
          }
        } else {
          fb.controls['spColMaxLength'].clearValidators()
        }
        if (row.spAutoGen?.Name !== '') {
          fb.get('spDefaultValue')?.setValue('');
        }
        fb.controls['spColMaxLength'].updateValueAndValidity()
        this.spRowArray.push(
          fb
        )
      }
    })
    this.spDataSource = this.spRowArray.controls
  }