Browse Source

UI: Improvement for entity autocomplete

pull/8929/head
Artem Dzhereleiko 3 years ago
parent
commit
b076a89b58
  1. 12
      ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts

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

@ -26,7 +26,7 @@ import {
ViewChild ViewChild
} from '@angular/core'; } from '@angular/core';
import { MatFormFieldAppearance } from '@angular/material/form-field'; import { MatFormFieldAppearance } from '@angular/material/form-field';
import { ControlValueAccessor, UntypedFormBuilder, UntypedFormGroup, NG_VALUE_ACCESSOR } from '@angular/forms'; import { ControlValueAccessor, NG_VALUE_ACCESSOR, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { merge, Observable, of, Subject } from 'rxjs'; import { merge, Observable, of, Subject } from 'rxjs';
import { catchError, debounceTime, map, share, switchMap, tap } from 'rxjs/operators'; import { catchError, debounceTime, map, share, switchMap, tap } from 'rxjs/operators';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
@ -55,7 +55,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
selectEntityFormGroup: UntypedFormGroup; selectEntityFormGroup: UntypedFormGroup;
modelValue: string | null; modelValue: string | EntityId | null;
entityTypeValue: EntityType | AliasEntityType; entityTypeValue: EntityType | AliasEntityType;
@ -113,6 +113,10 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
@Input() @Input()
requiredText: string; requiredText: string;
@Input()
@coerceBoolean()
useFullEntityId: boolean;
@Input() @Input()
appearance: MatFormFieldAppearance = 'fill'; appearance: MatFormFieldAppearance = 'fill';
@ -171,7 +175,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
if (typeof value === 'string' || !value) { if (typeof value === 'string' || !value) {
modelValue = null; modelValue = null;
} else { } else {
modelValue = value.id.id; modelValue = this.useFullEntityId ? value.id : value.id.id;
} }
this.updateView(modelValue, value); this.updateView(modelValue, value);
if (value === null) { if (value === null) {
@ -307,7 +311,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
} catch (e) { } catch (e) {
this.propagateChange(null); this.propagateChange(null);
} }
this.modelValue = entity !== null ? entity.id.id : null; this.modelValue = entity !== null ? (this.useFullEntityId ? entity.id : entity.id.id) : null;
this.selectEntityFormGroup.get('entity').patchValue(entity !== null ? entity : '', {emitEvent: false}); this.selectEntityFormGroup.get('entity').patchValue(entity !== null ? entity : '', {emitEvent: false});
this.entityChanged.emit(entity); this.entityChanged.emit(entity);
} else { } else {

Loading…
Cancel
Save