<commit_before>import { Template } from 'meteor/templating';
import { _ } from 'meteor/erasaur:meteor-lodash';
import { Roles } from 'meteor/alanning:roles';

import { Courses } from '../../../api/course/CourseCollection.js';
import { CourseInstances } from '../../../api/course/CourseInstanceCollection.js';
import { getUserIdFromRoute } from '../../components/shared/get-user-id-from-route';
import { AcademicPlans } from '../../../api/degree-plan/AcademicPlanCollection';
import { ROLE } from '../../../api/role/Role';
import { StudentProfiles } from '../../../api/user/StudentProfileCollection';

Template.Card_Explorer_Courses_Page.helpers({
  addedCourses() {
    let addedCourses = [];
    const allCourses = Courses.findNonRetired({}, { sort: { shortName: 1 } });
    const userID = getUserIdFromRoute();
    _.forEach(allCourses, (course) => {
      const ci = CourseInstances.find({
        studentID: userID,
        courseID: course._id,
      }).fetch();
      if (ci.length > 0) {
        if (course.shortName !== 'Non-CS Course') {
          addedCourses.push({ item: course, count: ci.length });
        }
      }
    });
    if (Roles.userIsInRole(userID, [ROLE.STUDENT])) {
      const profile = StudentProfiles.findDoc({ userID });
      const plan = AcademicPlans.findDoc(profile.academicPlanID);
      // CAM: why are we filtering?
      if (plan.coursesPerSemester.length < 15) { // not bachelors and masters
        const regex = /[1234]\d\d/g;
        addedCourses = _.filter(addedCourses, (c) => c.item.number.match(regex));
      }
    }
    console.log('addedCourses %o', addedCourses);
    return addedCourses;
  },
  nonAddedCourses() {
    const allCourses = Courses.findNonRetired({}, { sort: { shortName: 1 } });
    const userID = getUserIdFromRoute();
    const nonAddedCourses = _.filter(allCourses, function (course) {
      const ci = CourseInstances.find({
        studentID: userID,
        courseID: course._id,
      }).fetch();
      if (ci.length > 0) {
        return false;
      }
      if (course.shortName === 'Non-CS Course') {
        return false;
      }
      return true;
    });
    return nonAddedCourses;
  },
});<commit_msg>Update card-explorer-courses-page.js<commit_after>import { Template } from 'meteor/templating';
import { _ } from 'meteor/erasaur:meteor-lodash';
import { Roles } from 'meteor/alanning:roles';

import { Courses } from '../../../api/course/CourseCollection.js';
import { CourseInstances } from '../../../api/course/CourseInstanceCollection.js';
import { getUserIdFromRoute } from '../../components/shared/get-user-id-from-route';
import { AcademicPlans } from '../../../api/degree-plan/AcademicPlanCollection';
import { ROLE } from '../../../api/role/Role';
import { StudentProfiles } from '../../../api/user/StudentProfileCollection';
import { FavoriteCourses } from '../../../api/favorite/FavoriteCourseCollection';

Template.Card_Explorer_Courses_Page.helpers({
  addedCourses() {
    let addedCourses = [];
    const studentID = getUserIdFromRoute();
    const favorites = FavoriteCourses.find({ studentID }).fetch();
    return _.map(favorites, (f) => ({ item: Courses.findDoc(f.courseID), count: 1 }));
  },
  nonAddedCourses() {
    const allCourses = Courses.findNonRetired({}, { sort: { shortName: 1 } });
    const studentID = getUserIdFromRoute();
    const favoriteIDs = _.map(FavoriteCourses.find({ studentID }).fetch(), (f) => f.courseID);

    const nonAddedCourses = _.filter(allCourses, function (course) {
      return !_.includes(favoriteIDs, course._id);
    });
    console.log(nonAddedCourses);
    return nonAddedCourses;
  },
});
{'fraction_non_alphanumeric': 0.1670335718216841, 'fraction_numerical': 0.003302146395156852, 'mean_word_length': 3.1495433789954337, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3399018', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1131, 'n_words': 229}