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 6 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 List<EntityId> createdEntityIds;
private DashboardId dashboardId; private DashboardId dashboardId;
private String selectedConnectivity; private String selectedInstallMethod;
private Map<String, JsonNode> installState; 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"} {"entityType": "DASHBOARD", "id": "8bc229f0-2e5d-11f1-a802-c35a9af2ebde"}
], ],
"dashboardId": {"entityType": "DASHBOARD", "id": "8bc229f0-2e5d-11f1-a802-c35a9af2ebde"}, "dashboardId": {"entityType": "DASHBOARD", "id": "8bc229f0-2e5d-11f1-a802-c35a9af2ebde"},
"selectedConnectivity": "DIRECT_MQTT", "selectedInstallMethod": "DIRECT_MQTT",
"installState": { "installState": {
"Configuration": { "Configuration": {
"formValues": {"deviceName": "ESP32 Dev Kit", "wifiSsid": "MyWiFi", "wifiPassword": "secret"} "formValues": {"deviceName": "ESP32 Dev Kit", "wifiSsid": "MyWiFi", "wifiPassword": "secret"}
@ -103,7 +103,7 @@ class DeviceInstalledItemDescriptorTest {
DeviceInstalledItemDescriptor descriptor = mapper.treeToValue(node, DeviceInstalledItemDescriptor.class); DeviceInstalledItemDescriptor descriptor = mapper.treeToValue(node, DeviceInstalledItemDescriptor.class);
assertThat(descriptor).isNotNull(); assertThat(descriptor).isNotNull();
assertThat(descriptor.getSelectedConnectivity()).isEqualTo("DIRECT_MQTT"); assertThat(descriptor.getSelectedInstallMethod()).isEqualTo("DIRECT_MQTT");
assertThat(descriptor.getInstallState()).isNotNull(); assertThat(descriptor.getInstallState()).isNotNull();
assertThat(descriptor.getInstallState()).hasSize(3); assertThat(descriptor.getInstallState()).hasSize(3);
@ -122,7 +122,7 @@ class DeviceInstalledItemDescriptorTest {
String serialized = mapper.writeValueAsString(descriptor); String serialized = mapper.writeValueAsString(descriptor);
JsonNode roundTripped = mapper.readTree(serialized); JsonNode roundTripped = mapper.readTree(serialized);
DeviceInstalledItemDescriptor deserialized = mapper.treeToValue(roundTripped, DeviceInstalledItemDescriptor.class); 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()).hasSize(3);
assertThat(deserialized.getInstallState().get("Configuration").get("formValues").get("deviceName").asText()).isEqualTo("ESP32 Dev Kit"); 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( public registerDeviceInstall(
versionId: string, 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 config?: IotHubRequestConfig
): Observable<InstallItemVersionResult> { ): Observable<InstallItemVersionResult> {
return this.http.post<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 { } @else {
<div class="tb-device-install-header"> <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> <h2 class="tb-device-install-title">{{ 'iot-hub.device-install-title' | translate:{ name: packageInfo?.name || data.item.name } }}</h2>
@if (selectedConnectivity && wizardStarted) { @if (selectedInstallMethod && wizardStarted) {
<span class="tb-device-install-badge">{{ connectivityLabels.get(selectedConnectivity) }}</span> <span class="tb-device-install-badge">{{ installMethodLabels.get(selectedInstallMethod) }}</span>
} }
<button mat-icon-button (click)="cancel()" tabindex="-1"> <button mat-icon-button (click)="cancel()" tabindex="-1">
<mat-icon>close</mat-icon> <mat-icon>close</mat-icon>
@ -193,12 +193,12 @@
<div class="tb-device-install-connectivity"> <div class="tb-device-install-connectivity">
<p>{{ 'iot-hub.device-install-select-connectivity' | translate }}</p> <p>{{ 'iot-hub.device-install-select-connectivity' | translate }}</p>
<div class="tb-connectivity-options"> <div class="tb-connectivity-options">
@for (ct of availableConnectivityTypes; track ct) { @for (ct of availableInstallMethods; track ct) {
<button mat-stroked-button <button mat-stroked-button
class="tb-connectivity-button" class="tb-connectivity-button"
[class.selected]="selectedConnectivity === ct" [class.selected]="selectedInstallMethod === ct"
(click)="selectConnectivity(ct)"> (click)="selectConnectivity(ct)">
{{ connectivityLabels.get(ct) || ct }} {{ installMethodLabels.get(ct) || ct }}
</button> </button>
} }
</div> </div>
@ -207,7 +207,7 @@
<mat-dialog-actions align="end"> <mat-dialog-actions align="end">
<button mat-button (click)="cancel()">{{ 'action.cancel' | translate }}</button> <button mat-button (click)="cancel()">{{ 'action.cancel' | translate }}</button>
<button mat-flat-button color="primary" <button mat-flat-button color="primary"
[disabled]="!selectedConnectivity" [disabled]="!selectedInstallMethod"
(click)="confirmConnectivity()"> (click)="confirmConnectivity()">
{{ 'action.next' | translate }} {{ 'action.next' | translate }}
</button> </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 { AttributeScope } from '@shared/models/telemetry/telemetry.models';
import { EntityId } from '@shared/models/id/entity-id'; import { EntityId } from '@shared/models/id/entity-id';
import { import {
connectivityTypeTranslations, installMethodLabels as INSTALL_METHOD_LABELS,
DeviceInstallStep, DeviceInstallStep,
DevicePackageInfo, DevicePackageInfo,
ENTITY_STEP_TYPES, ENTITY_STEP_TYPES,
@ -50,7 +50,7 @@ export interface DeviceInstallDialogData {
item: MpItemVersionView; item: MpItemVersionView;
zipData: ArrayBuffer; zipData: ArrayBuffer;
reviewMode?: boolean; reviewMode?: boolean;
selectedConnectivity?: string; selectedInstallMethod?: string;
installState?: Record<string, any>; installState?: Record<string, any>;
} }
@ -91,9 +91,9 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
// Connectivity // Connectivity
showConnectivitySelector = false; showConnectivitySelector = false;
availableConnectivityTypes: string[] = []; availableInstallMethods: string[] = [];
selectedConnectivity: string | null = null; selectedInstallMethod: string | null = null;
connectivityLabels = connectivityTypeTranslations; installMethodLabels = INSTALL_METHOD_LABELS;
// Wizard // Wizard
wizardSteps: WizardStep[] = []; wizardSteps: WizardStep[] = [];
@ -142,7 +142,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
} }
} }
this.packageInfo = JSON.parse(this.zipFiles.get('device-info.json')); 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 ct => this.packageInfo.installSteps[ct]?.length > 0
); );
} catch (e) { } catch (e) {
@ -163,14 +163,14 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
console.error('Failed to fetch connectivity settings', _e); console.error('Failed to fetch connectivity settings', _e);
} }
// Review mode: restore state and start wizard with stored values // 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.reviewMode = true;
this.selectedConnectivity = this.data.selectedConnectivity; this.selectedInstallMethod = this.data.selectedInstallMethod;
this.showConnectivitySelector = false; this.showConnectivitySelector = false;
this.restoreInstallState(this.data.installState); this.restoreInstallState(this.data.installState);
this.startWizard(); this.startWizard();
} else if (this.availableConnectivityTypes.length === 1) { } else if (this.availableInstallMethods.length === 1) {
this.selectedConnectivity = this.availableConnectivityTypes[0]; this.selectedInstallMethod = this.availableInstallMethods[0];
this.showConnectivitySelector = false; this.showConnectivitySelector = false;
this.startWizard(); this.startWizard();
} else { } else {
@ -183,7 +183,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
// --- Connectivity --- // --- Connectivity ---
selectConnectivity(ct: string): void { selectConnectivity(ct: string): void {
this.selectedConnectivity = ct; this.selectedInstallMethod = ct;
} }
onStepChanged(): void { onStepChanged(): void {
@ -202,7 +202,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
} }
confirmConnectivity(): void { confirmConnectivity(): void {
if (!this.selectedConnectivity) { if (!this.selectedInstallMethod) {
return; return;
} }
this.startWizard(); this.startWizard();
@ -459,7 +459,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
} }
if (data.entityOutput) { if (data.entityOutput) {
// Find the step type alias from the raw steps to set the correct entity output key // 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); const matchingStep = rawSteps.find(s => s.name === stepName || this.resolveVariables(s.name) === stepName);
if (matchingStep) { if (matchingStep) {
const alias = stepTypeAliasMap[matchingStep.type]; const alias = stepTypeAliasMap[matchingStep.type];
@ -470,7 +470,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
} }
} }
// Resolve gateway docker-compose if available // 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) { if (gatewayStep?.dockerCompose) {
const raw = this.zipFiles.get(gatewayStep.dockerCompose); const raw = this.zipFiles.get(gatewayStep.dockerCompose);
if (raw) { if (raw) {
@ -505,7 +505,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
} }
private buildWizardSteps(): void { private buildWizardSteps(): void {
const rawSteps = this.packageInfo.installSteps[this.selectedConnectivity] || []; const rawSteps = this.packageInfo.installSteps[this.selectedInstallMethod] || [];
this.wizardSteps = []; this.wizardSteps = [];
let i = 0; let i = 0;
while (i < rawSteps.length) { while (i < rawSteps.length) {
@ -684,7 +684,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
await firstValueFrom( await firstValueFrom(
this.iotHubApiService.registerDeviceInstall( this.iotHubApiService.registerDeviceInstall(
this.data.item.id as string, this.data.item.id as string,
{ createdEntityIds, dashboardId, selectedConnectivity: this.selectedConnectivity, installState: this.buildInstallState() }, { createdEntityIds, dashboardId, selectedInstallMethod: this.selectedInstallMethod, installState: this.buildInstallState() },
{ ignoreLoading: true } { 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 { private openDeviceReviewDialog(item: IotHubInstalledItem): void {
const descriptor = item.descriptor as DeviceInstalledItemDescriptor; 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 // No install state — fall back to regular detail dialog
this.iotHubApiService.getVersionInfo(item.itemVersionId, {ignoreLoading: true}).subscribe(versionView => { this.iotHubApiService.getVersionInfo(item.itemVersionId, {ignoreLoading: true}).subscribe(versionView => {
this.dialog.open(TbIotHubItemDetailDialogComponent, { this.dialog.open(TbIotHubItemDetailDialogComponent, {
@ -265,10 +265,10 @@ export class TbIotHubInstalledItemsComponent implements OnInit, AfterViewInit, O
}); });
return; return;
} }
this.iotHubApiService.getVersionFileData(item.itemVersionId, { ignoreLoading: true }).subscribe({ this.iotHubApiService.getVersionFileData(item.itemVersionId, { ignoreLoading: true, ignoreErrors: true }).subscribe({
next: async (blob: Blob) => { next: async (blob: Blob) => {
const zipData = await blob.arrayBuffer(); 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, { this.dialog.open(TbDeviceInstallDialogComponent, {
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
disableClose: false, disableClose: false,
@ -277,7 +277,7 @@ export class TbIotHubInstalledItemsComponent implements OnInit, AfterViewInit, O
item: versionView, item: versionView,
zipData, zipData,
reviewMode: true, reviewMode: true,
selectedConnectivity: descriptor.selectedConnectivity, selectedInstallMethod: descriptor.selectedInstallMethod,
installState: descriptor.installState installState: descriptor.installState
} as DeviceInstallDialogData } as DeviceInstallDialogData
}); });

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

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

Loading…
Cancel
Save