@@ -7,6 +7,7 @@ import { StringUtils } from "@renderer/utils/string.utils";
77import { ActionEnum } from "@renderer/enum/action.enum" ;
88import { TypeEnum } from "@renderer/enum/type.enum" ;
99import { AssertUtils } from "@renderer/app/views/object_designer/utils/assert.utils" ;
10+ import { NzMessageService } from "ng-zorro-antd/message" ;
1011
1112@Component ( {
1213 selector : 'object-designer-layout-content-detail-database' ,
@@ -17,45 +18,92 @@ export class LayoutContentDetailDatabaseComponent implements AfterViewInit {
1718 @Input ( )
1819 applyData : DesignerApplyData ;
1920
21+ loading = {
22+ tableContainer : false ,
23+ }
2024 tableDataSize = 0 ;
2125 applyResultColumns = [ ] ;
22- loading = {
23- tableContainer : false
26+ applySelectTable = {
27+ checkedTables : new Set < string > ( )
28+ }
29+ deleteTable = {
30+ visible : false ,
31+ loading : false
2432 }
2533
2634 constructor ( private pluginFactory : PluginFactory ,
27- private configFactory : ConfigFactory ) {
35+ private configFactory : ConfigFactory ,
36+ private messageService : NzMessageService ) {
2837 }
2938
3039 ngAfterViewInit ( ) : void {
31- setTimeout ( ( ) => {
32- this . loading . tableContainer = true ;
33- this . tableDataSize = 0 ;
34- const request = new RequestModel ( ) ;
35- request . config = this . applyData . dataSource ;
36- const type = this . applyData . dataSource . type ;
37- const sql = StringUtils . format ( this . configFactory . createConfig ( type ) . getStatement ( 'metadataManagementFetchTables' ) ,
38- [ this . applyData . database ] ) ;
39-
40- this . pluginFactory . createService ( type )
41- . getResponse ( request , sql )
42- . then ( response => {
43- if ( response . status ) {
44- this . tableDataSize = response . data . rows ;
45- if ( this . tableDataSize > 0 ) {
46- this . applyResultColumns = response . data . columns ;
47- }
40+ setTimeout ( ( ) => this . handlerInitializer ( ) , 0 )
41+ }
42+
43+ handlerInitializer ( ) {
44+ this . loading . tableContainer = true ;
45+ this . tableDataSize = 0 ;
46+ const request = new RequestModel ( ) ;
47+ request . config = this . applyData . dataSource ;
48+ const type = this . applyData . dataSource . type ;
49+ const sql = StringUtils . format ( this . configFactory . createConfig ( type ) . getStatement ( 'metadataManagementFetchTables' ) ,
50+ [ this . applyData . database ] ) ;
51+
52+ this . pluginFactory . createService ( type )
53+ . getResponse ( request , sql )
54+ . then ( response => {
55+ if ( response . status ) {
56+ this . tableDataSize = response . data . rows ;
57+ if ( this . tableDataSize > 0 ) {
58+ this . applyResultColumns = response . data . columns ;
4859 }
49- this . loading . tableContainer = false ;
50- } ) ;
51- } , 0 )
60+ }
61+ this . loading . tableContainer = false ;
62+ } ) ;
5263 }
5364
5465 handlerNewTable ( ) {
5566 this . applyData . command . action = ActionEnum . create ;
5667 this . applyData . command . type = TypeEnum . table ;
5768 }
5869
70+ handlerTableChecked ( tableName : string , checked : boolean ) {
71+ if ( checked ) {
72+ this . applySelectTable . checkedTables . clear ( ) ;
73+ this . applySelectTable . checkedTables . add ( tableName ) ;
74+ this . applyData . table = tableName ;
75+ } else {
76+ this . applySelectTable . checkedTables . delete ( tableName ) ;
77+ this . applyData . table = null ;
78+ }
79+ }
80+
81+ handlerApplyDeleteTable ( ) {
82+ this . deleteTable . visible = true ;
83+ }
84+
85+ handlerCancelDeleteTable ( ) {
86+ this . deleteTable . visible = false ;
87+ }
88+
89+ handlerDeleteTable ( ) {
90+ this . deleteTable . loading = true ;
91+ const request = new RequestModel ( ) ;
92+ request . config = this . applyData . dataSource ;
93+ const sql = StringUtils . format ( 'DROP TABLE {0}.{1}' , [ this . applyData . database , this . applyData . table ] ) ;
94+ this . pluginFactory . createService ( this . applyData . dataSource . type )
95+ . getResponse ( request , sql )
96+ . then ( response => {
97+ if ( response . status ) {
98+ this . messageService . success ( "OK" ) ;
99+ this . applySelectTable . checkedTables . delete ( this . applyData . table ) ;
100+ this . handlerInitializer ( ) ;
101+ }
102+ this . deleteTable . loading = false ;
103+ this . deleteTable . visible = false ;
104+ } ) ;
105+ }
106+
59107 isCreateTable ( ) : boolean {
60108 return AssertUtils . isCreateTable ( this . applyData ) ;
61109 }
0 commit comments