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 | 29 | import { PageLink } from '@shared/models/page/page-link'; |
30 | 30 | import { FirmwaresComponent } from '@home/pages/firmware/firmwares.component'; |
31 | 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 | 34 | @Injectable() |
35 | 35 | export class FirmwareTableConfigResolve implements Resolve<EntityTableConfig<Firmware, PageLink, FirmwareInfo>> { |
... | ... | @@ -38,7 +38,8 @@ export class FirmwareTableConfigResolve implements Resolve<EntityTableConfig<Fir |
38 | 38 | |
39 | 39 | constructor(private translate: TranslateService, |
40 | 40 | private datePipe: DatePipe, |
41 | - private firmwareService: FirmwareService) { | |
41 | + private firmwareService: FirmwareService, | |
42 | + private fileSize: FileSizePipe) { | |
42 | 43 | this.config.entityType = EntityType.FIRMWARE; |
43 | 44 | this.config.entityComponent = FirmwaresComponent; |
44 | 45 | this.config.entityTranslations = entityTypeTranslations.get(EntityType.FIRMWARE); |
... | ... | @@ -48,13 +49,20 @@ export class FirmwareTableConfigResolve implements Resolve<EntityTableConfig<Fir |
48 | 49 | |
49 | 50 | this.config.columns.push( |
50 | 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 | 63 | this.config.cellActionDescriptors.push( |
56 | 64 | { |
57 | - name: this.translate.instant('firmware.export'), | |
65 | + name: this.translate.instant('firmware.download'), | |
58 | 66 | icon: 'file_download', |
59 | 67 | isEnabled: (firmware) => firmware.hasData, |
60 | 68 | onAction: ($event, entity) => this.exportFirmware($event, entity) | ... | ... |
... | ... | @@ -20,23 +20,31 @@ |
20 | 20 | [disabled]="(isLoading$ | async) || !entity?.hasData" |
21 | 21 | (click)="onEntityAction($event, 'uploadFirmware')" |
22 | 22 | [fxShow]="!isEdit"> |
23 | - {{'firmware.export' | translate }} | |
23 | + {{ 'firmware.download' | translate }} | |
24 | 24 | </button> |
25 | 25 | <button mat-raised-button color="primary" fxFlex.xs |
26 | 26 | [disabled]="(isLoading$ | async)" |
27 | 27 | (click)="onEntityAction($event, 'delete')" |
28 | 28 | [fxShow]="!hideDelete() && !isEdit"> |
29 | - {{'resource.delete' | translate }} | |
29 | + {{ 'firmware.delete' | translate }} | |
30 | 30 | </button> |
31 | 31 | <div fxLayout="row" fxLayout.xs="column"> |
32 | 32 | <button mat-raised-button |
33 | 33 | ngxClipboard |
34 | - (cbOnSuccess)="onFirmwareIdCopied($event)" | |
34 | + (cbOnSuccess)="onFirmwareIdCopied()" | |
35 | 35 | [cbContent]="entity?.id?.id" |
36 | 36 | [fxShow]="!isEdit"> |
37 | 37 | <mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon> |
38 | 38 | <span translate>firmware.copyId</span> |
39 | 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 | 48 | </div> |
41 | 49 | </div> |
42 | 50 | <div class="mat-padding" fxLayout="column"> |
... | ... | @@ -46,39 +54,40 @@ |
46 | 54 | <div fxLayout="row" fxLayoutGap.gt-xs="8px" fxLayout.xs="column"> |
47 | 55 | <mat-form-field class="mat-block" fxFlex="45"> |
48 | 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 | 58 | <mat-error *ngIf="entityForm.get('title').hasError('required')"> |
51 | 59 | {{ 'firmware.title-required' | translate }} |
52 | 60 | </mat-error> |
53 | 61 | </mat-form-field> |
54 | 62 | <mat-form-field class="mat-block" fxFlex> |
55 | 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 | 65 | <mat-error *ngIf="entityForm.get('version').hasError('required')"> |
58 | 66 | {{ 'firmware.version-required' | translate }} |
59 | 67 | </mat-error> |
60 | 68 | </mat-form-field> |
61 | 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 | 91 | <tb-file-input |
83 | 92 | formControlName="file" |
84 | 93 | workFromFileObj="true" |
... | ... | @@ -86,6 +95,22 @@ |
86 | 95 | dropLabel="{{'resource.drop-file' | translate}}"> |
87 | 96 | </tb-file-input> |
88 | 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 | 114 | <div formGroupName="additionalInfo"> |
90 | 115 | <mat-form-field class="mat-block"> |
91 | 116 | <mat-label translate>firmware.description</mat-label> | ... | ... |
... | ... | @@ -83,6 +83,8 @@ export class FirmwaresComponent extends EntityComponent<Firmware> implements OnI |
83 | 83 | const form = this.fb.group({ |
84 | 84 | title: [entity ? entity.title : '', [Validators.required, Validators.maxLength(255)]], |
85 | 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 | 88 | additionalInfo: this.fb.group( |
87 | 89 | { |
88 | 90 | description: [entity && entity.additionalInfo ? entity.additionalInfo.description : ''], |
... | ... | @@ -90,28 +92,31 @@ export class FirmwaresComponent extends EntityComponent<Firmware> implements OnI |
90 | 92 | ) |
91 | 93 | }); |
92 | 94 | if (this.isAdd) { |
93 | - form.addControl('checksumAlgorithm', this.fb.control(null)); | |
94 | - form.addControl('checksum', this.fb.control('', Validators.maxLength(1020))); | |
95 | 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 | 101 | return form; |
98 | 102 | } |
99 | 103 | |
100 | 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 | 105 | this.entityForm.patchValue({ |
106 | 106 | title: entity.title, |
107 | 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 | 113 | additionalInfo: { |
109 | 114 | description: entity.additionalInfo ? entity.additionalInfo.description : '' |
110 | 115 | } |
111 | 116 | }); |
112 | 117 | } |
113 | 118 | |
114 | - onFirmwareIdCopied($event) { | |
119 | + onFirmwareIdCopied() { | |
115 | 120 | this.store.dispatch(new ActionNotificationShow( |
116 | 121 | { |
117 | 122 | message: this.translate.instant('firmware.idCopiedMessage'), |
... | ... | @@ -121,4 +126,15 @@ export class FirmwaresComponent extends EntityComponent<Firmware> implements OnI |
121 | 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 | 37 | title?: string; |
38 | 38 | version?: string; |
39 | 39 | hasData?: boolean; |
40 | + fileName: string; | |
41 | + checksum?: ChecksumAlgorithm; | |
42 | + checksumAlgorithm?: string; | |
43 | + contentType: string; | |
44 | + dataSize?: number; | |
40 | 45 | additionalInfo?: any; |
41 | 46 | } |
42 | 47 | |
43 | 48 | export interface Firmware extends FirmwareInfo { |
44 | 49 | file?: File; |
45 | 50 | data: string; |
46 | - fileName: string; | |
47 | - checksum?: ChecksumAlgorithm; | |
48 | - checksumAlgorithm?: string; | |
49 | - contentType: string; | |
50 | 51 | } | ... | ... |
... | ... | @@ -1907,8 +1907,11 @@ |
1907 | 1907 | "firmware": { |
1908 | 1908 | "add": "Add firmware", |
1909 | 1909 | "checksum": "Checksum", |
1910 | + "checksum-copied-message": "Firmware checksum has been copied to clipboard", | |
1910 | 1911 | "checksum-required": "Checksum is required.", |
1911 | 1912 | "checksum-algorithm": "Checksum algorithm", |
1913 | + "content-type": "Content type", | |
1914 | + "copy-checksum": "Copy checksum", | |
1912 | 1915 | "copyId": "Copy firmware Id", |
1913 | 1916 | "description": "Description", |
1914 | 1917 | "delete": "Delete firmware", |
... | ... | @@ -1917,12 +1920,15 @@ |
1917 | 1920 | "delete-firmwares-action-title": "Delete { count, plural, 1 {1 firmware} other {# firmwares} }", |
1918 | 1921 | "delete-firmwares-text": "Be careful, after the confirmation all selected resources will be removed.", |
1919 | 1922 | "delete-firmwares-title": "Are you sure you want to delete { count, plural, 1 {1 firmware} other {# firmwares} }?", |
1923 | + "download": "Download firmware", | |
1920 | 1924 | "drop-file": "Drop a firmware file or click to select a file to upload.", |
1921 | 1925 | "empty": "Firmware is empty", |
1922 | - "export": "Export firmware", | |
1923 | 1926 | "idCopiedMessage": "Firmware Id has been copied to clipboard", |
1924 | 1927 | "no-firmware-matching": "No firmware matching '{{entity}}' were found.", |
1925 | 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 | 1932 | "firmware": "Firmware", |
1927 | 1933 | "firmware-details": "Firmware details", |
1928 | 1934 | "firmware-required": "Firmware is required.", | ... | ... |