Skip to content

Commit c844596

Browse files
authored
Merge branch 'release/6.2.5' into NAE-1758
2 parents 11a1efc + b990c70 commit c844596

File tree

4 files changed

+40
-50
lines changed

4 files changed

+40
-50
lines changed

projects/netgrif-components-core/src/lib/data-fields/enumeration-field/enumeration-autocomplete-select-field/abstract-enumeration-autocomplete-select-field.component.ts

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import {Component, Input, OnDestroy, OnInit, ViewChild} from '@angular/core';
2-
import {FormControl, NgModel} from '@angular/forms';
1+
import {Component, ElementRef, Input, OnDestroy, OnInit, ViewChild} from '@angular/core';
2+
import {FormControl} from '@angular/forms';
33
import {Observable, of} from 'rxjs';
44
import {map, startWith} from 'rxjs/operators';
55
import {EnumerationField, EnumerationFieldValidation, EnumerationFieldValue} from '../models/enumeration-field';
66
import {WrappedBoolean} from '../../data-field-template/models/wrapped-boolean';
77
import {TranslateService} from '@ngx-translate/core';
8-
import {MatAutocompleteSelectedEvent} from '@angular/material/autocomplete';
9-
import {EnumerationAutocompleteFilterProperty} from './enumeration-autocomplete-filter-property';
8+
import {EnumerationAutocompleteFilterProperty} from "./enumeration-autocomplete-filter-property";
109

1110
@Component({
1211
selector: 'ncc-abstract-enumeration-autocomplete-field',
@@ -17,49 +16,24 @@ export abstract class AbstractEnumerationAutocompleteSelectFieldComponent implem
1716
@Input() enumerationField: EnumerationField;
1817
@Input() formControlRef: FormControl;
1918
@Input() showLargeLayout: WrappedBoolean;
20-
@ViewChild('input') text: NgModel;
21-
public tmpValue: string;
19+
@ViewChild('input') text: ElementRef;
2220

2321
filteredOptions: Observable<Array<EnumerationFieldValue>>;
2422

2523
constructor(protected _translate: TranslateService) {
2624
}
2725

2826
ngOnInit() {
29-
this.tmpValue = this.formControlRef.value ?? '';
3027
this.filteredOptions = this.formControlRef.valueChanges.pipe(
3128
startWith(''),
3229
map(value => this._filter(value))
3330
);
34-
this.enumerationField.touch$.subscribe(touch => {
35-
if (touch) {
36-
this.text.control.markAsTouched();
37-
}
38-
});
39-
this.formControlRef.valueChanges.subscribe(it => {
40-
this.tmpValue = it ?? '';
41-
});
4231
}
4332

4433
ngOnDestroy(): void {
4534
this.filteredOptions = undefined;
4635
}
4736

48-
change() {
49-
if (this.text.value !== undefined) {
50-
this.filteredOptions = of(this._filter(this.text.value));
51-
}
52-
}
53-
54-
select(event: MatAutocompleteSelectedEvent) {
55-
this.formControlRef.setValue(event.option.value);
56-
}
57-
58-
59-
isInvalid(): boolean {
60-
return !this.formControlRef.disabled && !this.formControlRef.valid && this.text.control.touched;
61-
}
62-
6337
protected checkPropertyInComponent(property: string): boolean {
6438
return !!this.enumerationField.component && !!this.enumerationField.component.properties && property in this.enumerationField.component.properties;
6539
}
@@ -104,6 +78,12 @@ export abstract class AbstractEnumerationAutocompleteSelectFieldComponent implem
10478
.replace(/[\u0300-\u036f]/g, '').indexOf(filterValue) === 0);
10579
}
10680

81+
change() {
82+
if (this.text.nativeElement.value !== undefined) {
83+
this.filteredOptions = of(this._filter(this.text.nativeElement.value));
84+
}
85+
}
86+
10787
public renderSelection = (key) => {
10888
if (key !== undefined && key !== '' && key !== null) {
10989
if (this.enumerationField.choices.find(choice => choice.key === key)) {

projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {AbstractControl, ValidationErrors, ValidatorFn, Validators} from '@angul
55
import {FieldTypeResource} from '../../../task-content/model/field-type-resource';
66
import {Component} from '../../models/component';
77
import {Validation} from '../../models/validation';
8+
import {Observable} from "rxjs";
9+
import {debounceTime} from "rxjs/operators";
810

911
export interface EnumerationFieldValue {
1012
key: string;
@@ -17,6 +19,7 @@ export enum EnumerationFieldValidation {
1719
}
1820

1921
export class EnumerationField extends DataField<string> {
22+
protected REQUEST_DEBOUNCE_TIME = 600;
2023

2124
constructor(stringId: string, title: string, value: string,
2225
protected _choices: Array<EnumerationFieldValue>, behavior: Behavior, placeholder?: string, description?: string,
@@ -26,7 +29,7 @@ export class EnumerationField extends DataField<string> {
2629
}
2730

2831
set choices(choices: Array<EnumerationFieldValue>) {
29-
this._choices = choices;
32+
this._choices = choices;
3033
}
3134

3235
get choices(): Array<EnumerationFieldValue> {
@@ -37,6 +40,10 @@ export class EnumerationField extends DataField<string> {
3740
return this._fieldType;
3841
}
3942

43+
public valueChanges(): Observable<string> {
44+
return this._value.pipe(debounceTime(this.REQUEST_DEBOUNCE_TIME));
45+
}
46+
4047
protected resolveFormControlValidators(): Array<ValidatorFn> {
4148
const result = [];
4249

projects/netgrif-components-core/src/lib/task/services/task-data.service.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ import {UserComparatorService} from '../../user/services/user-comparator.service
3131
import {TaskSetDataRequestContext} from '../models/task-set-data-request-context';
3232
import {EventOutcomeMessageResource} from '../../resources/interface/message-resource';
3333
import {EventService} from '../../event/services/event.service';
34-
import {EventOutcome} from '../../resources/interface/event-outcome';
3534
import {ChangedFieldsService} from '../../changed-fields/services/changed-fields.service';
3635
import {ChangedFieldsMap} from '../../event/services/interfaces/changed-fields-map';
3736
import {TaskFields} from '../../task-content/model/task-fields';
37+
import {EnumerationField} from "../../data-fields/enumeration-field/models/enumeration-field";
3838

3939
/**
4040
* Handles the loading and updating of data fields and behaviour of
@@ -149,7 +149,7 @@ export class TaskDataService extends TaskHandlingService implements OnDestroy {
149149

150150
/**
151151
* Processes a successful outcome of a `getData` request
152-
* @param gottenTaskId the Id of the task whose data was requested
152+
* @param gottenTaskId the ID of the task whose data was requested
153153
* @param dataGroups the returned data groups of the task
154154
* @param afterAction the action that should be performed after the request is processed
155155
* @param nextEvent indicates to the event queue that the next event can be processed
@@ -233,7 +233,7 @@ export class TaskDataService extends TaskHandlingService implements OnDestroy {
233233

234234
/**
235235
* Processes an erroneous outcome of a `getData` request
236-
* @param gottenTaskId the Id of the task whose data was requested
236+
* @param gottenTaskId the ID of the task whose data was requested
237237
* @param error the returned error
238238
* @param afterAction the action that should be performed after the request is processed
239239
* @param nextEvent indicates to the event queue that the next event can be processed
@@ -348,12 +348,16 @@ export class TaskDataService extends TaskHandlingService implements OnDestroy {
348348
field.changed = false;
349349
}
350350

351+
protected isAutocompleteEnumException(field: DataField<unknown>): boolean{
352+
return (field instanceof EnumerationField) && (field.getComponentType() === 'autocomplete') && !field.valid;
353+
}
354+
351355
/**
352356
* @param field the checked field
353357
* @returns whether the field was updated on frontend and thus the backend should be notified
354358
*/
355359
protected wasFieldUpdated(field: DataField<unknown>): boolean {
356-
return field.initialized && field.changed && (field.valid || field.sendInvalidValues);
360+
return field.initialized && field.changed && (field.valid || field.sendInvalidValues) && (!this.isAutocompleteEnumException(field));
357361
}
358362

359363
/**
@@ -397,7 +401,7 @@ export class TaskDataService extends TaskHandlingService implements OnDestroy {
397401

398402
/**
399403
* Performs a `setData` request on the task currently stored in the `taskContent` service
400-
* @param setTaskId id of the task
404+
* @param setTaskId ID of the task
401405
* @param body content of the `setData` request
402406
* @param afterAction the action that should be performed after the request is processed
403407
* @param nextEvent indicates to the event queue that the next event can be processed
@@ -434,18 +438,18 @@ export class TaskDataService extends TaskHandlingService implements OnDestroy {
434438
}
435439

436440
/**
437-
* Processes a unsuccessful outcome of a `setData` request
438-
* @param setTaskId the Id of the task whose data was set
441+
* Processes an unsuccessful outcome of a `setData` request
442+
* @param setTaskId the ID of the task whose data was set
439443
* @param response the resulting Event outcome of the set data request
440444
* @param afterAction the action that should be performed after the request is processed
441445
* @param nextEvent indicates to the event queue that the next event can be processed
442446
* @param body hold the data that was sent in request
443447
*/
444448
protected processUnsuccessfulSetDataRequest(setTaskId: string,
445-
response: EventOutcomeMessageResource,
446-
afterAction: AfterAction,
447-
nextEvent: AfterAction,
448-
body: TaskSetDataRequestBody) {
449+
response: EventOutcomeMessageResource,
450+
afterAction: AfterAction,
451+
nextEvent: AfterAction,
452+
body: TaskSetDataRequestBody) {
449453
if (response.error !== '') {
450454
this._snackBar.openErrorSnackBar(this._translate.instant(response.error));
451455
} else {
@@ -468,7 +472,7 @@ export class TaskDataService extends TaskHandlingService implements OnDestroy {
468472

469473
/**
470474
* Processes a successful outcome of a `setData` request
471-
* @param setTaskId the Id of the task whose data was set
475+
* @param setTaskId the ID of the task whose data was set
472476
* @param response the resulting Event outcome of the set data request
473477
* @param afterAction the action that should be performed after the request is processed
474478
* @param nextEvent indicates to the event queue that the next event can be processed
@@ -493,7 +497,7 @@ export class TaskDataService extends TaskHandlingService implements OnDestroy {
493497

494498
/**
495499
* Processes an erroneous outcome of a `setData` request
496-
* @param setTaskId the Id of the task whose data was set
500+
* @param setTaskId the ID of the task whose data was set
497501
* @param error the returned error
498502
* @param afterAction the action that should be performed after the request is processed
499503
* @param nextEvent indicates to the event queue that the next event can be processed
@@ -586,7 +590,7 @@ export class TaskDataService extends TaskHandlingService implements OnDestroy {
586590
*
587591
* @param afterAction the call chain steam of the update data method
588592
* @param result result of the update data request
589-
* @param setTaskId the Id of the {@link Task}, who's state should be updated
593+
* @param setTaskId the ID of the {@link Task}, who's state should be updated
590594
*/
591595
protected updateStateInfo(afterAction: AfterAction, result: boolean, setTaskId: string): void {
592596
this._taskState.stopLoading(setTaskId);

projects/netgrif-components/src/lib/data-fields/enumeration-field/enumeration-autocomplete-select-field/enumeration-autocomplete-select-field.component.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33
<input type="text"
44
aria-label="Autocomplete"
55
matInput
6-
#input="ngModel"
6+
#input
77
[placeholder]="enumerationField.placeholder"
8+
[formControl]="formControlRef"
89
[matAutocomplete]="auto"
9-
[(ngModel)]="tmpValue"
1010
[required]="enumerationField.behavior.required"
11-
[disabled]="formControlRef.disabled"
1211
(focus)="change()"
1312
(keyup)="change()">
14-
<mat-autocomplete [displayWith]="renderSelection" autoActiveFirstOption #auto="matAutocomplete" (optionSelected)="select($event)">
13+
<mat-autocomplete [displayWith]="renderSelection" autoActiveFirstOption #auto="matAutocomplete">
1514
<mat-option [value]="null">---</mat-option>
1615
<mat-option *ngFor="let option of filteredOptions | async" [value]="option.key" (click)="change()">
1716
{{option.value}}
1817
</mat-option>
1918
</mat-autocomplete>
2019
<mat-hint>{{enumerationField.description}}</mat-hint>
21-
<mat-error *ngIf="isInvalid() !== undefined">{{buildErrorMessage()}}</mat-error>
20+
<mat-error *ngIf="enumerationField.isInvalid(formControlRef)">{{buildErrorMessage()}}</mat-error>
2221
</mat-form-field>

0 commit comments

Comments
 (0)