Skip to content

Commit b6ed831

Browse files
committed
MOBILE-2272 attachments: Make -1 mean unlimited in size and files
1 parent f780b3a commit b6ed831

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

src/assets/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,7 @@
18611861
"core.mainmenu.help": "Help",
18621862
"core.mainmenu.logout": "Log out",
18631863
"core.mainmenu.website": "Website",
1864+
"core.maxfilesize": "Maximum size for new files: {{$a}}",
18641865
"core.maxsizeandattachments": "Maximum file size: {{$a.size}}, maximum number of files: {{$a.attachments}}",
18651866
"core.min": "min",
18661867
"core.mins": "mins",

src/components/attachments/attachments.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import { CoreFileUploaderHelperProvider } from '@core/fileuploader/providers/hel
3939
})
4040
export class CoreAttachmentsComponent implements OnInit {
4141
@Input() files: any[]; // List of attachments. New attachments will be added to this array.
42-
@Input() maxSize: number; // Max size for attachments. If not defined, 0 or -1, unknown size.
43-
@Input() maxSubmissions: number; // Max number of attachments. If -1 or not defined, unknown limit.
42+
@Input() maxSize: number; // Max size for attachments. -1 means unlimited, not defined or 0 means unknown limit.
43+
@Input() maxSubmissions: number; // Max number of attachments. -1 means unlimited, not defined means unknown limit.
4444
@Input() component: string; // Component the downloaded files will be linked to.
4545
@Input() componentId: string | number; // Component ID.
4646
@Input() allowOffline: boolean | string; // Whether to allow selecting files in offline.
@@ -61,17 +61,18 @@ export class CoreAttachmentsComponent implements OnInit {
6161
* Component being initialized.
6262
*/
6363
ngOnInit(): void {
64-
this.maxSize = Number(this.maxSize); // Make sure it's defined and it's a number.
65-
this.maxSize = !isNaN(this.maxSize) && this.maxSize > 0 ? this.maxSize : -1;
64+
this.maxSize = Number(this.maxSize) || 0; // Make sure it's defined and it's a number.
6665

67-
if (this.maxSize == -1) {
66+
if (this.maxSize === 0) {
6867
this.maxSizeReadable = this.translate.instant('core.unknown');
69-
} else {
68+
} else if (this.maxSize > 0) {
7069
this.maxSizeReadable = this.textUtils.bytesToSize(this.maxSize, 2);
70+
} else {
71+
this.maxSizeReadable = this.translate.instant('core.unlimited');
7172
}
7273

7374
if (typeof this.maxSubmissions == 'undefined' || this.maxSubmissions < 0) {
74-
this.maxSubmissionsReadable = this.translate.instant('core.unknown');
75+
this.maxSubmissionsReadable = this.maxSubmissions < 0 ? undefined : this.translate.instant('core.unknown');
7576
this.unlimitedFiles = true;
7677
} else {
7778
this.maxSubmissionsReadable = String(this.maxSubmissions);

src/components/attachments/core-attachments.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<ion-item text-wrap>
2-
{{ 'core.maxsizeandattachments' | translate:{$a: {size: maxSizeReadable, attachments: maxSubmissionsReadable} } }}
2+
<span *ngIf="maxSubmissionsReadable">{{ 'core.maxsizeandattachments' | translate:{$a: {size: maxSizeReadable, attachments: maxSubmissionsReadable} } }}</span>
3+
<span *ngIf="!maxSubmissionsReadable">{{ 'core.maxfilesize' | translate:{$a: maxSizeReadable} }}</span>
34
<span [core-mark-required]="required" class="core-mark-required"></span>
45
</ion-item>
56
<ion-item text-wrap *ngIf="fileTypes && fileTypes.mimetypes && fileTypes.mimetypes.length">

src/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
"loadmore": "Load more",
144144
"location": "Location",
145145
"lostconnection": "Your authentication token is invalid or has expired. You will have to reconnect to the site.",
146+
"maxfilesize": "Maximum size for new files: {{$a}}",
146147
"maxsizeandattachments": "Maximum file size: {{$a.size}}, maximum number of files: {{$a.attachments}}",
147148
"min": "min",
148149
"mins": "mins",

upgrade.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
This files describes API changes in the Moodle Mobile app,
22
information provided here is intended especially for developers.
33

4+
=== 3.9.3 ===
5+
6+
- In the core-attachments component, passing a -1 as maxSize or maxSubmissions used to mean "unknown limit". Now -1 means unlimited.
7+
48
=== 3.8.3 ===
59

610
- CoreFileProvider.writeFileDataInFile has been deprecated. Please use CoreFileHelperProvider.writeFileDataInFile instead.

0 commit comments

Comments
 (0)