<commit_before>React = require 'react'
classnames = require 'classnames'
BS = require 'react-bootstrap'
_ = require 'lodash'

TutorLink = require '../link'

Router = require '../../helpers/router'
DnD = require './course-dnd'
BRAND = 'Openstax'

getCourseNameSegments = (course, courseSubject) ->
  courseRegex = new RegExp(courseSubject, 'i')
  courseNameMatches = courseRegex.exec(course.name)
  if courseSubject and courseNameMatches
    {index} = courseNameMatches

    before = course.name.substring(0, index)
    after = course.name.substring(index + courseSubject.length)

    [before, courseSubject, after]


CoursePropType = React.PropTypes.shape(
  id:   React.PropTypes.string.isRequired
  name: React.PropTypes.string.isRequired
  year: React.PropTypes.number.isRequired
  term: React.PropTypes.string.isRequired
  is_concept_coach: React.PropTypes.bool.isRequired
)

CourseBranding = React.createClass
  displayName: 'CourseBranding'
  propTypes:
    isConceptCoach: React.PropTypes.bool.isRequired
    isBeta:         React.PropTypes.bool
  render: ->
    {isConceptCoach, isBeta} = @props

    if isConceptCoach
      isBeta ?= false
      brand = "#{BRAND} Concept Coach"
    else
      isBeta ?= true
      brand = "#{BRAND} Tutor"

    <p
      className='course-listing-item-brand'
      data-is-beta={isBeta}
    >{brand}</p>

Course = React.createClass
  displayName: 'Course'
  propTypes:
    course:           CoursePropType.isRequired
    courseSubject:    React.PropTypes.string.isRequired
    courseIsTeacher:  React.PropTypes.bool.isRequired
    courseDataProps:  React.PropTypes.object.isRequired
    className:        React.PropTypes.string
    controls:         React.PropTypes.element

  Controls: ->
    {controls} = @props

    <div className='course-listing-item-controls'>
      {controls}
    </div>

  CourseName: ->
    {course, courseSubject} = @props
    courseNameSegments = getCourseNameSegments(course, courseSubject)
    hasNoSubject = _.isEmpty(courseNameSegments)
    courseNameSegments ?= course.name.split(' ')

    <TutorLink
      className={classnames('no-subject': hasNoSubject)}
      to='dashboard'
      params={courseId: course.id}
    >
      {_.map(courseNameSegments, (courseNameSegment, index) ->
        <span
          key="course-name-segment-#{index}"
          data-is-subject={courseNameSegment is courseSubject}
        >
          {"#{courseNameSegment} "}
        </span>
      )}
    </TutorLink>

  render: ->
    {course, courseDataProps, controls, courseIsTeacher, className} = @props

    itemClasses = classnames('course-listing-item', className)

    <div className='course-listing-item-wrapper'>
      <div
        {...courseDataProps}
        data-is-teacher={courseIsTeacher}
        data-course-id={course.id}
        className={itemClasses}
      >
        <div
          className='course-listing-item-title'>
          <@CourseName />
        </div>
        <div
          className='course-listing-item-details'
          data-has-controls={controls?}
        >
          <TutorLink to='dashboard' params={courseId: course.id}>
            <CourseBranding isConceptCoach={course.is_concept_coach or false} />
            <p className='course-listing-item-term'>{course.term} {course.year}</p>
          </TutorLink>
          {<@Controls /> if controls?}
        </div>
      </div>
    </div>

CourseTeacher = React.createClass
  displayName: 'CourseTeacher'
  propTypes:
    _.omit(Course.propTypes, 'controls')
  render: ->
    {course} = @props
    link =
      <TutorLink
        to='createNewCourse'
        params={sourceId: course.id}
        className='btn btn-default btn-sm'
      >Teach Again</TutorLink>

    @props.connectDragSource(
      <div className={classnames('course-teacher', 'is-dragging': @props.isDragging)}>
        <Course {...@props} controls={link} />
      </div>
    )


module.exports = {
  Course,
  CoursePropType,
  CourseTeacher: DnD.wrapCourseDragComponent(CourseTeacher)
}
<commit_msg>Strip non word characters from last segment<commit_after>React = require 'react'
classnames = require 'classnames'
BS = require 'react-bootstrap'
_ = require 'lodash'

TutorLink = require '../link'

Router = require '../../helpers/router'
DnD = require './course-dnd'
BRAND = 'Openstax'

getCourseNameSegments = (course, courseSubject) ->
  courseRegex = new RegExp(courseSubject, 'i')
  courseNameMatches = courseRegex.exec(course.name)
  if courseSubject and courseNameMatches
    {index} = courseNameMatches

    before = course.name.substring(0, index)
    after = course.name.substring(index + courseSubject.length).replace(/^\W+/, '')

    [before, courseSubject, after]


CoursePropType = React.PropTypes.shape(
  id:   React.PropTypes.string.isRequired
  name: React.PropTypes.string.isRequired
  year: React.PropTypes.number.isRequired
  term: React.PropTypes.string.isRequired
  is_concept_coach: React.PropTypes.bool.isRequired
)

CourseBranding = React.createClass
  displayName: 'CourseBranding'
  propTypes:
    isConceptCoach: React.PropTypes.bool.isRequired
    isBeta:         React.PropTypes.bool
  render: ->
    {isConceptCoach, isBeta} = @props

    if isConceptCoach
      isBeta ?= false
      brand = "#{BRAND} Concept Coach"
    else
      isBeta ?= true
      brand = "#{BRAND} Tutor"

    <p
      className='course-listing-item-brand'
      data-is-beta={isBeta}
    >{brand}</p>

Course = React.createClass
  displayName: 'Course'
  propTypes:
    course:           CoursePropType.isRequired
    courseSubject:    React.PropTypes.string.isRequired
    courseIsTeacher:  React.PropTypes.bool.isRequired
    courseDataProps:  React.PropTypes.object.isRequired
    className:        React.PropTypes.string
    controls:         React.PropTypes.element

  Controls: ->
    {controls} = @props

    <div className='course-listing-item-controls'>
      {controls}
    </div>

  CourseName: ->
    {course, courseSubject} = @props
    courseNameSegments = getCourseNameSegments(course, courseSubject)
    hasNoSubject = _.isEmpty(courseNameSegments)
    courseNameSegments ?= course.name.split(/\W+/)

    <TutorLink
      className={classnames('no-subject': hasNoSubject)}
      to='dashboard'
      params={courseId: course.id}
    >
      {_.map(courseNameSegments, (courseNameSegment, index) ->
        <span
          key="course-name-segment-#{index}"
          data-is-subject={courseNameSegment is courseSubject}
        >
          {"#{courseNameSegment} "}
        </span>
      )}
    </TutorLink>

  render: ->
    {course, courseDataProps, controls, courseIsTeacher, className} = @props

    itemClasses = classnames('course-listing-item', className)

    <div className='course-listing-item-wrapper'>
      <div
        {...courseDataProps}
        data-is-teacher={courseIsTeacher}
        data-course-id={course.id}
        className={itemClasses}
      >
        <div
          className='course-listing-item-title'>
          <@CourseName />
        </div>
        <div
          className='course-listing-item-details'
          data-has-controls={controls?}
        >
          <TutorLink to='dashboard' params={courseId: course.id}>
            <CourseBranding isConceptCoach={course.is_concept_coach or false} />
            <p className='course-listing-item-term'>{course.term} {course.year}</p>
          </TutorLink>
          {<@Controls /> if controls?}
        </div>
      </div>
    </div>

CourseTeacher = React.createClass
  displayName: 'CourseTeacher'
  propTypes:
    _.omit(Course.propTypes, 'controls')
  render: ->
    {course} = @props
    link =
      <TutorLink
        to='createNewCourse'
        params={sourceId: course.id}
        className='btn btn-default btn-sm'
      >Teach Again</TutorLink>

    @props.connectDragSource(
      <div className={classnames('course-teacher', 'is-dragging': @props.isDragging)}>
        <Course {...@props} controls={link} />
      </div>
    )


module.exports = {
  Course,
  CoursePropType,
  CourseTeacher: DnD.wrapCourseDragComponent(CourseTeacher)
}

{'fraction_non_alphanumeric': 0.12605354486861675, 'fraction_numerical': 0.00024789291026276647, 'mean_word_length': 2.8756003842459172, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 73, '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': '2005205', 'n_tokens_mistral': 2593, 'n_tokens_neox': 2493, 'n_words': 440}