From 78ffd10dd3d4ce285395fce3b22e8754266ecb17 Mon Sep 17 00:00:00 2001 From: kalytka Date: Mon, 27 Mar 2023 13:52:40 +0300 Subject: [PATCH 1/4] Changed labelText and reqiredText logic --- .../entity/entity-autocomplete.component.html | 4 ++-- .../entity/entity-autocomplete.component.ts | 21 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.html b/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.html index 2b69495a3c..6d8a424352 100644 --- a/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.html +++ b/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.html @@ -16,7 +16,7 @@ --> - {{ entityText | translate }} + {{ label | translate }} - {{ entityRequiredText | translate }} + {{ requiredErrorText | translate }} diff --git a/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts b/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts index 18a79fdb51..5ddc69426b 100644 --- a/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts +++ b/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts @@ -71,7 +71,6 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit this.dirty = true; } } - @Input() set entitySubtype(entitySubtype: string) { if (this.entitySubtypeValue !== entitySubtype) { @@ -249,12 +248,6 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit break; } } - if (this.labelText && this.labelText.length) { - this.entityText = this.labelText; - } - if (this.requiredText && this.requiredText.length) { - this.entityRequiredText = this.requiredText; - } const currentEntity = this.getCurrentEntity(); if (currentEntity) { const currentEntityType = currentEntity.id.entityType; @@ -384,4 +377,18 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit } return entityType; } + + get label(): string { + if (this.labelText && this.labelText.length) { + return this.labelText; + } + return this.entityText; + } + + get requiredErrorText(): string { + if (this.requiredText && this.requiredText.length) { + return this.requiredText; + } + return this.entityRequiredText; + } } From e984ef4fae574e322d86b0b73ffa7e74ce7a9fb4 Mon Sep 17 00:00:00 2001 From: kalytka Date: Mon, 27 Mar 2023 14:02:48 +0300 Subject: [PATCH 2/4] Refactoring --- .../entity/entity-autocomplete.component.ts | 63 ++++++++++--------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts b/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts index 5ddc69426b..0fe50d99ba 100644 --- a/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts +++ b/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts @@ -61,6 +61,24 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit entitySubtypeValue: string; + entityText: string; + + noEntitiesMatchingText: string; + + entityRequiredText: string; + + filteredEntities: Observable>>; + + searchText = ''; + + private requiredValue: boolean; + + private dirty = false; + + private refresh$ = new Subject>>(); + + private propagateChange = (v: any) => { }; + @Input() set entityType(entityType: EntityType) { if (this.entityTypeValue !== entityType) { @@ -71,6 +89,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit this.dirty = true; } } + @Input() set entitySubtype(entitySubtype: string) { if (this.entitySubtypeValue !== entitySubtype) { @@ -99,14 +118,13 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit @Input() appearance: MatFormFieldAppearance = 'fill'; - private requiredValue: boolean; - get required(): boolean { - return this.requiredValue; - } @Input() set required(value: boolean) { this.requiredValue = coerceBooleanProperty(value); } + get required(): boolean { + return this.requiredValue; + } @Input() disabled: boolean; @@ -116,19 +134,20 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit @ViewChild('entityInput', {static: true}) entityInput: ElementRef; - entityText: string; - noEntitiesMatchingText: string; - entityRequiredText: string; - - filteredEntities: Observable>>; - - searchText = ''; + get requiredErrorText(): string { + if (this.requiredText && this.requiredText.length) { + return this.requiredText; + } + return this.entityRequiredText; + } - private dirty = false; + get label(): string { + if (this.labelText && this.labelText.length) { + return this.labelText; + } + return this.entityText; + } - private refresh$ = new Subject>>(); - - private propagateChange = (v: any) => { }; constructor(private store: Store, public translate: TranslateService, @@ -377,18 +396,4 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit } return entityType; } - - get label(): string { - if (this.labelText && this.labelText.length) { - return this.labelText; - } - return this.entityText; - } - - get requiredErrorText(): string { - if (this.requiredText && this.requiredText.length) { - return this.requiredText; - } - return this.entityRequiredText; - } } From 3f5f0fb64192a34d51b85c6b83bd454c1c69026d Mon Sep 17 00:00:00 2001 From: kalytka Date: Mon, 27 Mar 2023 14:45:14 +0300 Subject: [PATCH 3/4] Refactoring --- .../entity/entity-autocomplete.component.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts b/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts index 0fe50d99ba..c5bf8b5700 100644 --- a/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts +++ b/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts @@ -36,10 +36,10 @@ import { AliasEntityType, EntityType } from '@shared/models/entity-type.models'; import { BaseData } from '@shared/models/base-data'; import { EntityId } from '@shared/models/id/entity-id'; import { EntityService } from '@core/http/entity.service'; -import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { getCurrentAuthUser } from '@core/auth/auth.selectors'; import { Authority } from '@shared/models/authority.enum'; import { isEqual } from '@core/utils'; +import {coerceBoolean} from '@shared/decorators/coerce-boolean'; @Component({ selector: 'tb-entity-autocomplete', @@ -71,8 +71,6 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit searchText = ''; - private requiredValue: boolean; - private dirty = false; private refresh$ = new Subject>>(); @@ -119,14 +117,11 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit appearance: MatFormFieldAppearance = 'fill'; @Input() - set required(value: boolean) { - this.requiredValue = coerceBooleanProperty(value); - } - get required(): boolean { - return this.requiredValue; - } + @coerceBoolean() + required: boolean; @Input() + @coerceBoolean() disabled: boolean; @Output() From b92e451926b036849b64cc6be1fa08773b0f1dd8 Mon Sep 17 00:00:00 2001 From: Vladyslav Date: Mon, 27 Mar 2023 14:49:22 +0300 Subject: [PATCH 4/4] Update entity-autocomplete.component.ts --- .../shared/components/entity/entity-autocomplete.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts b/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts index c5bf8b5700..74e0152ed7 100644 --- a/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts +++ b/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts @@ -39,7 +39,7 @@ import { EntityService } from '@core/http/entity.service'; import { getCurrentAuthUser } from '@core/auth/auth.selectors'; import { Authority } from '@shared/models/authority.enum'; import { isEqual } from '@core/utils'; -import {coerceBoolean} from '@shared/decorators/coerce-boolean'; +import { coerceBoolean } from '@shared/decorators/coerce-boolean'; @Component({ selector: 'tb-entity-autocomplete',