Skip to content

Commit 82dbbf6

Browse files
added excplicit sorting of attachments by id, increased preview file size to 10MB
1 parent 7fe7d0b commit 82dbbf6

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aquality-tracking-ui",
3-
"version": "1.4.3",
3+
"version": "1.4.4",
44
"scripts": {
55
"ng": "ng",
66
"start": "ng serve",

src/app/elements/lookup/attachment-modal/attachment-modal.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ <h6 class="modal-sub-title col-sm-8">{{subTitle}}</h6>
2121
</div>
2222
<div class="col-sm-4 line-margin">
2323
<div class="col-sm-12 btnGroup">
24-
<button *ngFor="let attach of testResultAttachments" (click)="showAttachment(attach)"
24+
<button *ngFor="let attach of sortedTestResultAttachmentsById" (click)="showAttachment(attach)"
2525
[class.selected]="attach === selectedTestResultAttachment"
2626
class="btn btn-group-item bg-light">{{attach['name']}}</button>
2727
</div>

src/app/elements/lookup/attachment-modal/attachment-modal.component.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export class AttachmentModalComponent implements OnChanges {
2424
selectedTestResultAttachment: TestResultAttachment;
2525
supportedPreviewTypes = ['text', 'image', 'message'];
2626
icon = faFile;
27+
private readonly maxFileSizeBytes = 10 * 1024 * 1024;
28+
private readonly base64SizeMultiplier = 4 / 3;
2729

2830
constructor(private sanitizer: DomSanitizer, private testResultService: TestResultService) {
2931
}
@@ -35,6 +37,10 @@ export class AttachmentModalComponent implements OnChanges {
3537
}
3638
}
3739

40+
get sortedTestResultAttachmentsById(): TestResultAttachment[] {
41+
return this.testResultAttachments?.sort((a, b) => a.id - b.id) || [];
42+
}
43+
3844
isSupportedPreviewFileType(): boolean {
3945
let isSupported = false;
4046
this.supportedPreviewTypes.forEach(type => {
@@ -48,7 +54,16 @@ export class AttachmentModalComponent implements OnChanges {
4854
}
4955

5056
isSupportedPreviewFileSize(): boolean {
51-
return this.testResultAttachment.attachment.toString().length / 1024 / 1024 < 5;
57+
let attachmentSize = 0;
58+
59+
if (typeof this.testResultAttachment?.attachment === 'string') {
60+
const base64Length = this.testResultAttachment.attachment.length;
61+
attachmentSize = base64Length / this.base64SizeMultiplier;
62+
} else if (this.testResultAttachment?.attachment instanceof ArrayBuffer) {
63+
attachmentSize = this.testResultAttachment.attachment.byteLength;
64+
}
65+
66+
return attachmentSize <= this.maxFileSizeBytes;
5267
}
5368

5469
getNotSupportedMessage(): string {
@@ -57,7 +72,7 @@ export class AttachmentModalComponent implements OnChanges {
5772
message = 'Preview is not available for this file type.';
5873
}
5974
if (!this.isSupportedPreviewFileSize()) {
60-
message = 'Preview is not available, the file size should be less than 5Mb.';
75+
message = 'Preview is not available, the file size should be less than 10MB.';
6176
} else { message = 'Preview is not available for the file.'; }
6277
return `${message} You can download the file.`;
6378
}

0 commit comments

Comments
 (0)