Merge pull request #18307 from edx/LEARNER-4351/extract-course-run-with-highest-grade
Extract course run with highest grades.
This commit is contained in:
@@ -38,6 +38,23 @@ class CourseCardModel extends Backbone.Model {
|
||||
return desiredCourseRun;
|
||||
}
|
||||
|
||||
getCourseRunWithHighestGrade(grades) {
|
||||
const allEnrolledCourseRuns = this.context.course_runs.filter(run => run.is_enrolled);
|
||||
if (allEnrolledCourseRuns.length <= 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
allEnrolledCourseRuns.sort((a, b) => (grades[a.key] || 0) - (grades[b.key] || 0));
|
||||
return allEnrolledCourseRuns[allEnrolledCourseRuns.length - 1];
|
||||
}
|
||||
|
||||
updateCourseRunWithHighestGrade(grades) {
|
||||
const courseRunWithHighestGrade = this.getCourseRunWithHighestGrade(grades);
|
||||
if (courseRunWithHighestGrade) {
|
||||
this.setActiveCourseRun(courseRunWithHighestGrade, this.context.user_preferences);
|
||||
}
|
||||
}
|
||||
|
||||
isEnrolledInSession() {
|
||||
// Returns true if the user is currently enrolled in a session of the course
|
||||
return this.context.course_runs.find(run => run.is_enrolled) !== undefined;
|
||||
|
||||
@@ -27,6 +27,9 @@ class CourseCardView extends Backbone.View {
|
||||
this.enrollModel.urlRoot = this.urlModel.get('commerce_api_url');
|
||||
}
|
||||
this.context = options.context || {};
|
||||
if (this.context.collectionCourseStatus === 'completed') {
|
||||
this.model.updateCourseRunWithHighestGrade(this.context.courseData.grades);
|
||||
}
|
||||
this.grade = this.context.courseData.grades[this.model.get('course_run_key')];
|
||||
this.grade = this.grade * 100;
|
||||
this.collectionCourseStatus = this.context.collectionCourseStatus || '';
|
||||
|
||||
Reference in New Issue
Block a user