Browse Source

Lwm2m: front: update filter for models

pull/3840/head
nickAS21 6 years ago
parent
commit
f770f40797
  1. 4
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts
  2. 45
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-list.component.ts

4
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts

@ -96,7 +96,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
configurationJson: [null, Validators.required] configurationJson: [null, Validators.required]
}); });
this.lwm2mDeviceProfileFormGroup.valueChanges.subscribe((value) => { this.lwm2mDeviceProfileFormGroup.valueChanges.subscribe((value) => {
console.warn('main form');
if (!this.disabled) { if (!this.disabled) {
this.updateDeviceProfileValue(value); this.updateDeviceProfileValue(value);
} }
@ -185,9 +184,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
observeAttrTelemetry: this.getObserveAttrTelemetryObjects(objectsList) observeAttrTelemetry: this.getObserveAttrTelemetryObjects(objectsList)
}, },
{emitEvent: false}); {emitEvent: false});
// this.lwm2mDeviceProfileFormGroup.get('observeAttrTelemetry').markAsPristine({
// onlySelf: true
// });
} }
private updateDeviceProfileValue(config): void { private updateDeviceProfileValue(config): void {

45
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-list.component.ts

@ -20,12 +20,12 @@ import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
import { Observable, of } from 'rxjs'; import { Observable, of } from 'rxjs';
import { filter, mergeMap, share, tap } from 'rxjs/operators'; import { filter, map, mergeMap, tap } from 'rxjs/operators';
import { ObjectLwM2M } from './profile-config.models'; import { ObjectLwM2M } from './profile-config.models';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { DeviceProfileService } from '@core/http/device-profile.service'; import { DeviceProfileService } from '@core/http/device-profile.service';
import { Direction } from '@shared/models/page/sort-order'; import { Direction } from '@shared/models/page/sort-order';
import { isDefined } from '@core/utils'; import { isDefined, isDefinedAndNotNull, isEmptyStr } from '@core/utils';
@Component({ @Component({
selector: 'tb-profile-lwm2m-object-list', selector: 'tb-profile-lwm2m-object-list',
@ -42,6 +42,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
private requiredValue: boolean; private requiredValue: boolean;
private dirty = false; private dirty = false;
private allObjectsList: Observable<Array<ObjectLwM2M>>;
lwm2mListFormGroup: FormGroup; lwm2mListFormGroup: FormGroup;
modelValue: Array<number> | null; modelValue: Array<number> | null;
@ -71,7 +72,8 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
@ViewChild('objectInput') objectInput: ElementRef<HTMLInputElement>; @ViewChild('objectInput') objectInput: ElementRef<HTMLInputElement>;
private propagateChange = (v: any) => { }; private propagateChange = (v: any) => {
};
constructor(private store: Store<AppState>, constructor(private store: Store<AppState>,
public translate: TranslateService, public translate: TranslateService,
@ -106,8 +108,8 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
} }
}), }),
filter((value) => typeof value === 'string'), filter((value) => typeof value === 'string'),
mergeMap(name => this.fetchListObjects(name)), // map(value => value ? value : ''),
share() mergeMap(searchText => this.fetchListObjects(searchText))
); );
} }
@ -147,7 +149,6 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
this.lwm2mListFormGroup.get('objectsList').setValue(this.objectsList); this.lwm2mListFormGroup.get('objectsList').setValue(this.objectsList);
this.addList.next(this.objectsList); this.addList.next(this.objectsList);
} }
// this.propagateChange(this.modelValue);
this.clear(); this.clear();
} }
@ -162,7 +163,6 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
if (!this.modelValue.length) { if (!this.modelValue.length) {
this.modelValue = null; this.modelValue = null;
} }
// this.propagateChange(this.modelValue);
this.clear(); this.clear();
} }
} }
@ -173,15 +173,34 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
private fetchListObjects = (searchText?: string): Observable<Array<ObjectLwM2M>> => { private fetchListObjects = (searchText?: string): Observable<Array<ObjectLwM2M>> => {
this.searchText = searchText; this.searchText = searchText;
const sortOrder = { const filters = {names: [], ids: []};
property: 'name', if (isDefinedAndNotNull(searchText) && !isEmptyStr(searchText)) {
direction: Direction.ASC const ids = searchText.match(/\d+/g);
}; filters.ids = isDefinedAndNotNull(ids) ? ids.map(Number) as [] : filters.ids;
return this.deviceProfileService.getLwm2mObjects(sortOrder, null, searchText).pipe( const names = searchText.trim().split(" ") as [];
mergeMap(objectsList => of(objectsList)) filters.names = names;
}
const predicate = objectLwM2M => filters.names.filter(word => objectLwM2M.name.toUpperCase().includes(word.toUpperCase())).length>0
|| filters.ids.includes(objectLwM2M.id);
return this.getListModels().pipe(
map(objectLwM2Ms => searchText ? objectLwM2Ms.filter(predicate) : objectLwM2Ms)
); );
} }
private getListModels(): Observable<Array<ObjectLwM2M>> {
if (!this.allObjectsList) {
const sortOrder = {
property: 'name',
direction: Direction.ASC
};
this.allObjectsList = this.deviceProfileService.getLwm2mObjects(sortOrder, null, null).pipe(
mergeMap(objectsList => of(objectsList))
);
}
return this.allObjectsList;
}
onFocus = (): void => { onFocus = (): void => {
if (this.dirty) { if (this.dirty) {
this.lwm2mListFormGroup.get('objectLwm2m').updateValueAndValidity({onlySelf: true, emitEvent: true}); this.lwm2mListFormGroup.get('objectLwm2m').updateValueAndValidity({onlySelf: true, emitEvent: true});

Loading…
Cancel
Save