Skip to content
Snippets Groups Projects
Unverified Commit a2d16de8 authored by Uzair Rasheed's avatar Uzair Rasheed Committed by GitHub
Browse files

Merge pull request #18307 from edx/LEARNER-4351/extract-course-run-with-highest-grade

Extract course run with highest grades.
parents 6e590255 b7c73d1a
No related merge requests found
......@@ -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 || '';
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment