<commit_before>import Ember from "ember";
import config from '../config/environment';

const {
  computed,
  run
} = Ember;

const MAX_COLUMNS = 3;

export default Ember.Controller.extend({
  emberCli: Ember.inject.service('ember-cli'),
  version: config.APP.version,

  queryParams: ['numColumns'],
  numColumns: 2,

  init() {
    this._super(...arguments);
    this.setupWindowUpdate();
  },

  /**
   * Output from the build, sets the `code` attr on the component
   * @type {String}
   */
  buildOutput: '',

  /**
   * If the code is currently being built
   * @type {boolean}
   */
  isBuilding: false,

  /**
   * If the edited code has not been saved by the user
   * @type {boolean}
   */
  unsaved: true,

  /**
   * File in the current active editor column
   * @type {Object}
   */
  activeFile: null,

  /**
   * Column which has the currently focused editor
   * @type {Number}
   */
  activeEditorCol: null,

  col1File: null,
  col2File: null,
  col3File: null,
  col1Active: computed.equal('activeEditorCol','1'),
  col2Active: computed.equal('activeEditorCol','2'),
  col3Active: computed.equal('activeEditorCol','3'),
  showCol1: computed.gte('realNumColumns', 1),
  showCol2: computed.gte('realNumColumns', 2),
  showCol3: computed.gte('realNumColumns', 3),

  /**
   * Errors during build
   * @type {Array}     Array of errors
   */
  buildErrors: null,

  /**
   * Whether user wishes the code to automatically run
   * @type {boolean}
   */
  isLiveReload: false,

  /**
   * Build the application and set the iframe code
   */
  buildApp () {
    if (this.get('isDestroyed')) {
      return;
    }

    this.set('isBuilding', true);
    this.set('buildErrors', []);

    this.get('emberCli').compileGist(this.get('model')).then(buildOutput => {
      this.set('isBuilding', false);
      this.set('buildOutput', buildOutput);
    })
    .catch(errors => {
      this.set('isBuilding', false);
      this.set('buildErrors', errors);
      errors.forEach(error => {
        console.error(error);
      });
    });
  },

  realNumColumns: computed('numColumns', function() {
    return Math.min(this.get('numColumns'), MAX_COLUMNS);
  }),

  /**
   * Set the initial file columns
   */
  initializeColumns() {
    let files = this.get('model.files');
    let numColumns = this.get('realNumColumns');

    let j = 0;
    for (let i = 0; i < numColumns; ++i) {
      let key = 'col' + (i + 1) + 'File';
      if (!this.get(key)) {
        if (files) {
          j = 0;
          while (!this.isOpen(files.objectAt(j))) {
            j++;
          }
          let file = files.objectAt(j);
          if (file) {
            this.set(key, file);
          }
        }
      }
    }
  },

  /**
   * Returns true if the passed in file is currently open
   * @param {Object} one of the files in the gist
   * @return {boolean}
   */
  isOpen(file) {
    if (!file) {
      return false;
    }

    console.log(this.get('col1File.fileName'), file.get('fileName'));
    if (this.get('col1File.fileName') === file.get('fileName')) {
      return false;
    }
    if (this.get('col2File.fileName') === file.get('fileName')) {
      return false;
    }
    if (this.get('col3File.fileName') === file.get('fileName')) {
      return false;
    }

    return true;
  },

  rebuildApp: function() {
    if (this.get('isLiveReload')) {
      run.debounce(this, this.buildApp, 500);
    }
  },

  actions: {
    contentsChanged() {
      this.set('unsaved', true);
      this.rebuildApp();
    },

    liveReloadChanged(isLiveReload) {
      this.set('isLiveReload', isLiveReload);
      this.rebuildApp();
    },

    focusEditor (editor) {<commit_msg>Cleanup<commit_after>import Ember from "ember";
import config from '../config/environment';

const {
  computed,
  run
} = Ember;

const MAX_COLUMNS = 3;

export default Ember.Controller.extend({
  emberCli: Ember.inject.service('ember-cli'),
  version: config.APP.version,

  queryParams: ['numColumns'],
  numColumns: 2,

  init() {
    this._super(...arguments);
    this.setupWindowUpdate();
  },

  /**
   * Output from the build, sets the `code` attr on the component
   * @type {String}
   */
  buildOutput: '',

  /**
   * If the code is currently being built
   * @type {boolean}
   */
  isBuilding: false,

  /**
   * If the edited code has not been saved by the user
   * @type {boolean}
   */
  unsaved: true,

  /**
   * File in the current active editor column
   * @type {Object}
   */
  activeFile: null,

  /**
   * Column which has the currently focused editor
   * @type {Number}
   */
  activeEditorCol: null,

  col1File: null,
  col2File: null,
  col3File: null,
  col1Active: computed.equal('activeEditorCol','1'),
  col2Active: computed.equal('activeEditorCol','2'),
  col3Active: computed.equal('activeEditorCol','3'),
  showCol1: computed.gte('realNumColumns', 1),
  showCol2: computed.gte('realNumColumns', 2),
  showCol3: computed.gte('realNumColumns', 3),

  /**
   * Errors during build
   * @type {Array}     Array of errors
   */
  buildErrors: null,

  /**
   * Whether user wishes the code to automatically run
   * @type {boolean}
   */
  isLiveReload: true,

  /**
   * Build the application and set the iframe code
   */
  buildApp () {
    if (this.get('isDestroyed')) {
      return;
    }

    this.set('isBuilding', true);
    this.set('buildErrors', []);

    this.get('emberCli').compileGist(this.get('model')).then(buildOutput => {
      this.set('isBuilding', false);
      this.set('buildOutput', buildOutput);
    })
    .catch(errors => {
      this.set('isBuilding', false);
      this.set('buildErrors', errors);
      errors.forEach(error => {
        console.error(error);
      });
    });
  },

  realNumColumns: computed('numColumns', function() {
    return Math.min(this.get('numColumns'), MAX_COLUMNS);
  }),

  /**
   * Set the initial file columns
   */
  initializeColumns() {
    let files = this.get('model.files');
    let numColumns = this.get('realNumColumns');

    let j = 0;
    for (let i = 0; i < numColumns; ++i) {
      let key = 'col' + (i + 1) + 'File';
      if (!this.get(key)) {
        if (files) {
          j = 0;
          while (!this.isOpen(files.objectAt(j))) {
            j++;
          }
          let file = files.objectAt(j);
          if (file) {
            this.set(key, file);
          }
        }
      }
    }
  },

  /**
   * Returns true if the passed in file is currently open
   * @param {Object} one of the files in the gist
   * @return {boolean}
   */
  isOpen(file) {
    if (!file) {
      return false;
    }

    if (this.get('col1File.fileName') === file.get('fileName')) {
      return false;
    }
    if (this.get('col2File.fileName') === file.get('fileName')) {
      return false;
    }
    if (this.get('col3File.fileName') === file.get('fileName')) {
      return false;
    }

    return true;
  },

  rebuildApp: function() {
    if (this.get('isLiveReload')) {
      run.debounce(this, this.buildApp, 500);
    }
  },

  actions: {
    contentsChanged() {
      this.set('unsaved', true);
      this.rebuildApp();
    },

    liveReloadChanged(isLiveReload) {
      this.set('isLiveReload', isLiveReload);
      this.rebuildApp();
    },

    focusEditor (editor) {
{'fraction_non_alphanumeric': 0.1592822636300897, 'fraction_numerical': 0.00759144237405107, 'mean_word_length': 2.536359199609566, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '1320145', 'n_tokens_mistral': 2446, 'n_tokens_neox': 2375, 'n_words': 546}