Browse Source

refactor(iot-hub): rename connectivityTypes to installMethods

Sync with IoT Hub field rename:
- Enum: ConnectivityType → InstallMethod
- Map: connectivityTypeTranslations → installMethodLabels
- Model: DevicePackageInfo.connectivityTypes → installMethods
- Descriptor: selectedConnectivity → selectedInstallMethod
- All component/template/service references updated
- Java descriptor and test updated
pull/15508/head
Andrii Shvaika 4 months ago
parent
commit
2f579273b5
  1. 2
      common/data/src/main/java/org/thingsboard/server/common/data/iot_hub/DeviceInstalledItemDescriptor.java
  2. 6
      common/data/src/test/java/org/thingsboard/server/common/data/iot_hub/DeviceInstalledItemDescriptorTest.java
  3. 2
      ui-ngx/src/app/core/http/iot-hub-api.service.ts
  4. 12
      ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.html
  5. 32
      ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts
  6. 8
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-installed-items.component.ts
  7. 30
      ui-ngx/src/app/shared/models/iot-hub/device-package.models.ts
  8. 2
      ui-ngx/src/app/shared/models/iot-hub/iot-hub-installed-item.models.ts

2
common/data/src/main/java/org/thingsboard/server/common/data/iot_hub/DeviceInstalledItemDescriptor.java

@ -28,7 +28,7 @@ public class DeviceInstalledItemDescriptor implements IotHubInstalledItemDescrip
private List<EntityId> createdEntityIds;
private DashboardId dashboardId;
private String selectedConnectivity;
private String selectedInstallMethod;
private Map<String, JsonNode> installState;
}

6
common/data/src/test/java/org/thingsboard/server/common/data/iot_hub/DeviceInstalledItemDescriptorTest.java

@ -84,7 +84,7 @@ class DeviceInstalledItemDescriptorTest {
{"entityType": "DASHBOARD", "id": "8bc229f0-2e5d-11f1-a802-c35a9af2ebde"}
],
"dashboardId": {"entityType": "DASHBOARD", "id": "8bc229f0-2e5d-11f1-a802-c35a9af2ebde"},
"selectedConnectivity": "DIRECT_MQTT",
"selectedInstallMethod": "DIRECT_MQTT",
"installState": {
"Configuration": {
"formValues": {"deviceName": "ESP32 Dev Kit", "wifiSsid": "MyWiFi", "wifiPassword": "secret"}
@ -103,7 +103,7 @@ class DeviceInstalledItemDescriptorTest {
DeviceInstalledItemDescriptor descriptor = mapper.treeToValue(node, DeviceInstalledItemDescriptor.class);
assertThat(descriptor).isNotNull();
assertThat(descriptor.getSelectedConnectivity()).isEqualTo("DIRECT_MQTT");
assertThat(descriptor.getSelectedInstallMethod()).isEqualTo("DIRECT_MQTT");
assertThat(descriptor.getInstallState()).isNotNull();
assertThat(descriptor.getInstallState()).hasSize(3);
@ -122,7 +122,7 @@ class DeviceInstalledItemDescriptorTest {
String serialized = mapper.writeValueAsString(descriptor);
JsonNode roundTripped = mapper.readTree(serialized);
DeviceInstalledItemDescriptor deserialized = mapper.treeToValue(roundTripped, DeviceInstalledItemDescriptor.class);
assertThat(deserialized.getSelectedConnectivity()).isEqualTo("DIRECT_MQTT");
assertThat(deserialized.getSelectedInstallMethod()).isEqualTo("DIRECT_MQTT");
assertThat(deserialized.getInstallState()).hasSize(3);
assertThat(deserialized.getInstallState().get("Configuration").get("formValues").get("deviceName").asText()).isEqualTo("ESP32 Dev Kit");
}

2
ui-ngx/src/app/core/http/iot-hub-api.service.ts

@ -122,7 +122,7 @@ export class IotHubApiService {
public registerDeviceInstall(
versionId: string,
descriptor: { type?: string; createdEntityIds: { entityType: string; id: string }[]; dashboardId?: { entityType: string; id: string }; selectedConnectivity?: string; installState?: Record<string, any> },
descriptor: { type?: string; createdEntityIds: { entityType: string; id: string }[]; dashboardId?: { entityType: string; id: string }; selectedInstallMethod?: string; installState?: Record<string, any> },
config?: IotHubRequestConfig
): Observable<InstallItemVersionResult> {
return this.http.post<InstallItemVersionResult>(

12
ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.html

@ -178,8 +178,8 @@
} @else {
<div class="tb-device-install-header">
<h2 class="tb-device-install-title">{{ 'iot-hub.device-install-title' | translate:{ name: packageInfo?.name || data.item.name } }}</h2>
@if (selectedConnectivity && wizardStarted) {
<span class="tb-device-install-badge">{{ connectivityLabels.get(selectedConnectivity) }}</span>
@if (selectedInstallMethod && wizardStarted) {
<span class="tb-device-install-badge">{{ installMethodLabels.get(selectedInstallMethod) }}</span>
}
<button mat-icon-button (click)="cancel()" tabindex="-1">
<mat-icon>close</mat-icon>
@ -193,12 +193,12 @@
<div class="tb-device-install-connectivity">
<p>{{ 'iot-hub.device-install-select-connectivity' | translate }}</p>
<div class="tb-connectivity-options">
@for (ct of availableConnectivityTypes; track ct) {
@for (ct of availableInstallMethods; track ct) {
<button mat-stroked-button
class="tb-connectivity-button"
[class.selected]="selectedConnectivity === ct"
[class.selected]="selectedInstallMethod === ct"
(click)="selectConnectivity(ct)">
{{ connectivityLabels.get(ct) || ct }}
{{ installMethodLabels.get(ct) || ct }}
</button>
}
</div>
@ -207,7 +207,7 @@
<mat-dialog-actions align="end">
<button mat-button (click)="cancel()">{{ 'action.cancel' | translate }}</button>
<button mat-flat-button color="primary"
[disabled]="!selectedConnectivity"
[disabled]="!selectedInstallMethod"
(click)="confirmConnectivity()">
{{ 'action.next' | translate }}
</button>

32
ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts

@ -34,7 +34,7 @@ import { AttributeService } from '@core/http/attribute.service';
import { AttributeScope } from '@shared/models/telemetry/telemetry.models';
import { EntityId } from '@shared/models/id/entity-id';
import {
connectivityTypeTranslations,
installMethodLabels as INSTALL_METHOD_LABELS,
DeviceInstallStep,
DevicePackageInfo,
ENTITY_STEP_TYPES,
@ -50,7 +50,7 @@ export interface DeviceInstallDialogData {
item: MpItemVersionView;
zipData: ArrayBuffer;
reviewMode?: boolean;
selectedConnectivity?: string;
selectedInstallMethod?: string;
installState?: Record<string, any>;
}
@ -91,9 +91,9 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
// Connectivity
showConnectivitySelector = false;
availableConnectivityTypes: string[] = [];
selectedConnectivity: string | null = null;
connectivityLabels = connectivityTypeTranslations;
availableInstallMethods: string[] = [];
selectedInstallMethod: string | null = null;
installMethodLabels = INSTALL_METHOD_LABELS;
// Wizard
wizardSteps: WizardStep[] = [];
@ -142,7 +142,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
}
}
this.packageInfo = JSON.parse(this.zipFiles.get('device-info.json'));
this.availableConnectivityTypes = this.packageInfo.connectivityTypes.filter(
this.availableInstallMethods = this.packageInfo.installMethods.filter(
ct => this.packageInfo.installSteps[ct]?.length > 0
);
} catch (e) {
@ -163,14 +163,14 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
console.error('Failed to fetch connectivity settings', _e);
}
// Review mode: restore state and start wizard with stored values
if (this.data.reviewMode && this.data.installState && this.data.selectedConnectivity) {
if (this.data.reviewMode && this.data.installState && this.data.selectedInstallMethod) {
this.reviewMode = true;
this.selectedConnectivity = this.data.selectedConnectivity;
this.selectedInstallMethod = this.data.selectedInstallMethod;
this.showConnectivitySelector = false;
this.restoreInstallState(this.data.installState);
this.startWizard();
} else if (this.availableConnectivityTypes.length === 1) {
this.selectedConnectivity = this.availableConnectivityTypes[0];
} else if (this.availableInstallMethods.length === 1) {
this.selectedInstallMethod = this.availableInstallMethods[0];
this.showConnectivitySelector = false;
this.startWizard();
} else {
@ -183,7 +183,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
// --- Connectivity ---
selectConnectivity(ct: string): void {
this.selectedConnectivity = ct;
this.selectedInstallMethod = ct;
}
onStepChanged(): void {
@ -202,7 +202,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
}
confirmConnectivity(): void {
if (!this.selectedConnectivity) {
if (!this.selectedInstallMethod) {
return;
}
this.startWizard();
@ -459,7 +459,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
}
if (data.entityOutput) {
// Find the step type alias from the raw steps to set the correct entity output key
const rawSteps = this.packageInfo.installSteps[this.selectedConnectivity] || [];
const rawSteps = this.packageInfo.installSteps[this.selectedInstallMethod] || [];
const matchingStep = rawSteps.find(s => s.name === stepName || this.resolveVariables(s.name) === stepName);
if (matchingStep) {
const alias = stepTypeAliasMap[matchingStep.type];
@ -470,7 +470,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
}
}
// Resolve gateway docker-compose if available
const gatewayStep = (this.packageInfo.installSteps[this.selectedConnectivity] || []).find(s => s.type === 'GATEWAY');
const gatewayStep = (this.packageInfo.installSteps[this.selectedInstallMethod] || []).find(s => s.type === 'GATEWAY');
if (gatewayStep?.dockerCompose) {
const raw = this.zipFiles.get(gatewayStep.dockerCompose);
if (raw) {
@ -505,7 +505,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
}
private buildWizardSteps(): void {
const rawSteps = this.packageInfo.installSteps[this.selectedConnectivity] || [];
const rawSteps = this.packageInfo.installSteps[this.selectedInstallMethod] || [];
this.wizardSteps = [];
let i = 0;
while (i < rawSteps.length) {
@ -684,7 +684,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
await firstValueFrom(
this.iotHubApiService.registerDeviceInstall(
this.data.item.id as string,
{ createdEntityIds, dashboardId, selectedConnectivity: this.selectedConnectivity, installState: this.buildInstallState() },
{ createdEntityIds, dashboardId, selectedInstallMethod: this.selectedInstallMethod, installState: this.buildInstallState() },
{ ignoreLoading: true }
)
);

8
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-installed-items.component.ts

@ -254,7 +254,7 @@ export class TbIotHubInstalledItemsComponent implements OnInit, AfterViewInit, O
private openDeviceReviewDialog(item: IotHubInstalledItem): void {
const descriptor = item.descriptor as DeviceInstalledItemDescriptor;
if (!descriptor.installState || !descriptor.selectedConnectivity) {
if (!descriptor.installState || !descriptor.selectedInstallMethod) {
// No install state — fall back to regular detail dialog
this.iotHubApiService.getVersionInfo(item.itemVersionId, {ignoreLoading: true}).subscribe(versionView => {
this.dialog.open(TbIotHubItemDetailDialogComponent, {
@ -265,10 +265,10 @@ export class TbIotHubInstalledItemsComponent implements OnInit, AfterViewInit, O
});
return;
}
this.iotHubApiService.getVersionFileData(item.itemVersionId, { ignoreLoading: true }).subscribe({
this.iotHubApiService.getVersionFileData(item.itemVersionId, { ignoreLoading: true, ignoreErrors: true }).subscribe({
next: async (blob: Blob) => {
const zipData = await blob.arrayBuffer();
this.iotHubApiService.getVersionInfo(item.itemVersionId, {ignoreLoading: true}).subscribe(versionView => {
this.iotHubApiService.getVersionInfo(item.itemVersionId, {ignoreLoading: true, ignoreErrors: true}).subscribe(versionView => {
this.dialog.open(TbDeviceInstallDialogComponent, {
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
disableClose: false,
@ -277,7 +277,7 @@ export class TbIotHubInstalledItemsComponent implements OnInit, AfterViewInit, O
item: versionView,
zipData,
reviewMode: true,
selectedConnectivity: descriptor.selectedConnectivity,
selectedInstallMethod: descriptor.selectedInstallMethod,
installState: descriptor.installState
} as DeviceInstallDialogData
});

30
ui-ngx/src/app/shared/models/iot-hub/device-package.models.ts

@ -14,7 +14,7 @@
/// limitations under the License.
///
export enum ConnectivityType {
export enum InstallMethod {
DIRECT_HTTP = 'DIRECT_HTTP',
DIRECT_MQTT = 'DIRECT_MQTT',
DIRECT_COAP = 'DIRECT_COAP',
@ -29,20 +29,20 @@ export enum ConnectivityType {
INTEGRATION_LORIOT = 'INTEGRATION_LORIOT'
}
export const connectivityTypeTranslations = new Map<string, string>(
export const installMethodLabels = new Map<string, string>(
[
[ConnectivityType.DIRECT_HTTP, 'HTTP'],
[ConnectivityType.DIRECT_MQTT, 'MQTT'],
[ConnectivityType.DIRECT_COAP, 'CoAP'],
[ConnectivityType.DIRECT_LWM2M, 'LwM2M'],
[ConnectivityType.DIRECT_SNMP, 'SNMP'],
[ConnectivityType.GATEWAY_MQTT, 'MQTT Gateway'],
[ConnectivityType.GATEWAY_MODBUS, 'Modbus Gateway'],
[ConnectivityType.GATEWAY_OPCUA, 'OPC-UA Gateway'],
[ConnectivityType.CHIRPSTACK, 'ChirpStack'],
[ConnectivityType.INTEGRATION_CHIRPSTACK, 'ChirpStack (PE)'],
[ConnectivityType.INTEGRATION_TTN, 'The Things Stack'],
[ConnectivityType.INTEGRATION_LORIOT, 'LORIOT']
[InstallMethod.DIRECT_HTTP, 'HTTP'],
[InstallMethod.DIRECT_MQTT, 'MQTT'],
[InstallMethod.DIRECT_COAP, 'CoAP'],
[InstallMethod.DIRECT_LWM2M, 'LwM2M'],
[InstallMethod.DIRECT_SNMP, 'SNMP'],
[InstallMethod.GATEWAY_MQTT, 'MQTT Gateway'],
[InstallMethod.GATEWAY_MODBUS, 'Modbus Gateway'],
[InstallMethod.GATEWAY_OPCUA, 'OPC-UA Gateway'],
[InstallMethod.CHIRPSTACK, 'ChirpStack'],
[InstallMethod.INTEGRATION_CHIRPSTACK, 'ChirpStack (PE)'],
[InstallMethod.INTEGRATION_TTN, 'The Things Stack'],
[InstallMethod.INTEGRATION_LORIOT, 'LORIOT']
]
);
@ -93,7 +93,7 @@ export interface DevicePackageInfo {
description: string;
vendor: string;
hardwareType: string;
connectivityTypes: string[];
installMethods: string[];
installSteps: Record<string, DeviceInstallStep[]>;
}

2
ui-ngx/src/app/shared/models/iot-hub/iot-hub-installed-item.models.ts

@ -41,7 +41,7 @@ export interface DeviceInstalledItemDescriptor {
type: 'DEVICE';
createdEntityIds?: { entityType: string; id: string }[];
dashboardId?: { id: string };
selectedConnectivity?: string;
selectedInstallMethod?: string;
installState?: Record<string, any>;
}

Loading…
Cancel
Save