saveColumnTable()

in ui/src/app/components/object-detail/object-detail.component.ts [430:536]


  saveColumnTable() {
    this.isEditMode = false
    let updateData: IUpdateTable = { UpdateCols: {} }
    let pgSQLToStandardTypeTypemap: Map<String, String>;
    this.conversion.pgSQLToStandardTypeTypeMap.subscribe((typemap) => {
      pgSQLToStandardTypeTypemap = typemap
    })
    this.spRowArray.value.forEach((col: IColumnTabData, i: number) => {
      for (let j = 0; j < this.tableData.length; j++) {
        let oldRow = this.tableData[j]
        let standardDataType = pgSQLToStandardTypeTypemap.get(col.spDataType)
        if (col.spColMaxLength !== undefined && col.spColMaxLength !== 'MAX') {
          if ((col.spDataType === 'STRING' || col.spDataType === 'VARCHAR') && typeof col.spColMaxLength === "number" && col.spColMaxLength > ColLength.StringMaxLength) {
            col.spColMaxLength = 'MAX'
          } else if (col.spDataType === 'BYTES' && typeof col.spColMaxLength === "number" && col.spColMaxLength > ColLength.ByteMaxLength) {
            col.spColMaxLength = 'MAX'
          }
        }
        if (typeof (col.spColMaxLength) === 'number') {
          col.spColMaxLength = col.spColMaxLength.toString()
        }
        if (col.spDataType != 'STRING' && col.spDataType != 'BYTES' && col.spDataType != 'VARCHAR') {
          col.spColMaxLength = ""
        }
        if (col.srcId == this.tableData[j].srcId && this.tableData[j].srcId != '') {
          updateData.UpdateCols[this.tableData[j].srcId] = {
            Add: this.tableData[j].spId == '',
            Rename: oldRow.spColName !== col.spColName ? col.spColName : '',
            NotNull: col.spIsNotNull ? 'ADDED' : 'REMOVED',
            Removed: false,
            ToType: (this.conv.SpDialect === Dialect.PostgreSQLDialect) ? (standardDataType === undefined ? col.spDataType : standardDataType) : col.spDataType,
            MaxColLength: col.spColMaxLength,
            AutoGen: col.spAutoGen,
            DefaultValue: {
              IsPresent: col.spDefaultValue ? true : false,
              Value: {
                ExpressionId: '',
                Statement: String(col.spDefaultValue)
              }
            }
          }
          break
        }
        else if (col.spId == this.tableData[j].spId) {
          updateData.UpdateCols[this.tableData[j].spId] = {
            Add: this.tableData[j].spId == '',
            Rename: oldRow.spColName !== col.spColName ? col.spColName : '',
            NotNull: col.spIsNotNull ? 'ADDED' : 'REMOVED',
            Removed: false,
            ToType: (this.conv.SpDialect === Dialect.PostgreSQLDialect) ? (standardDataType === undefined ? col.spDataType : standardDataType) : col.spDataType,
            MaxColLength: col.spColMaxLength,
            AutoGen: col.spAutoGen,
            DefaultValue: {
              IsPresent: col.spDefaultValue ? true : false,
              Value: {
                ExpressionId: '',
                Statement:  col.spDefaultValue? col.spDefaultValue.Value.Statement: ''
              }
            }
          }
        }
      }
    })

    this.droppedColumns.forEach((col: IColumnTabData) => {
      updateData.UpdateCols[col.spId] = {
        Add: false,
        Rename: '',
        NotNull: '',
        Removed: true,
        ToType: '',
        MaxColLength: '',
        AutoGen: {
          Name : '',
          GenerationType : ''
        },
        DefaultValue: {
          IsPresent: false,
          Value: {
            ExpressionId: '',
            Statement: ''
          }
        }
      }
    })

    this.data.reviewTableUpdate(this.currentObject!.id, updateData).subscribe({
      next: (res: string) => {
        if (res == '') {
          this.sidenav.openSidenav()
          this.sidenav.setSidenavComponent('reviewChanges')
          this.tableUpdatePubSub.setTableUpdateDetail({
            tableName: this.currentObject!.name,
            tableId: this.currentObject!.id,
            updateDetail: updateData,
          })
          this.isEditMode = true
        } else {
          this.dialog.open(InfodialogComponent, {
            data: { message: res, type: 'error' },
            maxWidth: '500px',
          })
          this.isEditMode = true
        }
      },
    })
  }