Browse Source

fix(iot-hub): lead the update of a device package to the upgrade on lts-4.3

This version can only reinstall a device package. Update opens the same kind of window as an item that needs ThingsBoard 4.4 (#16231): it says so, leads to the Community Grant Program, and keeps "Update anyway" to reinstall through the install wizard.
pull/16554/head
dpinkevych 4 weeks ago
parent
commit
aa18fd9214
Failed to extract signature
  1. 20
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-actions.service.ts
  2. 3
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-components.module.ts
  3. 29
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-device-update-dialog.component.html
  4. 47
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-device-update-dialog.component.ts
  5. 8
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-update-dialog.component.html
  6. 21
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-update-dialog.component.ts

20
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-actions.service.ts

@ -14,6 +14,10 @@ import { TbIotHubAddItemDialogComponent, IotHubAddItemDialogData, IotHubAddItemD
import { TbIotHubItemDetailDialogComponent, IotHubItemDetailDialogData, IotHubItemDetailDialogMode } from './iot-hub-item-detail-dialog.component';
import { TbIotHubInstallDialogComponent, IotHubInstallDialogData } from './iot-hub-install-dialog.component';
import { TbIotHubUpdateDialogComponent, IotHubUpdateDialogData } from './iot-hub-update-dialog.component';
import {
IotHubDeviceUpdateDialogData,
TbIotHubDeviceUpdateDialogComponent
} from './iot-hub-device-update-dialog.component';
import { TbIotHubDeleteDialogComponent, IotHubDeleteDialogData } from './iot-hub-delete-dialog.component';
import { TbDeviceInstallDialogComponent, DeviceInstallDialogData } from './device-install-dialog/device-install-dialog.component';
import { TbIotHubInstalledItemsDialogComponent, IotHubInstalledItemsDialogData } from './iot-hub-installed-items-dialog.component';
@ -154,6 +158,18 @@ export class IotHubActionsService {
if (!installedItem) {
return of(false);
}
if (installedItem.itemType === ItemType.DEVICE) {
// This version can only reinstall a device package: the dialog leads to the upgrade first.
return this.dialog.open<TbIotHubDeviceUpdateDialogComponent, IotHubDeviceUpdateDialogData, string | boolean>(
TbIotHubDeviceUpdateDialogComponent, {
panelClass: ['tb-dialog'],
disableClose: true,
autoFocus: false,
data: { itemName: installedItem.itemName }
}).afterClosed().pipe(
switchMap(result => result === 'reinstall' ? this.reinstallDevice(installedItem, versionId) : of(result))
);
}
return this.dialog.open<TbIotHubUpdateDialogComponent, IotHubUpdateDialogData, string | boolean>(TbIotHubUpdateDialogComponent, {
panelClass: ['tb-dialog'],
disableClose: true,
@ -165,9 +181,7 @@ export class IotHubActionsService {
version,
versionId
}
}).afterClosed().pipe(
switchMap(result => result === 'reinstall' ? this.reinstallDevice(installedItem, versionId) : of(result))
);
}).afterClosed();
}
/**

3
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-components.module.ts

@ -20,6 +20,7 @@ import { TbIotHubInstalledItemsDialogComponent } from './iot-hub-installed-items
import { TbIotHubSelectCfEntityDialogComponent } from './iot-hub-select-cf-entity-dialog.component';
import { TbPeConnectivityMethodPromptComponent } from './pe-connectivity-method-prompt.component';
import { TbIotHubPeRequiredDialogComponent } from './iot-hub-pe-required-dialog.component';
import { TbIotHubDeviceUpdateDialogComponent } from './iot-hub-device-update-dialog.component';
import { TbIotHubUpgradeRequiredDialogComponent } from './iot-hub-upgrade-required-dialog.component';
import { TbIotHubMarkdownComponent } from './iot-hub-markdown.component';
import { SolutionInstallDialogComponent } from './solution-install-dialog.component';
@ -47,6 +48,7 @@ import { IotHubItemLinkModule } from './iot-hub-item-link-card/iot-hub-item-link
SolutionInstallDialogComponent,
InstallFormRendererComponent,
TbIotHubPeRequiredDialogComponent,
TbIotHubDeviceUpdateDialogComponent,
TbIotHubUpgradeRequiredDialogComponent
],
imports: [
@ -76,6 +78,7 @@ import { IotHubItemLinkModule } from './iot-hub-item-link-card/iot-hub-item-link
TbIotHubMarkdownComponent,
SolutionInstallDialogComponent,
TbIotHubPeRequiredDialogComponent,
TbIotHubDeviceUpdateDialogComponent,
TbIotHubUpgradeRequiredDialogComponent
]
})

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

@ -0,0 +1,29 @@
<!--
SPDX-FileCopyrightText: Copyright The Thingsboard Authors
SPDX-License-Identifier: Apache-2.0
-->
<div class="tb-iot-hub-pe-required">
<button mat-icon-button class="tb-iot-hub-pe-required-close" (click)="close()" tabindex="-1">
<mat-icon>close</mat-icon>
</button>
<span class="tb-iot-hub-pe-required-icon" aria-hidden="true"></span>
<h2 class="tb-iot-hub-pe-required-title">
{{ 'iot-hub.update-confirm-title' | translate:{ name: data.itemName } }}
</h2>
<p class="tb-iot-hub-pe-required-message"
[innerHTML]="'iot-hub.update-desc-device' | translate"></p>
<div class="tb-iot-hub-pe-required-actions">
<button mat-stroked-button color="warn" (click)="reinstall()">
{{ 'iot-hub.update-anyway' | translate }}
</button>
<button mat-flat-button color="primary" (click)="viewUpgradeOptions()">
{{ 'iot-hub.view-upgrade-options' | translate }}
</button>
</div>
</div>

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

@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: Copyright The Thingsboard Authors
// SPDX-License-Identifier: Apache-2.0
import { Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { DialogComponent } from '@shared/components/dialog.component';
export interface IotHubDeviceUpdateDialogData {
itemName: string;
}
/**
* Update of a device package. This version can only reinstall it, so the dialog leads to the upgrade that updates device
* packages without reinstalling, as the dialog of an item that needs a newer version does, and keeps the reinstall as
* the other way. Closes with 'reinstall' when the user chooses it.
*/
@Component({
selector: 'tb-iot-hub-device-update-dialog',
standalone: false,
templateUrl: './iot-hub-device-update-dialog.component.html',
styleUrls: ['./iot-hub-pe-required-dialog.component.scss']
})
export class TbIotHubDeviceUpdateDialogComponent extends DialogComponent<TbIotHubDeviceUpdateDialogComponent, string | boolean> {
constructor(
protected store: Store<AppState>,
protected router: Router,
protected dialogRef: MatDialogRef<TbIotHubDeviceUpdateDialogComponent, string | boolean>,
@Inject(MAT_DIALOG_DATA) public data: IotHubDeviceUpdateDialogData
) {
super(store, router, dialogRef);
}
close(): void {
this.dialogRef.close(false);
}
reinstall(): void {
this.dialogRef.close('reinstall');
}
viewUpgradeOptions(): void {
window.open('https://thingsboard.io/community-grant-program/', '_blank');
}
}

8
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-update-dialog.component.html

@ -8,11 +8,11 @@
@switch (state) {
@case ('confirm') {
<h2 class="tb-iot-hub-install-title">{{ 'iot-hub.update-confirm-title' | translate:{ name: data.itemName } }}</h2>
<p class="tb-iot-hub-install-desc" [innerHTML]="updateDescKey | translate"></p>
<p class="tb-iot-hub-install-desc">{{ updateDescKey | translate }}</p>
}
@case ('updating') {
<h2 class="tb-iot-hub-install-title">{{ 'iot-hub.update-confirm-title' | translate:{ name: data.itemName } }}</h2>
<p class="tb-iot-hub-install-desc" [innerHTML]="updateDescKey | translate"></p>
<p class="tb-iot-hub-install-desc">{{ updateDescKey | translate }}</p>
}
@case ('success') {
<h2 class="tb-iot-hub-install-title">{{ 'iot-hub.update-success-title' | translate }}</h2>
@ -35,9 +35,7 @@
@switch (state) {
@case ('confirm') {
<button mat-button (click)="cancel()">{{ 'action.cancel' | translate }}</button>
<button mat-flat-button [color]="reinstalls ? 'warn' : 'primary'" (click)="update()">
{{ (reinstalls ? 'iot-hub.update-anyway' : 'iot-hub.update') | translate }}
</button>
<button mat-flat-button color="primary" (click)="update()">{{ 'iot-hub.update' | translate }}</button>
}
@case ('updating') {
<button mat-button disabled>{{ 'action.cancel' | translate }}</button>

21
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-update-dialog.component.ts

@ -59,33 +59,18 @@ export class TbIotHubUpdateDialogComponent extends DialogComponent<TbIotHubUpdat
return key ? this.translate.instant(key) : '';
}
/** A device package is reinstalled: its entities and their data are removed, as on Remove. */
get reinstalls(): boolean {
return this.data?.itemType === ItemType.DEVICE;
}
/**
* Updating a solution template is a delete + reinstall of every entity it created, and unlike the other item
* types it is not stopped by the modified-entity check, so the tenant's own edits to those dashboards, devices
* and rule chains are lost. Say that instead of the generic "replace the current version" wording.
*/
get updateDescKey(): string {
switch (this.data?.itemType) {
case ItemType.SOLUTION_TEMPLATE:
return 'iot-hub.update-desc-solution-template';
case ItemType.DEVICE:
return 'iot-hub.update-desc-device';
default:
return 'iot-hub.update-desc';
}
return this.data?.itemType === ItemType.SOLUTION_TEMPLATE
? 'iot-hub.update-desc-solution-template'
: 'iot-hub.update-desc';
}
update(force = false): void {
if (this.data.itemType === ItemType.DEVICE) {
// The install wizard of the new version does the update: it needs the user's input.
this.dialogRef.close('reinstall');
return;
}
this.state = 'updating';
this.iotHubApiService.updateItemVersion(this.data.installedItemId, this.data.versionId, { ignoreLoading: true }, force).subscribe({
next: (result) => {

Loading…
Cancel
Save