Showing
6 changed files
with
22 additions
and
18 deletions
... | ... | @@ -387,3 +387,19 @@ export function sortObjectKeys<T>(obj: T): T { |
387 | 387 | return acc; |
388 | 388 | }, {} as T); |
389 | 389 | } |
390 | + | |
391 | +export function deepTrim<T>(obj: T): T { | |
392 | + if (isNumber(obj) || isUndefined(obj) || isString(obj) || obj === null) { | |
393 | + return obj; | |
394 | + } | |
395 | + return Object.keys(obj).reduce((acc, curr) => { | |
396 | + if (isString(obj[curr])) { | |
397 | + acc[curr] = obj[curr].trim(); | |
398 | + } else if (isObject(obj[curr])) { | |
399 | + acc[curr] = deepTrim(obj[curr]); | |
400 | + } else { | |
401 | + acc[curr] = obj[curr]; | |
402 | + } | |
403 | + return acc; | |
404 | + }, (Array.isArray(obj) ? [] : {}) as T); | |
405 | +} | ... | ... |
... | ... | @@ -23,7 +23,7 @@ import { AppState } from '@core/core.state'; |
23 | 23 | import { EntityAction } from '@home/models/entity/entity-component.models'; |
24 | 24 | import { EntityTableConfig } from '@home/models/entity/entities-table-config.models'; |
25 | 25 | import { PageLink } from '@shared/models/page/page-link'; |
26 | -import { isObject, isString } from '@core/utils'; | |
26 | +import { deepTrim } from '@core/utils'; | |
27 | 27 | |
28 | 28 | // @dynamic |
29 | 29 | @Directive() |
... | ... | @@ -115,20 +115,7 @@ export abstract class EntityComponent<T extends BaseData<HasId>, |
115 | 115 | } |
116 | 116 | |
117 | 117 | prepareFormValue(formValue: any): any { |
118 | - return this.deepTrim(formValue); | |
119 | - } | |
120 | - | |
121 | - private deepTrim(obj: object): object { | |
122 | - return Object.keys(obj).reduce((acc, curr) => { | |
123 | - if (isString(obj[curr])) { | |
124 | - acc[curr] = obj[curr].trim(); | |
125 | - } else if (isObject(obj[curr])) { | |
126 | - acc[curr] = this.deepTrim(obj[curr]); | |
127 | - } else { | |
128 | - acc[curr] = obj[curr]; | |
129 | - } | |
130 | - return acc; | |
131 | - }, Array.isArray(obj) ? [] : {}); | |
118 | + return deepTrim(formValue); | |
132 | 119 | } |
133 | 120 | |
134 | 121 | protected setEntitiesTableConfig(entitiesTableConfig: C) { | ... | ... |
... | ... | @@ -44,6 +44,7 @@ import { EntityType } from '@shared/models/entity-type.models'; |
44 | 44 | import { MatHorizontalStepper } from '@angular/material/stepper'; |
45 | 45 | import { RuleChainId } from '@shared/models/id/rule-chain-id'; |
46 | 46 | import { StepperSelectionEvent } from '@angular/cdk/stepper'; |
47 | +import { deepTrim } from '@core/utils'; | |
47 | 48 | |
48 | 49 | export interface AddDeviceProfileDialogData { |
49 | 50 | deviceProfileName: string; |
... | ... | @@ -171,7 +172,7 @@ export class AddDeviceProfileDialogComponent extends |
171 | 172 | if (this.deviceProfileDetailsFormGroup.get('defaultRuleChainId').value) { |
172 | 173 | deviceProfile.defaultRuleChainId = new RuleChainId(this.deviceProfileDetailsFormGroup.get('defaultRuleChainId').value); |
173 | 174 | } |
174 | - this.deviceProfileService.saveDeviceProfile(deviceProfile).subscribe( | |
175 | + this.deviceProfileService.saveDeviceProfile(deepTrim(deviceProfile)).subscribe( | |
175 | 176 | (savedDeviceProfile) => { |
176 | 177 | this.dialogRef.close(savedDeviceProfile); |
177 | 178 | } | ... | ... |
ui-ngx/src/app/modules/home/components/profile/device-profile-data.component.html
deleted
100644 → 0
... | ... | @@ -142,7 +142,7 @@ export class DeviceProfileComponent extends EntityComponent<DeviceProfile> { |
142 | 142 | if (formValue.defaultRuleChainId) { |
143 | 143 | formValue.defaultRuleChainId = new RuleChainId(formValue.defaultRuleChainId); |
144 | 144 | } |
145 | - return formValue; | |
145 | + return super.prepareFormValue(formValue); | |
146 | 146 | } |
147 | 147 | |
148 | 148 | onDeviceProfileIdCopied(event) { | ... | ... |
... | ... | @@ -76,7 +76,7 @@ export const deviceTransportTypeHintMap = new Map<DeviceTransportType, string>( |
76 | 76 | [ |
77 | 77 | [DeviceTransportType.DEFAULT, 'device-profile.transport-type-default-hint'], |
78 | 78 | [DeviceTransportType.MQTT, 'device-profile.transport-type-mqtt-hint'], |
79 | - [DeviceTransportType.LWM2M, 'device-profile.transport-type-lwm2m-hint'] | |
79 | + // [DeviceTransportType.LWM2M, 'device-profile.transport-type-lwm2m-hint'] | |
80 | 80 | ] |
81 | 81 | ); |
82 | 82 | ... | ... |