<commit_before>import Ember from 'ember';

const {
  Component,
  computed,
  observer,
  run,
  assert,
  $
} = Ember;

const { bind } = run;
const { htmlSafe } = Ember.String;

export default Component.extend({
  classNames: ['file-picker'],
  classNameBindings: ['multiple:multiple:single'],
  accept: '*',
  multiple: false,
  preview: true,
  dropzone: true,
  progress: true,
  readAs: 'readAsFile',

  progressStyle: computed('progressValue', function() {
    var width = this.get('progressValue') || 0;
    return htmlSafe('width: ' + width + '%;');
  }),

  /**
   * When the component got inserted
   */
  didInsertElement: function() {
    this.hideInput();
    this.hidePreview();
    this.hideProgress();

    this.$('.file-picker__input').on(
      'change', bind(this, 'filesSelected')
    );
  },

  willDestroyElement: function() {
    this.$('.file-picker__input').off(
      'change', bind(this, 'filesSelected')
    );
  },

  /**
   * When the file input changed (a file got selected)
   * @param  {Event} event The file change event
   */
  filesSelected: function(event) {
    this.handleFiles(event.target.files);
  },

  handleFiles: function(files) {
    // TODO implement
    // if (!this.isValidFileType(files)) {
    //   this.set('errors.fileTypeNotAllowed', true);
    //   return;
    // }

    if (this.get('preview')) {
      this.updatePreview(files);
    }

    if (this.get('multiple')) {
      this.sendAction('filesLoaded', files);
    } else {
      if (this.get('readAs') === 'readAsFile') {
        this.sendAction('fileLoaded', files[0]);
      } else {
        this.readFile(files[0], this.get('readAs'))<commit_msg>add option to validate files<commit_after>import Ember from 'ember';

const {
  Component,
  computed,
  observer,
  run,
  assert,
  $
} = Ember;

const { bind } = run;
const { htmlSafe } = Ember.String;

export default Component.extend({
  classNames: ['file-picker'],
  classNameBindings: ['multiple:multiple:single'],
  accept: '*',
  multiple: false,
  preview: true,
  dropzone: true,
  progress: true,
  readAs: 'readAsFile',

  progressStyle: computed('progressValue', function() {
    var width = this.get('progressValue') || 0;
    return htmlSafe('width: ' + width + '%;');
  }),

  /**
   * When the component got inserted
   */
  didInsertElement: function() {
    this.hideInput();
    this.hidePreview();
    this.hideProgress();

    this.$('.file-picker__input').on(
      'change', bind(this, 'filesSelected')
    );
  },

  willDestroyElement: function() {
    this.$('.file-picker__input').off(
      'change', bind(this, 'filesSelected')
    );
  },

  /**
   * When the file input changed (a file got selected)
   * @param  {Event} event The file change event
   */
  filesSelected: function(event) {
    this.handleFiles(event.target.files);
  },

  handleFiles: function(files) {
    if (this.filesAreValid === 'function') {
      if (!this.filesAreValid(files)) {
        return;
      }
    }

    if (this.get('preview')) {
      this.updatePreview(files);
    }

    if (this.get('multiple')) {
      this.sendAction('filesLoaded', files);
    } else {
      if (this.get('readAs') === 'readAsFile') {
        this.sendAction('fileLoaded', files[0]);
      } else {
        this.readFile(files[0], this.get('readAs'))
{'fraction_non_alphanumeric': 0.16822995461422088, 'fraction_numerical': 0.001815431164901664, 'mean_word_length': 3.046511627906977, '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': '2825756', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1050, 'n_words': 220}