<commit_before>import {
  Component,
  Input,
  Output,
  ElementRef,
  EventEmitter,
  HostListener,
  KeyValueDiffers,
  ContentChildren,
  OnInit,
  QueryList,
  DoCheck,
  AfterViewInit,
  IterableDiffer,
  HostBinding
} from '@angular/core';
import { StateService } from '../services/State';
import { Visibility } from '../directives/Visibility';
import { forceFillColumnWidths, adjustColumnWidths } from '../utils/math';
import { ColumnMode } from '../enums/ColumnMode';
import { TableOptions } from '../models/TableOptions';
import { TableColumn } from '../models/TableColumn';
import { DataTableColumn } from './DataTableColumn';
import { DataTableHeader } from './header/Header';
import { DataTableBody } from './body/Body';
import { DataTableFooter } from './footer/Footer';
import './datatable.scss';

@Component({
  selector: 'datatable',
  template: `
  	<div
      visibility-observer
      (onVisibilityChange)="adjustSizes()">
      <datatable-header
        (onColumnChange)="onColumnChange.emit($event)">
      </datatable-header>
      <datatable-body
        (onRowClick)="onRowClick.emit($event)"
        (onRowSelect)="onRowSelect($event)">
      </datatable-body>
      <datatable-footer
        (onPageChange)="onPageChanged($event)">
      </datatable-footer>
    </div>
  `,
  directives: [
    DataTableHeader,
    DataTableBody,
    DataTableFooter,
    Visibility
  ],
  providers: [StateService]
})
export class DataTable implements OnInit, DoCheck, AfterViewInit {

  @Input() options: TableOptions;
  @Input() rows: any[];
  @Input() selected: any[];

  @Output() onPageChange: EventEmitter<any> = new EventEmitter();
  @Output() onRowsUpdate: EventEmitter<any> = new EventEmitter();
  @Output() onRowClick: EventEmitter<any> = new EventEmitter();
  @Output() onSelectionChange: EventEmitter<any> = new EventEmitter();
  @Output() onColumnChange: EventEmitter<any> = new EventEmitter();

  @ContentChildren(DataTableColumn) columns: QueryList<DataTableColumn>;

  private element: HTMLElement;
  private rowDiffer: IterableDiffer;
  private colDiffer: IterableDiffer;

  @HostBinding('class.datatable') isDatatable: boolean = true;

  constructor(element: ElementRef, private state: StateService, differs: KeyValueDiffers) {
    this.element = element.nativeElement;
    this.rowDiffer = differs.find({}).create(null);
    this.colDiffer = differs.find({}).create(null);
  }

  ngOnInit(): void {
    const {options, rows, selected} = this;

    this.state
      .setOptions(options)
      .setRows(rows)
      .setSelected(selected);
  }

  ngAfterViewInit(): void {
    this.adjustColumns();

    if (this.columns.length) {
      setTimeout(() => {
        for (let col of this.columns.toArray()) {
          this.options.columns.push(new TableColumn(col));
        }
      });
    }
  }

  ngDoCheck(): void {
    if (this.rowDiffer.diff(this.rows)) {
      this.state.setRows(this.rows);
      this.onRowsUpdate.emit(this.rows);
    }

    this.checkColumnToggles();
  }

  checkColumnToggles(): void {
    const colDiff: any = this.colDiffer.diff(this.options.columns);
    if (colDiff) {
      let chngd: boolean = false;
      colDiff.forEachAddedItem(() => {
        chngd = true;
        return;
      });

      if (!chngd) {
        colDiff.forEachRemovedItem(() => {
          chngd = true;
          return;
        });
      }

      // if a column was added or removed
      // we need to re-adjust columns
      if (chngd) this.adjustColumns();
    }
  }

  adjustSizes(): void {
    let {height, width} = this.element.getBoundingClientRect();
    this.state.innerWidth = Math.floor(width);

    if (this.options.scrollbarV) {
      if (this.options.headerHeight) height = -this.options.headerHeight;
      if (this.options.footerHeight) height = -this.options.footerHeight;
      this.state.bodyHeight = height;
    }

    this.adjustColumns();
  }

  adjustColumns(forceIdx?: number): void {
    if (!this.options.columns) return;

    let width: number = this.state.innerWidth;
    if (this.options.scrollbarV) {
      width = -this.state.scrollbarWidth;
    }

    if (this.options.columnMode === ColumnMode.force) {
      forceFillColumnWidths(this.options.columns, width, forceIdx);
    } else if (this.options.columnMode === ColumnMode.flex) {
      adjustColumnWidths(this.options.columns, width);
    }
  }

  onPageChanged(event): void {
    this.state.setPage(event);
    this.onPageChange.emit(event);
  }

  onRowSelect(event): void {
    this.state.setSelected(event);
    this.onSelectionChange.emit(event);
  }

  @HostListener('window:resize') resize(): void {
    this.adjustSizes();
  }

  @HostBinding('class.fixed-header') get isFixedHeader() {
    const headerHeight: number|string = this.options.headerHeight;
    return (typeof headerHeight === 'string') ? (<string>headerHeight) !== 'auto' : true;
  }

  @HostBinding('class.fixed-row') get isFixedRow() {
    const rowHeight: number|string = this.options.rowHeight;
    return (typeof rowHeight === 'string') ? (<string>rowHeight) !== 'auto' : true;
  }

  @HostBinding('class.scroll-vertical') get isVertScroll() {
    return this.options.scrollbarV;
  }

  @HostBinding('class.scroll-horz') get isHorScroll() {
    return this.options.scrollbarH;
  }

  @HostBinding('class.selectable') get isSelectable() {
    // return this.options.selectable; //fixme doesn't exist
    return false;
  }

  @HostBinding('class.checkboxable') get isCheckboxable() {
    // return this.options.checkboxable; //fixme doesn't exist
    return false;
  }

}
<commit_msg>fix(datatable): revert changes<commit_after>import {
  Component,
  Input,
  Output,
  ElementRef,
  EventEmitter,
  HostListener,
  KeyValueDiffers,
  ContentChildren,
  OnInit,
  QueryList,
  DoCheck,
  AfterViewInit,
  IterableDiffer,
  HostBinding
} from '@angular/core';
import { StateService } from '../services/State';
import { Visibility } from '../directives/Visibility';
import { forceFillColumnWidths, adjustColumnWidths } from '../utils/math';
import { ColumnMode } from '../enums/ColumnMode';
import { TableOptions } from '../models/TableOptions';
import { TableColumn } from '../models/TableColumn';
import { DataTableColumn } from './DataTableColumn';
import { DataTableHeader } from './header/Header';
import { DataTableBody } from './body/Body';
import { DataTableFooter } from './footer/Footer';
import './datatable.scss';

@Component({
  selector: 'datatable',
  template: `
  	<div
      visibility-observer
      (onVisibilityChange)="adjustSizes()">
      <datatable-header
        (onColumnChange)="onColumnChange.emit($event)">
      </datatable-header>
      <datatable-body
        (onRowClick)="onRowClick.emit($event)"
        (onRowSelect)="onRowSelect($event)">
      </datatable-body>
      <datatable-footer
        (onPageChange)="onPageChanged($event)">
      </datatable-footer>
    </div>
  `,
  directives: [
    DataTableHeader,
    DataTableBody,
    DataTableFooter,
    Visibility
  ],
  providers: [StateService]
})
export class DataTable implements OnInit, DoCheck, AfterViewInit {

  @Input() options: TableOptions;
  @Input() rows: any[];
  @Input() selected: any[];

  @Output() onPageChange: EventEmitter<any> = new EventEmitter();
  @Output() onRowsUpdate: EventEmitter<any> = new EventEmitter();
  @Output() onRowClick: EventEmitter<any> = new EventEmitter();
  @Output() onSelectionChange: EventEmitter<any> = new EventEmitter();
  @Output() onColumnChange: EventEmitter<any> = new EventEmitter();

  @ContentChildren(DataTableColumn) columns: QueryList<DataTableColumn>;

  private element: HTMLElement;
  private rowDiffer: IterableDiffer;
  private colDiffer: IterableDiffer;

  @HostBinding('class.datatable') isDatatable: boolean = true;

  constructor(element: ElementRef, private state: StateService, differs: KeyValueDiffers) {
    this.element = element.nativeElement;
    this.rowDiffer = differs.find({}).create(null);
    this.colDiffer = differs.find({}).create(null);
  }

  ngOnInit(): void {
    const {options, rows, selected} = this;

    this.state
      .setOptions(options)
      .setRows(rows)
      .setSelected(selected);
  }

  ngAfterViewInit(): void {
    this.adjustColumns();

    if (this.columns.length) {
      setTimeout(() => {
        for (let col of this.columns.toArray()) {
          this.options.columns.push(new TableColumn(col));
        }
      });
    }
  }

  ngDoCheck(): void {
    if (this.rowDiffer.diff(this.rows)) {
      this.state.setRows(this.rows);
      this.onRowsUpdate.emit(this.rows);
    }

    this.checkColumnToggles();
  }

  checkColumnToggles(): void {
    const colDiff: any = this.colDiffer.diff(this.options.columns);
    if (colDiff) {
      let chngd: boolean = false;
      colDiff.forEachAddedItem(() => {
        chngd = true;
        return false;
      });

      if (!chngd) {
        colDiff.forEachRemovedItem(() => {
          chngd = true;
          return false;
        });
      }

      // if a column was added or removed
      // we need to re-adjust columns
      if (chngd) this.adjustColumns();
    }
  }

  adjustSizes(): void {
    let {height, width} = this.element.getBoundingClientRect();
    this.state.innerWidth = Math.floor(width);

    if (this.options.scrollbarV) {
      if (this.options.headerHeight) height = -this.options.headerHeight;
      if (this.options.footerHeight) height = -this.options.footerHeight;
      this.state.bodyHeight = height;
    }

    this.adjustColumns();
  }

  adjustColumns(forceIdx?: number): void {
    if (!this.options.columns) return;

    let width: number = this.state.innerWidth;
    if (this.options.scrollbarV) {
      width = -this.state.scrollbarWidth;
    }

    if (this.options.columnMode === ColumnMode.force) {
      forceFillColumnWidths(this.options.columns, width, forceIdx);
    } else if (this.options.columnMode === ColumnMode.flex) {
      adjustColumnWidths(this.options.columns, width);
    }
  }

  onPageChanged(event): void {
    this.state.setPage(event);
    this.onPageChange.emit(event);
  }

  onRowSelect(event): void {
    this.state.setSelected(event);
    this.onSelectionChange.emit(event);
  }

  @HostListener('window:resize') resize(): void {
    this.adjustSizes();
  }

  @HostBinding('class.fixed-header') get isFixedHeader() {
    const headerHeight: number|string = this.options.headerHeight;
    return (typeof headerHeight === 'string') ? (<string>headerHeight) !== 'auto' : true;
  }

  @HostBinding('class.fixed-row') get isFixedRow() {
    const rowHeight: number|string = this.options.rowHeight;
    return (typeof rowHeight === 'string') ? (<string>rowHeight) !== 'auto' : true;
  }

  @HostBinding('class.scroll-vertical') get isVertScroll() {
    return this.options.scrollbarV;
  }

  @HostBinding('class.scroll-horz') get isHorScroll() {
    return this.options.scrollbarH;
  }

  @HostBinding('class.selectable') get isSelectable() {
    // return this.options.selectable; //fixme doesn't exist
    return false;
  }

  @HostBinding('class.checkboxable') get isCheckboxable() {
    // return this.options.checkboxable; //fixme doesn't exist
    return false;
  }

}

{'fraction_non_alphanumeric': 0.14135002235136343, 'fraction_numerical': 0.0, 'mean_word_length': 3.391833529642717, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 41, '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': '7529002', 'n_tokens_mistral': 3504, 'n_tokens_neox': 3450, 'n_words': 684}