Skip to content

Commit

Permalink
Update formly-autocomplete.component.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
polterguy committed Jan 3, 2024
1 parent cd33bc3 commit 76914d6
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ export class FormlyAutocompleteComponent extends FieldType<FieldTypeConfig> impl
this.getDatabases();
})).subscribe();
}
} else if (this.field.key === 'table') {
if (this.form.controls['database-type'] && this.form.controls['connection-string'] && this.form.controls['table']) {
this.form.controls['database'].valueChanges.pipe(
debounceTime(400),
distinctUntilChanged(),
tap(() => {
this.getTables();
})).subscribe();
}
}
}

Expand All @@ -104,6 +113,7 @@ export class FormlyAutocompleteComponent extends FieldType<FieldTypeConfig> impl
this.field.props.options.push({
value: idx,
label: idx,
complete: true,
});
}
for (const idx of expOptions) {
Expand Down Expand Up @@ -140,6 +150,46 @@ export class FormlyAutocompleteComponent extends FieldType<FieldTypeConfig> impl
this.field.props.options.push({
value: idx.name,
label: idx.name,
complete: true,
});
}
for (const idx of expOptions) {
this.field.props.options.push(idx);
}
this.formControl.setValue('');
},

error: () => {

this.generalService.hideLoading();
}
});
}

private getTables() {

if (!this.model['database-type'] || this.model['database-type'] === '' ||
!this.model['connection-string'] || this.model['connection-string'] === '' ||
!this.model['database'] || this.model['database'] === '') {
return;
}

this.generalService.showLoading();
this.sqlService.getDatabaseMetaInfo(
<string>this.model['database-type'],
<string>this.model['connection-string']).subscribe({

next: (result: any) => {

this.generalService.hideLoading();
const db = result.databases.filter((x: any) => x.name === <string>this.model['database'])[0];
const expOptions = (<any[]>this.field.props.options).filter(x => x.value.startsWith(':x:'));
this.field.props.options = [];
for (const idx of db.tables) {
this.field.props.options.push({
value: idx.name,
label: idx.name,
complete: true,
});
}
for (const idx of expOptions) {
Expand Down

0 comments on commit 76914d6

Please sign in to comment.