<commit_before>Handlebars.registerHelper('department_code', function (id) {
  return new Handlebars.SafeString(Yacs.models.departments.store.id[id].code);
});

Handlebars.registerHelper('course_credits', function (c) {
  var outString = '';
  // render "credit(s)" properly
  if(c.min_credits < c.max_credits) {
    outString = c.min_credits + '-' + c.max_credits + ' credits';
  }
  else {
    outString = c.max_credits + ' credit' + (c.max_credits === 1 ? 's' : '');
  }
  return new Handlebars.SafeString(outString);
});

Handlebars.registerHelper('join', function (arr) {
  return new Handlebars.SafeString(arr.join(', '));
});

Handlebars.registerHelper('course_seats', function (c) {
  var remaining = c.seats - c.seats_taken;
  return new Handlebars.SafeString(remaining);
});

/**
 * Courses view. Displays courses and their sections
 * @param {Object} data - Object containing Courses model collection
 * @param {Model[]} data.courses - Courses model collection
 * @return {undefined}
 * @memberOf Yacs.views
 */
Yacs.views.courses = function (data) {
  var html = HandlebarsTemplates.courses(data);
  Yacs.setContents(html);

  var updateCourseSelected = function (course) {
    if (course.querySelector('section:not(.selected)')) {
      course.classList.remove('selected');
    } else {
      course.classList.add('selected');
    }
  }

  // Add event listeners to sections
  document.getElementsByTagName('section').each(function (s) {
    Yacs.on('click', s, function(sect) {
      /* If there happens to be a mismatch between the data and the display,
         we care about the data - e.g. if the id is in the array, we will
         always deselect it regardless of whether it was being rendered as
         selected or not.
      */
      var sid = sect.dataset.id;
      if(Yacs.user.removeSelection(sid)) {
        // index is real, section is selected, remove selected class
        sect.classList.remove('selected');
      }
      else {
        // section is not selected, select it and add it to the array
        Yacs.user.addSelection(sid);
        sect.classList.add('selected');
      }
      updateCourseSelected(sect.closest('course'));
    });
  });

  document.getElementsByTagName('course').each(function (c) {
    Yacs.on('click', c.getElementsByTagName('course-info')[0], function (ci) {
      var selected = c.classList.contains('selected');
      c.getElementsByTagName('section').each(function (s) {
        if (selected) s.classList.remove('selected');
        else s.classList.add('selected')
      })
      if (selected) c.classList.remove('selected');
      else c.classList.add('selected')
    });
  })
};<commit_msg>Added a TODO for course clicks<commit_after>Handlebars.registerHelper('department_code', function (id) {
  return new Handlebars.SafeString(Yacs.models.departments.store.id[id].code);
});

Handlebars.registerHelper('course_credits', function (c) {
  var outString = '';
  // render "credit(s)" properly
  if(c.min_credits < c.max_credits) {
    outString = c.min_credits + '-' + c.max_credits + ' credits';
  }
  else {
    outString = c.max_credits + ' credit' + (c.max_credits === 1 ? 's' : '');
  }
  return new Handlebars.SafeString(outString);
});

Handlebars.registerHelper('join', function (arr) {
  return new Handlebars.SafeString(arr.join(', '));
});

Handlebars.registerHelper('course_seats', function (c) {
  var remaining = c.seats - c.seats_taken;
  return new Handlebars.SafeString(remaining);
});

/**
 * Courses view. Displays courses and their sections
 * @param {Object} data - Object containing Courses model collection
 * @param {Model[]} data.courses - Courses model collection
 * @return {undefined}
 * @memberOf Yacs.views
 */
Yacs.views.courses = function (data) {
  var html = HandlebarsTemplates.courses(data);
  Yacs.setContents(html);

  var updateCourseSelected = function (course) {
    if (course.querySelector('section:not(.selected)')) {
      course.classList.remove('selected');
    } else {
      course.classList.add('selected');
    }
  }

  // Add event listeners to sections
  document.getElementsByTagName('section').each(function (s) {
    Yacs.on('click', s, function(sect) {
      /* If there happens to be a mismatch between the data and the display,
         we care about the data - e.g. if the id is in the array, we will
         always deselect it regardless of whether it was being rendered as
         selected or not.
      */
      var sid = sect.dataset.id;
      if(Yacs.user.removeSelection(sid)) {
        // index is real, section is selected, remove selected class
        sect.classList.remove('selected');
      }
      else {
        // section is not selected, select it and add it to the array
        Yacs.user.addSelection(sid);
        sect.classList.add('selected');
      }
      updateCourseSelected(sect.closest('course'));
    });
  });

  /* This does not actually add or remove sections from the selected list.
     TODO: implement this
  */
  document.getElementsByTagName('course').each(function (c) {
    Yacs.on('click', c.getElementsByTagName('course-info')[0], function (ci) {
      var selected = c.classList.contains('selected');
      c.getElementsByTagName('section').each(function (s) {
        if (selected) s.classList.remove('selected');
        else s.classList.add('selected')
      })
      if (selected) c.classList.remove('selected');
      else c.classList.add('selected')
    });
  })
};
{'fraction_non_alphanumeric': 0.13921028466483013, 'fraction_numerical': 0.0007346189164370982, 'mean_word_length': 3.3256552819698175, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3809554', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1647, 'n_words': 400}