Commit c8488aa52b48b20d649660544a19533134360898
Committed by
Andrew Shvayka
1 parent
5f8a9e9f
UI: Update firmware table config
Showing
6 changed files
with
99 additions
and
43 deletions
@@ -29,7 +29,7 @@ import { FirmwareService } from '@core/http/firmware.service'; | @@ -29,7 +29,7 @@ import { FirmwareService } from '@core/http/firmware.service'; | ||
29 | import { PageLink } from '@shared/models/page/page-link'; | 29 | import { PageLink } from '@shared/models/page/page-link'; |
30 | import { FirmwaresComponent } from '@home/pages/firmware/firmwares.component'; | 30 | import { FirmwaresComponent } from '@home/pages/firmware/firmwares.component'; |
31 | import { EntityAction } from '@home/models/entity/entity-component.models'; | 31 | import { EntityAction } from '@home/models/entity/entity-component.models'; |
32 | -import { DeviceInfo } from '@shared/models/device.models'; | 32 | +import { FileSizePipe } from '@shared/pipe/file-size.pipe'; |
33 | 33 | ||
34 | @Injectable() | 34 | @Injectable() |
35 | export class FirmwareTableConfigResolve implements Resolve<EntityTableConfig<Firmware, PageLink, FirmwareInfo>> { | 35 | export class FirmwareTableConfigResolve implements Resolve<EntityTableConfig<Firmware, PageLink, FirmwareInfo>> { |
@@ -38,7 +38,8 @@ export class FirmwareTableConfigResolve implements Resolve<EntityTableConfig<Fir | @@ -38,7 +38,8 @@ export class FirmwareTableConfigResolve implements Resolve<EntityTableConfig<Fir | ||
38 | 38 | ||
39 | constructor(private translate: TranslateService, | 39 | constructor(private translate: TranslateService, |
40 | private datePipe: DatePipe, | 40 | private datePipe: DatePipe, |
41 | - private firmwareService: FirmwareService) { | 41 | + private firmwareService: FirmwareService, |
42 | + private fileSize: FileSizePipe) { | ||
42 | this.config.entityType = EntityType.FIRMWARE; | 43 | this.config.entityType = EntityType.FIRMWARE; |
43 | this.config.entityComponent = FirmwaresComponent; | 44 | this.config.entityComponent = FirmwaresComponent; |
44 | this.config.entityTranslations = entityTypeTranslations.get(EntityType.FIRMWARE); | 45 | this.config.entityTranslations = entityTypeTranslations.get(EntityType.FIRMWARE); |
@@ -48,13 +49,20 @@ export class FirmwareTableConfigResolve implements Resolve<EntityTableConfig<Fir | @@ -48,13 +49,20 @@ export class FirmwareTableConfigResolve implements Resolve<EntityTableConfig<Fir | ||
48 | 49 | ||
49 | this.config.columns.push( | 50 | this.config.columns.push( |
50 | new DateEntityTableColumn<FirmwareInfo>('createdTime', 'common.created-time', this.datePipe, '150px'), | 51 | new DateEntityTableColumn<FirmwareInfo>('createdTime', 'common.created-time', this.datePipe, '150px'), |
51 | - new EntityTableColumn<FirmwareInfo>('title', 'firmware.title', '50%'), | ||
52 | - new EntityTableColumn<FirmwareInfo>('version', 'firmware.version', '50%') | 52 | + new EntityTableColumn<FirmwareInfo>('title', 'firmware.title', '33%'), |
53 | + new EntityTableColumn<FirmwareInfo>('version', 'firmware.version', '33%'), | ||
54 | + new EntityTableColumn<FirmwareInfo>('fileName', 'firmware.file-name', '33%'), | ||
55 | + new EntityTableColumn<FirmwareInfo>('dataSize', 'firmware.file-size', '70px', entity => { | ||
56 | + return this.fileSize.transform(entity.dataSize || 0); | ||
57 | + }), | ||
58 | + new EntityTableColumn<FirmwareInfo>('checksum', 'firmware.checksum', '540px', entity => { | ||
59 | + return `${entity.checksumAlgorithm}: ${entity.checksum}`; | ||
60 | + }, () => ({}), false) | ||
53 | ); | 61 | ); |
54 | 62 | ||
55 | this.config.cellActionDescriptors.push( | 63 | this.config.cellActionDescriptors.push( |
56 | { | 64 | { |
57 | - name: this.translate.instant('firmware.export'), | 65 | + name: this.translate.instant('firmware.download'), |
58 | icon: 'file_download', | 66 | icon: 'file_download', |
59 | isEnabled: (firmware) => firmware.hasData, | 67 | isEnabled: (firmware) => firmware.hasData, |
60 | onAction: ($event, entity) => this.exportFirmware($event, entity) | 68 | onAction: ($event, entity) => this.exportFirmware($event, entity) |
@@ -20,23 +20,31 @@ | @@ -20,23 +20,31 @@ | ||
20 | [disabled]="(isLoading$ | async) || !entity?.hasData" | 20 | [disabled]="(isLoading$ | async) || !entity?.hasData" |
21 | (click)="onEntityAction($event, 'uploadFirmware')" | 21 | (click)="onEntityAction($event, 'uploadFirmware')" |
22 | [fxShow]="!isEdit"> | 22 | [fxShow]="!isEdit"> |
23 | - {{'firmware.export' | translate }} | 23 | + {{ 'firmware.download' | translate }} |
24 | </button> | 24 | </button> |
25 | <button mat-raised-button color="primary" fxFlex.xs | 25 | <button mat-raised-button color="primary" fxFlex.xs |
26 | [disabled]="(isLoading$ | async)" | 26 | [disabled]="(isLoading$ | async)" |
27 | (click)="onEntityAction($event, 'delete')" | 27 | (click)="onEntityAction($event, 'delete')" |
28 | [fxShow]="!hideDelete() && !isEdit"> | 28 | [fxShow]="!hideDelete() && !isEdit"> |
29 | - {{'resource.delete' | translate }} | 29 | + {{ 'firmware.delete' | translate }} |
30 | </button> | 30 | </button> |
31 | <div fxLayout="row" fxLayout.xs="column"> | 31 | <div fxLayout="row" fxLayout.xs="column"> |
32 | <button mat-raised-button | 32 | <button mat-raised-button |
33 | ngxClipboard | 33 | ngxClipboard |
34 | - (cbOnSuccess)="onFirmwareIdCopied($event)" | 34 | + (cbOnSuccess)="onFirmwareIdCopied()" |
35 | [cbContent]="entity?.id?.id" | 35 | [cbContent]="entity?.id?.id" |
36 | [fxShow]="!isEdit"> | 36 | [fxShow]="!isEdit"> |
37 | <mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon> | 37 | <mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon> |
38 | <span translate>firmware.copyId</span> | 38 | <span translate>firmware.copyId</span> |
39 | </button> | 39 | </button> |
40 | + <button mat-raised-button | ||
41 | + ngxClipboard | ||
42 | + (cbOnSuccess)="onFirmwareChecksumCopied()" | ||
43 | + [cbContent]="entity?.checksum" | ||
44 | + [fxShow]="!isEdit"> | ||
45 | + <mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon> | ||
46 | + <span translate>firmware.copy-checksum</span> | ||
47 | + </button> | ||
40 | </div> | 48 | </div> |
41 | </div> | 49 | </div> |
42 | <div class="mat-padding" fxLayout="column"> | 50 | <div class="mat-padding" fxLayout="column"> |
@@ -46,39 +54,40 @@ | @@ -46,39 +54,40 @@ | ||
46 | <div fxLayout="row" fxLayoutGap.gt-xs="8px" fxLayout.xs="column"> | 54 | <div fxLayout="row" fxLayoutGap.gt-xs="8px" fxLayout.xs="column"> |
47 | <mat-form-field class="mat-block" fxFlex="45"> | 55 | <mat-form-field class="mat-block" fxFlex="45"> |
48 | <mat-label translate>firmware.title</mat-label> | 56 | <mat-label translate>firmware.title</mat-label> |
49 | - <input matInput formControlName="title" type="text" required> | 57 | + <input matInput formControlName="title" type="text" required [readonly]="!isAdd"> |
50 | <mat-error *ngIf="entityForm.get('title').hasError('required')"> | 58 | <mat-error *ngIf="entityForm.get('title').hasError('required')"> |
51 | {{ 'firmware.title-required' | translate }} | 59 | {{ 'firmware.title-required' | translate }} |
52 | </mat-error> | 60 | </mat-error> |
53 | </mat-form-field> | 61 | </mat-form-field> |
54 | <mat-form-field class="mat-block" fxFlex> | 62 | <mat-form-field class="mat-block" fxFlex> |
55 | <mat-label translate>firmware.version</mat-label> | 63 | <mat-label translate>firmware.version</mat-label> |
56 | - <input matInput formControlName="version" type="text" required> | 64 | + <input matInput formControlName="version" type="text" required [readonly]="!isAdd"> |
57 | <mat-error *ngIf="entityForm.get('version').hasError('required')"> | 65 | <mat-error *ngIf="entityForm.get('version').hasError('required')"> |
58 | {{ 'firmware.version-required' | translate }} | 66 | {{ 'firmware.version-required' | translate }} |
59 | </mat-error> | 67 | </mat-error> |
60 | </mat-form-field> | 68 | </mat-form-field> |
61 | </div> | 69 | </div> |
62 | - <section *ngIf="isAdd" style="padding-bottom: 8px"> | ||
63 | - <div fxLayout="row" fxLayoutGap.gt-xs="8px" fxLayout.xs="column"> | ||
64 | - <mat-form-field class="mat-block" fxFlex="45"> | ||
65 | - <mat-label translate>firmware.checksum-algorithm</mat-label> | ||
66 | - <mat-select formControlName="checksumAlgorithm"> | ||
67 | - <mat-option [value]=null></mat-option> | ||
68 | - <mat-option *ngFor="let checksumAlgorithm of checksumAlgorithms" [value]="checksumAlgorithm"> | ||
69 | - {{ checksumAlgorithmTranslationMap.get(checksumAlgorithm) }} | ||
70 | - </mat-option> | ||
71 | - </mat-select> | ||
72 | - </mat-form-field> | ||
73 | - <mat-form-field class="mat-block" fxFlex> | ||
74 | - <mat-label translate>firmware.checksum</mat-label> | ||
75 | - <input matInput formControlName="checksum" type="text" | ||
76 | - [required]="entityForm.get('checksumAlgorithm').value != null"> | ||
77 | - <mat-error *ngIf="entityForm.get('checksumAlgorithm').hasError('required')"> | ||
78 | - {{ 'firmware.checksum-required' | translate }} | ||
79 | - </mat-error> | ||
80 | - </mat-form-field> | ||
81 | - </div> | 70 | + <div fxLayout="row" fxLayoutGap.gt-xs="8px" fxLayoutGap.sm="8px" fxLayout.xs="column" fxLayout.md="column"> |
71 | + <mat-form-field class="mat-block" fxFlex="33"> | ||
72 | + <mat-label translate>firmware.checksum-algorithm</mat-label> | ||
73 | + <input *ngIf="!isAdd" matInput formControlName="checksumAlgorithm" type="text" [readonly]="isEdit"> | ||
74 | + <mat-select formControlName="checksumAlgorithm" *ngIf="isAdd"> | ||
75 | + <mat-option [value]=null></mat-option> | ||
76 | + <mat-option *ngFor="let checksumAlgorithm of checksumAlgorithms" [value]="checksumAlgorithm"> | ||
77 | + {{ checksumAlgorithmTranslationMap.get(checksumAlgorithm) }} | ||
78 | + </mat-option> | ||
79 | + </mat-select> | ||
80 | + </mat-form-field> | ||
81 | + <mat-form-field class="mat-block" fxFlex> | ||
82 | + <mat-label translate>firmware.checksum</mat-label> | ||
83 | + <input matInput formControlName="checksum" type="text" [readonly]="!isAdd" | ||
84 | + [required]="entityForm.get('checksumAlgorithm').value != null"> | ||
85 | + <mat-error *ngIf="entityForm.get('checksumAlgorithm').hasError('required')"> | ||
86 | + {{ 'firmware.checksum-required' | translate }} | ||
87 | + </mat-error> | ||
88 | + </mat-form-field> | ||
89 | + </div> | ||
90 | + <section *ngIf="isAdd" style="padding-top: 8px"> | ||
82 | <tb-file-input | 91 | <tb-file-input |
83 | formControlName="file" | 92 | formControlName="file" |
84 | workFromFileObj="true" | 93 | workFromFileObj="true" |
@@ -86,6 +95,22 @@ | @@ -86,6 +95,22 @@ | ||
86 | dropLabel="{{'resource.drop-file' | translate}}"> | 95 | dropLabel="{{'resource.drop-file' | translate}}"> |
87 | </tb-file-input> | 96 | </tb-file-input> |
88 | </section> | 97 | </section> |
98 | + <section *ngIf="!isAdd"> | ||
99 | + <div fxLayout="row" fxLayoutGap.gt-md="8px" fxLayoutGap.sm="8px" fxLayout.xs="column" fxLayout.md="column"> | ||
100 | + <mat-form-field class="mat-block" fxFlex="33"> | ||
101 | + <mat-label translate>firmware.file-name</mat-label> | ||
102 | + <input matInput formControlName="fileName" type="text" readonly> | ||
103 | + </mat-form-field> | ||
104 | + <mat-form-field class="mat-block" fxFlex> | ||
105 | + <mat-label translate>firmware.file-size-bytes</mat-label> | ||
106 | + <input matInput formControlName="dataSize" type="text" readonly> | ||
107 | + </mat-form-field> | ||
108 | + <mat-form-field class="mat-block" fxFlex> | ||
109 | + <mat-label translate>firmware.content-type</mat-label> | ||
110 | + <input matInput formControlName="contentType" type="text" readonly> | ||
111 | + </mat-form-field> | ||
112 | + </div> | ||
113 | + </section> | ||
89 | <div formGroupName="additionalInfo"> | 114 | <div formGroupName="additionalInfo"> |
90 | <mat-form-field class="mat-block"> | 115 | <mat-form-field class="mat-block"> |
91 | <mat-label translate>firmware.description</mat-label> | 116 | <mat-label translate>firmware.description</mat-label> |
@@ -83,6 +83,8 @@ export class FirmwaresComponent extends EntityComponent<Firmware> implements OnI | @@ -83,6 +83,8 @@ export class FirmwaresComponent extends EntityComponent<Firmware> implements OnI | ||
83 | const form = this.fb.group({ | 83 | const form = this.fb.group({ |
84 | title: [entity ? entity.title : '', [Validators.required, Validators.maxLength(255)]], | 84 | title: [entity ? entity.title : '', [Validators.required, Validators.maxLength(255)]], |
85 | version: [entity ? entity.version : '', [Validators.required, Validators.maxLength(255)]], | 85 | version: [entity ? entity.version : '', [Validators.required, Validators.maxLength(255)]], |
86 | + checksumAlgorithm: [entity ? entity.checksumAlgorithm : null], | ||
87 | + checksum: [entity ? entity.checksum : '', Validators.maxLength(1020)], | ||
86 | additionalInfo: this.fb.group( | 88 | additionalInfo: this.fb.group( |
87 | { | 89 | { |
88 | description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''], | 90 | description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''], |
@@ -90,28 +92,31 @@ export class FirmwaresComponent extends EntityComponent<Firmware> implements OnI | @@ -90,28 +92,31 @@ export class FirmwaresComponent extends EntityComponent<Firmware> implements OnI | ||
90 | ) | 92 | ) |
91 | }); | 93 | }); |
92 | if (this.isAdd) { | 94 | if (this.isAdd) { |
93 | - form.addControl('checksumAlgorithm', this.fb.control(null)); | ||
94 | - form.addControl('checksum', this.fb.control('', Validators.maxLength(1020))); | ||
95 | form.addControl('file', this.fb.control(null, Validators.required)); | 95 | form.addControl('file', this.fb.control(null, Validators.required)); |
96 | + } else { | ||
97 | + form.addControl('fileName', this.fb.control(null)); | ||
98 | + form.addControl('dataSize', this.fb.control(null)); | ||
99 | + form.addControl('contentType', this.fb.control(null)); | ||
96 | } | 100 | } |
97 | return form; | 101 | return form; |
98 | } | 102 | } |
99 | 103 | ||
100 | updateForm(entity: Firmware) { | 104 | updateForm(entity: Firmware) { |
101 | - if (this.isEdit) { | ||
102 | - this.entityForm.get('title').disable({emitEvent: false}); | ||
103 | - this.entityForm.get('version').disable({emitEvent: false}); | ||
104 | - } | ||
105 | this.entityForm.patchValue({ | 105 | this.entityForm.patchValue({ |
106 | title: entity.title, | 106 | title: entity.title, |
107 | version: entity.version, | 107 | version: entity.version, |
108 | + checksumAlgorithm: entity.checksumAlgorithm, | ||
109 | + checksum: entity.checksum, | ||
110 | + fileName: entity.fileName, | ||
111 | + dataSize: entity.dataSize, | ||
112 | + contentType: entity.contentType, | ||
108 | additionalInfo: { | 113 | additionalInfo: { |
109 | description: entity.additionalInfo ? entity.additionalInfo.description : '' | 114 | description: entity.additionalInfo ? entity.additionalInfo.description : '' |
110 | } | 115 | } |
111 | }); | 116 | }); |
112 | } | 117 | } |
113 | 118 | ||
114 | - onFirmwareIdCopied($event) { | 119 | + onFirmwareIdCopied() { |
115 | this.store.dispatch(new ActionNotificationShow( | 120 | this.store.dispatch(new ActionNotificationShow( |
116 | { | 121 | { |
117 | message: this.translate.instant('firmware.idCopiedMessage'), | 122 | message: this.translate.instant('firmware.idCopiedMessage'), |
@@ -121,4 +126,15 @@ export class FirmwaresComponent extends EntityComponent<Firmware> implements OnI | @@ -121,4 +126,15 @@ export class FirmwaresComponent extends EntityComponent<Firmware> implements OnI | ||
121 | horizontalPosition: 'right' | 126 | horizontalPosition: 'right' |
122 | })); | 127 | })); |
123 | } | 128 | } |
129 | + | ||
130 | + onFirmwareChecksumCopied() { | ||
131 | + this.store.dispatch(new ActionNotificationShow( | ||
132 | + { | ||
133 | + message: this.translate.instant('firmware.checksum-copied-message'), | ||
134 | + type: 'success', | ||
135 | + duration: 750, | ||
136 | + verticalPosition: 'bottom', | ||
137 | + horizontalPosition: 'right' | ||
138 | + })); | ||
139 | + } | ||
124 | } | 140 | } |
@@ -37,14 +37,15 @@ export interface FirmwareInfo extends BaseData<FirmwareId> { | @@ -37,14 +37,15 @@ export interface FirmwareInfo extends BaseData<FirmwareId> { | ||
37 | title?: string; | 37 | title?: string; |
38 | version?: string; | 38 | version?: string; |
39 | hasData?: boolean; | 39 | hasData?: boolean; |
40 | + fileName: string; | ||
41 | + checksum?: ChecksumAlgorithm; | ||
42 | + checksumAlgorithm?: string; | ||
43 | + contentType: string; | ||
44 | + dataSize?: number; | ||
40 | additionalInfo?: any; | 45 | additionalInfo?: any; |
41 | } | 46 | } |
42 | 47 | ||
43 | export interface Firmware extends FirmwareInfo { | 48 | export interface Firmware extends FirmwareInfo { |
44 | file?: File; | 49 | file?: File; |
45 | data: string; | 50 | data: string; |
46 | - fileName: string; | ||
47 | - checksum?: ChecksumAlgorithm; | ||
48 | - checksumAlgorithm?: string; | ||
49 | - contentType: string; | ||
50 | } | 51 | } |
@@ -23,7 +23,7 @@ type unitPrecisionMap = { | @@ -23,7 +23,7 @@ type unitPrecisionMap = { | ||
23 | 23 | ||
24 | const defaultPrecisionMap: unitPrecisionMap = { | 24 | const defaultPrecisionMap: unitPrecisionMap = { |
25 | bytes: 0, | 25 | bytes: 0, |
26 | - KB: 0, | 26 | + KB: 1, |
27 | MB: 1, | 27 | MB: 1, |
28 | GB: 1, | 28 | GB: 1, |
29 | TB: 2, | 29 | TB: 2, |
@@ -1907,8 +1907,11 @@ | @@ -1907,8 +1907,11 @@ | ||
1907 | "firmware": { | 1907 | "firmware": { |
1908 | "add": "Add firmware", | 1908 | "add": "Add firmware", |
1909 | "checksum": "Checksum", | 1909 | "checksum": "Checksum", |
1910 | + "checksum-copied-message": "Firmware checksum has been copied to clipboard", | ||
1910 | "checksum-required": "Checksum is required.", | 1911 | "checksum-required": "Checksum is required.", |
1911 | "checksum-algorithm": "Checksum algorithm", | 1912 | "checksum-algorithm": "Checksum algorithm", |
1913 | + "content-type": "Content type", | ||
1914 | + "copy-checksum": "Copy checksum", | ||
1912 | "copyId": "Copy firmware Id", | 1915 | "copyId": "Copy firmware Id", |
1913 | "description": "Description", | 1916 | "description": "Description", |
1914 | "delete": "Delete firmware", | 1917 | "delete": "Delete firmware", |
@@ -1917,12 +1920,15 @@ | @@ -1917,12 +1920,15 @@ | ||
1917 | "delete-firmwares-action-title": "Delete { count, plural, 1 {1 firmware} other {# firmwares} }", | 1920 | "delete-firmwares-action-title": "Delete { count, plural, 1 {1 firmware} other {# firmwares} }", |
1918 | "delete-firmwares-text": "Be careful, after the confirmation all selected resources will be removed.", | 1921 | "delete-firmwares-text": "Be careful, after the confirmation all selected resources will be removed.", |
1919 | "delete-firmwares-title": "Are you sure you want to delete { count, plural, 1 {1 firmware} other {# firmwares} }?", | 1922 | "delete-firmwares-title": "Are you sure you want to delete { count, plural, 1 {1 firmware} other {# firmwares} }?", |
1923 | + "download": "Download firmware", | ||
1920 | "drop-file": "Drop a firmware file or click to select a file to upload.", | 1924 | "drop-file": "Drop a firmware file or click to select a file to upload.", |
1921 | "empty": "Firmware is empty", | 1925 | "empty": "Firmware is empty", |
1922 | - "export": "Export firmware", | ||
1923 | "idCopiedMessage": "Firmware Id has been copied to clipboard", | 1926 | "idCopiedMessage": "Firmware Id has been copied to clipboard", |
1924 | "no-firmware-matching": "No firmware matching '{{entity}}' were found.", | 1927 | "no-firmware-matching": "No firmware matching '{{entity}}' were found.", |
1925 | "no-firmware-text": "No firmwares found", | 1928 | "no-firmware-text": "No firmwares found", |
1929 | + "file-name": "File name", | ||
1930 | + "file-size": "File size", | ||
1931 | + "file-size-bytes": "File size in bytes", | ||
1926 | "firmware": "Firmware", | 1932 | "firmware": "Firmware", |
1927 | "firmware-details": "Firmware details", | 1933 | "firmware-details": "Firmware details", |
1928 | "firmware-required": "Firmware is required.", | 1934 | "firmware-required": "Firmware is required.", |