<commit_before>React             = require 'react/addons'

TextInput         = require '../common/text_input'
TextAreaInput     = require '../common/text_area_input'
TrainingModules   = require '../training_modules'
Checkbox          = require '../common/checkbox'
Select            = require '../common/select'
BlockActions      = require '../../actions/block_actions'
GradeableActions  = require '../../actions/gradeable_actions'
Reorderable       = require '../high_order/reorderable'

Block = React.createClass(
  displayName: 'Block'
  updateBlock: (value_key, value) ->
    to_pass = $.extend(true, {}, @props.block)
    to_pass[value_key] = value
    delete to_pass.deleteBlock
    BlockActions.updateBlock to_pass
  passedUpdateBlock: (_, modules) ->
    newBlock = $.extend(true, {}, @props.block)
    selectedIds = modules.map (module) -> module.value
    newBlock.training_module_ids = selectedIds
    BlockActions.updateBlock newBlock
  deleteBlock: ->
    BlockActions.deleteBlock @props.block.id
  updateGradeable: (value_key, value) ->
    if value == 'true'
      GradeableActions.addGradeable @props.block
    else
      GradeableActions.deleteGradeable @props.gradeable.id
  render: ->
    is_graded = @props.gradeable != undefined && !@props.gradeable.deleted
    className = 'block'
    className += " block-kind-#{@props.block.kind}"
    if @props.block.due_date?
      dueDateRead = (
        <TextInput
          onChange={@updateBlock}
          value={moment(@props.block.due_date).format("YYYY-MM-DD")}
          value_key={'due_date'}
          editable={false}
          label='Due'
          show={@props.block.due_date?}
          onFocus={@props.toggleFocused}
          onBlur={@props.toggleFocused}
        />
      )
    if @props.editable
      deleteBlock = <button className='button danger right' onClick={@deleteBlock}>Delete Block</button>
      className += ' editable'
      className += ' dragging' if @props.isDragging
      graded = (
        <Checkbox
          value={is_graded}
          onChange={@updateGradeable}
          value_key={'gradeable'}
          editable={@props.editable}
          label='Graded'
          container_class='graded'
        />
      )
    if (@props.block.kind < 3 && !@props.editable)
      spacer = <span>  —  </span>

    modules = undefined
    if @props.block.training_modules || (@props.block.kind is 1 && @props.editable)
      modules = (
        <TrainingModules
          onChange={@passedUpdateBlock}
          all_modules={@props.all_training_modules}
          block_modules={@props.block.training_modules}
          editable={@props.editable}
          block={@props.block}
        />
      )

    content = (
      <div>
        <TextAreaInput
          onChange={@updateBlock}
          value={@props.block.content}
          value_key='content'
          editable={@props.editable}
          rows='4'
          placeholder='Block description'
          autoExpand=true
          onFocus={@props.toggleFocused}
          onBlur={@props.toggleFocused}
        />
        {modules}
      </div>
    )

    <li className={className} draggable={@props.canDrag && @props.editable}>
      <div className="drag-handle">
        <div className="drag-handle__bar"></div>
        <div className="drag-handle__bar"></div>
        <div className="drag-handle__bar"></div>
      </div>
      <h4 className={"block-title" + (if @props.editable then " block-title--editing" else "")}>
        <Select
          onChange={@updateBlock}
          value={@props.block.kind}
          value_key={'kind'}
          editable={@props.editable}
          options={['In Class', 'Assignment', 'Milestone', 'Custom', 'Training']}
          show={@props.block.kind < 3 || @props.editable}
          label='Block type'
          popover_text={I18n.t('timeline.block_type')}
          inline=true
        />
        {spacer}
        <TextInput
          onChange={@updateBlock}
          value={@props.block.title}<commit_msg>allow adding trainings to newly created block<commit_after>React             = require 'react/addons'

TextInput         = require '../common/text_input'
TextAreaInput     = require '../common/text_area_input'
TrainingModules   = require '../training_modules'
Checkbox          = require '../common/checkbox'
Select            = require '../common/select'
BlockActions      = require '../../actions/block_actions'
GradeableActions  = require '../../actions/gradeable_actions'
Reorderable       = require '../high_order/reorderable'

Block = React.createClass(
  displayName: 'Block'
  updateBlock: (value_key, value) ->
    to_pass = $.extend(true, {}, @props.block)
    to_pass[value_key] = value
    delete to_pass.deleteBlock
    BlockActions.updateBlock to_pass
  passedUpdateBlock: (_, modules) ->
    newBlock = $.extend(true, {}, @props.block)
    selectedIds = modules.map (module) -> module.value
    newBlock.training_module_ids = selectedIds
    BlockActions.updateBlock newBlock
  deleteBlock: ->
    BlockActions.deleteBlock @props.block.id
  updateGradeable: (value_key, value) ->
    if value == 'true'
      GradeableActions.addGradeable @props.block
    else
      GradeableActions.deleteGradeable @props.gradeable.id
  render: ->
    is_graded = @props.gradeable != undefined && !@props.gradeable.deleted
    className = 'block'
    className += " block-kind-#{@props.block.kind}"
    if @props.block.due_date?
      dueDateRead = (
        <TextInput
          onChange={@updateBlock}
          value={moment(@props.block.due_date).format("YYYY-MM-DD")}
          value_key={'due_date'}
          editable={false}
          label='Due'
          show={@props.block.due_date?}
          onFocus={@props.toggleFocused}
          onBlur={@props.toggleFocused}
        />
      )
    if @props.editable
      deleteBlock = <button className='button danger right' onClick={@deleteBlock}>Delete Block</button>
      className += ' editable'
      className += ' dragging' if @props.isDragging
      graded = (
        <Checkbox
          value={is_graded}
          onChange={@updateGradeable}
          value_key={'gradeable'}
          editable={@props.editable}
          label='Graded'
          container_class='graded'
        />
      )
    if (@props.block.kind < 3 && !@props.editable)
      spacer = <span>  —  </span>

    modules = undefined
    if @props.block.training_modules || (parseInt(@props.block.kind) is 1 && @props.editable)
      modules = (
        <TrainingModules
          onChange={@passedUpdateBlock}
          all_modules={@props.all_training_modules}
          block_modules={@props.block.training_modules}
          editable={@props.editable}
          block={@props.block}
        />
      )

    content = (
      <div>
        <TextAreaInput
          onChange={@updateBlock}
          value={@props.block.content}
          value_key='content'
          editable={@props.editable}
          rows='4'
          placeholder='Block description'
          autoExpand=true
          onFocus={@props.toggleFocused}
          onBlur={@props.toggleFocused}
        />
        {modules}
      </div>
    )

    <li className={className} draggable={@props.canDrag && @props.editable}>
      <div className="drag-handle">
        <div className="drag-handle__bar"></div>
        <div className="drag-handle__bar"></div>
        <div className="drag-handle__bar"></div>
      </div>
      <h4 className={"block-title" + (if @props.editable then " block-title--editing" else "")}>
        <Select
          onChange={@updateBlock}
          value={@props.block.kind}
          value_key={'kind'}
          editable={@props.editable}
          options={['In Class', 'Assignment', 'Milestone', 'Custom']}
          show={@props.block.kind < 3 || @props.editable}
          label='Block type'
          popover_text={I18n.t('timeline.block_type')}
          inline=true
        />
        {spacer}
        <TextInput
          onChange={@updateBlock}
          value={@props.block.title}
{'fraction_non_alphanumeric': 0.13666999500748878, 'fraction_numerical': 0.001747378931602596, 'mean_word_length': 2.392464013547841, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 57, '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': '5931572', 'n_tokens_mistral': 2351, 'n_tokens_neox': 2345, 'n_words': 392}