Commit 41e9fd57c57821d2bf5a1991451f4448ce87c64d
Committed by
Andrew Shvayka
1 parent
0fbd95cd
Improvement view filter dialog setting
Showing
2 changed files
with
47 additions
and
9 deletions
@@ -29,13 +29,6 @@ | @@ -29,13 +29,6 @@ | ||
29 | <fieldset [disabled]="isLoading$ | async" fxLayout="column"> | 29 | <fieldset [disabled]="isLoading$ | async" fxLayout="column"> |
30 | <section fxLayout="row" fxLayoutGap="8px" class="entity-key"> | 30 | <section fxLayout="row" fxLayoutGap="8px" class="entity-key"> |
31 | <section fxFlex="70" fxLayout="row" formGroupName="key" fxLayoutGap="8px"> | 31 | <section fxFlex="70" fxLayout="row" formGroupName="key" fxLayoutGap="8px"> |
32 | - <mat-form-field fxFlex="60" class="mat-block"> | ||
33 | - <mat-label translate>filter.key-name</mat-label> | ||
34 | - <input matInput required formControlName="key"> | ||
35 | - <mat-error *ngIf="keyFilterFormGroup.get('key.key').hasError('required')"> | ||
36 | - {{ 'filter.key-name-required' | translate }} | ||
37 | - </mat-error> | ||
38 | - </mat-form-field> | ||
39 | <mat-form-field fxFlex="40" class="mat-block"> | 32 | <mat-form-field fxFlex="40" class="mat-block"> |
40 | <mat-label translate>filter.key-type.key-type</mat-label> | 33 | <mat-label translate>filter.key-type.key-type</mat-label> |
41 | <mat-select required formControlName="type"> | 34 | <mat-select required formControlName="type"> |
@@ -44,10 +37,24 @@ | @@ -44,10 +37,24 @@ | ||
44 | </mat-option> | 37 | </mat-option> |
45 | </mat-select> | 38 | </mat-select> |
46 | </mat-form-field> | 39 | </mat-form-field> |
40 | + <mat-form-field fxFlex="60" class="mat-block"> | ||
41 | + <mat-label translate>filter.key-name</mat-label> | ||
42 | + <input matInput required formControlName="key" | ||
43 | + [matAutocomplete]="auto" | ||
44 | + [matAutocompleteDisabled]="keyFilterFormGroup.get('key.type').value !== entityField"> | ||
45 | + <mat-autocomplete autoActiveFirstOption #auto="matAutocomplete"> | ||
46 | + <mat-option *ngFor="let option of filteredEntityFields | async" [value]="option"> | ||
47 | + {{option}} | ||
48 | + </mat-option> | ||
49 | + </mat-autocomplete> | ||
50 | + <mat-error *ngIf="keyFilterFormGroup.get('key.key').hasError('required')"> | ||
51 | + {{ 'filter.key-name-required' | translate }} | ||
52 | + </mat-error> | ||
53 | + </mat-form-field> | ||
47 | </section> | 54 | </section> |
48 | <mat-form-field fxFlex="30" class="mat-block"> | 55 | <mat-form-field fxFlex="30" class="mat-block"> |
49 | <mat-label translate>filter.value-type.value-type</mat-label> | 56 | <mat-label translate>filter.value-type.value-type</mat-label> |
50 | - <mat-select matInput formControlName="valueType"> | 57 | + <mat-select formControlName="valueType"> |
51 | <mat-select-trigger> | 58 | <mat-select-trigger> |
52 | <mat-icon class="tb-mat-18" svgIcon="{{ entityKeyValueTypes.get(keyFilterFormGroup.get('valueType').value)?.icon }}"></mat-icon> | 59 | <mat-icon class="tb-mat-18" svgIcon="{{ entityKeyValueTypes.get(keyFilterFormGroup.get('valueType').value)?.icon }}"></mat-icon> |
53 | <span>{{ entityKeyValueTypes.get(keyFilterFormGroup.get('valueType').value)?.name | translate }}</span> | 60 | <span>{{ entityKeyValueTypes.get(keyFilterFormGroup.get('valueType').value)?.name | translate }}</span> |
@@ -27,10 +27,14 @@ import { | @@ -27,10 +27,14 @@ import { | ||
27 | entityKeyTypeTranslationMap, | 27 | entityKeyTypeTranslationMap, |
28 | EntityKeyValueType, | 28 | EntityKeyValueType, |
29 | entityKeyValueTypesMap, | 29 | entityKeyValueTypesMap, |
30 | - KeyFilterInfo, KeyFilterPredicate | 30 | + KeyFilterInfo, |
31 | + KeyFilterPredicate | ||
31 | } from '@shared/models/query/query.models'; | 32 | } from '@shared/models/query/query.models'; |
32 | import { DialogService } from '@core/services/dialog.service'; | 33 | import { DialogService } from '@core/services/dialog.service'; |
33 | import { TranslateService } from '@ngx-translate/core'; | 34 | import { TranslateService } from '@ngx-translate/core'; |
35 | +import { EntityField, entityFields } from '@shared/models/entity.models'; | ||
36 | +import { Observable } from 'rxjs'; | ||
37 | +import { filter, map, startWith } from 'rxjs/operators'; | ||
34 | 38 | ||
35 | export interface KeyFilterDialogData { | 39 | export interface KeyFilterDialogData { |
36 | keyFilter: KeyFilterInfo; | 40 | keyFilter: KeyFilterInfo; |
@@ -61,6 +65,14 @@ export class KeyFilterDialogComponent extends | @@ -61,6 +65,14 @@ export class KeyFilterDialogComponent extends | ||
61 | 65 | ||
62 | submitted = false; | 66 | submitted = false; |
63 | 67 | ||
68 | + entityFields: { [fieldName: string]: EntityField }; | ||
69 | + | ||
70 | + entityFieldsList: string[]; | ||
71 | + | ||
72 | + readonly entityField = EntityKeyType.ENTITY_FIELD; | ||
73 | + | ||
74 | + filteredEntityFields: Observable<string[]>; | ||
75 | + | ||
64 | constructor(protected store: Store<AppState>, | 76 | constructor(protected store: Store<AppState>, |
65 | protected router: Router, | 77 | protected router: Router, |
66 | @Inject(MAT_DIALOG_DATA) public data: KeyFilterDialogData, | 78 | @Inject(MAT_DIALOG_DATA) public data: KeyFilterDialogData, |
@@ -99,9 +111,28 @@ export class KeyFilterDialogComponent extends | @@ -99,9 +111,28 @@ export class KeyFilterDialogComponent extends | ||
99 | ); | 111 | ); |
100 | } | 112 | } |
101 | }); | 113 | }); |
114 | + | ||
115 | + this.keyFilterFormGroup.get('key.key').valueChanges.pipe( | ||
116 | + filter((keyName) => this.keyFilterFormGroup.get('key.type').value === this.entityField && this.entityFields.hasOwnProperty(keyName)) | ||
117 | + ).subscribe((keyName: string) => { | ||
118 | + const prevValueType: EntityKeyValueType = this.keyFilterFormGroup.value.valueType; | ||
119 | + const newValueType = this.entityFields[keyName]?.time ? EntityKeyValueType.DATE_TIME : EntityKeyValueType.STRING; | ||
120 | + if (prevValueType !== newValueType) { | ||
121 | + this.keyFilterFormGroup.get('valueType').patchValue(newValueType, {emitEvent: false}); | ||
122 | + } | ||
123 | + }); | ||
124 | + | ||
125 | + this.entityFields = entityFields; | ||
126 | + this.entityFieldsList = Object.values(entityFields).map(entityField => entityField.keyName).sort(); | ||
102 | } | 127 | } |
103 | 128 | ||
104 | ngOnInit(): void { | 129 | ngOnInit(): void { |
130 | + this.filteredEntityFields = this.keyFilterFormGroup.get('key.key').valueChanges.pipe( | ||
131 | + startWith(''), | ||
132 | + map(value => { | ||
133 | + return this.entityFieldsList.filter(option => option.startsWith(value)); | ||
134 | + }) | ||
135 | + ); | ||
105 | } | 136 | } |
106 | 137 | ||
107 | isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { | 138 | isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { |