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