MOBILE-3780 course: Use right max upload size when set to course limit
parent
9a63793cf2
commit
628f380d7c
|
@ -35,6 +35,7 @@ import { CoreGroups } from '@services/groups';
|
|||
import { AddonModAssignSync, AddonModAssignSyncResult } from '../assign-sync';
|
||||
import { CoreUser } from '@features/user/services/user';
|
||||
import { CoreGradesHelper } from '@features/grades/services/grades-helper';
|
||||
import { CoreCourses } from '@features/courses/services/courses';
|
||||
|
||||
/**
|
||||
* Handler to prefetch assigns.
|
||||
|
@ -252,6 +253,8 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref
|
|||
promises.push(this.prefetchSubmissions(assign, courseId, module.id, userId, siteId));
|
||||
|
||||
promises.push(CoreCourseHelper.getModuleCourseIdByInstance(assign.id, 'assign', siteId));
|
||||
// Get course data, needed to determine upload max size if it's configured to be course limit.
|
||||
promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId)));
|
||||
|
||||
// Download intro files and attachments. Do not call getFiles because it'd call some WS twice.
|
||||
let files: CoreWSFile[] = assign.introattachments || [];
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<ion-item-divider class="ion-text-wrap" sticky="true">
|
||||
<ion-label><h2>{{ plugin.name }}</h2></ion-label>
|
||||
</ion-item-divider>
|
||||
<core-attachments [files]="files" [maxSize]="maxSize" [maxSubmissions]="maxSubmissions"
|
||||
<core-attachments [files]="files" [maxSize]="maxSize" [maxSubmissions]="maxSubmissions" [courseId]="assign.course"
|
||||
[component]="component" [componentId]="assign.cmid" [acceptedTypes]="acceptedTypes" [allowOffline]="allowOffline">
|
||||
</core-attachments>
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<span *ngIf="editMode && form">
|
||||
<span [core-mark-required]="field.required" class="core-mark-required"></span>
|
||||
<core-attachments [files]="files" [maxSize]="maxSizeBytes" maxSubmissions="1" [component]="component"
|
||||
[componentId]="componentId" [allowOffline]="true">
|
||||
[componentId]="componentId" [allowOffline]="true" [courseId]="database?.course">
|
||||
</core-attachments>
|
||||
<core-input-errors *ngIf="error" [errorText]="error"></core-input-errors>
|
||||
</span>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<span *ngIf="editMode && form" [formGroup]="form">
|
||||
<span [core-mark-required]="field.required" class="core-mark-required"></span>
|
||||
<core-attachments [files]="files" [maxSize]="maxSizeBytes" maxSubmissions="1" [component]="component"
|
||||
[componentId]="componentId" [allowOffline]="true" acceptedTypes="image">
|
||||
[componentId]="componentId" [allowOffline]="true" acceptedTypes="image" [courseId]="database?.course">
|
||||
</core-attachments>
|
||||
<core-input-errors *ngIf="error" [errorText]="error"></core-input-errors>
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import { Injectable } from '@angular/core';
|
|||
import { CoreComments } from '@features/comments/services/comments';
|
||||
import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/activity-prefetch-handler';
|
||||
import { CoreCourseCommonModWSOptions, CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course';
|
||||
import { CoreCourses } from '@features/courses/services/courses';
|
||||
import { CoreFilepool } from '@services/filepool';
|
||||
import { CoreGroup, CoreGroups } from '@services/groups';
|
||||
import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
||||
|
@ -269,6 +270,9 @@ export class AddonModDataPrefetchHandlerService extends CoreCourseActivityPrefet
|
|||
// Add Basic Info to manage links.
|
||||
promises.push(CoreCourse.getModuleBasicInfoByInstance(database.id, 'data', siteId));
|
||||
|
||||
// Get course data, needed to determine upload max size if it's configured to be course limit.
|
||||
promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId)));
|
||||
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
<div *ngIf="advanced" id="addon-mod-forum-advanced">
|
||||
<core-attachments *ngIf="forum.id && forum.maxattachments > 0"
|
||||
[maxSize]="forum.maxbytes" [maxSubmissions]="forum.maxattachments" [allowOffline]="true" [files]="replyData.files"
|
||||
[component]="component" [componentId]="forum.cmid">
|
||||
[component]="component" [componentId]="forum.cmid" [courseId]="forum.course">
|
||||
</core-attachments>
|
||||
</div>
|
||||
<ion-grid>
|
||||
|
|
|
@ -139,7 +139,7 @@
|
|||
<div *ngIf="advanced" [id]="'addon-forum-reply-edit-form-advanced-' + uniqueId">
|
||||
<core-attachments
|
||||
[files]="replyData.files" [maxSize]="forum.maxbytes" [maxSubmissions]="forum.maxattachments"
|
||||
[component]="component" [componentId]="forum.cmid" [allowOffline]="true">
|
||||
[component]="component" [componentId]="forum.cmid" [allowOffline]="true" [courseId]="courseId">
|
||||
</core-attachments>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
</ion-item>
|
||||
<core-attachments *ngIf="canCreateAttachments && forum && forum.maxattachments > 0"
|
||||
[files]="newDiscussion.files" [maxSize]="forum.maxbytes" [maxSubmissions]="forum.maxattachments"
|
||||
[component]="component" [componentId]="forum.cmid" [allowOffline]="true">
|
||||
[component]="component" [componentId]="forum.cmid" [allowOffline]="true" [courseId]="courseId">
|
||||
</core-attachments>
|
||||
</div>
|
||||
<ion-item>
|
||||
|
|
|
@ -86,8 +86,8 @@ export class AddonModForumNewDiscussionPage implements OnInit, OnDestroy, CanLea
|
|||
|
||||
advanced = false; // Display all form fields.
|
||||
accessInfo: AddonModForumAccessInformation = {};
|
||||
courseId!: number;
|
||||
|
||||
protected courseId!: number;
|
||||
protected cmId!: number;
|
||||
protected forumId!: number;
|
||||
protected timeCreated!: number;
|
||||
|
|
|
@ -24,6 +24,7 @@ import { CoreGroups, CoreGroupsProvider } from '@services/groups';
|
|||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { AddonModForumSync } from '../forum-sync';
|
||||
import { makeSingleton } from '@singletons';
|
||||
import { CoreCourses } from '@features/courses/services/courses';
|
||||
|
||||
/**
|
||||
* Handler to prefetch forums.
|
||||
|
@ -229,6 +230,9 @@ export class AddonModForumPrefetchHandlerService extends CoreCourseActivityPrefe
|
|||
promises.push(CoreUser.getUserPreference(AddonModForumProvider.PREFERENCE_SORTORDER, siteId));
|
||||
}
|
||||
|
||||
// Get course data, needed to determine upload max size if it's configured to be course limit.
|
||||
promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId)));
|
||||
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
<ion-label><h2>{{ 'addon.mod_glossary.attachment' | translate }}</h2></ion-label>
|
||||
</ion-item-divider>
|
||||
<core-attachments [files]="attachments" [component]="component" [componentId]="glossary.coursemodule"
|
||||
[allowOffline]="true">
|
||||
[allowOffline]="true" [courseId]="courseId">
|
||||
</core-attachments>
|
||||
<ng-container *ngIf="glossary.usedynalink">
|
||||
<ion-item-divider>
|
||||
|
|
|
@ -16,9 +16,11 @@ import { Injectable } from '@angular/core';
|
|||
import { CoreComments } from '@features/comments/services/comments';
|
||||
import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/activity-prefetch-handler';
|
||||
import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course';
|
||||
import { CoreCourses } from '@features/courses/services/courses';
|
||||
import { CoreUser } from '@features/user/services/user';
|
||||
import { CoreFilepool } from '@services/filepool';
|
||||
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSFile } from '@services/ws';
|
||||
import { makeSingleton } from '@singletons';
|
||||
import { AddonModGlossary, AddonModGlossaryEntry, AddonModGlossaryGlossary, AddonModGlossaryProvider } from '../glossary';
|
||||
|
@ -210,6 +212,9 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr
|
|||
promises.push(CoreCourse.getModuleBasicInfo(module.id, siteId));
|
||||
promises.push(CoreCourse.getModuleBasicInfoByInstance(glossary.id, 'glossary', siteId));
|
||||
|
||||
// Get course data, needed to determine upload max size if it's configured to be course limit.
|
||||
promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId)));
|
||||
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import { Injectable } from '@angular/core';
|
|||
import { CoreError } from '@classes/errors/error';
|
||||
import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/activity-prefetch-handler';
|
||||
import { CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features/course/services/course';
|
||||
import { CoreCourses } from '@features/courses/services/courses';
|
||||
import { CoreQuestionHelper } from '@features/question/services/question-helper';
|
||||
import { CoreFilepool } from '@services/filepool';
|
||||
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
||||
|
@ -374,6 +375,9 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
|
|||
promises.push(this.prefetchGradeAndFeedback(quiz, modOptions, siteId));
|
||||
promises.push(AddonModQuiz.getAttemptAccessInformation(quiz.id, 0, modOptions)); // Last attempt.
|
||||
|
||||
// Get course data, needed to determine upload max size if it's configured to be course limit.
|
||||
promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId)));
|
||||
|
||||
await Promise.all(promises);
|
||||
|
||||
// We have quiz data, now we'll get specific data for each attempt.
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
</ion-item>
|
||||
<core-attachments *ngIf="edit && workshop.overallfeedbackfiles" [files]="data.assessment?.feedbackattachmentfiles"
|
||||
[maxSize]="workshop.overallfeedbackmaxbytes" [maxSubmissions]="workshop.overallfeedbackfiles"
|
||||
[component]="component" [componentId]="componentId" [allowOffline]="true">
|
||||
[component]="component" [componentId]="componentId" [allowOffline]="true" [courseId]="workshop.course">
|
||||
</core-attachments>
|
||||
<ion-item *ngIf="edit && access && access.canallocate">
|
||||
<ion-label position="stacked">
|
||||
|
|
|
@ -39,7 +39,8 @@
|
|||
|
||||
<core-attachments *ngIf="fileAvailable" [files]="attachments" [maxSize]="workshop.maxbytes"
|
||||
[maxSubmissions]="workshop.nattachments" [component]="component" [componentId]="workshop.coursemodule"
|
||||
allowOffline="true" [acceptedTypes]="workshop.submissionfiletypes" [required]="fileRequired">
|
||||
allowOffline="true" [acceptedTypes]="workshop.submissionfiletypes" [required]="fileRequired"
|
||||
[courseId]="workshop.course">
|
||||
</core-attachments>
|
||||
</form>
|
||||
</core-loading>
|
||||
|
|
|
@ -16,6 +16,7 @@ import { AddonModDataSyncResult } from '@addons/mod/data/services/data-sync';
|
|||
import { Injectable } from '@angular/core';
|
||||
import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/activity-prefetch-handler';
|
||||
import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course';
|
||||
import { CoreCourses } from '@features/courses/services/courses';
|
||||
import { CoreUser } from '@features/user/services/user';
|
||||
import { CoreFilepool } from '@services/filepool';
|
||||
import { CoreGroup, CoreGroups } from '@services/groups';
|
||||
|
@ -372,6 +373,9 @@ export class AddonModWorkshopPrefetchHandlerService extends CoreCourseActivityPr
|
|||
promises.push(CoreCourse.getModuleBasicInfoByInstance(workshop.id, 'workshop', siteId));
|
||||
promises.push(CoreCourse.getModuleBasicGradeInfo(module.id, siteId));
|
||||
|
||||
// Get course data, needed to determine upload max size if it's configured to be course limit.
|
||||
promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId)));
|
||||
|
||||
await Promise.all(promises);
|
||||
|
||||
// Prefetch user profiles.
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
<core-attachments *ngIf="uploadFilesSupported && essayQuestion.attachmentsDraftIdInput" [files]="attachments"
|
||||
[component]="component" [componentId]="componentId" [maxSize]="essayQuestion.attachmentsMaxBytes"
|
||||
[maxSubmissions]="essayQuestion.attachmentsMaxFiles" [allowOffline]="offlineEnabled"
|
||||
[acceptedTypes]="essayQuestion.attachmentsAcceptedTypes">
|
||||
[acceptedTypes]="essayQuestion.attachmentsAcceptedTypes" [courseId]="courseId">
|
||||
</core-attachments>
|
||||
|
||||
<input *ngIf="essayQuestion.attachmentsDraftIdInput" type="hidden" [name]="essayQuestion.attachmentsDraftIdInput.name"
|
||||
|
|
|
@ -23,6 +23,8 @@ import { CoreApp } from '@services/app';
|
|||
import { CoreDomUtils } from '@services/utils/dom';
|
||||
import { CoreFileUploaderHelper } from '@features/fileuploader/services/fileuploader-helper';
|
||||
import { CoreFileEntry } from '@services/file-helper';
|
||||
import { CoreCourses } from '@features/courses/services/courses';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
|
||||
/**
|
||||
* Component to render attachments, allow adding more and delete the current ones.
|
||||
|
@ -44,13 +46,14 @@ import { CoreFileEntry } from '@services/file-helper';
|
|||
export class CoreAttachmentsComponent implements OnInit {
|
||||
|
||||
@Input() files?: CoreFileEntry[]; // List of attachments. New attachments will be added to this array.
|
||||
@Input() maxSize?: number; // Max size for attachments. -1 means unlimited, 0 means user max size, not defined means unknown.
|
||||
@Input() maxSize?: number; // Max size. -1 means unlimited, 0 means course/user max size, not defined means unknown.
|
||||
@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() componentId?: string | number; // Component ID.
|
||||
@Input() allowOffline?: boolean | string; // Whether to allow selecting files in offline.
|
||||
@Input() acceptedTypes?: string; // List of supported filetypes. If undefined, all types supported.
|
||||
@Input() required?: boolean; // Whether to display the required mark.
|
||||
@Input() courseId?: number; // Course ID.
|
||||
|
||||
maxSizeReadable?: string;
|
||||
maxSubmissionsReadable?: string;
|
||||
|
@ -65,15 +68,7 @@ export class CoreAttachmentsComponent implements OnInit {
|
|||
this.maxSize = this.maxSize !== null ? Number(this.maxSize) : NaN;
|
||||
|
||||
if (this.maxSize === 0) {
|
||||
const currentSite = CoreSites.getCurrentSite();
|
||||
const siteInfo = currentSite?.getInfo();
|
||||
|
||||
if (siteInfo?.usermaxuploadfilesize) {
|
||||
this.maxSize = siteInfo.usermaxuploadfilesize;
|
||||
this.maxSizeReadable = CoreTextUtils.bytesToSize(this.maxSize, 2);
|
||||
} else {
|
||||
this.maxSizeReadable = Translate.instant('core.unknown');
|
||||
}
|
||||
this.getMaxSizeOfArea();
|
||||
} else if (this.maxSize > 0) {
|
||||
this.maxSizeReadable = CoreTextUtils.bytesToSize(this.maxSize, 2);
|
||||
} else if (this.maxSize === -1) {
|
||||
|
@ -97,6 +92,36 @@ export class CoreAttachmentsComponent implements OnInit {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max size of the area.
|
||||
*
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
protected async getMaxSizeOfArea(): Promise<void> {
|
||||
if (this.courseId) {
|
||||
// Check course max size.
|
||||
const course = await CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', this.courseId));
|
||||
|
||||
if (course?.maxbytes) {
|
||||
this.maxSize = course.maxbytes;
|
||||
this.maxSizeReadable = CoreTextUtils.bytesToSize(this.maxSize, 2);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check user max size.
|
||||
const currentSite = CoreSites.getCurrentSite();
|
||||
const siteInfo = currentSite?.getInfo();
|
||||
|
||||
if (siteInfo?.usermaxuploadfilesize) {
|
||||
this.maxSize = siteInfo.usermaxuploadfilesize;
|
||||
this.maxSizeReadable = CoreTextUtils.bytesToSize(this.maxSize, 2);
|
||||
} else {
|
||||
this.maxSizeReadable = Translate.instant('core.unknown');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new attachment.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue