UI: Fixed clear and add an object at LwM2M device profile

This commit is contained in:
Vladyslav Prykhodko 2021-07-19 23:50:51 +03:00
parent ae667e5af1
commit 0301c1e32c
2 changed files with 9 additions and 9 deletions

View File

@ -40,7 +40,7 @@
class="tb-autocomplete" class="tb-autocomplete"
[displayWith]="displayObjectLwm2mFn"> [displayWith]="displayObjectLwm2mFn">
<mat-option *ngFor="let objectLwm2m of filteredObjectsList | async" [value]="objectLwm2m"> <mat-option *ngFor="let objectLwm2m of filteredObjectsList | async" [value]="objectLwm2m">
<span [innerHTML]="objectLwm2m.keyId + ': ' + objectLwm2m.name | highlight:searchText"></span> <span [innerHTML]="objectLwm2m.keyId + ': ' + (objectLwm2m.name | highlight: searchText)"></span>
</mat-option> </mat-option>
<mat-option *ngIf="!(filteredObjectsList | async)?.length" [value]="null"> <mat-option *ngIf="!(filteredObjectsList | async)?.length" [value]="null">
<span> <span>

View File

@ -112,15 +112,15 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
ngOnInit() { ngOnInit() {
this.filteredObjectsList = this.lwm2mListFormGroup.get('objectLwm2m').valueChanges this.filteredObjectsList = this.lwm2mListFormGroup.get('objectLwm2m').valueChanges
.pipe( .pipe(
distinctUntilChanged(),
tap((value) => { tap((value) => {
if (value && typeof value !== 'string') { if (value && !isString(value)) {
this.add(value); this.add(value);
} else if (value === null) { } else if (value === null) {
this.clear(); this.clear(this.objectInput.nativeElement.value);
} }
}), }),
filter(searchText => isString(searchText)), filter(searchText => isString(searchText)),
distinctUntilChanged(),
mergeMap(searchText => this.fetchListObjects(searchText)), mergeMap(searchText => this.fetchListObjects(searchText)),
share() share()
); );
@ -176,8 +176,8 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
} }
} }
displayObjectLwm2mFn = (object?: ObjectLwM2M): string | undefined => { displayObjectLwm2mFn = (object?: ObjectLwM2M): string => {
return object ? object.name : undefined; return object ? object.name : '';
} }
private fetchListObjects = (searchText: string): Observable<Array<ObjectLwM2M>> => { private fetchListObjects = (searchText: string): Observable<Array<ObjectLwM2M>> => {
@ -196,9 +196,9 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
} }
} }
private clear() { private clear(value: string = '') {
this.searchText = ''; this.objectInput.nativeElement.value = value;
this.lwm2mListFormGroup.get('objectLwm2m').patchValue(null, {emitEvent: false}); this.lwm2mListFormGroup.get('objectLwm2m').patchValue(value);
setTimeout(() => { setTimeout(() => {
this.objectInput.nativeElement.blur(); this.objectInput.nativeElement.blur();
this.objectInput.nativeElement.focus(); this.objectInput.nativeElement.focus();