MOBILE-2272 attachments: Make -1 mean unlimited in size and files

main
Dani Palou 2020-09-25 15:11:32 +02:00
parent f780b3afc3
commit b6ed831b25
5 changed files with 16 additions and 8 deletions

View File

@ -1861,6 +1861,7 @@
"core.mainmenu.help": "Help", "core.mainmenu.help": "Help",
"core.mainmenu.logout": "Log out", "core.mainmenu.logout": "Log out",
"core.mainmenu.website": "Website", "core.mainmenu.website": "Website",
"core.maxfilesize": "Maximum size for new files: {{$a}}",
"core.maxsizeandattachments": "Maximum file size: {{$a.size}}, maximum number of files: {{$a.attachments}}", "core.maxsizeandattachments": "Maximum file size: {{$a.size}}, maximum number of files: {{$a.attachments}}",
"core.min": "min", "core.min": "min",
"core.mins": "mins", "core.mins": "mins",

View File

@ -39,8 +39,8 @@ import { CoreFileUploaderHelperProvider } from '@core/fileuploader/providers/hel
}) })
export class CoreAttachmentsComponent implements OnInit { export class CoreAttachmentsComponent implements OnInit {
@Input() files: any[]; // List of attachments. New attachments will be added to this array. @Input() files: any[]; // List of attachments. New attachments will be added to this array.
@Input() maxSize: number; // Max size for attachments. If not defined, 0 or -1, unknown size. @Input() maxSize: number; // Max size for attachments. -1 means unlimited, not defined or 0 means unknown limit.
@Input() maxSubmissions: number; // Max number of attachments. If -1 or not defined, unknown limit. @Input() maxSubmissions: number; // Max number of attachments. -1 means unlimited, not defined means unknown limit.
@Input() component: string; // Component the downloaded files will be linked to. @Input() component: string; // Component the downloaded files will be linked to.
@Input() componentId: string | number; // Component ID. @Input() componentId: string | number; // Component ID.
@Input() allowOffline: boolean | string; // Whether to allow selecting files in offline. @Input() allowOffline: boolean | string; // Whether to allow selecting files in offline.
@ -61,17 +61,18 @@ export class CoreAttachmentsComponent implements OnInit {
* Component being initialized. * Component being initialized.
*/ */
ngOnInit(): void { ngOnInit(): void {
this.maxSize = Number(this.maxSize); // Make sure it's defined and it's a number. this.maxSize = Number(this.maxSize) || 0; // Make sure it's defined and it's a number.
this.maxSize = !isNaN(this.maxSize) && this.maxSize > 0 ? this.maxSize : -1;
if (this.maxSize == -1) { if (this.maxSize === 0) {
this.maxSizeReadable = this.translate.instant('core.unknown'); this.maxSizeReadable = this.translate.instant('core.unknown');
} else { } else if (this.maxSize > 0) {
this.maxSizeReadable = this.textUtils.bytesToSize(this.maxSize, 2); this.maxSizeReadable = this.textUtils.bytesToSize(this.maxSize, 2);
} else {
this.maxSizeReadable = this.translate.instant('core.unlimited');
} }
if (typeof this.maxSubmissions == 'undefined' || this.maxSubmissions < 0) { if (typeof this.maxSubmissions == 'undefined' || this.maxSubmissions < 0) {
this.maxSubmissionsReadable = this.translate.instant('core.unknown'); this.maxSubmissionsReadable = this.maxSubmissions < 0 ? undefined : this.translate.instant('core.unknown');
this.unlimitedFiles = true; this.unlimitedFiles = true;
} else { } else {
this.maxSubmissionsReadable = String(this.maxSubmissions); this.maxSubmissionsReadable = String(this.maxSubmissions);

View File

@ -1,5 +1,6 @@
<ion-item text-wrap> <ion-item text-wrap>
{{ 'core.maxsizeandattachments' | translate:{$a: {size: maxSizeReadable, attachments: maxSubmissionsReadable} } }} <span *ngIf="maxSubmissionsReadable">{{ 'core.maxsizeandattachments' | translate:{$a: {size: maxSizeReadable, attachments: maxSubmissionsReadable} } }}</span>
<span *ngIf="!maxSubmissionsReadable">{{ 'core.maxfilesize' | translate:{$a: maxSizeReadable} }}</span>
<span [core-mark-required]="required" class="core-mark-required"></span> <span [core-mark-required]="required" class="core-mark-required"></span>
</ion-item> </ion-item>
<ion-item text-wrap *ngIf="fileTypes && fileTypes.mimetypes && fileTypes.mimetypes.length"> <ion-item text-wrap *ngIf="fileTypes && fileTypes.mimetypes && fileTypes.mimetypes.length">

View File

@ -143,6 +143,7 @@
"loadmore": "Load more", "loadmore": "Load more",
"location": "Location", "location": "Location",
"lostconnection": "Your authentication token is invalid or has expired. You will have to reconnect to the site.", "lostconnection": "Your authentication token is invalid or has expired. You will have to reconnect to the site.",
"maxfilesize": "Maximum size for new files: {{$a}}",
"maxsizeandattachments": "Maximum file size: {{$a.size}}, maximum number of files: {{$a.attachments}}", "maxsizeandattachments": "Maximum file size: {{$a.size}}, maximum number of files: {{$a.attachments}}",
"min": "min", "min": "min",
"mins": "mins", "mins": "mins",

View File

@ -1,6 +1,10 @@
This files describes API changes in the Moodle Mobile app, This files describes API changes in the Moodle Mobile app,
information provided here is intended especially for developers. information provided here is intended especially for developers.
=== 3.9.3 ===
- In the core-attachments component, passing a -1 as maxSize or maxSubmissions used to mean "unknown limit". Now -1 means unlimited.
=== 3.8.3 === === 3.8.3 ===
- CoreFileProvider.writeFileDataInFile has been deprecated. Please use CoreFileHelperProvider.writeFileDataInFile instead. - CoreFileProvider.writeFileDataInFile has been deprecated. Please use CoreFileHelperProvider.writeFileDataInFile instead.