36 changed files with 25 additions and 581 deletions
@ -1,55 +0,0 @@ |
|||
<!-- |
|||
|
|||
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> |
|||
<div> |
|||
<ul class="tb-converter-update-packages"> |
|||
@for (name of usedByShown; track $index) { |
|||
<li>{{ name }}</li> |
|||
} |
|||
</ul> |
|||
@if (usedByHidden.length) { |
|||
<div id="tb-converter-update-more" class="tb-converter-update-more" [class.expanded]="usedByExpanded" |
|||
[attr.aria-hidden]="!usedByExpanded"> |
|||
<ul class="tb-converter-update-packages"> |
|||
@for (name of usedByHidden; track $index) { |
|||
<li>{{ name }}</li> |
|||
} |
|||
</ul> |
|||
</div> |
|||
} |
|||
</div> |
|||
@if (usedByHidden.length) { |
|||
<button type="button" class="tb-converter-update-toggle self-start" aria-controls="tb-converter-update-more" |
|||
[attr.aria-expanded]="usedByExpanded" (click)="usedByExpanded = !usedByExpanded"> |
|||
@if (usedByExpanded) { |
|||
{{ 'iot-hub.device-update-shared-less' | translate }} |
|||
} @else { |
|||
{{ 'iot-hub.device-update-shared-more' | translate:{ count: usedByHidden.length } }} |
|||
} |
|||
</button> |
|||
} |
|||
} |
|||
@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> |
|||
@ -1,97 +0,0 @@ |
|||
// 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); |
|||
} |
|||
|
|||
// Material expansion-panel timing |
|||
.tb-converter-update-more { |
|||
display: grid; |
|||
grid-template-rows: 0fr; |
|||
transition: grid-template-rows 225ms cubic-bezier(0.4, 0, 0.2, 1); |
|||
> ul { |
|||
overflow: hidden; |
|||
min-height: 0; |
|||
} |
|||
&.expanded { |
|||
grid-template-rows: 1fr; |
|||
} |
|||
@media (prefers-reduced-motion: reduce) { |
|||
transition: none; |
|||
} |
|||
} |
|||
|
|||
.tb-converter-update-toggle { |
|||
padding: 0; |
|||
border: none; |
|||
background: none; |
|||
font-size: 12px; |
|||
font-weight: 500; |
|||
line-height: 16px; |
|||
color: var(--tb-primary-500); |
|||
cursor: pointer; |
|||
&:hover, |
|||
&:focus-visible { |
|||
text-decoration: underline; |
|||
} |
|||
} |
|||
|
|||
.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; |
|||
} |
|||
} |
|||
@ -1,88 +0,0 @@ |
|||
// 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[]; |
|||
} |
|||
|
|||
const USED_BY_SHOWN = 3; |
|||
|
|||
/** |
|||
* 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')); |
|||
readonly usedByShown: string[]; |
|||
readonly usedByHidden: string[]; |
|||
usedByExpanded = false; |
|||
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); |
|||
// Collapse only when at least 2 packages would be hidden
|
|||
const shownCount = data.usedBy.length > USED_BY_SHOWN + 1 ? USED_BY_SHOWN : data.usedBy.length; |
|||
this.usedByShown = data.usedBy.slice(0, shownCount); |
|||
this.usedByHidden = data.usedBy.slice(shownCount); |
|||
} |
|||
|
|||
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