<commit_before>import Ember from 'ember';
import layout from '../templates/components/justa-table';

const {
  A,
  Component,
  run,
  isEmpty,
  RSVP,
  assert,
  get,
  getWithDefault,
  set,
  setProperties,
  computed,
  computed: { empty }
} = Ember;

export default Component.extend({
  layout,
  classNames: ['justa-table'],
  classNameBindings: ['isLoading', 'stickyHeaders'],

  init() {
    this._super(...arguments);

    let onLoadMoreRowsAction = this.getAttr('on-load-more-rows');
    if (!onLoadMoreRowsAction) {
      this.attrs['on-load-more-rows'] = RSVP.resolve();
    }
  },

  /**
    Adds a dynamic key based on rowGroupDataName that recomputes the
    collapseTableData. Only adds the key if using a collapsable table.
    @private
  */
  _addRowGroupDataNamePropertyKey() {
    let rowGroupDataName = this.get('rowGroupDataName');
    this.get('collapseTableData').property(`content.@each.${rowGroupDataName}`);
  },

  /**
    The initial / max height of the table, will overflow if rows exceed this
    number.
    @public
  */
  tableHeight: 500,

  /**
    If the table should use pagination. Will fire the 'on-load-more-rows'
    action when it enters the viewport.
    @public
  */
  paginate: false,

  /**
    Css classes to apply to table rows.
    @public
  */
  rowClasses: null,

  /**
    If content is empty.
    @public
  */
  noContent: empty('content'),

  /**
    Name of data property for row groups in the table columns
    @public
  */
  rowGroupDataName: 'data',

  /**
    Ensure header heights are equal. Schedules after render to ensure it's
    called once per table.
    @public
  */
  ensureEqualHeaderHeight() {
    run.scheduleOnce('afterRender', this, this._ensureEqualHeaderHeight);
  },

  /**
    If we have any fixed columns, make sure the fixed columns and standard
    table column header heights stay in sync.
    @private
  */
  _ensureEqualHeaderHeight() {
    let fixedHeader = this.$('.fixed-table-columns-wrapper th:first-of-type');
    if (isEmpty(fixedHeader)) {
      return;
    }
    let columnHeader = this.$('.table-columns-wrapper:not(.fixed-table-columns-wrapper) th:first-of-type');
    let maxHeight = Math.max(fixedHeader.height(), columnHeader.height());

    fixedHeader.height(maxHeight);
    columnHeader.height(maxHeight);

    this._resizeTable();
  },

  /**
    Sets the table height before rendering. If the height of the rows is less
    than the specified tableHeight, it will resize.
    @private
  */
  _resizeTable() {
    let requestedHeight = this.get('tableHeight');
    let actualHeight = this.$('.table-columns table').outerHeight();
    let totalHeight = Math.min(requestedHeight, actualHeight);

    this.$().height(totalHeight);
    this.$('.table-columns').height(totalHeight);
  },

  /**
    Queues sending 'didRenderTable' action. This is called once the columns
    have rendered data.
    @public
  */
  didRenderCollection() {
    run.scheduleOnce('afterRender', this, this._sendRenderAction);
    this.ensureEqualHeaderHeight();
  },

  /**<commit_msg>disable height resize<commit_after>import Ember from 'ember';
import layout from '../templates/components/justa-table';

const {
  A,
  Component,
  run,
  isEmpty,
  RSVP,
  assert,
  get,
  getWithDefault,
  set,
  setProperties,
  computed,
  computed: { empty }
} = Ember;

export default Component.extend({
  layout,
  classNames: ['justa-table'],
  classNameBindings: ['isLoading', 'stickyHeaders'],

  init() {
    this._super(...arguments);

    let onLoadMoreRowsAction = this.getAttr('on-load-more-rows');
    if (!onLoadMoreRowsAction) {
      this.attrs['on-load-more-rows'] = RSVP.resolve();
    }
  },

  /**
    Adds a dynamic key based on rowGroupDataName that recomputes the
    collapseTableData. Only adds the key if using a collapsable table.
    @private
  */
  _addRowGroupDataNamePropertyKey() {
    let rowGroupDataName = this.get('rowGroupDataName');
    this.get('collapseTableData').property(`content.@each.${rowGroupDataName}`);
  },

  /**
    The initial / max height of the table, will overflow if rows exceed this
    number.
    @public
  */
  tableHeight: 500,

  /**
    If the table should use pagination. Will fire the 'on-load-more-rows'
    action when it enters the viewport.
    @public
  */
  paginate: false,

  /**
    Css classes to apply to table rows.
    @public
  */
  rowClasses: null,

  /**
    If content is empty.
    @public
  */
  noContent: empty('content'),

  /**
    Name of data property for row groups in the table columns
    @public
  */
  rowGroupDataName: 'data',

  /**
    Ensure header heights are equal. Schedules after render to ensure it's
    called once per table.
    @public
  */
  ensureEqualHeaderHeight() {
    run.scheduleOnce('afterRender', this, this._ensureEqualHeaderHeight);
  },

  /**
    If we have any fixed columns, make sure the fixed columns and standard
    table column header heights stay in sync.
    @private
  */
  _ensureEqualHeaderHeight() {
    let fixedHeader = this.$('.fixed-table-columns-wrapper th:first-of-type');
    if (isEmpty(fixedHeader)) {
      return;
    }
    let columnHeader = this.$('.table-columns-wrapper:not(.fixed-table-columns-wrapper) th:first-of-type');
    let maxHeight = Math.max(fixedHeader.height(), columnHeader.height());

    fixedHeader.height(maxHeight);
    columnHeader.height(maxHeight);

    this._resizeTable();
  },

  /**
    Sets the table height before rendering. If the height of the rows is less
    than the specified tableHeight, it will resize.
    @private
  */
  _resizeTable() {
    // TODO reenable with better height logic for tables without many rows
    // let requestedHeight = this.get('tableHeight');
    // let actualHeight = this.$('.table-columns table').outerHeight();
    // let totalHeight = Math.min(requestedHeight, actualHeight);

    // this.$().height(totalHeight);
    // this.$('.table-columns').height(totalHeight);
  },

  /**
    Queues sending 'didRenderTable' action. This is called once the columns
    have rendered data.
    @public
  */
  didRenderCollection() {
    run.scheduleOnce('afterRender', this, this._sendRenderAction);
    this.ensureEqualHeaderHeight();
  },

  /**
{'fraction_non_alphanumeric': 0.1247187399549984, 'fraction_numerical': 0.0009643201542912247, 'mean_word_length': 3.1211920529801325, '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': '4715291', 'n_tokens_mistral': 1894, 'n_tokens_neox': 1846, 'n_words': 511}