commit
6cdc80a104
|
@ -408,7 +408,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy {
|
|||
return Promise.all(promises);
|
||||
}).then(() => {
|
||||
// Get submission status.
|
||||
return this.assignProvider.getSubmissionStatus(this.assign.id, this.submitId, isBlind);
|
||||
return this.assignProvider.getSubmissionStatusWithRetry(this.assign, this.submitId, isBlind);
|
||||
}).then((response) => {
|
||||
|
||||
const promises = [];
|
||||
|
|
|
@ -221,7 +221,7 @@ export class AddonModAssignSyncProvider extends CoreSyncBaseProvider {
|
|||
|
||||
courseId = submissions.length > 0 ? submissions[0].courseid : grades[0].courseid;
|
||||
|
||||
return this.assignProvider.getAssignmentById(courseId, assignId, siteId).then((assignData) => {
|
||||
return this.assignProvider.getAssignmentById(courseId, assignId, false, siteId).then((assignData) => {
|
||||
assign = assignData;
|
||||
|
||||
const promises = [];
|
||||
|
|
|
@ -120,11 +120,12 @@ export class AddonModAssignProvider {
|
|||
*
|
||||
* @param {number} courseId Course ID the assignment belongs to.
|
||||
* @param {number} cmId Assignment module ID.
|
||||
* @param {boolean} [ignoreCache] True if it should ignore cached data (it will always fail in offline or server down).
|
||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||
* @return {Promise<any>} Promise resolved with the assignment.
|
||||
*/
|
||||
getAssignment(courseId: number, cmId: number, siteId?: string): Promise<any> {
|
||||
return this.getAssignmentByField(courseId, 'cmid', cmId, siteId);
|
||||
getAssignment(courseId: number, cmId: number, ignoreCache?: boolean, siteId?: string): Promise<any> {
|
||||
return this.getAssignmentByField(courseId, 'cmid', cmId, ignoreCache, siteId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,19 +134,27 @@ export class AddonModAssignProvider {
|
|||
* @param {number} courseId Course ID.
|
||||
* @param {string} key Name of the property to check.
|
||||
* @param {any} value Value to search.
|
||||
* @param {boolean} [ignoreCache] True if it should ignore cached data (it will always fail in offline or server down).
|
||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||
* @return {Promise<any>} Promise resolved when the assignment is retrieved.
|
||||
*/
|
||||
protected getAssignmentByField(courseId: number, key: string, value: any, siteId?: string): Promise<any> {
|
||||
protected getAssignmentByField(courseId: number, key: string, value: any, ignoreCache?: boolean, siteId?: string)
|
||||
: Promise<any> {
|
||||
|
||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||
const params = {
|
||||
courseids: [courseId],
|
||||
includenotenrolledcourses: 1
|
||||
},
|
||||
preSets = {
|
||||
preSets: CoreSiteWSPreSets = {
|
||||
cacheKey: this.getAssignmentCacheKey(courseId)
|
||||
};
|
||||
|
||||
if (ignoreCache) {
|
||||
preSets.getFromCache = false;
|
||||
preSets.emergencyCache = false;
|
||||
}
|
||||
|
||||
return site.read('mod_assign_get_assignments', params, preSets).catch(() => {
|
||||
// In 3.6 we added a new parameter includenotenrolledcourses that could cause offline data not to be found.
|
||||
// Retry again without the param to check if the request is already cached.
|
||||
|
@ -174,11 +183,12 @@ export class AddonModAssignProvider {
|
|||
*
|
||||
* @param {number} courseId Course ID the assignment belongs to.
|
||||
* @param {number} cmId Assignment instance ID.
|
||||
* @param {boolean} [ignoreCache] True if it should ignore cached data (it will always fail in offline or server down).
|
||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||
* @return {Promise<any>} Promise resolved with the assignment.
|
||||
*/
|
||||
getAssignmentById(courseId: number, id: number, siteId?: string): Promise<any> {
|
||||
return this.getAssignmentByField(courseId, 'id', id, siteId);
|
||||
getAssignmentById(courseId: number, id: number, ignoreCache?: boolean, siteId?: string): Promise<any> {
|
||||
return this.getAssignmentByField(courseId, 'id', id, ignoreCache, siteId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -196,18 +206,24 @@ export class AddonModAssignProvider {
|
|||
*
|
||||
* @param {number} assignId Assignment Id.
|
||||
* @param {number} userId User Id to be blinded.
|
||||
* @param {boolean} [ignoreCache] True if it should ignore cached data (it will always fail in offline or server down).
|
||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||
* @return {Promise<number>} Promise resolved with the user blind id.
|
||||
*/
|
||||
getAssignmentUserMappings(assignId: number, userId: number, siteId?: string): Promise<number> {
|
||||
getAssignmentUserMappings(assignId: number, userId: number, ignoreCache?: boolean, siteId?: string): Promise<number> {
|
||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||
const params = {
|
||||
assignmentids: [assignId]
|
||||
},
|
||||
preSets = {
|
||||
preSets: CoreSiteWSPreSets = {
|
||||
cacheKey: this.getAssignmentUserMappingsCacheKey(assignId)
|
||||
};
|
||||
|
||||
if (ignoreCache) {
|
||||
preSets.getFromCache = false;
|
||||
preSets.emergencyCache = false;
|
||||
}
|
||||
|
||||
return site.read('mod_assign_get_user_mappings', params, preSets).then((response) => {
|
||||
// Search the user.
|
||||
if (response.assignments && response.assignments.length) {
|
||||
|
@ -250,18 +266,24 @@ export class AddonModAssignProvider {
|
|||
* Returns grade information from assign_grades for the requested assignment id
|
||||
*
|
||||
* @param {number} assignId Assignment Id.
|
||||
* @param {boolean} [ignoreCache] True if it should ignore cached data (it will always fail in offline or server down).
|
||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||
* @return {Promise<any>} Resolved with requested info when done.
|
||||
*/
|
||||
getAssignmentGrades(assignId: number, siteId?: string): Promise<any> {
|
||||
getAssignmentGrades(assignId: number, ignoreCache?: boolean, siteId?: string): Promise<any> {
|
||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||
const params = {
|
||||
assignmentids: [assignId]
|
||||
},
|
||||
preSets = {
|
||||
preSets: CoreSiteWSPreSets = {
|
||||
cacheKey: this.getAssignmentGradesCacheKey(assignId)
|
||||
};
|
||||
|
||||
if (ignoreCache) {
|
||||
preSets.getFromCache = false;
|
||||
preSets.emergencyCache = false;
|
||||
}
|
||||
|
||||
return site.read('mod_assign_get_grades', params, preSets).then((response) => {
|
||||
// Search the assignment.
|
||||
if (response.assignments && response.assignments.length) {
|
||||
|
@ -421,18 +443,26 @@ export class AddonModAssignProvider {
|
|||
* Get an assignment submissions.
|
||||
*
|
||||
* @param {number} assignId Assignment id.
|
||||
* @param {boolean} [ignoreCache] True if it should ignore cached data (it will always fail in offline or server down).
|
||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||
* @return {Promise<{canviewsubmissions: boolean, submissions?: any[]}>} Promise resolved when done.
|
||||
*/
|
||||
getSubmissions(assignId: number, siteId?: string): Promise<{canviewsubmissions: boolean, submissions?: any[]}> {
|
||||
getSubmissions(assignId: number, ignoreCache?: boolean, siteId?: string)
|
||||
: Promise<{canviewsubmissions: boolean, submissions?: any[]}> {
|
||||
|
||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||
const params = {
|
||||
assignmentids: [assignId]
|
||||
},
|
||||
preSets = {
|
||||
preSets: CoreSiteWSPreSets = {
|
||||
cacheKey: this.getSubmissionsCacheKey(assignId)
|
||||
};
|
||||
|
||||
if (ignoreCache) {
|
||||
preSets.getFromCache = false;
|
||||
preSets.emergencyCache = false;
|
||||
}
|
||||
|
||||
return site.read('mod_assign_get_submissions', params, preSets).then((response): any => {
|
||||
// Check if we can view submissions, with enough permissions.
|
||||
if (response.warnings.length > 0 && response.warnings[0].warningcode == 1) {
|
||||
|
@ -505,6 +535,36 @@ export class AddonModAssignProvider {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about an assignment submission status for a given user.
|
||||
* If the data doesn't include the user submission, retry ignoring cache.
|
||||
*
|
||||
* @param {any} assign Assignment.
|
||||
* @param {number} [userId] User id (empty for current user).
|
||||
* @param {boolean} [isBlind] If blind marking is enabled or not.
|
||||
* @param {number} [filter=true] True to filter WS response and rewrite URLs, false otherwise.
|
||||
* @param {boolean} [ignoreCache] True if it should ignore cached data (it will always fail in offline or server down).
|
||||
* @param {string} [siteId] Site id (empty for current site).
|
||||
* @return {Promise<any>} Promise always resolved with the user submission status.
|
||||
*/
|
||||
getSubmissionStatusWithRetry(assign: any, userId?: number, isBlind?: boolean, filter: boolean = true, ignoreCache?: boolean,
|
||||
siteId?: string): Promise<any> {
|
||||
|
||||
return this.getSubmissionStatus(assign.id, userId, isBlind, filter, ignoreCache, siteId).then((response) => {
|
||||
const userSubmission = this.getSubmissionObjectFromAttempt(assign, response.lastattempt);
|
||||
|
||||
if (!userSubmission) {
|
||||
// Try again, ignoring cache.
|
||||
return this.getSubmissionStatus(assign.id, userId, isBlind, filter, true, siteId).catch(() => {
|
||||
// Error, return the first result even if it doesn't have the user submission.
|
||||
return response;
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cache key for get submission status data WS calls.
|
||||
*
|
||||
|
@ -553,11 +613,12 @@ export class AddonModAssignProvider {
|
|||
* @param {number} assignId ID of the assignment the submissions belong to.
|
||||
* @param {boolean} [blind] Whether the user data need to be blinded.
|
||||
* @param {any[]} [participants] List of participants in the assignment.
|
||||
* @param {boolean} [ignoreCache] True if it should ignore cached data (it will always fail in offline or server down).
|
||||
* @param {string} [siteId] Site id (empty for current site).
|
||||
* @return {Promise<any[]>} Promise always resolved. Resolve param is the formatted submissions.
|
||||
*/
|
||||
getSubmissionsUserData(submissions: any[], courseId: number, assignId: number, blind?: boolean, participants?: any[],
|
||||
siteId?: string): Promise<any[]> {
|
||||
ignoreCache?: boolean, siteId?: string): Promise<any[]> {
|
||||
|
||||
const promises = [],
|
||||
subs = [],
|
||||
|
@ -594,7 +655,7 @@ export class AddonModAssignProvider {
|
|||
// Blind but not blinded! (Moodle < 3.1.1, 3.2).
|
||||
delete submission.userid;
|
||||
|
||||
promise = this.getAssignmentUserMappings(assignId, submission.submitid, siteId).then((blindId) => {
|
||||
promise = this.getAssignmentUserMappings(assignId, submission.submitid, ignoreCache, siteId).then((blindId) => {
|
||||
submission.blindid = blindId;
|
||||
});
|
||||
} else if (!participant) {
|
||||
|
@ -677,10 +738,11 @@ export class AddonModAssignProvider {
|
|||
*
|
||||
* @param {number} assignId Assignment id.
|
||||
* @param {number} [groupId] Group id. If not defined, 0.
|
||||
* @param {boolean} [ignoreCache] True if it should ignore cached data (it will always fail in offline or server down).
|
||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||
* @return {Promise<any[]>} Promise resolved with the list of participants and summary of submissions.
|
||||
*/
|
||||
listParticipants(assignId: number, groupId?: number, siteId?: string): Promise<any[]> {
|
||||
listParticipants(assignId: number, groupId?: number, ignoreCache?: boolean, siteId?: string): Promise<any[]> {
|
||||
groupId = groupId || 0;
|
||||
|
||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||
|
@ -694,10 +756,15 @@ export class AddonModAssignProvider {
|
|||
groupid: groupId,
|
||||
filter: ''
|
||||
},
|
||||
preSets = {
|
||||
preSets: CoreSiteWSPreSets = {
|
||||
cacheKey: this.listParticipantsCacheKey(assignId, groupId)
|
||||
};
|
||||
|
||||
if (ignoreCache) {
|
||||
preSets.getFromCache = false;
|
||||
preSets.emergencyCache = false;
|
||||
}
|
||||
|
||||
return site.read('mod_assign_list_participants', params, preSets);
|
||||
});
|
||||
}
|
||||
|
@ -787,7 +854,7 @@ export class AddonModAssignProvider {
|
|||
invalidateContent(moduleId: number, courseId: number, siteId?: string): Promise<any> {
|
||||
siteId = siteId || this.sitesProvider.getCurrentSiteId();
|
||||
|
||||
return this.getAssignment(courseId, moduleId, siteId).then((assign) => {
|
||||
return this.getAssignment(courseId, moduleId, false, siteId).then((assign) => {
|
||||
const promises = [];
|
||||
|
||||
// Do not invalidate assignment data before getting assignment info, we need it!
|
||||
|
|
|
@ -150,14 +150,15 @@ export class AddonModAssignHelperProvider {
|
|||
* List the participants for a single assignment, with some summary info about their submissions.
|
||||
*
|
||||
* @param {any} assign Assignment object
|
||||
* @param {boolean} [ignoreCache] True if it should ignore cached data (it will always fail in offline or server down).
|
||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||
* @return {Promise<any[]} Promise resolved with the list of participants and summary of submissions.
|
||||
*/
|
||||
getParticipants(assign: any, siteId?: string): Promise<any[]> {
|
||||
getParticipants(assign: any, ignoreCache?: boolean, siteId?: string): Promise<any[]> {
|
||||
siteId = siteId || this.sitesProvider.getCurrentSiteId();
|
||||
|
||||
// Get the participants without specifying a group.
|
||||
return this.assignProvider.listParticipants(assign.id, undefined, siteId).then((participants) => {
|
||||
return this.assignProvider.listParticipants(assign.id, undefined, ignoreCache, siteId).then((participants) => {
|
||||
if (participants && participants.length > 0) {
|
||||
return participants;
|
||||
}
|
||||
|
@ -168,7 +169,8 @@ export class AddonModAssignHelperProvider {
|
|||
participants = {};
|
||||
|
||||
userGroups.forEach((userGroup) => {
|
||||
promises.push(this.assignProvider.listParticipants(assign.id, userGroup.id, siteId).then((parts) => {
|
||||
promises.push(this.assignProvider.listParticipants(assign.id, userGroup.id, ignoreCache, siteId)
|
||||
.then((parts) => {
|
||||
// Do not get repeated users.
|
||||
parts.forEach((participant) => {
|
||||
participants[participant.id] = participant;
|
||||
|
|
|
@ -92,19 +92,19 @@ export class AddonModAssignPrefetchHandler extends CoreCourseActivityPrefetchHan
|
|||
|
||||
siteId = siteId || this.sitesProvider.getCurrentSiteId();
|
||||
|
||||
return this.assignProvider.getAssignment(courseId, module.id, siteId).then((assign) => {
|
||||
return this.assignProvider.getAssignment(courseId, module.id, false, siteId).then((assign) => {
|
||||
// Get intro files and attachments.
|
||||
let files = assign.introattachments || [];
|
||||
files = files.concat(this.getIntroFilesFromInstance(module, assign));
|
||||
|
||||
// Now get the files in the submissions.
|
||||
return this.assignProvider.getSubmissions(assign.id, siteId).then((data) => {
|
||||
return this.assignProvider.getSubmissions(assign.id, false, siteId).then((data) => {
|
||||
const blindMarking = assign.blindmarking && !assign.revealidentities;
|
||||
|
||||
if (data.canviewsubmissions) {
|
||||
// Teacher, get all submissions.
|
||||
return this.assignProvider.getSubmissionsUserData(data.submissions, courseId, assign.id, blindMarking,
|
||||
undefined, siteId).then((submissions) => {
|
||||
undefined, false, siteId).then((submissions) => {
|
||||
|
||||
const promises = [];
|
||||
|
||||
|
@ -156,7 +156,8 @@ export class AddonModAssignPrefetchHandler extends CoreCourseActivityPrefetchHan
|
|||
protected getSubmissionFiles(assign: any, submitId: number, blindMarking: boolean, siteId?: string)
|
||||
: Promise<any[]> {
|
||||
|
||||
return this.assignProvider.getSubmissionStatus(assign.id, submitId, blindMarking, true, false, siteId).then((response) => {
|
||||
return this.assignProvider.getSubmissionStatusWithRetry(assign, submitId, blindMarking, true, false, siteId)
|
||||
.then((response) => {
|
||||
const promises = [];
|
||||
|
||||
if (response.lastattempt) {
|
||||
|
@ -200,6 +201,17 @@ export class AddonModAssignPrefetchHandler extends CoreCourseActivityPrefetchHan
|
|||
return this.assignProvider.invalidateContent(moduleId, courseId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidate WS calls needed to determine module status.
|
||||
*
|
||||
* @param {any} module Module.
|
||||
* @param {number} courseId Course ID the module belongs to.
|
||||
* @return {Promise<any>} Promise resolved when invalidated.
|
||||
*/
|
||||
invalidateModule(module: any, courseId: number): Promise<any> {
|
||||
return this.assignProvider.invalidateAssignmentData(courseId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the handler is enabled on a site level.
|
||||
*
|
||||
|
@ -238,12 +250,12 @@ export class AddonModAssignPrefetchHandler extends CoreCourseActivityPrefetchHan
|
|||
siteId = siteId || this.sitesProvider.getCurrentSiteId();
|
||||
|
||||
// Get assignment to retrieve all its submissions.
|
||||
promises.push(this.assignProvider.getAssignment(courseId, module.id, siteId).then((assign) => {
|
||||
promises.push(this.assignProvider.getAssignment(courseId, module.id, true, siteId).then((assign) => {
|
||||
const subPromises = [],
|
||||
blindMarking = assign.blindmarking && !assign.revealidentities;
|
||||
|
||||
if (blindMarking) {
|
||||
subPromises.push(this.assignProvider.getAssignmentUserMappings(assign.id, undefined, siteId).catch(() => {
|
||||
subPromises.push(this.assignProvider.getAssignmentUserMappings(assign.id, undefined, true, siteId).catch(() => {
|
||||
// Ignore errors.
|
||||
}));
|
||||
}
|
||||
|
@ -252,10 +264,11 @@ export class AddonModAssignPrefetchHandler extends CoreCourseActivityPrefetchHan
|
|||
|
||||
subPromises.push(this.courseHelper.getModuleCourseIdByInstance(assign.id, 'assign', siteId));
|
||||
|
||||
// Get all files and fetch them.
|
||||
subPromises.push(this.getFiles(module, courseId, single, siteId).then((files) => {
|
||||
return this.filepoolProvider.addFilesToQueue(siteId, files, this.component, module.id);
|
||||
}));
|
||||
// Download intro files and attachments. Do not call getFiles because it'd call some WS twice.
|
||||
let files = assign.introattachments || [];
|
||||
files = files.concat(this.getIntroFilesFromInstance(module, assign));
|
||||
|
||||
subPromises.push(this.filepoolProvider.addFilesToQueue(siteId, files, this.component, module.id));
|
||||
|
||||
return Promise.all(subPromises);
|
||||
}));
|
||||
|
@ -276,20 +289,20 @@ export class AddonModAssignPrefetchHandler extends CoreCourseActivityPrefetchHan
|
|||
protected prefetchSubmissions(assign: any, courseId: number, moduleId: number, userId: number, siteId: string): Promise<any> {
|
||||
|
||||
// Get submissions.
|
||||
return this.assignProvider.getSubmissions(assign.id, siteId).then((data) => {
|
||||
return this.assignProvider.getSubmissions(assign.id, true, siteId).then((data) => {
|
||||
const promises = [],
|
||||
blindMarking = assign.blindmarking && !assign.revealidentities;
|
||||
|
||||
if (data.canviewsubmissions) {
|
||||
// Teacher. Do not send participants to getSubmissionsUserData to retrieve user profiles.
|
||||
promises.push(this.assignProvider.getSubmissionsUserData(data.submissions, courseId, assign.id, blindMarking,
|
||||
undefined, siteId).then((submissions) => {
|
||||
undefined, true, siteId).then((submissions) => {
|
||||
|
||||
const subPromises = [];
|
||||
|
||||
submissions.forEach((submission) => {
|
||||
subPromises.push(this.assignProvider.getSubmissionStatus(assign.id, submission.submitid,
|
||||
!!submission.blindid, true, false, siteId).then((subm) => {
|
||||
subPromises.push(this.assignProvider.getSubmissionStatusWithRetry(assign, submission.submitid,
|
||||
!!submission.blindid, true, true, siteId).then((subm) => {
|
||||
return this.prefetchSubmission(assign, courseId, moduleId, subm, submission.submitid, siteId);
|
||||
}).catch((error) => {
|
||||
if (error && error.errorcode == 'nopermission') {
|
||||
|
@ -303,12 +316,12 @@ export class AddonModAssignPrefetchHandler extends CoreCourseActivityPrefetchHan
|
|||
|
||||
if (!assign.markingworkflow) {
|
||||
// Get assignment grades only if workflow is not enabled to check grading date.
|
||||
subPromises.push(this.assignProvider.getAssignmentGrades(assign.id, siteId));
|
||||
subPromises.push(this.assignProvider.getAssignmentGrades(assign.id, true, siteId));
|
||||
}
|
||||
|
||||
// Prefetch the submission of the current user even if it does not exist, this will be create it.
|
||||
if (!data.submissions || !data.submissions.find((subm) => subm.submitid == userId)) {
|
||||
subPromises.push(this.assignProvider.getSubmissionStatus(assign.id, userId, false, true, false, siteId)
|
||||
subPromises.push(this.assignProvider.getSubmissionStatusWithRetry(assign, userId, false, true, true, siteId)
|
||||
.then((subm) => {
|
||||
return this.prefetchSubmission(assign, courseId, moduleId, subm, userId, siteId);
|
||||
}));
|
||||
|
@ -318,7 +331,7 @@ export class AddonModAssignPrefetchHandler extends CoreCourseActivityPrefetchHan
|
|||
}));
|
||||
|
||||
// Get list participants.
|
||||
promises.push(this.assignHelper.getParticipants(assign, siteId).then((participants) => {
|
||||
promises.push(this.assignHelper.getParticipants(assign, true, siteId).then((participants) => {
|
||||
participants.forEach((participant) => {
|
||||
if (participant.profileimageurl) {
|
||||
this.filepoolProvider.addToQueueByUrl(siteId, participant.profileimageurl);
|
||||
|
@ -330,7 +343,7 @@ export class AddonModAssignPrefetchHandler extends CoreCourseActivityPrefetchHan
|
|||
} else {
|
||||
// Student.
|
||||
promises.push(
|
||||
this.assignProvider.getSubmissionStatus(assign.id, userId, false, true, false, siteId).then((subm) => {
|
||||
this.assignProvider.getSubmissionStatusWithRetry(assign, userId, false, true, true, siteId).then((subm) => {
|
||||
return this.prefetchSubmission(assign, courseId, moduleId, subm, userId, siteId);
|
||||
}).catch((error) => {
|
||||
// Ignore if the user can't view their own submission.
|
||||
|
@ -341,8 +354,8 @@ export class AddonModAssignPrefetchHandler extends CoreCourseActivityPrefetchHan
|
|||
);
|
||||
}
|
||||
|
||||
promises.push(this.groupsProvider.activityHasGroups(assign.cmid));
|
||||
promises.push(this.groupsProvider.getActivityAllowedGroups(assign.cmid, undefined, siteId));
|
||||
promises.push(this.groupsProvider.activityHasGroups(assign.cmid, siteId, true));
|
||||
promises.push(this.groupsProvider.getActivityAllowedGroups(assign.cmid, undefined, siteId, true));
|
||||
|
||||
return Promise.all(promises);
|
||||
});
|
||||
|
@ -378,7 +391,16 @@ export class AddonModAssignPrefetchHandler extends CoreCourseActivityPrefetchHan
|
|||
// Prefetch submission plugins data.
|
||||
if (userSubmission.plugins) {
|
||||
userSubmission.plugins.forEach((plugin) => {
|
||||
// Prefetch the plugin WS data.
|
||||
promises.push(this.submissionDelegate.prefetch(assign, userSubmission, plugin, siteId));
|
||||
|
||||
// Prefetch the plugin files.
|
||||
promises.push(this.submissionDelegate.getPluginFiles(assign, userSubmission, plugin, siteId)
|
||||
.then((files) => {
|
||||
return this.filepoolProvider.addFilesToQueue(siteId, files, this.component, module.id);
|
||||
}).catch(() => {
|
||||
// Ignore errors.
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -397,13 +419,21 @@ export class AddonModAssignPrefetchHandler extends CoreCourseActivityPrefetchHan
|
|||
}
|
||||
|
||||
if (userId) {
|
||||
promises.push(this.gradesHelper.getGradeModuleItems(courseId, moduleId, userId, undefined, siteId));
|
||||
promises.push(this.gradesHelper.getGradeModuleItems(courseId, moduleId, userId, undefined, siteId, true));
|
||||
}
|
||||
|
||||
// Prefetch feedback plugins data.
|
||||
if (submission.feedback.plugins) {
|
||||
submission.feedback.plugins.forEach((plugin) => {
|
||||
// Prefetch the plugin WS data.
|
||||
promises.push(this.feedbackDelegate.prefetch(assign, submission, plugin, siteId));
|
||||
|
||||
// Prefetch the plugin files.
|
||||
promises.push(this.feedbackDelegate.getPluginFiles(assign, submission, plugin, siteId).then((files) => {
|
||||
return this.filepoolProvider.addFilesToQueue(siteId, files, this.component, module.id);
|
||||
}).catch(() => {
|
||||
// Ignore errors.
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import { Injectable } from '@angular/core';
|
|||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { CoreSitesProvider } from './sites';
|
||||
import { CoreCoursesProvider } from '@core/courses/providers/courses';
|
||||
import { CoreSiteWSPreSets } from '@classes/site';
|
||||
|
||||
/**
|
||||
* Group info for an activity.
|
||||
|
@ -59,10 +60,11 @@ export class CoreGroupsProvider {
|
|||
*
|
||||
* @param {number} cmId Course module ID.
|
||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||
* @param {boolean} [ignoreCache] True if it should ignore cached data (it will always fail in offline or server down).
|
||||
* @return {Promise<boolean>} Promise resolved with true if the activity has groups, resolved with false otherwise.
|
||||
*/
|
||||
activityHasGroups(cmId: number, siteId?: string): Promise<boolean> {
|
||||
return this.getActivityGroupMode(cmId, siteId).then((groupmode) => {
|
||||
activityHasGroups(cmId: number, siteId?: string, ignoreCache?: boolean): Promise<boolean> {
|
||||
return this.getActivityGroupMode(cmId, siteId, ignoreCache).then((groupmode) => {
|
||||
return groupmode === CoreGroupsProvider.SEPARATEGROUPS || groupmode === CoreGroupsProvider.VISIBLEGROUPS;
|
||||
}).catch(() => {
|
||||
return false;
|
||||
|
@ -75,9 +77,10 @@ export class CoreGroupsProvider {
|
|||
* @param {number} cmId Course module ID.
|
||||
* @param {number} [userId] User ID. If not defined, use current user.
|
||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||
* @param {boolean} [ignoreCache] True if it should ignore cached data (it will always fail in offline or server down).
|
||||
* @return {Promise<any>} Promise resolved when the groups are retrieved.
|
||||
*/
|
||||
getActivityAllowedGroups(cmId: number, userId?: number, siteId?: string): Promise<any> {
|
||||
getActivityAllowedGroups(cmId: number, userId?: number, siteId?: string, ignoreCache?: boolean): Promise<any> {
|
||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||
userId = userId || site.getUserId();
|
||||
|
||||
|
@ -85,10 +88,15 @@ export class CoreGroupsProvider {
|
|||
cmid: cmId,
|
||||
userid: userId
|
||||
},
|
||||
preSets = {
|
||||
preSets: CoreSiteWSPreSets = {
|
||||
cacheKey: this.getActivityAllowedGroupsCacheKey(cmId, userId)
|
||||
};
|
||||
|
||||
if (ignoreCache) {
|
||||
preSets.getFromCache = false;
|
||||
preSets.emergencyCache = false;
|
||||
}
|
||||
|
||||
return site.read('core_group_get_activity_allowed_groups', params, preSets).then((response) => {
|
||||
if (!response || !response.groups) {
|
||||
return Promise.reject(null);
|
||||
|
@ -175,17 +183,23 @@ export class CoreGroupsProvider {
|
|||
*
|
||||
* @param {number} cmId Course module ID.
|
||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||
* @param {boolean} [ignoreCache] True if it should ignore cached data (it will always fail in offline or server down).
|
||||
* @return {Promise<number>} Promise resolved when the group mode is retrieved.
|
||||
*/
|
||||
getActivityGroupMode(cmId: number, siteId?: string): Promise<number> {
|
||||
getActivityGroupMode(cmId: number, siteId?: string, ignoreCache?: boolean): Promise<number> {
|
||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||
const params = {
|
||||
cmid: cmId
|
||||
},
|
||||
preSets = {
|
||||
preSets: CoreSiteWSPreSets = {
|
||||
cacheKey: this.getActivityGroupModeCacheKey(cmId)
|
||||
};
|
||||
|
||||
if (ignoreCache) {
|
||||
preSets.getFromCache = false;
|
||||
preSets.emergencyCache = false;
|
||||
}
|
||||
|
||||
return site.read('core_group_get_activity_groupmode', params, preSets).then((response) => {
|
||||
if (!response || typeof response.groupmode == 'undefined') {
|
||||
return Promise.reject(null);
|
||||
|
|
Loading…
Reference in New Issue