diff --git a/ui-ngx/src/app/modules/home/components/profile/device-profile-autocomplete.component.ts b/ui-ngx/src/app/modules/home/components/profile/device-profile-autocomplete.component.ts index 1a155391de..d7ed08ae9c 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device-profile-autocomplete.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/device-profile-autocomplete.component.ts @@ -64,6 +64,9 @@ export class DeviceProfileAutocompleteComponent implements ControlValueAccessor, @Input() selectDefaultProfile = false; + @Input() + selectFirstProfile = false; + @Input() displayAllOnEmpty = false; @@ -183,12 +186,34 @@ export class DeviceProfileAutocompleteComponent implements ControlValueAccessor, if (this.selectDefaultProfile && !this.modelValue) { this.deviceProfileService.getDefaultDeviceProfileInfo().subscribe( (profile) => { - if (profile && !this.transportType || (profile.transportType === this.transportType)) { + if (profile && (!this.transportType || (profile.transportType === this.transportType))) { this.selectDeviceProfileFormGroup.get('deviceProfile').patchValue(profile, {emitEvent: false}); this.updateView(profile); + } else { + this.selectFirstDeviceProfileIfNeeded(); } } ); + } else { + this.selectFirstDeviceProfileIfNeeded(); + } + } + + selectFirstDeviceProfileIfNeeded(): void { + if (this.selectFirstProfile && !this.modelValue) { + const pageLink = new PageLink(1, 0, null, { + property: 'createdTime', + direction: Direction.DESC + }); + this.deviceProfileService.getDeviceProfileInfos(pageLink, this.transportType, {ignoreLoading: true}).subscribe( + (pageData => { + const data = pageData.data; + if (data.length) { + this.selectDeviceProfileFormGroup.get('deviceProfile').patchValue(data[0], {emitEvent: false}); + this.updateView(data[0]); + } + }) + ); } } diff --git a/ui-ngx/src/app/modules/home/components/wizard/device-wizard-dialog.component.html b/ui-ngx/src/app/modules/home/components/wizard/device-wizard-dialog.component.html index 6cf1e687e3..1e59f0c9e1 100644 --- a/ui-ngx/src/app/modules/home/components/wizard/device-wizard-dialog.component.html +++ b/ui-ngx/src/app/modules/home/components/wizard/device-wizard-dialog.component.html @@ -79,6 +79,7 @@ (deviceProfileChanged)="$event?.transportType ? deviceWizardFormGroup.get('transportType').patchValue($event?.transportType) : {}" [addNewProfile]="false" [selectDefaultProfile]="true" + [selectFirstProfile]="true" [editProfileEnabled]="false"> diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 08aa57b61a..1cefe69874 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -794,9 +794,9 @@ "transport-type": "Transport type", "transport-type-required": "Transport type is required.", "transport-type-default": "Default", - "transport-type-default-hint": "Default transport type", + "transport-type-default-hint": "Refers to already existing transport configuration or basic MQTT, HTTP, CoAP settings", "transport-type-mqtt": "MQTT", - "transport-type-mqtt-hint": "MQTT transport type", + "transport-type-mqtt-hint": "Advanced MQTT topic filters and Device profile settings", "transport-type-lwm2m": "LWM2M", "transport-type-lwm2m-hint": "LWM2M transport type", "description": "Description",