@@ -16,12 +16,17 @@ 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' ;
20
+ import 'qui-assistant-button' ;
21
+ import 'qui-assistant-warning' ;
19
22
import { dialogFooterRenderer , dialogHeaderRenderer , dialogRenderer } from '@vaadin/dialog/lit.js' ;
23
+ import { observeState } from 'lit-element-state' ;
24
+ import { assistantState } from 'assistant-state' ;
20
25
21
26
/**
22
27
* Allows interaction with your Datasource
23
28
*/
24
- export class QwcAgroalDatasource extends QwcHotReloadElement {
29
+ export class QwcAgroalDatasource extends observeState ( QwcHotReloadElement ) {
25
30
jsonRpc = new JsonRpc ( this ) ;
26
31
configJsonRpc = new JsonRpc ( "devui-configuration" ) ;
27
32
@@ -50,6 +55,12 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
50
55
align-items: baseline;
51
56
gap: 20px;
52
57
}
58
+ .tables {
59
+ display: flex;
60
+ flex-direction: column;
61
+ justify-content: space-between;
62
+ }
63
+
53
64
.tablesAndData {
54
65
display: flex;
55
66
height: 100%;
@@ -78,10 +89,8 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
78
89
79
90
.sqlInput {
80
91
display: flex;
81
- justify-content: space-between;
82
- gap: 10px;
83
92
align-items: center;
84
- padding-bottom: 20px ;
93
+ padding-bottom: 10px ;
85
94
border-bottom-style: dotted;
86
95
border-bottom-color: var(--lumo-contrast-10pct);
87
96
}
@@ -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,18 @@ 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
+ _showAssistantWarning : { state : true } ,
184
+ _showImportSQLDialog : { state : true } ,
185
+ _showErDiagramDialog : { state : true }
173
186
} ;
174
187
175
188
constructor ( ) {
176
189
super ( ) ;
177
190
this . _dataSources = null ;
178
191
this . _selectedDataSource = null ;
179
192
this . _tables = null ;
193
+ this . _dot = null ;
180
194
this . _selectedTable = null ;
181
195
this . _selectedTableCols = null ;
182
196
this . _selectedTableIndex = 0 ;
@@ -192,7 +206,10 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
192
206
this . _allowedHost = null ;
193
207
this . _displaymessage = null ;
194
208
this . _insertSQL = null ;
195
- this . _dialogOpened = false ;
209
+ this . _showBusyLoadingDialog = null ;
210
+ this . _showAssistantWarning = false ;
211
+ this . _showImportSQLDialog = false ;
212
+ this . _showErDiagramDialog = false ;
196
213
}
197
214
198
215
connectedCallback ( ) {
@@ -234,34 +251,55 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
234
251
</ div >
235
252
${ this . _renderDataOrWarning ( ) }
236
253
</ div >
237
- ${ this . _renderImportSqlDialog ( ) } ` ;
254
+ ${ this . _renderBusyLoadingDialog ( ) }
255
+ ${ this . _renderImportSqlDialog ( ) }
256
+ ${ this . _renderDotViewerDialog ( ) } ` ;
238
257
} else {
239
- return html `< div style ="color: var(--lumo-secondary-text-color);width: 95%; " >
240
- < div > Fetching data sources...</ div >
258
+ return this . _renderProgressBar ( "Fetching data sources..." ) ;
259
+ }
260
+ }
261
+
262
+ _renderProgressBar ( message ) {
263
+ return html `< div style ="color: var(--lumo-secondary-text-color);width: 95%; " >
264
+ < div > ${ message } </ div >
241
265
< vaadin-progress-bar indeterminate > </ vaadin-progress-bar >
242
266
</ div > ` ;
267
+ }
268
+
269
+ _renderBusyLoadingDialog ( ) {
270
+ if ( this . _showBusyLoadingDialog ) {
271
+ return html `< vaadin-dialog
272
+ resizable
273
+ draggable
274
+ header-title ="Loading "
275
+ .opened ="${ true } "
276
+
277
+ ${ dialogRenderer ( this . _renderBusyLoadingDialogContents ) }
278
+ > </ vaadin-dialog > ` ;
243
279
}
244
280
}
245
281
246
282
_renderImportSqlDialog ( ) {
247
- if ( this . _insertSQL ) {
283
+ if ( this . _insertSQL && ! this . _showBusyLoadingDialog ) {
248
284
return html `
249
285
< vaadin-dialog
250
286
resizable
251
287
draggable
252
288
header-title ="Import SQL Script "
253
- .opened ="${ this . _dialogOpened } "
289
+ .opened ="${ this . _showImportSQLDialog } "
254
290
@opened-changed ="${ ( event ) => {
255
- this . _dialogOpened = event . detail . value ;
291
+ this . _showImportSQLDialog = event . detail . value ;
256
292
} } "
257
293
${ dialogHeaderRenderer (
258
294
( ) => html `
295
+ ${ this . _renderAssistantWarning ( ) }
259
296
< vaadin-button title ="Save insert script " theme ="tertiary " @click ="${ this . _saveInsertScript } ">
260
297
< vaadin-icon icon ="font-awesome-solid:floppy-disk "> </ vaadin-icon >
261
298
</ vaadin-button >
262
299
< vaadin-button title ="Copy insert script " theme ="tertiary " @click ="${ this . _copyInsertScript } ">
263
300
< vaadin-icon icon ="font-awesome-solid:copy "> </ vaadin-icon >
264
301
</ vaadin-button >
302
+ ${ this . _renderAssistantButton ( ) }
265
303
< vaadin-button theme ="tertiary " @click ="${ this . _closeDialog } ">
266
304
< vaadin-icon icon ="font-awesome-solid:xmark "> </ vaadin-icon >
267
305
</ vaadin-button > ` ,
@@ -272,6 +310,61 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
272
310
}
273
311
}
274
312
313
+ _renderDotViewerDialog ( ) {
314
+ if ( this . _dot && ! this . _showBusyLoadingDialog ) {
315
+ return html `
316
+ < vaadin-dialog
317
+ resizable
318
+ draggable
319
+ header-title ="ER Diagram "
320
+ .opened ="${ this . _showErDiagramDialog } "
321
+ @opened-changed ="${ ( event ) => {
322
+ this . _showErDiagramDialog = event . detail . value ;
323
+ } } "
324
+ ${ dialogHeaderRenderer (
325
+ ( ) => html `
326
+ < vaadin-button theme ="tertiary " @click ="${ this . _closeDialog } ">
327
+ < vaadin-icon icon ="font-awesome-solid:xmark "> </ vaadin-icon >
328
+ </ vaadin-button > ` ,
329
+ [ ]
330
+ ) }
331
+ ${ dialogRenderer ( this . _renderDotViewerDialogContents ) }
332
+ > </ vaadin-dialog > ` ;
333
+ }
334
+ }
335
+
336
+ _renderAssistantButton ( ) {
337
+ if ( assistantState . current . isConfigured && this . _insertSQL ) {
338
+ return html `< qui-assistant-button title ="Use Quarkus Assistant to generate more data " @click ="${ this . _generateMoreData } "> </ qui-assistant-button > ` ;
339
+ }
340
+ }
341
+
342
+ _renderAssistantWarning ( ) {
343
+ if ( this . _showAssistantWarning ) {
344
+ return html `< qui-assistant-warning > </ qui-assistant-warning > ` ;
345
+ }
346
+ }
347
+
348
+ _generateMoreData ( ) {
349
+ if ( this . _insertSQL ) {
350
+ this . _showBusyLoadingDialog = "Quarkus Assistant is generating more data ... please wait" ;
351
+
352
+ this . jsonRpc . generateMoreData ( {
353
+ currentInsertScript :this . _insertSQL
354
+ } ) . then ( jsonRpcResponse => {
355
+ const script = jsonRpcResponse . result . script ;
356
+ if ( Array . isArray ( script ) ) {
357
+ this . _insertSQL = script . join ( '\n' ) ;
358
+ } else {
359
+ this . _insertSQL = script ;
360
+ }
361
+ this . _showBusyLoadingDialog = null ;
362
+ this . _showImportSQLDialog = true ;
363
+ this . _showAssistantWarning = true ;
364
+ } ) ;
365
+ }
366
+ }
367
+
275
368
_saveInsertScript ( ) {
276
369
try {
277
370
const blob = new Blob ( [ this . value ] , { type : 'text/sql' } ) ;
@@ -305,18 +398,30 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
305
398
306
399
_closeDialog ( ) {
307
400
this . _insertSQL = null ;
308
- this . _dialogOpened = false ;
401
+ this . _dot = null ;
402
+ this . _showImportSQLDialog = false ;
403
+ this . _showErDiagramDialog = false ;
404
+ this . _showAssistantWarning = false ;
309
405
}
310
406
311
407
_renderImportSqlDialogContents ( ) {
312
408
return html `< qui-code-block content ="${ this . _insertSQL } " mode ="sql " theme ="dark "> </ qui-code-block > ` ;
313
409
}
314
410
411
+ _renderDotViewerDialogContents ( ) {
412
+ return html `< qui-dot dot ="${ this . _dot } "> </ qui-dot > ` ;
413
+ }
414
+
415
+ _renderBusyLoadingDialogContents ( ) {
416
+ return this . _renderProgressBar ( this . _showBusyLoadingDialog ) ;
417
+ }
418
+
315
419
_renderDataOrWarning ( ) {
316
420
if ( this . _isAllowedDB ) {
317
421
return html `< div class ="tablesAndData ">
318
422
< div class ="tables ">
319
423
${ this . _renderTables ( ) }
424
+ ${ this . _renderGenerateErDiagramButton ( ) }
320
425
</ div >
321
426
< div class ="tableData ">
322
427
${ this . _renderDataAndDefinition ( ) }
@@ -377,6 +482,15 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
377
482
378
483
}
379
484
485
+ _renderGenerateErDiagramButton ( ) {
486
+ if ( this . _selectedDataSource ) {
487
+ return html `< vaadin-button @click =${ this . _generateErDiagram } title ="Generate an ER Diagram for the tables">
488
+ < vaadin-icon icon ="font-awesome-solid:table " slot ="prefix "> </ vaadin-icon >
489
+ ER Diagram
490
+ </ vaadin-button > ` ;
491
+ }
492
+ }
493
+
380
494
_renderDataAndDefinition ( ) {
381
495
return html `< vaadin-tabsheet class ="fill " theme ="bordered ">
382
496
< vaadin-button slot ="suffix " theme ="icon " title ="Refresh " aria-label ="Refresh ">
@@ -487,12 +601,12 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
487
601
< qui-code-block @shiftEnter =${ this . _shiftEnterPressed } content ="${ this . _currentSQL } "
488
602
class="font-large cursor-text" id="sql" mode="sql" theme="dark"
489
603
value='${ this . _currentSQL } ' editable> </ qui-code-block >
490
- < vaadin-button class ="no-margin " slot ="suffix " theme ="icon " aria-label ="Clear ">
604
+ < vaadin-button class ="no-margin " slot ="suffix " theme ="icon tertiary small " aria-label ="Clear ">
491
605
< vaadin-tooltip .hoverDelay =${ 500 } slot ="tooltip" text="Clear"> </ vaadin-tooltip >
492
606
< vaadin-icon class ="small-icon " @click =${ this . _clearSqlInput }
493
- icon ="font-awesome-solid:trash "> </ vaadin-icon >
607
+ icon ="font-awesome-solid:broom "> </ vaadin-icon >
494
608
</ vaadin-button >
495
- < vaadin-button class ="no-margin " slot ="suffix " theme ="icon " aria-label ="Run ">
609
+ < vaadin-button class ="no-margin " slot ="suffix " theme ="icon tertiary small " aria-label ="Run ">
496
610
< vaadin-tooltip .hoverDelay =${ 500 } slot ="tooltip" text="Run"> </ vaadin-tooltip >
497
611
< vaadin-icon class ="small-icon " @click =${ this . _executeClicked }
498
612
icon ="font-awesome-solid:play"> </ vaadin-icon >
@@ -503,6 +617,18 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
503
617
}
504
618
}
505
619
620
+ _generateErDiagram ( ) {
621
+ if ( this . _selectedDataSource ) {
622
+ this . _showBusyLoadingDialog = "Generating ER Diagram ... please wait" ;
623
+ this . _insertSQL = null ;
624
+ this . jsonRpc . generateDot ( { datasource :this . _selectedDataSource . name } ) . then ( jsonRpcResponse => {
625
+ this . _showBusyLoadingDialog = null ;
626
+ this . _dot = jsonRpcResponse . result ;
627
+ this . _showErDiagramDialog = true ;
628
+ } ) ;
629
+ }
630
+ }
631
+
506
632
_handleAllowSqlChange ( ) {
507
633
this . configJsonRpc . updateProperty ( {
508
634
'name' : '%dev.quarkus.datasource.dev-ui.allow-sql' ,
@@ -673,7 +799,7 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
673
799
if ( this . _selectedDataSource ) {
674
800
this . jsonRpc . getInsertScript ( { datasource :this . _selectedDataSource . name } ) . then ( jsonRpcResponse => {
675
801
this . _insertSQL = jsonRpcResponse . result ;
676
- this . _dialogOpened = true ;
802
+ this . _showImportSQLDialog = true ;
677
803
} ) ;
678
804
}
679
805
}
0 commit comments