<commit_before>React = require 'react'
BS = require 'react-bootstrap'
EventEmitter2 = require 'eventemitter2'
{CloseButton} = require 'openstax-react-components'

Status = require './status-mixin'

Course = require '../course/model'

api = require '../api'

getWaitingText = (status) ->
  "#{status}…"

UserMenu = React.createClass
  mixins: [Status]

  contextTypes:
    close: React.PropTypes.func
    navigator: React.PropTypes.instanceOf(EventEmitter2)

  propTypes:
    course: React.PropTypes.instanceOf(Course)

  componentWillMount: ->
    @getUser().ensureStatusLoaded()

  logoutUser: (clickEvent) ->
    clickEvent.preventDefault()
    @context.navigator.emit('show.logout', view: 'logout')

  showProfile: (clickEvent) ->
    clickEvent.preventDefault()
    @context.navigator.emit('show.profile', view: 'profile')

  updateStudentId: (clickEvent) ->
    clickEvent.preventDefault()
    @context.navigator.emit('show.student_id', view: 'student_id')

  update: ->
    @forceUpdate() if @isMounted()

  close: (clickEvent) ->
    clickEvent.preventDefault()
    @context.close?()

  modifyCourse: (clickEvent) ->
    clickEvent.preventDefault()
    @context.navigator.emit('show.registration', view: 'registration')

  renderCourseOption: ->
    if @props.course?.isRegistered()
      courseChangeText = 'Change Course'
    else
      courseChangeText = 'Register for Course'
    <BS.MenuItem onClick={@modifyCourse}>{courseChangeText}</BS.MenuItem>

  renderStudentIdOption: ->
    return null unless @props.course?.isRegistered()
    <BS.MenuItem onClick={@updateStudentId}>Change student ID</BS.MenuItem>

  render: ->
    # The menu has no valid actions unless the useris logged in
    user = @getUser()
    return null unless user.isLoggedIn()
    <BS.DropdownButton navItem className='concept-coach-user' title={user.name}>
      {@renderCourseOption()}
      <BS.MenuItem onClick={@showProfile}>Account Profile</BS.MenuItem>
      {@renderStudentIdOption()}
      <BS.MenuItem onClick={@logoutUser}>Logout</BS.MenuItem>
    </BS.DropdownButton>

module.exports = UserMenu<commit_msg>minimal change to add help link into dropdown menu<commit_after>React = require 'react'
BS = require 'react-bootstrap'
EventEmitter2 = require 'eventemitter2'
{CloseButton} = require 'openstax-react-components'

Status = require './status-mixin'

Course = require '../course/model'

api = require '../api'

# TODO combine this with link in error notification
GET_HELP_LINK = 'http://openstax.force.com/support?l=en_US&c=Products%3AConcept_Coach'

getWaitingText = (status) ->
  "#{status}…"

UserMenu = React.createClass
  mixins: [Status]

  contextTypes:
    close: React.PropTypes.func
    navigator: React.PropTypes.instanceOf(EventEmitter2)

  propTypes:
    course: React.PropTypes.instanceOf(Course)

  componentWillMount: ->
    @getUser().ensureStatusLoaded()

  logoutUser: (clickEvent) ->
    clickEvent.preventDefault()
    @context.navigator.emit('show.logout', view: 'logout')

  showProfile: (clickEvent) ->
    clickEvent.preventDefault()
    @context.navigator.emit('show.profile', view: 'profile')

  updateStudentId: (clickEvent) ->
    clickEvent.preventDefault()
    @context.navigator.emit('show.student_id', view: 'student_id')

  update: ->
    @forceUpdate() if @isMounted()

  close: (clickEvent) ->
    clickEvent.preventDefault()
    @context.close?()

  modifyCourse: (clickEvent) ->
    clickEvent.preventDefault()
    @context.navigator.emit('show.registration', view: 'registration')

  renderCourseOption: ->
    if @props.course?.isRegistered()
      courseChangeText = 'Change Course'
    else
      courseChangeText = 'Register for Course'
    <BS.MenuItem onClick={@modifyCourse}>{courseChangeText}</BS.MenuItem>

  renderStudentIdOption: ->
    return null unless @props.course?.isRegistered()
    <BS.MenuItem onClick={@updateStudentId}>Change student ID</BS.MenuItem>

  render: ->
    # The menu has no valid actions unless the useris logged in
    user = @getUser()
    return null unless user.isLoggedIn()
    <BS.DropdownButton navItem className='concept-coach-user' title={user.name}>
      {@renderCourseOption()}
      <BS.MenuItem onClick={@showProfile}>Account Profile</BS.MenuItem>
      {@renderStudentIdOption()}
      <BS.MenuItem divider key='dropdown-item-divider'/>
      <BS.MenuItem
        key='nav-help-link'
        className='-help-link'
        target='_blank'
        href={GET_HELP_LINK}>
          Get Help
      </BS.MenuItem>
      <BS.MenuItem onClick={@logoutUser}>Logout</BS.MenuItem>
    </BS.DropdownButton>

module.exports = UserMenu
{'fraction_non_alphanumeric': 0.13606770833333334, 'fraction_numerical': 0.0015190972222222222, 'mean_word_length': 4.026172300981461, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 48, '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': '5960050', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1398, 'n_words': 276}