From cf12ed48f0952e159c14a40d80e2458fbaf5502f Mon Sep 17 00:00:00 2001 From: Maksym Tsymbarov Date: Fri, 21 Nov 2025 16:51:47 +0200 Subject: [PATCH 1/2] fixed sync entities id select with db --- ...cipient-notification-dialog.component.html | 3 ++ .../entity/entity-autocomplete.component.ts | 41 ++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/notification/recipient/recipient-notification-dialog.component.html b/ui-ngx/src/app/modules/home/pages/notification/recipient/recipient-notification-dialog.component.html index 95715bef87..5012fa5336 100644 --- a/ui-ngx/src/app/modules/home/pages/notification/recipient/recipient-notification-dialog.component.html +++ b/ui-ngx/src/app/modules/home/pages/notification/recipient/recipient-notification-dialog.component.html @@ -70,6 +70,7 @@ 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 8cb785c6f1..b18224e29b 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 @@ -138,6 +138,11 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit @coerceArray() additionalClasses: Array; + @Input() + @coerceBoolean() + syncIdsWithDB = false; + + @Output() entityChanged = new EventEmitter>(); @@ -360,12 +365,38 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit try { entity = await firstValueFrom(this.entityService.getEntity(targetEntityType, id, {ignoreLoading: true, ignoreErrors: true})); } catch (e) { - this.propagateChange(null); + if (this.syncIdsWithDB) { + this.modelValue = null; + this.entityURL = ''; + this.selectEntityFormGroup.get('entity').patchValue('', {emitEvent: false}); + this.entityChanged.emit(null); + this.propagateChange(null); + this.dirty = true; + return; + } else { + this.propagateChange(null); + } + } + + if (entity !== null) { + this.modelValue = this.useFullEntityId ? entity.id : entity.id.id; + this.entityURL = getEntityDetailsPageURL(entity.id.id, targetEntityType); + this.selectEntityFormGroup.get('entity').patchValue(entity, {emitEvent: false}); + this.entityChanged.emit(entity); + } else { + if (this.syncIdsWithDB) { + this.modelValue = null; + this.entityURL = ''; + this.selectEntityFormGroup.get('entity').patchValue('', {emitEvent: false}); + this.entityChanged.emit(null); + this.propagateChange(null); + } else { + this.modelValue = null; + this.entityURL = ''; + this.selectEntityFormGroup.get('entity').patchValue('', {emitEvent: false}); + this.entityChanged.emit(null); + } } - this.modelValue = entity !== null ? (this.useFullEntityId ? entity.id : entity.id.id) : null; - this.entityURL = !entity ? '' : getEntityDetailsPageURL(entity.id.id, targetEntityType); - this.selectEntityFormGroup.get('entity').patchValue(entity !== null ? entity : '', {emitEvent: false}); - this.entityChanged.emit(entity); } else { this.modelValue = null; this.entityURL = ''; From 0750728bab278184725f45bdee197e8cd8342e1d Mon Sep 17 00:00:00 2001 From: Maksym Tsymbarov Date: Mon, 24 Nov 2025 15:51:34 +0200 Subject: [PATCH 2/2] revert changes for tb-entity-autocomplete --- ...cipient-notification-dialog.component.html | 1 - .../entity/entity-autocomplete.component.ts | 41 +++---------------- 2 files changed, 5 insertions(+), 37 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/notification/recipient/recipient-notification-dialog.component.html b/ui-ngx/src/app/modules/home/pages/notification/recipient/recipient-notification-dialog.component.html index 5012fa5336..560db89dbc 100644 --- a/ui-ngx/src/app/modules/home/pages/notification/recipient/recipient-notification-dialog.component.html +++ b/ui-ngx/src/app/modules/home/pages/notification/recipient/recipient-notification-dialog.component.html @@ -105,7 +105,6 @@ 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 b18224e29b..8cb785c6f1 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 @@ -138,11 +138,6 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit @coerceArray() additionalClasses: Array; - @Input() - @coerceBoolean() - syncIdsWithDB = false; - - @Output() entityChanged = new EventEmitter>(); @@ -365,38 +360,12 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit try { entity = await firstValueFrom(this.entityService.getEntity(targetEntityType, id, {ignoreLoading: true, ignoreErrors: true})); } catch (e) { - if (this.syncIdsWithDB) { - this.modelValue = null; - this.entityURL = ''; - this.selectEntityFormGroup.get('entity').patchValue('', {emitEvent: false}); - this.entityChanged.emit(null); - this.propagateChange(null); - this.dirty = true; - return; - } else { - this.propagateChange(null); - } - } - - if (entity !== null) { - this.modelValue = this.useFullEntityId ? entity.id : entity.id.id; - this.entityURL = getEntityDetailsPageURL(entity.id.id, targetEntityType); - this.selectEntityFormGroup.get('entity').patchValue(entity, {emitEvent: false}); - this.entityChanged.emit(entity); - } else { - if (this.syncIdsWithDB) { - this.modelValue = null; - this.entityURL = ''; - this.selectEntityFormGroup.get('entity').patchValue('', {emitEvent: false}); - this.entityChanged.emit(null); - this.propagateChange(null); - } else { - this.modelValue = null; - this.entityURL = ''; - this.selectEntityFormGroup.get('entity').patchValue('', {emitEvent: false}); - this.entityChanged.emit(null); - } + this.propagateChange(null); } + this.modelValue = entity !== null ? (this.useFullEntityId ? entity.id : entity.id.id) : null; + this.entityURL = !entity ? '' : getEntityDetailsPageURL(entity.id.id, targetEntityType); + this.selectEntityFormGroup.get('entity').patchValue(entity !== null ? entity : '', {emitEvent: false}); + this.entityChanged.emit(entity); } else { this.modelValue = null; this.entityURL = '';