1
1
import { QwcHotReloadElement , html , css } from 'qwc-hot-reload-element' ;
2
- import { RouterController } from 'router-controller' ;
3
2
import { JsonRpc } from 'jsonrpc' ;
3
+ import { StorageController } from 'storage-controller' ;
4
4
import '@vaadin/combo-box' ;
5
5
import '@vaadin/item' ;
6
6
import '@vaadin/icon' ;
@@ -10,7 +10,7 @@ import '@qomponent/qui-card';
10
10
import '@vaadin/grid' ;
11
11
import '@vaadin/tabs' ;
12
12
import '@vaadin/tabsheet' ;
13
- import { columnBodyRenderer , columnHeaderRenderer } from '@vaadin/grid/lit.js' ;
13
+ import { columnBodyRenderer } from '@vaadin/grid/lit.js' ;
14
14
import 'qui-themed-code-block' ;
15
15
import { notifier } from 'notifier' ;
16
16
import '@vaadin/progress-bar' ;
@@ -21,7 +21,7 @@ import '@qomponent/qui-dot';
21
21
import 'qui-assistant-button' ;
22
22
import 'qui-assistant-warning' ;
23
23
import '@qomponent/qui-badge' ;
24
- import { dialogFooterRenderer , dialogHeaderRenderer , dialogRenderer } from '@vaadin/dialog/lit.js' ;
24
+ import { dialogHeaderRenderer , dialogRenderer } from '@vaadin/dialog/lit.js' ;
25
25
import { observeState } from 'lit-element-state' ;
26
26
import { assistantState } from 'assistant-state' ;
27
27
@@ -31,9 +31,8 @@ import { assistantState } from 'assistant-state';
31
31
export class QwcAgroalDatasource extends observeState ( QwcHotReloadElement ) {
32
32
jsonRpc = new JsonRpc ( this ) ;
33
33
configJsonRpc = new JsonRpc ( "devui-configuration" ) ;
34
-
35
- routerController = new RouterController ( this ) ;
36
-
34
+ storageControl = new StorageController ( this ) ;
35
+
37
36
static styles = css `
38
37
.dataSources{
39
38
display: flex;
@@ -228,32 +227,31 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
228
227
this . _showAssistantWarning = false ;
229
228
this . _showImportSQLDialog = false ;
230
229
this . _showErDiagramDialog = false ;
231
- this . _englishToSQLEnabled = false ;
230
+ this . _englishToSQLEnabled = this . storageControl . get ( "english-to-sql" ) === "true" ;
232
231
this . _englishToSQLLoadingMessage = null ;
233
232
}
234
233
235
234
connectedCallback ( ) {
236
235
super . connectedCallback ( ) ;
237
-
238
- var page = this . routerController . getCurrentPage ( ) ;
239
- if ( page && page . metadata ) {
240
- this . _allowSql = ( page . metadata . allowSql === "true" ) ;
241
- this . _appendSql = page . metadata . appendSql ;
242
- this . _allowedHost = page . metadata . allowedHost ;
243
- } else {
244
- this . _allowSql = false ;
245
- this . _appendSql = "" ;
246
- this . _allowedHost = null ;
247
- }
248
-
249
- this . jsonRpc . getDataSources ( ) . then ( jsonRpcResponse => {
250
- this . _dataSources = jsonRpcResponse . result . reduce ( ( map , obj ) => {
236
+ this . hotReload ( ) ;
237
+ }
238
+
239
+ hotReload ( ) {
240
+ const configPromise = this . configJsonRpc . getAllValues ( ) ;
241
+ const dbPromise = this . jsonRpc . getDataSources ( ) ;
242
+ Promise . all ( [ configPromise , dbPromise ] ) . then ( values => {
243
+ const configValues = values [ 0 ] . result ;
244
+ this . _allowSql = configValues [ 'quarkus.datasource.dev-ui.allow-sql' ] === 'true' ;
245
+ this . _appendSql = configValues [ 'quarkus.datasource.dev-ui.append-to-default-select' ] || "" ;
246
+ this . _allowedHost = configValues [ 'quarkus.datasource.dev-ui.allowed-db-host' ] || null ;
247
+ const dsResponse = values [ 1 ] . result ;
248
+ if ( dsResponse ) {
249
+ this . _dataSources = dsResponse . reduce ( ( map , obj ) => {
251
250
map [ obj . name ] = obj ;
252
251
return map ;
253
- } , { } ) ;
252
+ } , { } ) ;
253
+ }
254
254
} ) ;
255
-
256
- this . _englishToSQLEnabled = false ; // TODO: Load from storage
257
255
}
258
256
259
257
disconnectedCallback ( ) {
@@ -663,7 +661,7 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
663
661
${ this . _renderInputTextField ( ) }
664
662
< vaadin-button class ="no-margin " theme ="icon tertiary small " aria-label ="Clear ">
665
663
< vaadin-tooltip .hoverDelay =${ 500 } slot ="tooltip" text="Clear"> </ vaadin-tooltip >
666
- < vaadin-icon class ="small-icon " @click =${ this . _clearInput }
664
+ < vaadin-icon class ="small-icon " @click =${ ( ) => this . _clearInput ( this . _englishToSQLEnabled ) }
667
665
icon ="font-awesome-solid:broom"> </ vaadin-icon >
668
666
</ vaadin-button >
669
667
< vaadin-button class ="no-margin " theme ="icon tertiary small " aria-label ="Run ">
@@ -700,11 +698,8 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
700
698
}
701
699
702
700
_switchEnglishToSQL ( ) {
703
- if ( this . _englishToSQLEnabled ) {
704
- this . _englishToSQLEnabled = false ;
705
- } else {
706
- this . _englishToSQLEnabled = true ;
707
- }
701
+ this . _englishToSQLEnabled = ! this . _englishToSQLEnabled ;
702
+ this . storageControl . set ( "english-to-sql" , this . _englishToSQLEnabled ) ;
708
703
}
709
704
710
705
_englishKeyDown ( e ) {
@@ -823,7 +818,7 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
823
818
this . _fetchTableDefinitions ( ) ;
824
819
this . _selectedTableIndex = event . detail . value ;
825
820
this . _selectedTable = this . _tables [ this . _selectedTableIndex ] ;
826
- this . _clearInput ( ) ;
821
+ this . _clearInput ( false ) ;
827
822
}
828
823
829
824
_previousPage ( ) {
@@ -862,7 +857,7 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
862
857
notifier . showErrorMessage ( jsonRpcResponse . result . error ) ;
863
858
} else if ( jsonRpcResponse . result . message ) {
864
859
notifier . showInfoMessage ( jsonRpcResponse . result . message ) ;
865
- this . _clearInput ( ) ;
860
+ this . _clearInput ( false ) ;
866
861
} else {
867
862
this . _currentDataSet = jsonRpcResponse . result ;
868
863
this . _currentNumberOfPages = this . _getNumberOfPages ( ) ;
@@ -934,13 +929,13 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
934
929
this . _executeSQL ( sql ) ;
935
930
}
936
931
} ) ;
937
-
938
-
932
+
933
+
939
934
940
935
}
941
936
942
- _clearInput ( ) {
943
- if ( assistantState . current . isConfigured && this . _englishToSQLEnabled ) {
937
+ _clearInput ( englishToSql ) {
938
+ if ( englishToSql && assistantState . current . isConfigured ) {
944
939
this . _currentEnglish = null ;
945
940
this . shadowRoot . getElementById ( 'assistantInput' ) . value = '' ;
946
941
} else {
@@ -968,10 +963,6 @@ export class QwcAgroalDatasource extends observeState(QwcHotReloadElement) {
968
963
return str . trim ( ) . toLowerCase ( ) . startsWith ( searchString . toLowerCase ( ) ) ;
969
964
}
970
965
971
- hotReload ( ) {
972
- this . _fetchTableDefinitions ( ) ;
973
- }
974
-
975
966
_isAllowedHostDatabase ( ) {
976
967
977
968
let jdbcUrl = this . _selectedDataSource . jdbcUrl ;
0 commit comments