UI: Update firmware table config

This commit is contained in:
Vladyslav_Prykhodko 2021-04-23 17:38:26 +03:00 committed by Andrew Shvayka
parent 5f8a9e9f67
commit c8488aa52b
6 changed files with 99 additions and 43 deletions

View File

@ -29,7 +29,7 @@ import { FirmwareService } from '@core/http/firmware.service';
import { PageLink } from '@shared/models/page/page-link'; import { PageLink } from '@shared/models/page/page-link';
import { FirmwaresComponent } from '@home/pages/firmware/firmwares.component'; import { FirmwaresComponent } from '@home/pages/firmware/firmwares.component';
import { EntityAction } from '@home/models/entity/entity-component.models'; import { EntityAction } from '@home/models/entity/entity-component.models';
import { DeviceInfo } from '@shared/models/device.models'; import { FileSizePipe } from '@shared/pipe/file-size.pipe';
@Injectable() @Injectable()
export class FirmwareTableConfigResolve implements Resolve<EntityTableConfig<Firmware, PageLink, FirmwareInfo>> { export class FirmwareTableConfigResolve implements Resolve<EntityTableConfig<Firmware, PageLink, FirmwareInfo>> {
@ -38,7 +38,8 @@ export class FirmwareTableConfigResolve implements Resolve<EntityTableConfig<Fir
constructor(private translate: TranslateService, constructor(private translate: TranslateService,
private datePipe: DatePipe, private datePipe: DatePipe,
private firmwareService: FirmwareService) { private firmwareService: FirmwareService,
private fileSize: FileSizePipe) {
this.config.entityType = EntityType.FIRMWARE; this.config.entityType = EntityType.FIRMWARE;
this.config.entityComponent = FirmwaresComponent; this.config.entityComponent = FirmwaresComponent;
this.config.entityTranslations = entityTypeTranslations.get(EntityType.FIRMWARE); this.config.entityTranslations = entityTypeTranslations.get(EntityType.FIRMWARE);
@ -48,13 +49,20 @@ export class FirmwareTableConfigResolve implements Resolve<EntityTableConfig<Fir
this.config.columns.push( this.config.columns.push(
new DateEntityTableColumn<FirmwareInfo>('createdTime', 'common.created-time', this.datePipe, '150px'), new DateEntityTableColumn<FirmwareInfo>('createdTime', 'common.created-time', this.datePipe, '150px'),
new EntityTableColumn<FirmwareInfo>('title', 'firmware.title', '50%'), new EntityTableColumn<FirmwareInfo>('title', 'firmware.title', '33%'),
new EntityTableColumn<FirmwareInfo>('version', 'firmware.version', '50%') new EntityTableColumn<FirmwareInfo>('version', 'firmware.version', '33%'),
new EntityTableColumn<FirmwareInfo>('fileName', 'firmware.file-name', '33%'),
new EntityTableColumn<FirmwareInfo>('dataSize', 'firmware.file-size', '70px', entity => {
return this.fileSize.transform(entity.dataSize || 0);
}),
new EntityTableColumn<FirmwareInfo>('checksum', 'firmware.checksum', '540px', entity => {
return `${entity.checksumAlgorithm}: ${entity.checksum}`;
}, () => ({}), false)
); );
this.config.cellActionDescriptors.push( this.config.cellActionDescriptors.push(
{ {
name: this.translate.instant('firmware.export'), name: this.translate.instant('firmware.download'),
icon: 'file_download', icon: 'file_download',
isEnabled: (firmware) => firmware.hasData, isEnabled: (firmware) => firmware.hasData,
onAction: ($event, entity) => this.exportFirmware($event, entity) onAction: ($event, entity) => this.exportFirmware($event, entity)

View File

@ -20,23 +20,31 @@
[disabled]="(isLoading$ | async) || !entity?.hasData" [disabled]="(isLoading$ | async) || !entity?.hasData"
(click)="onEntityAction($event, 'uploadFirmware')" (click)="onEntityAction($event, 'uploadFirmware')"
[fxShow]="!isEdit"> [fxShow]="!isEdit">
{{'firmware.export' | translate }} {{ 'firmware.download' | translate }}
</button> </button>
<button mat-raised-button color="primary" fxFlex.xs <button mat-raised-button color="primary" fxFlex.xs
[disabled]="(isLoading$ | async)" [disabled]="(isLoading$ | async)"
(click)="onEntityAction($event, 'delete')" (click)="onEntityAction($event, 'delete')"
[fxShow]="!hideDelete() && !isEdit"> [fxShow]="!hideDelete() && !isEdit">
{{'resource.delete' | translate }} {{ 'firmware.delete' | translate }}
</button> </button>
<div fxLayout="row" fxLayout.xs="column"> <div fxLayout="row" fxLayout.xs="column">
<button mat-raised-button <button mat-raised-button
ngxClipboard ngxClipboard
(cbOnSuccess)="onFirmwareIdCopied($event)" (cbOnSuccess)="onFirmwareIdCopied()"
[cbContent]="entity?.id?.id" [cbContent]="entity?.id?.id"
[fxShow]="!isEdit"> [fxShow]="!isEdit">
<mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon> <mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon>
<span translate>firmware.copyId</span> <span translate>firmware.copyId</span>
</button> </button>
<button mat-raised-button
ngxClipboard
(cbOnSuccess)="onFirmwareChecksumCopied()"
[cbContent]="entity?.checksum"
[fxShow]="!isEdit">
<mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon>
<span translate>firmware.copy-checksum</span>
</button>
</div> </div>
</div> </div>
<div class="mat-padding" fxLayout="column"> <div class="mat-padding" fxLayout="column">
@ -46,24 +54,24 @@
<div fxLayout="row" fxLayoutGap.gt-xs="8px" fxLayout.xs="column"> <div fxLayout="row" fxLayoutGap.gt-xs="8px" fxLayout.xs="column">
<mat-form-field class="mat-block" fxFlex="45"> <mat-form-field class="mat-block" fxFlex="45">
<mat-label translate>firmware.title</mat-label> <mat-label translate>firmware.title</mat-label>
<input matInput formControlName="title" type="text" required> <input matInput formControlName="title" type="text" required [readonly]="!isAdd">
<mat-error *ngIf="entityForm.get('title').hasError('required')"> <mat-error *ngIf="entityForm.get('title').hasError('required')">
{{ 'firmware.title-required' | translate }} {{ 'firmware.title-required' | translate }}
</mat-error> </mat-error>
</mat-form-field> </mat-form-field>
<mat-form-field class="mat-block" fxFlex> <mat-form-field class="mat-block" fxFlex>
<mat-label translate>firmware.version</mat-label> <mat-label translate>firmware.version</mat-label>
<input matInput formControlName="version" type="text" required> <input matInput formControlName="version" type="text" required [readonly]="!isAdd">
<mat-error *ngIf="entityForm.get('version').hasError('required')"> <mat-error *ngIf="entityForm.get('version').hasError('required')">
{{ 'firmware.version-required' | translate }} {{ 'firmware.version-required' | translate }}
</mat-error> </mat-error>
</mat-form-field> </mat-form-field>
</div> </div>
<section *ngIf="isAdd" style="padding-bottom: 8px"> <div fxLayout="row" fxLayoutGap.gt-xs="8px" fxLayoutGap.sm="8px" fxLayout.xs="column" fxLayout.md="column">
<div fxLayout="row" fxLayoutGap.gt-xs="8px" fxLayout.xs="column"> <mat-form-field class="mat-block" fxFlex="33">
<mat-form-field class="mat-block" fxFlex="45">
<mat-label translate>firmware.checksum-algorithm</mat-label> <mat-label translate>firmware.checksum-algorithm</mat-label>
<mat-select formControlName="checksumAlgorithm"> <input *ngIf="!isAdd" matInput formControlName="checksumAlgorithm" type="text" [readonly]="isEdit">
<mat-select formControlName="checksumAlgorithm" *ngIf="isAdd">
<mat-option [value]=null></mat-option> <mat-option [value]=null></mat-option>
<mat-option *ngFor="let checksumAlgorithm of checksumAlgorithms" [value]="checksumAlgorithm"> <mat-option *ngFor="let checksumAlgorithm of checksumAlgorithms" [value]="checksumAlgorithm">
{{ checksumAlgorithmTranslationMap.get(checksumAlgorithm) }} {{ checksumAlgorithmTranslationMap.get(checksumAlgorithm) }}
@ -72,13 +80,14 @@
</mat-form-field> </mat-form-field>
<mat-form-field class="mat-block" fxFlex> <mat-form-field class="mat-block" fxFlex>
<mat-label translate>firmware.checksum</mat-label> <mat-label translate>firmware.checksum</mat-label>
<input matInput formControlName="checksum" type="text" <input matInput formControlName="checksum" type="text" [readonly]="!isAdd"
[required]="entityForm.get('checksumAlgorithm').value != null"> [required]="entityForm.get('checksumAlgorithm').value != null">
<mat-error *ngIf="entityForm.get('checksumAlgorithm').hasError('required')"> <mat-error *ngIf="entityForm.get('checksumAlgorithm').hasError('required')">
{{ 'firmware.checksum-required' | translate }} {{ 'firmware.checksum-required' | translate }}
</mat-error> </mat-error>
</mat-form-field> </mat-form-field>
</div> </div>
<section *ngIf="isAdd" style="padding-top: 8px">
<tb-file-input <tb-file-input
formControlName="file" formControlName="file"
workFromFileObj="true" workFromFileObj="true"
@ -86,6 +95,22 @@
dropLabel="{{'resource.drop-file' | translate}}"> dropLabel="{{'resource.drop-file' | translate}}">
</tb-file-input> </tb-file-input>
</section> </section>
<section *ngIf="!isAdd">
<div fxLayout="row" fxLayoutGap.gt-md="8px" fxLayoutGap.sm="8px" fxLayout.xs="column" fxLayout.md="column">
<mat-form-field class="mat-block" fxFlex="33">
<mat-label translate>firmware.file-name</mat-label>
<input matInput formControlName="fileName" type="text" readonly>
</mat-form-field>
<mat-form-field class="mat-block" fxFlex>
<mat-label translate>firmware.file-size-bytes</mat-label>
<input matInput formControlName="dataSize" type="text" readonly>
</mat-form-field>
<mat-form-field class="mat-block" fxFlex>
<mat-label translate>firmware.content-type</mat-label>
<input matInput formControlName="contentType" type="text" readonly>
</mat-form-field>
</div>
</section>
<div formGroupName="additionalInfo"> <div formGroupName="additionalInfo">
<mat-form-field class="mat-block"> <mat-form-field class="mat-block">
<mat-label translate>firmware.description</mat-label> <mat-label translate>firmware.description</mat-label>

View File

@ -83,6 +83,8 @@ export class FirmwaresComponent extends EntityComponent<Firmware> implements OnI
const form = this.fb.group({ const form = this.fb.group({
title: [entity ? entity.title : '', [Validators.required, Validators.maxLength(255)]], title: [entity ? entity.title : '', [Validators.required, Validators.maxLength(255)]],
version: [entity ? entity.version : '', [Validators.required, Validators.maxLength(255)]], version: [entity ? entity.version : '', [Validators.required, Validators.maxLength(255)]],
checksumAlgorithm: [entity ? entity.checksumAlgorithm : null],
checksum: [entity ? entity.checksum : '', Validators.maxLength(1020)],
additionalInfo: this.fb.group( additionalInfo: this.fb.group(
{ {
description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''], description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''],
@ -90,28 +92,31 @@ export class FirmwaresComponent extends EntityComponent<Firmware> implements OnI
) )
}); });
if (this.isAdd) { if (this.isAdd) {
form.addControl('checksumAlgorithm', this.fb.control(null));
form.addControl('checksum', this.fb.control('', Validators.maxLength(1020)));
form.addControl('file', this.fb.control(null, Validators.required)); form.addControl('file', this.fb.control(null, Validators.required));
} else {
form.addControl('fileName', this.fb.control(null));
form.addControl('dataSize', this.fb.control(null));
form.addControl('contentType', this.fb.control(null));
} }
return form; return form;
} }
updateForm(entity: Firmware) { updateForm(entity: Firmware) {
if (this.isEdit) {
this.entityForm.get('title').disable({emitEvent: false});
this.entityForm.get('version').disable({emitEvent: false});
}
this.entityForm.patchValue({ this.entityForm.patchValue({
title: entity.title, title: entity.title,
version: entity.version, version: entity.version,
checksumAlgorithm: entity.checksumAlgorithm,
checksum: entity.checksum,
fileName: entity.fileName,
dataSize: entity.dataSize,
contentType: entity.contentType,
additionalInfo: { additionalInfo: {
description: entity.additionalInfo ? entity.additionalInfo.description : '' description: entity.additionalInfo ? entity.additionalInfo.description : ''
} }
}); });
} }
onFirmwareIdCopied($event) { onFirmwareIdCopied() {
this.store.dispatch(new ActionNotificationShow( this.store.dispatch(new ActionNotificationShow(
{ {
message: this.translate.instant('firmware.idCopiedMessage'), message: this.translate.instant('firmware.idCopiedMessage'),
@ -121,4 +126,15 @@ export class FirmwaresComponent extends EntityComponent<Firmware> implements OnI
horizontalPosition: 'right' horizontalPosition: 'right'
})); }));
} }
onFirmwareChecksumCopied() {
this.store.dispatch(new ActionNotificationShow(
{
message: this.translate.instant('firmware.checksum-copied-message'),
type: 'success',
duration: 750,
verticalPosition: 'bottom',
horizontalPosition: 'right'
}));
}
} }

View File

@ -37,14 +37,15 @@ export interface FirmwareInfo extends BaseData<FirmwareId> {
title?: string; title?: string;
version?: string; version?: string;
hasData?: boolean; hasData?: boolean;
fileName: string;
checksum?: ChecksumAlgorithm;
checksumAlgorithm?: string;
contentType: string;
dataSize?: number;
additionalInfo?: any; additionalInfo?: any;
} }
export interface Firmware extends FirmwareInfo { export interface Firmware extends FirmwareInfo {
file?: File; file?: File;
data: string; data: string;
fileName: string;
checksum?: ChecksumAlgorithm;
checksumAlgorithm?: string;
contentType: string;
} }

View File

@ -23,7 +23,7 @@ type unitPrecisionMap = {
const defaultPrecisionMap: unitPrecisionMap = { const defaultPrecisionMap: unitPrecisionMap = {
bytes: 0, bytes: 0,
KB: 0, KB: 1,
MB: 1, MB: 1,
GB: 1, GB: 1,
TB: 2, TB: 2,

View File

@ -1907,8 +1907,11 @@
"firmware": { "firmware": {
"add": "Add firmware", "add": "Add firmware",
"checksum": "Checksum", "checksum": "Checksum",
"checksum-copied-message": "Firmware checksum has been copied to clipboard",
"checksum-required": "Checksum is required.", "checksum-required": "Checksum is required.",
"checksum-algorithm": "Checksum algorithm", "checksum-algorithm": "Checksum algorithm",
"content-type": "Content type",
"copy-checksum": "Copy checksum",
"copyId": "Copy firmware Id", "copyId": "Copy firmware Id",
"description": "Description", "description": "Description",
"delete": "Delete firmware", "delete": "Delete firmware",
@ -1917,12 +1920,15 @@
"delete-firmwares-action-title": "Delete { count, plural, 1 {1 firmware} other {# firmwares} }", "delete-firmwares-action-title": "Delete { count, plural, 1 {1 firmware} other {# firmwares} }",
"delete-firmwares-text": "Be careful, after the confirmation all selected resources will be removed.", "delete-firmwares-text": "Be careful, after the confirmation all selected resources will be removed.",
"delete-firmwares-title": "Are you sure you want to delete { count, plural, 1 {1 firmware} other {# firmwares} }?", "delete-firmwares-title": "Are you sure you want to delete { count, plural, 1 {1 firmware} other {# firmwares} }?",
"download": "Download firmware",
"drop-file": "Drop a firmware file or click to select a file to upload.", "drop-file": "Drop a firmware file or click to select a file to upload.",
"empty": "Firmware is empty", "empty": "Firmware is empty",
"export": "Export firmware",
"idCopiedMessage": "Firmware Id has been copied to clipboard", "idCopiedMessage": "Firmware Id has been copied to clipboard",
"no-firmware-matching": "No firmware matching '{{entity}}' were found.", "no-firmware-matching": "No firmware matching '{{entity}}' were found.",
"no-firmware-text": "No firmwares found", "no-firmware-text": "No firmwares found",
"file-name": "File name",
"file-size": "File size",
"file-size-bytes": "File size in bytes",
"firmware": "Firmware", "firmware": "Firmware",
"firmware-details": "Firmware details", "firmware-details": "Firmware details",
"firmware-required": "Firmware is required.", "firmware-required": "Firmware is required.",