<commit_before>import React from 'react';
import Select from 'react-select';
import Expandable from '../high_order/expandable.jsx';
import Popover from '../common/popover.jsx';
import Lookup from '../common/lookup.jsx';
import Confirm from '../common/confirm.jsx';
import ConfirmActions from '../../actions/confirm_actions.js';
import ConfirmationStore from '../../stores/confirmation_store.js';
import ServerActions from '../../actions/server_actions.js';
import AssignmentActions from '../../actions/assignment_actions.js';
import AssignmentStore from '../../stores/assignment_store.js';
import CourseUtils from '../../utils/course_utils.js';
import shallowCompare from 'react-addons-shallow-compare';

const AssignButton = React.createClass({
  displayName: 'AssignButton',

  propTypes: {
    course: React.PropTypes.object.isRequired,
    role: React.PropTypes.number.isRequired,
    student: React.PropTypes.object,
    current_user: React.PropTypes.object,
    course_id: React.PropTypes.string.isRequired,
    is_open: React.PropTypes.bool,
    permitted: React.PropTypes.bool,
    add_available: React.PropTypes.bool,
    assignments: React.PropTypes.array,
    open: React.PropTypes.func.isRequired
  },

  mixins: [ConfirmationStore.mixin],

  getInitialState() {
    return ({
      showOptions: false,
      language: this.props.course.home_wiki.language,
      project: this.props.course.home_wiki.project,
      title: '',
      showConfirm: false
    });
  },

  shouldComponentUpdate(nextProps, nextState) {
    return shallowCompare(this, nextProps, nextState);
  },

  getKey() {
    const tag = this.props.role === 0 ? 'assign_' : 'review_';
    if (this.props.student) {
      return tag + this.props.student.id;
    }
    return tag;
  },

  storeDidChange() {
    return this.setState(this.getInitialState());
  },

  stop(e) {
    return e.stopPropagation();
  },


  handleShowOptions(e) {
    e.preventDefault();
    return this.setState(
      { showOptions: true });
  },

  handleChangeTitle(e) {
    e.preventDefault();
    const title = e.target.value;
    const assignment = CourseUtils.articleFromTitleInput(title);
    const language = assignment.language ? assignment.language : this.state.language;
    const project = assignment.project ? assignment.project : this.state.project;
    return this.setState({
      title: assignment.title,
      project,
      language
    });
  },
  handleChangeLanguage(val) {
    return this.setState(
      { language: val.value });
  },
  handleChangeProject(val) {
    return this.setState(
      { project: val.value });
  },

  assign(e) {
    e.preventDefault();

    let student;
    if (this.props.student) {
      student = this.props.student.id;
    } else {
      student = null;
    }

    const assignment = {
      title: decodeURIComponent(this.state.title).trim(),
      project: this.state.project,
      language: this.state.language,
      course_id: this.props.course_id,
      user_id: student,
      role: this.props.role
    };

    if (assignment.title === '' || assignment.title === 'undefined') {
      return;
    }

    const articleTitle = assignment.title;

    // Check if the assignment exists
    if (this.props.student && AssignmentStore.getFiltered({
      articleTitle,
      user_id: this.props.student.id,
      role: this.props.role
    }).length !== 0) {
      alert(I18n.t('assignments.already_exists'));
      return;
    }

    const onConfirm = function () {
      // Update the store
      AssignmentActions.addAssignment(assignment);
      // Post the new assignment to the server
      ServerActions.addAssignment(assignment);
      // Send the confirm signal
      return ConfirmActions.actionConfirmed();
    };
    const onCancel = function () {
      return ConfirmActions.actionCancelled();
    };

    let confirmMessage;
    // Confirm for assigning an article to a student<commit_msg>Close the popup once an available article has been created<commit_after>import React from 'react';
import Select from 'react-select';
import Expandable from '../high_order/expandable.jsx';
import Popover from '../common/popover.jsx';
import Lookup from '../common/lookup.jsx';
import Confirm from '../common/confirm.jsx';
import ConfirmActions from '../../actions/confirm_actions.js';
import ConfirmationStore from '../../stores/confirmation_store.js';
import ServerActions from '../../actions/server_actions.js';
import AssignmentActions from '../../actions/assignment_actions.js';
import AssignmentStore from '../../stores/assignment_store.js';
import CourseUtils from '../../utils/course_utils.js';
import shallowCompare from 'react-addons-shallow-compare';

const AssignButton = React.createClass({
  displayName: 'AssignButton',

  propTypes: {
    course: React.PropTypes.object.isRequired,
    role: React.PropTypes.number.isRequired,
    student: React.PropTypes.object,
    current_user: React.PropTypes.object,
    course_id: React.PropTypes.string.isRequired,
    is_open: React.PropTypes.bool,
    permitted: React.PropTypes.bool,
    add_available: React.PropTypes.bool,
    assignments: React.PropTypes.array,
    open: React.PropTypes.func.isRequired
  },

  mixins: [ConfirmationStore.mixin],

  getInitialState() {
    return ({
      showOptions: false,
      language: this.props.course.home_wiki.language,
      project: this.props.course.home_wiki.project,
      title: '',
      showConfirm: false
    });
  },

  shouldComponentUpdate(nextProps, nextState) {
    return shallowCompare(this, nextProps, nextState);
  },

  getKey() {
    const tag = this.props.role === 0 ? 'assign_' : 'review_';
    if (this.props.student) {
      return tag + this.props.student.id;
    }
    return tag;
  },

  storeDidChange() {
    return this.setState(this.getInitialState());
  },

  stop(e) {
    return e.stopPropagation();
  },


  handleShowOptions(e) {
    e.preventDefault();
    return this.setState(
      { showOptions: true });
  },

  handleChangeTitle(e) {
    e.preventDefault();
    const title = e.target.value;
    const assignment = CourseUtils.articleFromTitleInput(title);
    const language = assignment.language ? assignment.language : this.state.language;
    const project = assignment.project ? assignment.project : this.state.project;
    return this.setState({
      title: assignment.title,
      project,
      language
    });
  },
  handleChangeLanguage(val) {
    return this.setState(
      { language: val.value });
  },
  handleChangeProject(val) {
    return this.setState(
      { project: val.value });
  },

  assign(e) {
    e.preventDefault();

    let student;
    if (this.props.student) {
      student = this.props.student.id;
    } else {
      student = null;
    }

    const assignment = {
      title: decodeURIComponent(this.state.title).trim(),
      project: this.state.project,
      language: this.state.language,
      course_id: this.props.course_id,
      user_id: student,
      role: this.props.role
    };

    if (assignment.title === '' || assignment.title === 'undefined') {
      return;
    }

    const articleTitle = assignment.title;

    // Check if the assignment exists
    if (this.props.student && AssignmentStore.getFiltered({
      articleTitle,
      user_id: this.props.student.id,
      role: this.props.role
    }).length !== 0) {
      alert(I18n.t('assignments.already_exists'));
      return;
    }

    // Close the popup after adding an available article
    const closePopup = this.props.open;
    // While adding other assignments, popup can remain open to assign multiple assignments at once
    const closeOnConfirm = this.props.add_available;

    const onConfirm = function () {
      // Close the popup after confirmation
      if (closeOnConfirm) {
        closePopup(e);
      }
      // Update the store
      AssignmentActions.addAssignment(assignment);
      // Post the new assignment to the server
      ServerActions.addAssignment(assignment);
      // Send the confirm signal
      return ConfirmActions.actionConfirmed();
    };
    const onCancel = function () {
      return ConfirmActions.actionCancelled();
    };

    let confirmMessage;
    // Confirm for assigning an article to a student
{'fraction_non_alphanumeric': 0.12455905607590317, 'fraction_numerical': 0.0009731176255929935, 'mean_word_length': 3.0343473994111876, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4553366', 'n_tokens_mistral': 2392, 'n_tokens_neox': 2384, 'n_words': 530}