Commit f770f407971c6d99e39ce488fe29cf08c9a76442
1 parent
ca940ba1
Lwm2m: front: update filter for models
Showing
2 changed files
with
32 additions
and
17 deletions
@@ -96,7 +96,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | @@ -96,7 +96,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | ||
96 | configurationJson: [null, Validators.required] | 96 | configurationJson: [null, Validators.required] |
97 | }); | 97 | }); |
98 | this.lwm2mDeviceProfileFormGroup.valueChanges.subscribe((value) => { | 98 | this.lwm2mDeviceProfileFormGroup.valueChanges.subscribe((value) => { |
99 | - console.warn('main form'); | ||
100 | if (!this.disabled) { | 99 | if (!this.disabled) { |
101 | this.updateDeviceProfileValue(value); | 100 | this.updateDeviceProfileValue(value); |
102 | } | 101 | } |
@@ -185,9 +184,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | @@ -185,9 +184,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | ||
185 | observeAttrTelemetry: this.getObserveAttrTelemetryObjects(objectsList) | 184 | observeAttrTelemetry: this.getObserveAttrTelemetryObjects(objectsList) |
186 | }, | 185 | }, |
187 | {emitEvent: false}); | 186 | {emitEvent: false}); |
188 | - // this.lwm2mDeviceProfileFormGroup.get('observeAttrTelemetry').markAsPristine({ | ||
189 | - // onlySelf: true | ||
190 | - // }); | ||
191 | } | 187 | } |
192 | 188 | ||
193 | private updateDeviceProfileValue(config): void { | 189 | private updateDeviceProfileValue(config): void { |
@@ -20,12 +20,12 @@ import { coerceBooleanProperty } from '@angular/cdk/coercion'; | @@ -20,12 +20,12 @@ import { coerceBooleanProperty } from '@angular/cdk/coercion'; | ||
20 | import { Store } from '@ngrx/store'; | 20 | import { Store } from '@ngrx/store'; |
21 | import { AppState } from '@core/core.state'; | 21 | import { AppState } from '@core/core.state'; |
22 | import { Observable, of } from 'rxjs'; | 22 | import { Observable, of } from 'rxjs'; |
23 | -import { filter, mergeMap, share, tap } from 'rxjs/operators'; | 23 | +import { filter, map, mergeMap, tap } from 'rxjs/operators'; |
24 | import { ObjectLwM2M } from './profile-config.models'; | 24 | import { ObjectLwM2M } from './profile-config.models'; |
25 | import { TranslateService } from '@ngx-translate/core'; | 25 | import { TranslateService } from '@ngx-translate/core'; |
26 | import { DeviceProfileService } from '@core/http/device-profile.service'; | 26 | import { DeviceProfileService } from '@core/http/device-profile.service'; |
27 | import { Direction } from '@shared/models/page/sort-order'; | 27 | import { Direction } from '@shared/models/page/sort-order'; |
28 | -import { isDefined } from '@core/utils'; | 28 | +import { isDefined, isDefinedAndNotNull, isEmptyStr } from '@core/utils'; |
29 | 29 | ||
30 | @Component({ | 30 | @Component({ |
31 | selector: 'tb-profile-lwm2m-object-list', | 31 | selector: 'tb-profile-lwm2m-object-list', |
@@ -42,6 +42,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | @@ -42,6 +42,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | ||
42 | 42 | ||
43 | private requiredValue: boolean; | 43 | private requiredValue: boolean; |
44 | private dirty = false; | 44 | private dirty = false; |
45 | + private allObjectsList: Observable<Array<ObjectLwM2M>>; | ||
45 | 46 | ||
46 | lwm2mListFormGroup: FormGroup; | 47 | lwm2mListFormGroup: FormGroup; |
47 | modelValue: Array<number> | null; | 48 | modelValue: Array<number> | null; |
@@ -71,7 +72,8 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | @@ -71,7 +72,8 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | ||
71 | 72 | ||
72 | @ViewChild('objectInput') objectInput: ElementRef<HTMLInputElement>; | 73 | @ViewChild('objectInput') objectInput: ElementRef<HTMLInputElement>; |
73 | 74 | ||
74 | - private propagateChange = (v: any) => { }; | 75 | + private propagateChange = (v: any) => { |
76 | + }; | ||
75 | 77 | ||
76 | constructor(private store: Store<AppState>, | 78 | constructor(private store: Store<AppState>, |
77 | public translate: TranslateService, | 79 | public translate: TranslateService, |
@@ -106,8 +108,8 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | @@ -106,8 +108,8 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | ||
106 | } | 108 | } |
107 | }), | 109 | }), |
108 | filter((value) => typeof value === 'string'), | 110 | filter((value) => typeof value === 'string'), |
109 | - mergeMap(name => this.fetchListObjects(name)), | ||
110 | - share() | 111 | + // map(value => value ? value : ''), |
112 | + mergeMap(searchText => this.fetchListObjects(searchText)) | ||
111 | ); | 113 | ); |
112 | } | 114 | } |
113 | 115 | ||
@@ -147,7 +149,6 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | @@ -147,7 +149,6 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | ||
147 | this.lwm2mListFormGroup.get('objectsList').setValue(this.objectsList); | 149 | this.lwm2mListFormGroup.get('objectsList').setValue(this.objectsList); |
148 | this.addList.next(this.objectsList); | 150 | this.addList.next(this.objectsList); |
149 | } | 151 | } |
150 | - // this.propagateChange(this.modelValue); | ||
151 | this.clear(); | 152 | this.clear(); |
152 | } | 153 | } |
153 | 154 | ||
@@ -162,7 +163,6 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | @@ -162,7 +163,6 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | ||
162 | if (!this.modelValue.length) { | 163 | if (!this.modelValue.length) { |
163 | this.modelValue = null; | 164 | this.modelValue = null; |
164 | } | 165 | } |
165 | - // this.propagateChange(this.modelValue); | ||
166 | this.clear(); | 166 | this.clear(); |
167 | } | 167 | } |
168 | } | 168 | } |
@@ -173,15 +173,34 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | @@ -173,15 +173,34 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | ||
173 | 173 | ||
174 | private fetchListObjects = (searchText?: string): Observable<Array<ObjectLwM2M>> => { | 174 | private fetchListObjects = (searchText?: string): Observable<Array<ObjectLwM2M>> => { |
175 | this.searchText = searchText; | 175 | this.searchText = searchText; |
176 | - const sortOrder = { | ||
177 | - property: 'name', | ||
178 | - direction: Direction.ASC | ||
179 | - }; | ||
180 | - return this.deviceProfileService.getLwm2mObjects(sortOrder, null, searchText).pipe( | ||
181 | - mergeMap(objectsList => of(objectsList)) | 176 | + const filters = {names: [], ids: []}; |
177 | + if (isDefinedAndNotNull(searchText) && !isEmptyStr(searchText)) { | ||
178 | + const ids = searchText.match(/\d+/g); | ||
179 | + filters.ids = isDefinedAndNotNull(ids) ? ids.map(Number) as [] : filters.ids; | ||
180 | + const names = searchText.trim().split(" ") as []; | ||
181 | + filters.names = names; | ||
182 | + } | ||
183 | + const predicate = objectLwM2M => filters.names.filter(word => objectLwM2M.name.toUpperCase().includes(word.toUpperCase())).length>0 | ||
184 | + || filters.ids.includes(objectLwM2M.id); | ||
185 | + return this.getListModels().pipe( | ||
186 | + map(objectLwM2Ms => searchText ? objectLwM2Ms.filter(predicate) : objectLwM2Ms) | ||
182 | ); | 187 | ); |
183 | } | 188 | } |
184 | 189 | ||
190 | + private getListModels(): Observable<Array<ObjectLwM2M>> { | ||
191 | + if (!this.allObjectsList) { | ||
192 | + const sortOrder = { | ||
193 | + property: 'name', | ||
194 | + direction: Direction.ASC | ||
195 | + }; | ||
196 | + this.allObjectsList = this.deviceProfileService.getLwm2mObjects(sortOrder, null, null).pipe( | ||
197 | + mergeMap(objectsList => of(objectsList)) | ||
198 | + ); | ||
199 | + } | ||
200 | + return this.allObjectsList; | ||
201 | + } | ||
202 | + | ||
203 | + | ||
185 | onFocus = (): void => { | 204 | onFocus = (): void => { |
186 | if (this.dirty) { | 205 | if (this.dirty) { |
187 | this.lwm2mListFormGroup.get('objectLwm2m').updateValueAndValidity({onlySelf: true, emitEvent: true}); | 206 | this.lwm2mListFormGroup.get('objectLwm2m').updateValueAndValidity({onlySelf: true, emitEvent: true}); |