@@ -16,12 +16,15 @@ import '@vaadin/progress-bar';
16
16
import '@vaadin/button' ;
17
17
import '@qomponent/qui-alert' ;
18
18
import '@vaadin/dialog' ;
19
+ import '@qomponent/qui-dot' ;
19
20
import { dialogFooterRenderer , dialogHeaderRenderer , dialogRenderer } from '@vaadin/dialog/lit.js' ;
21
+ import { devuiState } from 'devui-state' ;
22
+ import { observeState } from 'lit-element-state' ;
20
23
21
24
/**
22
25
* Allows interaction with your Datasource
23
26
*/
24
- export class QwcAgroalDatasource extends QwcHotReloadElement {
27
+ export class QwcAgroalDatasource extends observeState ( QwcHotReloadElement ) {
25
28
jsonRpc = new JsonRpc ( this ) ;
26
29
configJsonRpc = new JsonRpc ( "devui-configuration" ) ;
27
30
@@ -50,6 +53,12 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
50
53
align-items: baseline;
51
54
gap: 20px;
52
55
}
56
+ .tables {
57
+ display: flex;
58
+ flex-direction: column;
59
+ justify-content: space-between;
60
+ }
61
+
53
62
.tablesAndData {
54
63
display: flex;
55
64
height: 100%;
@@ -154,6 +163,7 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
154
163
_dataSources : { state : true } ,
155
164
_selectedDataSource : { state : true } ,
156
165
_tables : { state : true } ,
166
+ _dot : { state : true } ,
157
167
_selectedTable : { state : true } ,
158
168
_selectedTableIndex :{ state : true } ,
159
169
_selectedTableCols :{ state : true } ,
@@ -169,14 +179,17 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
169
179
_isAllowedDB : { state : true } ,
170
180
_displaymessage : { state : true } ,
171
181
_insertSQL : { state : true } ,
172
- _dialogOpened : { state : true }
182
+ _showBusyLoadingDialog : { state : true } ,
183
+ _showImportSQLDialog : { state : true } ,
184
+ _showErDiagramDialog : { state : true }
173
185
} ;
174
186
175
187
constructor ( ) {
176
188
super ( ) ;
177
189
this . _dataSources = null ;
178
190
this . _selectedDataSource = null ;
179
191
this . _tables = null ;
192
+ this . _dot = null ;
180
193
this . _selectedTable = null ;
181
194
this . _selectedTableCols = null ;
182
195
this . _selectedTableIndex = 0 ;
@@ -192,7 +205,9 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
192
205
this . _allowedHost = null ;
193
206
this . _displaymessage = null ;
194
207
this . _insertSQL = null ;
195
- this . _dialogOpened = false ;
208
+ this . _showBusyLoadingDialog = false ;
209
+ this . _showImportSQLDialog = false ;
210
+ this . _showErDiagramDialog = false ;
196
211
}
197
212
198
213
connectedCallback ( ) {
@@ -234,25 +249,44 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
234
249
</ div >
235
250
${ this . _renderDataOrWarning ( ) }
236
251
</ div >
237
- ${ this . _renderImportSqlDialog ( ) } ` ;
252
+ ${ this . _renderBusyLoadingDialog ( ) }
253
+ ${ this . _renderImportSqlDialog ( ) }
254
+ ${ this . _renderDotViewerDialog ( ) } ` ;
238
255
} else {
239
- return html `< div style ="color: var(--lumo-secondary-text-color);width: 95%; " >
240
- < div > Fetching data sources...</ div >
256
+ return this . _renderProgressBar ( "Fetching data sources..." ) ;
257
+ }
258
+ }
259
+
260
+ _renderProgressBar ( message ) {
261
+ return html `< div style ="color: var(--lumo-secondary-text-color);width: 95%; " >
262
+ < div > ${ message } </ div >
241
263
< vaadin-progress-bar indeterminate > </ vaadin-progress-bar >
242
264
</ div > ` ;
265
+ }
266
+
267
+ _renderBusyLoadingDialog ( ) {
268
+ if ( this . _showBusyLoadingDialog ) {
269
+ return html `< vaadin-dialog
270
+ resizable
271
+ draggable
272
+ header-title ="Loading "
273
+ .opened ="${ true } "
274
+
275
+ ${ dialogRenderer ( this . _renderBusyLoadingDialogContents ) }
276
+ > </ vaadin-dialog > ` ;
243
277
}
244
278
}
245
279
246
280
_renderImportSqlDialog ( ) {
247
- if ( this . _insertSQL ) {
281
+ if ( this . _insertSQL && ! this . _showBusyLoadingDialog ) {
248
282
return html `
249
283
< vaadin-dialog
250
284
resizable
251
285
draggable
252
286
header-title ="Import SQL Script "
253
- .opened ="${ this . _dialogOpened } "
287
+ .opened ="${ this . _showImportSQLDialog } "
254
288
@opened-changed ="${ ( event ) => {
255
- this . _dialogOpened = event . detail . value ;
289
+ this . _showImportSQLDialog = event . detail . value ;
256
290
} } "
257
291
${ dialogHeaderRenderer (
258
292
( ) => html `
@@ -262,6 +296,7 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
262
296
< vaadin-button title ="Copy insert script " theme ="tertiary " @click ="${ this . _copyInsertScript } ">
263
297
< vaadin-icon icon ="font-awesome-solid:copy "> </ vaadin-icon >
264
298
</ vaadin-button >
299
+ ${ this . _renderAssistantButton ( ) }
265
300
< vaadin-button theme ="tertiary " @click ="${ this . _closeDialog } ">
266
301
< vaadin-icon icon ="font-awesome-solid:xmark "> </ vaadin-icon >
267
302
</ vaadin-button > ` ,
@@ -272,6 +307,56 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
272
307
}
273
308
}
274
309
310
+ _renderDotViewerDialog ( ) {
311
+ if ( this . _dot && ! this . _showBusyLoadingDialog ) {
312
+ return html `
313
+ < vaadin-dialog
314
+ resizable
315
+ draggable
316
+ header-title ="ER Diagram "
317
+ .opened ="${ this . _showErDiagramDialog } "
318
+ @opened-changed ="${ ( event ) => {
319
+ this . _showErDiagramDialog = event . detail . value ;
320
+ } } "
321
+ ${ dialogHeaderRenderer (
322
+ ( ) => html `
323
+ < vaadin-button theme ="tertiary " @click ="${ this . _closeDialog } ">
324
+ < vaadin-icon icon ="font-awesome-solid:xmark "> </ vaadin-icon >
325
+ </ vaadin-button > ` ,
326
+ [ ]
327
+ ) }
328
+ ${ dialogRenderer ( this . _renderDotViewerDialogContents ) }
329
+ > </ vaadin-dialog > ` ;
330
+ }
331
+ }
332
+
333
+ _renderAssistantButton ( ) {
334
+ if ( devuiState . applicationInfo . assistantAvailable && this . _insertSQL ) {
335
+ return html `< vaadin-button title ="Generate mode data " theme ="tertiary " @click ="${ this . _generateMoreData } ">
336
+ < vaadin-icon icon ="font-awesome-solid:wand-magic-sparkles "> </ vaadin-icon >
337
+ </ vaadin-button > ` ;
338
+ }
339
+ }
340
+
341
+ _generateMoreData ( ) {
342
+ if ( this . _insertSQL ) {
343
+ this . _showBusyLoadingDialog = true ;
344
+
345
+ this . jsonRpc . generateMoreData ( {
346
+ currentInsertScript :this . _insertSQL
347
+ } ) . then ( jsonRpcResponse => {
348
+ const script = jsonRpcResponse . result . script ;
349
+ if ( Array . isArray ( script ) ) {
350
+ this . _insertSQL = script . join ( '\n' ) ;
351
+ } else {
352
+ this . _insertSQL = script ;
353
+ }
354
+ this . _showBusyLoadingDialog = false ;
355
+ this . _showImportSQLDialog = true ;
356
+ } ) ;
357
+ }
358
+ }
359
+
275
360
_saveInsertScript ( ) {
276
361
try {
277
362
const blob = new Blob ( [ this . value ] , { type : 'text/sql' } ) ;
@@ -305,18 +390,29 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
305
390
306
391
_closeDialog ( ) {
307
392
this . _insertSQL = null ;
308
- this . _dialogOpened = false ;
393
+ this . _dot = null ;
394
+ this . _showImportSQLDialog = false ;
395
+ this . _showErDiagramDialog = false ;
309
396
}
310
397
311
398
_renderImportSqlDialogContents ( ) {
312
399
return html `< qui-code-block content ="${ this . _insertSQL } " mode ="sql " theme ="dark "> </ qui-code-block > ` ;
313
400
}
314
401
402
+ _renderDotViewerDialogContents ( ) {
403
+ return html `< qui-dot dot ="${ this . _dot } "> </ qui-dot > ` ;
404
+ }
405
+
406
+ _renderBusyLoadingDialogContents ( ) {
407
+ return this . _renderProgressBar ( "Busy loading... please hold on" ) ;
408
+ }
409
+
315
410
_renderDataOrWarning ( ) {
316
411
if ( this . _isAllowedDB ) {
317
412
return html `< div class ="tablesAndData ">
318
413
< div class ="tables ">
319
414
${ this . _renderTables ( ) }
415
+ ${ this . _renderGenerateErDiagramButton ( ) }
320
416
</ div >
321
417
< div class ="tableData ">
322
418
${ this . _renderDataAndDefinition ( ) }
@@ -377,6 +473,15 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
377
473
378
474
}
379
475
476
+ _renderGenerateErDiagramButton ( ) {
477
+ if ( this . _selectedDataSource ) {
478
+ return html `< vaadin-button @click =${ this . _generateErDiagram } title ="Generate an ER Diagram for the tables">
479
+ < vaadin-icon icon ="font-awesome-solid:table " slot ="prefix "> </ vaadin-icon >
480
+ ER Diagram
481
+ </ vaadin-button > ` ;
482
+ }
483
+ }
484
+
380
485
_renderDataAndDefinition ( ) {
381
486
return html `< vaadin-tabsheet class ="fill " theme ="bordered ">
382
487
< vaadin-button slot ="suffix " theme ="icon " title ="Refresh " aria-label ="Refresh ">
@@ -503,6 +608,18 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
503
608
}
504
609
}
505
610
611
+ _generateErDiagram ( ) {
612
+ if ( this . _selectedDataSource ) {
613
+ this . _showBusyLoadingDialog = true ;
614
+ this . _insertSQL = null ;
615
+ this . jsonRpc . generateDot ( { datasource :this . _selectedDataSource . name } ) . then ( jsonRpcResponse => {
616
+ this . _showBusyLoadingDialog = false ;
617
+ this . _dot = jsonRpcResponse . result ;
618
+ this . _showErDiagramDialog = true ;
619
+ } ) ;
620
+ }
621
+ }
622
+
506
623
_handleAllowSqlChange ( ) {
507
624
this . configJsonRpc . updateProperty ( {
508
625
'name' : '%dev.quarkus.datasource.dev-ui.allow-sql' ,
@@ -671,7 +788,7 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
671
788
if ( this . _selectedDataSource ) {
672
789
this . jsonRpc . getInsertScript ( { datasource :this . _selectedDataSource . name } ) . then ( jsonRpcResponse => {
673
790
this . _insertSQL = jsonRpcResponse . result ;
674
- this . _dialogOpened = true ;
791
+ this . _showImportSQLDialog = true ;
675
792
} ) ;
676
793
}
677
794
}
0 commit comments