Skip to content

Commit

Permalink
b
Browse files Browse the repository at this point in the history
  • Loading branch information
polterguy committed Dec 24, 2023
1 parent 1b840de commit e5513c2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
1 change: 1 addition & 0 deletions backend/files/misc/workflows/actions/sql-select.hl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
mandatory:bool:true
params
type:key-value
mandatory:bool:false
.icon:cloud_download

// Sanity checking invocation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Angular and system imports.
import { FieldType, FieldTypeConfig } from '@ngx-formly/core';
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Observable, debounceTime, distinctUntilChanged, map, startWith, tap } from 'rxjs';
import { SqlService } from 'src/app/services/sql.service';
import { GeneralService } from 'src/app/services/general.service';
Expand All @@ -21,8 +20,9 @@ import { GeneralService } from 'src/app/services/general.service';
template: `
<mat-form-field class="w-100 standalone-field mb-2">
<mat-label>{{field.props.label}}</mat-label>
<input type="text"
<input
[id]="field.key"
type="text"
[placeholder]="field.props.label"
matInput
[formControl]="formControl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ import { CodemirrorActionsService } from 'src/app/services/codemirror-actions.se
[(ngModel)]="model[field.key]">
</ngx-codemirror>
</div>`,
styleUrls: ['./formly-sql.scss']
styleUrls: ['./formly-sql.scss'],
})
export class FormlySqlComponent extends FieldType<FieldTypeConfig> implements OnInit {

private databases: Databases = null;
@ViewChild('editor') private editor: CodemirrorComponent;
private databases: Databases = null;
cmOptions: any = null;
connected: boolean = false;

Expand Down Expand Up @@ -75,6 +75,14 @@ export class FormlySqlComponent extends FieldType<FieldTypeConfig> implements On
this.editor.codeMirror.getDoc().markClean();
this.editor.codeMirror.getDoc().clearHistory();

this.editor.codeMirror.on('change', () => {
if (this.valid()) {
this.formControl.setErrors(null);
} else {
this.formControl.setErrors({hasError: true});
}
});

// Verifying we've got database type, connection string, and database values.
if (this.form.controls['database-type'] &&
this.form.controls['connection-string'] &&
Expand Down Expand Up @@ -138,7 +146,11 @@ export class FormlySqlComponent extends FieldType<FieldTypeConfig> implements On
this.generalService.hideLoading();
this.databases = result;
this.connected = true;
this.formControl.setErrors(null);
if (this.valid()) {
this.formControl.setErrors(null);
} else {
this.formControl.setErrors({hasError: true});
}
this.cdr.detectChanges();
this.databaseChanged();
},
Expand All @@ -147,7 +159,7 @@ export class FormlySqlComponent extends FieldType<FieldTypeConfig> implements On

this.generalService.hideLoading();
this.connected = false;
this.formControl.setErrors({connected: false});
this.formControl.setErrors({hasError: true});
this.cmOptions.hintOptions = {
tables: [],
};
Expand Down Expand Up @@ -178,8 +190,22 @@ export class FormlySqlComponent extends FieldType<FieldTypeConfig> implements On
tables: hints,
};
this.connected = true;
this.formControl.setErrors(null);
if (this.valid()) {
this.formControl.setErrors(null);
} else {
this.formControl.setErrors({hasError: true});
}
this.cdr.detectChanges();
}
}

private valid() {
if (!this.connected) {
return false;
}
if (this.field.props.required === true && this.editor.codeMirror.getValue() === '') {
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ export class ParametriseActionDialog implements OnInit {
// Because Formly turns 'foo.bar' into a nested object in model, we need this little hack around
key: this.replaceAll(idx, '.', '$__$'),
className: 'w-100 standalone-field',
options: {

},
props: {
placeholder: idx,
label: idx,
Expand Down

0 comments on commit e5513c2

Please sign in to comment.