extended base dialog for file attributes configurations dialog and updated form
This commit is contained in:
parent
83c698b2da
commit
48335773c5
@ -38,7 +38,7 @@
|
||||
</ng-container>
|
||||
</div>
|
||||
<div class="dialog-actions">
|
||||
<button (click)="save()" color="primary" mat-flat-button>
|
||||
<button (click)="save()" [disabled]="disabled" color="primary" mat-flat-button>
|
||||
{{ 'file-attributes-configurations.save' | translate }}
|
||||
</button>
|
||||
|
||||
@ -46,5 +46,5 @@
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<iqser-circle-button class="dialog-close" icon="iqser:close" mat-dialog-close></iqser-circle-button>
|
||||
<iqser-circle-button class="dialog-close" icon="iqser:close" (action)="close()"></iqser-circle-button>
|
||||
</section>
|
||||
|
||||
@ -1,37 +1,57 @@
|
||||
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, Inject, Injector } from '@angular/core';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { FileAttributeEncodingTypes, IFileAttributesConfig } from '../../../../../../../../libs/red-domain/src';
|
||||
import { fileAttributeEncodingTypesTranslations } from '../../translations/file-attribute-encoding-types-translations';
|
||||
import { BaseDialogComponent } from '../../../../../../../../libs/common-ui/src';
|
||||
|
||||
@Component({
|
||||
templateUrl: './file-attributes-configurations-dialog.component.html',
|
||||
styleUrls: ['./file-attributes-configurations-dialog.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class FileAttributesConfigurationsDialogComponent {
|
||||
export class FileAttributesConfigurationsDialogComponent extends BaseDialogComponent {
|
||||
private readonly _configuration: IFileAttributesConfig = this._data;
|
||||
|
||||
readonly form: FormGroup;
|
||||
readonly encodingTypeOptions = Object.keys(FileAttributeEncodingTypes);
|
||||
readonly translations = fileAttributeEncodingTypesTranslations;
|
||||
|
||||
constructor(
|
||||
private readonly _formBuilder: FormBuilder,
|
||||
readonly dialogRef: MatDialogRef<FileAttributesConfigurationsDialogComponent>,
|
||||
protected readonly _injector: Injector,
|
||||
protected readonly _dialogRef: MatDialogRef<FileAttributesConfigurationsDialogComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) private _data: IFileAttributesConfig,
|
||||
) {
|
||||
super(_injector, _dialogRef);
|
||||
this.form = this._getForm();
|
||||
this.initialFormValue = this.form.getRawValue();
|
||||
}
|
||||
|
||||
save() {}
|
||||
get disabled() {
|
||||
if (!this.changed) {
|
||||
return true;
|
||||
}
|
||||
if (!this.form.get('supportCsvMapping').value) {
|
||||
return false;
|
||||
}
|
||||
return !this.valid;
|
||||
}
|
||||
|
||||
save() {
|
||||
this._configuration.filenameMappingColumnHeaderName = this.form.get('supportCsvMapping').value ? 'Path' : '';
|
||||
this._configuration.keyColumn = this.form.get('keyColumn').value;
|
||||
this._configuration.delimiter = this.form.get('delimiter').value;
|
||||
this._configuration.encoding = this.form.get('encodingType').value;
|
||||
|
||||
this._dialogRef.close();
|
||||
}
|
||||
|
||||
private _getForm(): FormGroup {
|
||||
return this._formBuilder.group({
|
||||
supportCsvMapping: [!!this._configuration.filenameMappingColumnHeaderName],
|
||||
keyColumn: [''],
|
||||
delimiter: [this._configuration.delimiter],
|
||||
encodingType: [FileAttributeEncodingTypes.UTF8],
|
||||
keyColumn: [this._configuration.keyColumn || '', [Validators.required]],
|
||||
delimiter: [this._configuration.delimiter || '', [Validators.required]],
|
||||
encodingType: [this._configuration.encoding || FileAttributeEncodingTypes['UTF-8'], [Validators.required]],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ import { FileAttributeEncodingType } from '@red/domain';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
|
||||
export const fileAttributeEncodingTypesTranslations: { [key in FileAttributeEncodingType]: string } = {
|
||||
UTF8: _('file-attribute-encoding-types.utf8'),
|
||||
'UTF-8': _('file-attribute-encoding-types.utf8'),
|
||||
ASCII: _('file-attribute-encoding-types.ascii'),
|
||||
ISO: _('file-attribute-encoding-types.iso'),
|
||||
};
|
||||
|
||||
@ -19,7 +19,7 @@ export const FileAttributeConfigTypes = {
|
||||
export type FileAttributeConfigType = keyof typeof FileAttributeConfigTypes;
|
||||
|
||||
export const FileAttributeEncodingTypes = {
|
||||
UTF8: 'UTF8',
|
||||
'UTF-8': 'UTF-8',
|
||||
ASCII: 'ASCII',
|
||||
ISO: 'ISO',
|
||||
} as const;
|
||||
|
||||
@ -3,7 +3,7 @@ import { IFileAttributeConfig } from './file-attribute-config';
|
||||
export interface IFileAttributesConfig {
|
||||
delimiter?: string;
|
||||
encoding?: string;
|
||||
keyColumn?: string
|
||||
filenameMappingColumnHeaderName?: string;
|
||||
|
||||
fileAttributeConfigs?: IFileAttributeConfig[];
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user