@@ -4,10 +4,10 @@ import IUpdateTable from '../../model/update-table'
4
4
import { DataService } from 'src/app/services/data/data.service'
5
5
import { MatDialog } from '@angular/material/dialog'
6
6
import { InfodialogComponent } from '../infodialog/infodialog.component'
7
- import IColumnTabData , { IIndexData } from '../../model/edit-table'
7
+ import IColumnTabData , { AutoGen , IIndexData } from '../../model/edit-table'
8
8
import { SnackbarService } from 'src/app/services/snackbar/snackbar.service'
9
9
import IFkTabData from 'src/app/model/fk-tab-data'
10
- import { ColLength , Dialect , ObjectDetailNodeType , ObjectExplorerNodeType , StorageKeys } from 'src/app/app.constants'
10
+ import { ColLength , Dialect , ObjectDetailNodeType , ObjectExplorerNodeType , SourceDbNames , StorageKeys } from 'src/app/app.constants'
11
11
import FlatNode from 'src/app/model/schema-object-node'
12
12
import { Subscription , take } from 'rxjs'
13
13
import { MatTabChangeEvent } from '@angular/material/tabs/'
@@ -22,6 +22,7 @@ import { DropIndexOrTableDialogComponent } from '../drop-index-or-table-dialog/d
22
22
import { SidenavService } from 'src/app/services/sidenav/sidenav.service'
23
23
import { TableUpdatePubSubService } from 'src/app/services/table-update-pub-sub/table-update-pub-sub.service'
24
24
import { AddNewColumnComponent } from '../add-new-column/add-new-column.component'
25
+ import { GroupedAutoGens , processAutoGens } from 'src/app/utils/utils'
25
26
26
27
@Component ( {
27
28
selector : 'app-object-detail' ,
@@ -43,12 +44,13 @@ export class ObjectDetailComponent implements OnInit {
43
44
@Input ( ) currentObject : FlatNode | null = null
44
45
@Input ( ) typeMap : any = { }
45
46
@Input ( ) defaultTypeMap : any = { }
47
+ @Input ( ) autoGenMap : any = { }
46
48
@Input ( ) ddlStmts : any = { }
47
49
@Input ( ) fkData : IFkTabData [ ] = [ ]
48
50
@Input ( ) tableData : IColumnTabData [ ] = [ ]
49
51
@Input ( ) currentDatabase : string = 'spanner'
50
52
@Input ( ) indexData : IIndexData [ ] = [ ]
51
- @Input ( ) srcDbName : String = localStorage . getItem ( StorageKeys . SourceDbName ) as string
53
+ @Input ( ) srcDbName : string = localStorage . getItem ( StorageKeys . SourceDbName ) as string
52
54
@Output ( ) updateSidebar = new EventEmitter < boolean > ( )
53
55
ObjectExplorerNodeType = ObjectExplorerNodeType
54
56
conv : IConv = { } as IConv
@@ -59,13 +61,17 @@ export class ObjectDetailComponent implements OnInit {
59
61
localIndexData : IIndexData [ ] = [ ]
60
62
isMiddleColumnCollapse : boolean = false
61
63
isPostgreSQLDialect : boolean = false
64
+ processedAutoGenMap : GroupedAutoGens = { } ;
65
+ autoGenSupportedDbs : string [ ] = [ 'MySQL' ]
66
+ autGenSupported : boolean = false
62
67
ngOnInit ( ) : void {
63
68
this . data . conv . subscribe ( {
64
69
next : ( res : IConv ) => {
65
70
this . conv = res
66
71
this . isPostgreSQLDialect = this . conv . SpDialect === Dialect . PostgreSQLDialect
67
72
} ,
68
73
} )
74
+ this . autGenSupported = this . autoGenSupportedDbs . includes ( this . srcDbName )
69
75
}
70
76
71
77
srcDisplayedColumns = [ 'srcOrder' , 'srcColName' , 'srcDataType' , 'srcColMaxLength' , 'srcIsPk' , 'srcIsNotNull' ]
@@ -141,6 +147,7 @@ export class ObjectDetailComponent implements OnInit {
141
147
} )
142
148
pkObj : IPrimaryKey = { } as IPrimaryKey
143
149
dataTypesWithColLen : string [ ] = ColLength . DataTypes
150
+ spColspan : number = 6
144
151
145
152
ngOnChanges ( changes : SimpleChanges ) : void {
146
153
this . fkData = changes [ 'fkData' ] ?. currentValue || this . fkData
@@ -167,6 +174,11 @@ export class ObjectDetailComponent implements OnInit {
167
174
this . localTableData = JSON . parse ( JSON . stringify ( this . tableData ) )
168
175
this . localIndexData = JSON . parse ( JSON . stringify ( this . indexData ) )
169
176
177
+ if ( this . srcDbName == SourceDbNames . MySQL && ! this . spDisplayedColumns . includes ( "spAutoGen" ) ) {
178
+ this . spDisplayedColumns . splice ( 2 , 0 , "spAutoGen" ) ;
179
+ this . spColspan ++ ;
180
+ }
181
+
170
182
if ( this . currentObject ?. type === ObjectExplorerNodeType . Table ) {
171
183
this . checkIsInterleave ( )
172
184
@@ -183,6 +195,7 @@ export class ObjectDetailComponent implements OnInit {
183
195
this . setFkRows ( )
184
196
this . updateSpTableSuggestion ( )
185
197
this . setShardIdColumn ( )
198
+ this . processedAutoGenMap = processAutoGens ( this . autoGenMap )
186
199
} else if ( this . currentObject ?. type === ObjectExplorerNodeType . Index ) {
187
200
this . indexOrderValidation ( )
188
201
this . setIndexRows ( )
@@ -213,6 +226,7 @@ export class ObjectDetailComponent implements OnInit {
213
226
srcId : new FormControl ( row . srcId ) ,
214
227
spColMaxLength : new FormControl ( row . spColMaxLength , [
215
228
Validators . required ] ) ,
229
+ spAutoGen : new FormControl ( row . spAutoGen ) ,
216
230
} )
217
231
if ( this . dataTypesWithColLen . indexOf ( row . spDataType . toString ( ) ) > - 1 ) {
218
232
fb . get ( 'spColMaxLength' ) ?. setValidators ( [ Validators . required , Validators . pattern ( '([1-9][0-9]*|MAX)' ) ] )
@@ -259,6 +273,7 @@ export class ObjectDetailComponent implements OnInit {
259
273
spId : new FormControl ( col . spId ) ,
260
274
srcId : new FormControl ( col . srcId ) ,
261
275
spColMaxLength : new FormControl ( col . spColMaxLength ) ,
276
+ spAutoGen : new FormControl ( col . spAutoGen ) ,
262
277
} )
263
278
)
264
279
} else {
@@ -278,6 +293,7 @@ export class ObjectDetailComponent implements OnInit {
278
293
spIsPk : new FormControl ( col . srcIsPk ) ,
279
294
spIsNotNull : new FormControl ( col . srcIsNotNull ) ,
280
295
spColMaxLength : new FormControl ( col . srcColMaxLength ) ,
296
+ spAutoGen : new FormControl ( col . spAutoGen )
281
297
} )
282
298
)
283
299
}
@@ -340,7 +356,8 @@ export class ObjectDetailComponent implements OnInit {
340
356
NotNull : col . spIsNotNull ? 'ADDED' : 'REMOVED' ,
341
357
Removed : false ,
342
358
ToType : ( this . conv . SpDialect === Dialect . PostgreSQLDialect ) ? ( standardDataType === undefined ? col . spDataType : standardDataType ) : col . spDataType ,
343
- MaxColLength : col . spColMaxLength
359
+ MaxColLength : col . spColMaxLength ,
360
+ AutoGen : col . spAutoGen
344
361
}
345
362
break
346
363
}
@@ -351,7 +368,8 @@ export class ObjectDetailComponent implements OnInit {
351
368
NotNull : col . spIsNotNull ? 'ADDED' : 'REMOVED' ,
352
369
Removed : false ,
353
370
ToType : ( this . conv . SpDialect === Dialect . PostgreSQLDialect ) ? ( standardDataType === undefined ? col . spDataType : standardDataType ) : col . spDataType ,
354
- MaxColLength : col . spColMaxLength
371
+ MaxColLength : col . spColMaxLength ,
372
+ AutoGen : col . spAutoGen
355
373
}
356
374
}
357
375
}
@@ -365,6 +383,10 @@ export class ObjectDetailComponent implements OnInit {
365
383
Removed : true ,
366
384
ToType : '' ,
367
385
MaxColLength : '' ,
386
+ AutoGen : {
387
+ Name : '' ,
388
+ GenerationType : ''
389
+ }
368
390
}
369
391
} )
370
392
@@ -418,6 +440,7 @@ export class ObjectDetailComponent implements OnInit {
418
440
this . localTableData [ index ] . spIsPk = this . droppedColumns [ addedRowIndex ] . spIsPk
419
441
this . localTableData [ index ] . spIsNotNull = this . droppedColumns [ addedRowIndex ] . spIsNotNull
420
442
this . localTableData [ index ] . spColMaxLength = this . droppedColumns [ addedRowIndex ] . spColMaxLength
443
+ this . localTableData [ index ] . spAutoGen = this . droppedColumns [ addedRowIndex ] . spAutoGen
421
444
let ind = this . droppedColumns
422
445
. map ( ( col : IColumnTabData ) => col . spColName )
423
446
. indexOf ( this . addedColumnName )
@@ -512,6 +535,10 @@ export class ObjectDetailComponent implements OnInit {
512
535
col . spIsPk = false
513
536
col . spOrder = ''
514
537
col . spColMaxLength = ''
538
+ col . spAutoGen = {
539
+ Name : '' ,
540
+ GenerationType : ''
541
+ }
515
542
}
516
543
} )
517
544
this . setSpTableRows ( )
@@ -541,6 +568,10 @@ export class ObjectDetailComponent implements OnInit {
541
568
this . spTableSuggestion [ index ] = brief
542
569
}
543
570
571
+ compareAutoGen ( t1 : any , t2 : any ) : boolean {
572
+ return t1 && t2 ? t1 . Name === t2 . Name && t1 . GenerationType === t2 . GenerationType : t1 === t2 ;
573
+ }
574
+
544
575
setPkRows ( ) {
545
576
this . pkArray = this . fb . array ( [ ] )
546
577
this . pkOrderValidation ( )
@@ -565,6 +596,7 @@ export class ObjectDetailComponent implements OnInit {
565
596
spIsPk : row . spIsPk ,
566
597
spOrder : row . spOrder ,
567
598
spId : row . spId ,
599
+ spAutoGen : row . spAutoGen
568
600
} )
569
601
}
570
602
} )
@@ -590,6 +622,7 @@ export class ObjectDetailComponent implements OnInit {
590
622
spIsPk : new FormControl ( spArr [ i ] . spIsPk ) ,
591
623
spIsNotNull : new FormControl ( spArr [ i ] . spIsNotNull ) ,
592
624
spId : new FormControl ( spArr [ i ] . spId ) ,
625
+ spAutoGen : new FormControl ( spArr [ i ] . spAutoGen ) ,
593
626
} )
594
627
)
595
628
}
@@ -609,6 +642,7 @@ export class ObjectDetailComponent implements OnInit {
609
642
spIsPk : new FormControl ( false ) ,
610
643
spIsNotNull : new FormControl ( false ) ,
611
644
spId : new FormControl ( '' ) ,
645
+ spAutoGen : new FormControl ( spArr [ i ] . spAutoGen ) ,
612
646
} )
613
647
)
614
648
}
@@ -628,6 +662,7 @@ export class ObjectDetailComponent implements OnInit {
628
662
spIsPk : new FormControl ( spArr [ i ] . spIsPk ) ,
629
663
spIsNotNull : new FormControl ( spArr [ i ] . spIsNotNull ) ,
630
664
spId : new FormControl ( spArr [ i ] . spId ) ,
665
+ spAutoGenGen : new FormControl ( spArr [ i ] . spAutoGen )
631
666
} )
632
667
)
633
668
}
0 commit comments