<commit_before>var Attachments = React.createClass({
  getInitialState: function(){
    return({
      subjectId: null,
      attachments: [],
      newAttachment: false,
      loading: false
    })
  },
  init: function(){
    var input_id = `#file_input_${this.props.customerId}`;
    var file = $(input_id);
    var _this = this;
    $(file).fileupload({
      dataType: 'json',
      url: this.url(),
      done: function (e, data) {
        _this.loadAttachments();
        $('#progress').hide();
        $('#progress .progress-bar').css('width', '0%');
        _this.toggleNew();
      },
      progressall: function (e, data) {
        $('#progress').show();
        $('#file_input').blur();
        var progress = parseInt(data.loaded / data.total * 100, 10);
        $('#progress .progress-bar').css('width', progress + '%');
      }
    });
  },
  componentDidMount: function(){
    this.loadAttachments();
    this.init();
  },
  componentDidUpdate: function(){
    if (this.props.subjectId != null && this.props.subjectId != this.state.subjectId && !this.state.loading){
      this.loadAttachments();
      this.init();
    }
  },
  url: function(){
    return `/crm/attachments?subject_id=${this.props.subjectId}&subject_type=${this.props.subjectType}`
  },
  render: function(){
    return(
      <div>
        {this.list()}
        {this.newAttachment()}
        <div id="new_attachment_form" style={{display: 'none'}}>
          <div className="form-group">
            <input id={`file_input_${this.props.customerId}`} type="file" className="form-control" ref='fileUpload' />
            <div id="progress" className="progress" style={{display: 'none'}}>
              <div className="progress-bar progress-bar-primary"></div>
            </div>
          </div>
        </div>
      </div>
    );
  },
  list: function(){
    var attachments = [];
    if (this.state.attachments.length==0 && (this.props.new==undefined || this.props.new==true)){
      return(<div className="alert alert-info alert-sm">There are no attachments to list</div>);
    }else if (this.state.attachments.length>0){
      this.state.attachments.forEach(function(attachment){
        attachments.push(
          <li key={attachment.id}><a href={attachment.url} target="_blank">{attachment.file}</a></li>
        )
      });
      return(
        <div>
          <hr />
          <ol>{attachments}</ol>
        </div>
      );
    }
  },
  loadAttachments: function(){
    if (!this.state.loading){
      this.setState({loading: true});
      $.ajax({<commit_msg>cleaned up attachments<commit_after>var Attachments = React.createClass({
  getInitialState: function(){
    return({
      subjectId: null,
      attachments: [],
      newAttachment: false,
      loading: false
    })
  },
  init: function(){
    var input_id = `#file_input_${this.props.customerId}`;
    var file = $(input_id);
    var _this = this;
    $(file).fileupload({
      dataType: 'json',
      url: this.url(),
      done: function (e, data) {
        _this.loadAttachments();
        $('#progress').hide();
        $('#progress .progress-bar').css('width', '0%');
        _this.toggleNew();
      },
      progressall: function (e, data) {
        $('#progress').show();
        $('#file_input').blur();
        var progress = parseInt(data.loaded / data.total * 100, 10);
        $('#progress .progress-bar').css('width', progress + '%');
      }
    });
  },
  componentDidMount: function(){
    this.loadAttachments();
    this.init();
  },
  componentDidUpdate: function(){
    if (this.props.subjectId != null && this.props.subjectId != this.state.subjectId && !this.state.loading){
      this.loadAttachments();
      this.init();
    }
  },
  url: function(){
    return `/crm/attachments?subject_id=${this.props.subjectId}&subject_type=${this.props.subjectType}`
  },
  render: function(){
    return(
      <div>
        {this.list()}
        {this.newAttachment()}
        <div id="new_attachment_form" style={{display: 'none'}}>
          <div className="form-group">
            <input id={`file_input_${this.props.customerId}`} type="file" className="form-control" ref='fileUpload' />
            <div id="progress" className="progress" style={{display: 'none'}}>
              <div className="progress-bar progress-bar-primary"></div>
            </div>
          </div>
        </div>
      </div>
    );
  },
  list: function(){
    var attachments = [];
    if (this.state.attachments.length==0 && (this.props.new==undefined || this.props.new==true)){
      return(<div className="alert alert-info alert-sm">There are no attachments to list</div>);
    }else if (this.state.attachments.length>0){
      this.state.attachments.forEach(function(attachment){
        if (attachment.name){
          var filename = attachment.name;
        }else{
          var filename = attachment.file;
        }
        attachments.push(
          <li key={attachment.id}><a href={attachment.url} target="_blank">{filename}</a></li>
        )
      });
      return(
        <div className="well well-sm">
          <ol style={{marginBottom: 0}}>{attachments}</ol>
        </div>
      );
    }
  },
  loadAttachments: function(){
    if (!this.state.loading){
      this.setState({loading: true});
      $.ajax({
{'fraction_non_alphanumeric': 0.18114707552526974, 'fraction_numerical': 0.003217868635245126, 'mean_word_length': 2.5486903962390866, 'pattern_counts': {'":': 0, '<': 46, '<?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': '2648987', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1614, 'n_words': 291}