@@ -15,6 +15,7 @@ import { MatTooltipModule } from '@angular/material/tooltip';
1515import { Subject } from 'rxjs' ;
1616import { TablesService } from 'src/app/services/tables.service' ;
1717import { RouterModule } from '@angular/router' ;
18+ import { TableForeignKey } from 'src/app/models/table' ;
1819
1920interface Suggestion {
2021 displayString : string ;
@@ -50,6 +51,7 @@ export class ForeignKeyRowComponent extends BaseRowFieldComponent {
5051 public identityColumn : string ;
5152 public primaeyKeys : { data_type : string , column_name : string } [ ] ;
5253
54+ public fkRelations : TableForeignKey = null ;
5355 autocmpleteUpdate = new Subject < string > ( ) ;
5456
5557 constructor (
@@ -69,12 +71,22 @@ export class ForeignKeyRowComponent extends BaseRowFieldComponent {
6971 ngOnInit ( ) : void {
7072 super . ngOnInit ( ) ;
7173 this . connectionID = this . _connections . currentConnectionID ;
72- this . relations && this . _tables . fetchTable ( {
74+
75+ if ( this . widgetStructure && this . widgetStructure . widget_params ) {
76+ this . fkRelations = this . widgetStructure . widget_params as TableForeignKey ;
77+ } else if ( this . relations ) {
78+ this . fkRelations = this . relations ;
79+ }
80+
81+ console . log ( 'test fkRelations' ) ;
82+ console . log ( this . fkRelations ) ;
83+
84+ this . fkRelations && this . _tables . fetchTable ( {
7385 connectionID : this . connectionID ,
74- tableName : this . relations . referenced_table_name ,
86+ tableName : this . fkRelations . referenced_table_name ,
7587 requstedPage : 1 ,
7688 chunkSize : 10 ,
77- foreignKeyRowName : this . relations . referenced_column_name ,
89+ foreignKeyRowName : this . fkRelations . referenced_column_name ,
7890 foreignKeyRowValue : this . value
7991 } ) . subscribe ( ( res : any ) => {
8092 if ( res . rows . length ) {
@@ -88,28 +100,28 @@ export class ForeignKeyRowComponent extends BaseRowFieldComponent {
88100 Object . values ( modifiedRow ) . filter ( value => value ) . join ( ' | ' ) ;
89101 console . log ( 'test identityColumn' ) ;
90102 console . log ( this . currentDisplayedString ) ;
91- this . currentFieldValue = res . rows [ 0 ] [ this . relations . referenced_column_name ] ;
103+ this . currentFieldValue = res . rows [ 0 ] [ this . fkRelations . referenced_column_name ] ;
92104 this . currentFieldQueryParams = Object . assign ( { } , ...res . primaryColumns . map ( ( primaeyKey ) => ( { [ primaeyKey . column_name ] : res . rows [ 0 ] [ primaeyKey . column_name ] } ) ) ) ;
93105 this . onFieldChange . emit ( this . currentFieldValue ) ;
94106 }
95107 }
96108
97109 this . _tables . fetchTable ( {
98110 connectionID : this . connectionID ,
99- tableName : this . relations . referenced_table_name ,
111+ tableName : this . fkRelations . referenced_table_name ,
100112 requstedPage : 1 ,
101113 chunkSize : 20 ,
102114 foreignKeyRowName : 'autocomplete' ,
103115 foreignKeyRowValue : '' ,
104- referencedColumn : this . relations . referenced_column_name
116+ referencedColumn : this . fkRelations . referenced_column_name
105117 } ) . subscribe ( ( res :any ) => {
106118 this . identityColumn = res . identity_column ;
107119 this . suggestions = res . rows . map ( row => {
108120 const modifiedRow = this . getModifiedRow ( row ) ;
109121 return {
110122 displayString : this . identityColumn ? `${ row [ this . identityColumn ] } (${ Object . values ( modifiedRow ) . filter ( value => value ) . join ( ' | ' ) } )` : Object . values ( modifiedRow ) . filter ( value => value ) . join ( ' | ' ) ,
111123 primaryKeys : Object . assign ( { } , ...res . primaryColumns . map ( ( primaeyKey ) => ( { [ primaeyKey . column_name ] : row [ primaeyKey . column_name ] } ) ) ) ,
112- fieldValue : row [ this . relations . referenced_column_name ]
124+ fieldValue : row [ this . fkRelations . referenced_column_name ]
113125 }
114126 } ) ;
115127 this . fetching = false ;
@@ -127,12 +139,12 @@ export class ForeignKeyRowComponent extends BaseRowFieldComponent {
127139 this . fetching = true ;
128140 this . _tables . fetchTable ( {
129141 connectionID : this . connectionID ,
130- tableName : this . relations . referenced_table_name ,
142+ tableName : this . fkRelations . referenced_table_name ,
131143 requstedPage : 1 ,
132144 chunkSize : 20 ,
133145 foreignKeyRowName : 'autocomplete' ,
134146 foreignKeyRowValue : this . currentDisplayedString ,
135- referencedColumn : this . relations . referenced_column_name
147+ referencedColumn : this . fkRelations . referenced_column_name
136148 } ) . subscribe ( ( res : any ) => {
137149 this . identityColumn = res . identity_column ;
138150 if ( res . rows . length === 0 ) {
@@ -145,7 +157,7 @@ export class ForeignKeyRowComponent extends BaseRowFieldComponent {
145157 return {
146158 displayString : this . identityColumn ? `${ row [ this . identityColumn ] } (${ Object . values ( modifiedRow ) . filter ( value => value ) . join ( ' | ' ) } )` : Object . values ( modifiedRow ) . filter ( value => value ) . join ( ' | ' ) ,
147159 primaryKeys : Object . assign ( { } , ...res . primaryColumns . map ( ( primaeyKey ) => ( { [ primaeyKey . column_name ] : row [ primaeyKey . column_name ] } ) ) ) ,
148- fieldValue : row [ this . relations . referenced_column_name ]
160+ fieldValue : row [ this . fkRelations . referenced_column_name ]
149161 }
150162 } ) ;
151163 }
@@ -156,9 +168,9 @@ export class ForeignKeyRowComponent extends BaseRowFieldComponent {
156168
157169 getModifiedRow ( row ) {
158170 let modifiedRow ;
159- if ( this . relations . autocomplete_columns && this . relations . autocomplete_columns . length > 0 ) {
160- let autocompleteColumns = [ ...this . relations . autocomplete_columns ]
161- if ( this . identityColumn ) autocompleteColumns . splice ( this . relations . autocomplete_columns . indexOf ( this . identityColumn ) , 1 ) ;
171+ if ( this . fkRelations . autocomplete_columns && this . fkRelations . autocomplete_columns . length > 0 ) {
172+ let autocompleteColumns = [ ...this . fkRelations . autocomplete_columns ]
173+ if ( this . identityColumn ) autocompleteColumns . splice ( this . fkRelations . autocomplete_columns . indexOf ( this . identityColumn ) , 1 ) ;
162174 modifiedRow = autocompleteColumns
163175 . reduce ( ( rowObject , columnName ) => ( rowObject [ columnName ] = row [ columnName ] , rowObject ) , { } ) ;
164176 } else {
0 commit comments