[+] Implement sort by popularity

This commit is contained in:
Hykilpikonna
2020-04-20 14:19:00 -04:00
parent cc4cbe0b28
commit 8e4557af18
+17 -3
View File
@@ -2,6 +2,7 @@ import {Component, Prop, Vue} from 'vue-property-decorator'
import App from '@/components/app/app'; import App from '@/components/app/app';
import CourseInfo, {ClassInfo, UniqueCourse} from '@/logic/course-info'; import CourseInfo, {ClassInfo, UniqueCourse} from '@/logic/course-info';
import {GPAUtils} from '@/logic/utils/gpa-utils'; import {GPAUtils} from '@/logic/utils/gpa-utils';
// @ts-ignore
import SearchSettingsComponent, {SearchSettings} from '@/pages/course-selection/search-settings/search-settings.vue'; import SearchSettingsComponent, {SearchSettings} from '@/pages/course-selection/search-settings/search-settings.vue';
@Component({components: {SearchSettings: SearchSettingsComponent}}) @Component({components: {SearchSettings: SearchSettingsComponent}})
@@ -75,8 +76,6 @@ export default class CourseSelection extends Vue
} }
}) })
}) })
this.courseInfo.sort((one, two) => one.name.localeCompare(two.name))
} }
}); });
} }
@@ -130,7 +129,7 @@ export default class CourseSelection extends Vue
c.level != null && c.level !== 'Club' && c.level !== 'Sport' && c.level !== 'None' && c.level != null && c.level !== 'Club' && c.level !== 'Sport' && c.level !== 'None' &&
c.year == year && c.year == year &&
(this.settings.showAllCourses || c.gradeLevels.includes(this.app.user.gradeLevel + 1)) (this.settings.showAllCourses || c.gradeLevels.includes(this.app.user.gradeLevel + 1))
); )
} }
/** /**
@@ -155,6 +154,21 @@ export default class CourseSelection extends Vue
list[names.indexOf(c.uniqueName)].enrollments += c.enrollments; list[names.indexOf(c.uniqueName)].enrollments += c.enrollments;
}) })
// Sorting
switch (this.settings.sortBy)
{
case 'Popularity':
{
list.sort((a, b) => b.enrollments - a.enrollments);
break
}
default:
{
list.sort((a, b) => a.name.localeCompare(b.name));
break
}
}
return list; return list;
} }