@@ -156,7 +156,7 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
156156 _tables : { state : true } ,
157157 _selectedTable : { state : true } ,
158158 _selectedTableIndex :{ state : true } ,
159- _selectedTableCols :{ state : false } ,
159+ _selectedTableCols :{ state : true } ,
160160 _currentSQL : { state : true } ,
161161 _currentDataSet : { state : true } ,
162162 _isWatching : { state : true } ,
@@ -524,36 +524,53 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
524524 const value = item [ columnName ] ;
525525 if ( value ) {
526526 let colDef = this . _selectedTableCols . get ( columnName ) ;
527- let colType = colDef . columnType . toLowerCase ( ) ;
527+ if ( colDef ) {
528+ let colType = colDef . columnType . toLowerCase ( ) ;
528529
529- if ( colDef . binary ) {
530- const byteCharacters = atob ( value ) ;
531- const byteNumbers = new Array ( byteCharacters . length ) ;
532- for ( let i = 0 ; i < byteCharacters . length ; i ++ ) {
533- byteNumbers [ i ] = byteCharacters . charCodeAt ( i ) ;
534- }
535- const byteArray = new Uint8Array ( byteNumbers ) ;
536-
537- const blob = new Blob ( [ byteArray ] , { type : 'application/octet-stream' } ) ;
538- const url = URL . createObjectURL ( blob ) ;
539-
540- return html `< a class ="download " href ="${ url } " download ="download "> download</ span > ` ;
541- } else if ( colType === "bool" || colType === "boolean" ) { // TODO: Can we do int(1) and asume this will be a boolean ?
542- if ( value && value === "true" ) {
543- return html `< vaadin-icon style ="color: var(--lumo-contrast-50pct); " title ="${ value } " icon ="font-awesome-regular:square-check "> </ vaadin-icon > ` ;
530+ if ( colDef . binary ) {
531+ return this . _renderBinaryCell ( value , colType ) ;
544532 } else {
545- return html `< vaadin-icon style ="color: var(--lumo-contrast-50pct); " title ="${ value } " icon ="font-awesome-regular:square "> </ vaadin-icon > ` ;
546- }
547- } else {
548- if ( value . startsWith ( "http://" ) || value . startsWith ( "https://" ) ) {
549- return html `< a href ="${ value } " target ="_blank "> ${ value } </ a > ` ;
550- } else {
551- return html `< span > ${ value } </ span > ` ;
533+ return this . _renderTextCell ( value , colType ) ;
552534 }
553535 }
554536 }
555537 }
556538
539+ _renderTextCell ( value , colType ) {
540+ if ( colType === "bool" || colType === "boolean" ) { // TODO: Can we do int(1) and asume this will be a boolean ?
541+ if ( value && value === "true" ) {
542+ return html `< vaadin-icon style ="color: var(--lumo-contrast-50pct); " title ="${ value } " icon ="font-awesome-regular:square-check "> </ vaadin-icon > ` ;
543+ } else {
544+ return html `< vaadin-icon style ="color: var(--lumo-contrast-50pct); " title ="${ value } " icon ="font-awesome-regular:square "> </ vaadin-icon > ` ;
545+ }
546+ } else {
547+ if ( value . startsWith ( "http://" ) || value . startsWith ( "https://" ) ) {
548+ return html `< a href ="${ value } " target ="_blank "> ${ value } </ a > ` ;
549+ } else {
550+ return html `< span > ${ value } </ span > ` ;
551+ }
552+ }
553+ }
554+
555+ _renderBinaryCell ( value , colType ) {
556+ try {
557+ const byteCharacters = atob ( value ) ;
558+ const byteNumbers = new Array ( byteCharacters . length ) ;
559+ for ( let i = 0 ; i < byteCharacters . length ; i ++ ) {
560+ byteNumbers [ i ] = byteCharacters . charCodeAt ( i ) ;
561+ }
562+ const byteArray = new Uint8Array ( byteNumbers ) ;
563+
564+ const blob = new Blob ( [ byteArray ] , { type : 'application/octet-stream' } ) ;
565+ const url = URL . createObjectURL ( blob ) ;
566+
567+ return html `< a class ="download " href ="${ url } " download ="download "> download</ span > ` ;
568+ } catch ( e ) {
569+ // Here try a normal render. Sometimes Java objects can render in String format (eg. UUID)
570+ return this . _renderTextCell ( value , colType ) ;
571+ }
572+ }
573+
557574 _watch ( ) {
558575 this . _isWatching = true ;
559576 this . _watchId = setInterval ( ( ) => {
@@ -579,6 +596,7 @@ export class QwcAgroalDatasource extends QwcHotReloadElement {
579596 }
580597
581598 _onTableChanged ( event ) {
599+ this . _fetchTableDefinitions ( ) ;
582600 this . _selectedTableIndex = event . detail . value ;
583601 this . _selectedTable = this . _tables [ this . _selectedTableIndex ] ;
584602 this . _clearSqlInput ( ) ;
0 commit comments