Browse Source
IoT Hub: a confirm dialog updates a device package's default converterpull/16545/head
committed by
GitHub
26 changed files with 439 additions and 85 deletions
@ -0,0 +1,33 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. |
||||
|
SPDX-License-Identifier: BUSL-1.1 |
||||
|
|
||||
|
--> |
||||
|
<div class="flex flex-col gap-4 p-6"> |
||||
|
<h2 class="tb-converter-update-title">{{ 'iot-hub.converter-update-title' | translate }}</h2> |
||||
|
<p class="tb-converter-update-text">{{ 'iot-hub.device-update-new-default-converter' | translate }}</p> |
||||
|
<div class="tb-converter-update-box flex flex-col gap-2"> |
||||
|
<div class="tb-converter-update-name">{{ data.update.converter.name }}</div> |
||||
|
@if (data.usedBy.length) { |
||||
|
<span class="tb-progress-alert-msg tb-progress-alert-msg-warning">{{ 'iot-hub.device-update-shared' | translate }}</span> |
||||
|
<ul class="tb-converter-update-packages"> |
||||
|
@for (name of data.usedBy; track $index) { |
||||
|
<li>{{ name }}</li> |
||||
|
} |
||||
|
</ul> |
||||
|
} |
||||
|
@if (data.modified) { |
||||
|
<span class="tb-progress-alert-msg tb-progress-alert-msg-warning"> |
||||
|
{{ modifiedHint.before }}<a class="tb-converter-update-link" href="#" (click)="$event.preventDefault(); downloadCurrent()">{{ modifiedHint.link }}</a>{{ modifiedHint.after }} |
||||
|
</span> |
||||
|
} |
||||
|
</div> |
||||
|
@if (errorMessage) { |
||||
|
<span class="tb-progress-alert-msg tb-progress-alert-msg-error">{{ errorMessage }}</span> |
||||
|
} |
||||
|
</div> |
||||
|
<div class="flex items-center justify-end gap-2 p-2"> |
||||
|
<button mat-button (click)="cancel()" [disabled]="updating">{{ 'action.cancel' | translate }}</button> |
||||
|
<button mat-flat-button color="primary" (click)="update()" [disabled]="updating">{{ 'iot-hub.update' | translate }}</button> |
||||
|
</div> |
||||
@ -0,0 +1,65 @@ |
|||||
|
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. |
||||
|
// SPDX-License-Identifier: BUSL-1.1 |
||||
|
:host { |
||||
|
display: block; |
||||
|
max-width: 600px; |
||||
|
} |
||||
|
|
||||
|
.tb-converter-update-title { |
||||
|
font-size: 20px; |
||||
|
font-weight: 600; |
||||
|
line-height: 24px; |
||||
|
letter-spacing: 0.1px; |
||||
|
color: rgba(0, 0, 0, 0.87); |
||||
|
margin: 0; |
||||
|
} |
||||
|
|
||||
|
.tb-converter-update-text { |
||||
|
font-size: 14px; |
||||
|
line-height: 20px; |
||||
|
letter-spacing: 0.2px; |
||||
|
color: rgba(0, 0, 0, 0.54); |
||||
|
margin: 0; |
||||
|
} |
||||
|
|
||||
|
.tb-converter-update-box { |
||||
|
padding: 12px 16px; |
||||
|
border: 1px solid rgba(0, 0, 0, 0.12); |
||||
|
border-radius: 8px; |
||||
|
} |
||||
|
|
||||
|
.tb-converter-update-name { |
||||
|
font-size: 14px; |
||||
|
font-weight: 500; |
||||
|
line-height: 20px; |
||||
|
color: rgba(0, 0, 0, 0.87); |
||||
|
} |
||||
|
|
||||
|
.tb-converter-update-packages { |
||||
|
margin: 0; |
||||
|
padding-left: 20px; |
||||
|
font-size: 12px; |
||||
|
line-height: 16px; |
||||
|
color: rgba(0, 0, 0, 0.54); |
||||
|
} |
||||
|
|
||||
|
.tb-converter-update-link { |
||||
|
color: #305680; |
||||
|
text-decoration: underline; |
||||
|
cursor: pointer; |
||||
|
} |
||||
|
|
||||
|
.tb-progress-alert-msg { |
||||
|
font-size: 12px; |
||||
|
font-weight: 400; |
||||
|
line-height: 16px; |
||||
|
letter-spacing: 0.4px; |
||||
|
|
||||
|
&.tb-progress-alert-msg-warning { |
||||
|
color: #f66716; |
||||
|
} |
||||
|
|
||||
|
&.tb-progress-alert-msg-error { |
||||
|
color: #dd2c00; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,79 @@ |
|||||
|
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
|
||||
|
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
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 { TranslateService } from '@ngx-translate/core'; |
||||
|
import { AppState } from '@core/core.state'; |
||||
|
import { DialogComponent } from '@shared/components/dialog.component'; |
||||
|
import { IotHubApiService } from '@core/http/iot-hub-api.service'; |
||||
|
import { DefaultConverterUpdate, defaultConverterUpdateRequest } from '@home/components/iot-hub/iot-hub-default-converter'; |
||||
|
import { downloadEntityJson, readableMessage, requestFailureMessage, splitTextWithLink } from '@home/components/iot-hub/iot-hub-utils'; |
||||
|
|
||||
|
export interface IotHubConverterUpdateDialogData { |
||||
|
update: DefaultConverterUpdate; |
||||
|
// The version of the converter the dialog downloads: the server refuses the update if someone saved the converter since
|
||||
|
version?: number; |
||||
|
// Someone changed the converter since a package installed or last updated it
|
||||
|
modified: boolean; |
||||
|
// The names of the other installed packages that use the converter
|
||||
|
usedBy: string[]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Brings an installed device package's default converter to ThingsBoard's default converter now, without a new version of |
||||
|
* the package. Closes with true once it is updated. |
||||
|
*/ |
||||
|
@Component({ |
||||
|
selector: 'tb-iot-hub-converter-update-dialog', |
||||
|
standalone: false, |
||||
|
templateUrl: './iot-hub-converter-update-dialog.component.html', |
||||
|
styleUrls: ['./iot-hub-converter-update-dialog.component.scss'] |
||||
|
}) |
||||
|
export class TbIotHubConverterUpdateDialogComponent extends DialogComponent<TbIotHubConverterUpdateDialogComponent, boolean> { |
||||
|
|
||||
|
readonly modifiedHint = splitTextWithLink(this.translate.instant('iot-hub.device-update-modified')); |
||||
|
updating = false; |
||||
|
errorMessage: string | null = null; |
||||
|
|
||||
|
constructor( |
||||
|
protected store: Store<AppState>, |
||||
|
protected router: Router, |
||||
|
protected dialogRef: MatDialogRef<TbIotHubConverterUpdateDialogComponent, boolean>, |
||||
|
@Inject(MAT_DIALOG_DATA) public data: IotHubConverterUpdateDialogData, |
||||
|
private iotHubApiService: IotHubApiService, |
||||
|
private translate: TranslateService |
||||
|
) { |
||||
|
super(store, router, dialogRef); |
||||
|
} |
||||
|
|
||||
|
downloadCurrent(): void { |
||||
|
downloadEntityJson(this.data.update.converter, this.data.update.converter.name); |
||||
|
} |
||||
|
|
||||
|
update(): void { |
||||
|
this.updating = true; |
||||
|
this.errorMessage = null; |
||||
|
this.iotHubApiService.updateDevicePackage(this.data.update.installedItem.id.id, |
||||
|
defaultConverterUpdateRequest(this.data.update, this.data.version), { ignoreErrors: true }).subscribe({ |
||||
|
next: result => { |
||||
|
if (result.success) { |
||||
|
this.dialogRef.close(true); |
||||
|
return; |
||||
|
} |
||||
|
// Nothing was changed: the server rolled it back
|
||||
|
this.updating = false; |
||||
|
this.errorMessage = readableMessage(result.errorMessage) ?? this.translate.instant('iot-hub.device-install-unexpected-error'); |
||||
|
}, |
||||
|
error: error => { |
||||
|
this.updating = false; |
||||
|
this.errorMessage = requestFailureMessage(error, this.translate); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
cancel(): void { |
||||
|
this.dialogRef.close(false); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue