Browse Source

fixed sync entities id select with db

pull/14399/head
Maksym Tsymbarov 10 months ago
parent
commit
cf12ed48f0
  1. 3
      ui-ngx/src/app/modules/home/pages/notification/recipient/recipient-notification-dialog.component.html
  2. 41
      ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts

3
ui-ngx/src/app/modules/home/pages/notification/recipient/recipient-notification-dialog.component.html

@ -70,6 +70,7 @@
<ng-container *ngIf="targetNotificationForm.get('configuration.usersFilter.filterByTenants').value; else tenantProfiles">
<tb-entity-list
formControlName="tenantsIds"
syncIdsWithDB
subscriptSizing="dynamic"
labelText="{{ 'tenant.tenants' | translate }}"
placeholderText="{{ 'tenant.tenants' | translate }}"
@ -80,6 +81,7 @@
<ng-template #tenantProfiles>
<tb-entity-list
formControlName="tenantProfilesIds"
syncIdsWithDB
subscriptSizing="dynamic"
labelText="{{ 'tenant-profile.tenant-profiles' | translate }}"
placeholderText="{{ 'tenant-profile.tenant-profiles' | translate }}"
@ -103,6 +105,7 @@
<ng-container *ngSwitchCase="notificationTargetConfigType.CUSTOMER_USERS">
<tb-entity-autocomplete
required
syncIdsWithDB
formControlName="customerId"
[entityType]="entityType.CUSTOMER">
</tb-entity-autocomplete>

41
ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts

@ -138,6 +138,11 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
@coerceArray()
additionalClasses: Array<string>;
@Input()
@coerceBoolean()
syncIdsWithDB = false;
@Output()
entityChanged = new EventEmitter<BaseData<EntityId>>();
@ -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 = '';

Loading…
Cancel
Save