<commit_before>import {
  AfterViewInit,
  ChangeDetectionStrategy,
  Component,
  ElementRef,
  Inject,
  ViewChild,
  ViewEncapsulation,
} from '@angular/core';
import { FormControl } from '@angular/forms';
import { MAT_DIALOG_DATA, MatCheckboxChange, MatDialogRef, MatSelectionList, MatSlideToggleChange } from '@angular/material';
import { BehaviorSubject, fromEvent, Observable } from 'rxjs';
import { debounceTime, distinctUntilChanged } from 'rxjs/operators';

import { ColumnValueFilterOperator, OColumnValueFilter } from '../../../../../types/o-column-value-filter.type';
import { TableFilterByColumnData } from '../../../../../types/o-table-filter-by-column-data.type';
import { Util } from '../../../../../util/util';
import { OColumn } from '../../../column/o-column.class';

@Component({
  selector: 'o-table-filter-by-column-data-dialog',
  templateUrl: 'o-table-filter-by-column-data-dialog.component.html',
  styleUrls: ['o-table-filter-by-column-data-dialog.component.scss'],
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: {
    '[class.o-filter-by-column-dialog]': 'true'
  }
})
export class OTableFilterByColumnDataDialogComponent implements AfterViewInit {

  column: OColumn;
  preloadValues: boolean = true;
  mode: string;
  private isCustomFilterSubject = new BehaviorSubject<boolean>(false);
  isCustomFilter: Observable<boolean> = this.isCustomFilterSubject.asObservable();

  private isDefaultFilterSubject = new BehaviorSubject<boolean>(false);
  isDefaultFilter: Observable<boolean> = this.isDefaultFilterSubject.asObservable();

  fcText = new FormControl();
  fcFrom = new FormControl();
  fcTo = new FormControl();

  protected columnData: Array<TableFilterByColumnData> = [];
  protected tableData: Array<any> = [];
  protected _listData: Array<TableFilterByColumnData>;

  @ViewChild('filter', { static: false }) filter: ElementRef;
  @ViewChild('filterValueList', { static: false }) filterValueList: MatSelectionList;

  constructor(
    public dialogRef: MatDialogRef<OTableFilterByColumnDataDialogComponent>,
    @Inject(MAT_DIALOG_DATA) data: any
  ) {
    if (data.column) {
      this.column = data.column;
    }
    let previousFilter: OColumnValueFilter = {
      attr: undefined,
      operator: undefined,
      values: undefined
    };
    if (data.mode) {
      this.isDefaultFilterSubject.next(data.mode === 'default');
      this.isCustomFilterSubject.next(data.mode === 'custom');
      this.mode = data.mode;
    }

    if (data.previousFilter) {
      previousFilter = data.previousFilter;
      this.isCustomFilterSubject.next([ColumnValueFilterOperator.LESS_EQUAL, ColumnValueFilterOperator.MORE_EQUAL, ColumnValueFilterOperator.BETWEEN, ColumnValueFilterOperator.EQUAL].indexOf(previousFilter.operator) !== -1);
    }
    if (data.hasOwnProperty('preloadValues')) {
      this.preloadValues = data.preloadValues;
    }
    if (data.tableData && Array.isArray(data.tableData)) {
      this.tableData = data.tableData;
      this.getDistinctValues(data.tableData, previousFilter);
      this.initializeCustomFilterValues(previousFilter);
      this.initializeDataList(previousFilter);
    }
    if (data.mode) {
      this.mode = data.mode;
    }
  }

  ngAfterViewInit() {
    this.initializeFilterEvent();
  }

  get listData(): Array<TableFilterByColumnData> {
    return this._listData;
  }

  set listData(arg: Array<TableFilterByColumnData>) {
    this._listData = arg;
  }

  initializeDataList(filter?: OColumnValueFilter): void {
    if (this.preloadValues || (filter && filter.operator === ColumnValueFilterOperator.IN)) {
      this.listData = this.columnData.slice();
    }
  }

  initializeFilterEvent() {
    if (this.filter) {
      const self = this;
      fromEvent(this.filter.nativeElement, 'keyup')
        .pipe(debounceTime(150))
        .pipe(distinctUntilChanged())
        .subscribe(() => {
          let filterValue: string = self.filter.nativeElement.value;
          filterValue = Util.normalizeString(filterValue);
          if (filterValue.indexOf('*') !== -1) {
            self.listData = self.columnData.filter(item => new RegExp('^' + Util.normalizeString(filterValue).split('*').join('.*') + '$').test(Util.normalizeString(item.value)));
          } else {
            self.listData = self.columnData.filter(item => (Util.normalizeString(item.value).indexOf(filterValue) !== -1));
          }
        });
    }
  }

  initializeCustomFilterValues(filter: OColumnValueFilter): void {
    if (filter.operator !== ColumnValueFilterOperator.IN) {
      if (ColumnValueFilterOperator.EQUAL === filter.operator) {
        if (this.isTextType()) {
          this.fcText.setValue(filter.values);
        }
      }
      if (filter.operator === ColumnValueFilterOperator.BETWEEN) {
        if (this.isDateType()) {
          this.fcFrom.setValue(new Date(filter.values[0]));
          this.fcTo.setValue(new Date(filter.values[1]));
        } else {
          this.fcFrom.setValue(filter.values[0]);<commit_msg>Fixed filtering by render value<commit_after>import {
  AfterViewInit,
  ChangeDetectionStrategy,
  Component,
  ElementRef,
  Inject,
  ViewChild,
  ViewEncapsulation,
} from '@angular/core';
import { FormControl } from '@angular/forms';
import { MAT_DIALOG_DATA, MatCheckboxChange, MatDialogRef, MatSelectionList, MatSlideToggleChange } from '@angular/material';
import { BehaviorSubject, fromEvent, Observable } from 'rxjs';
import { debounceTime, distinctUntilChanged } from 'rxjs/operators';

import { ColumnValueFilterOperator, OColumnValueFilter } from '../../../../../types/o-column-value-filter.type';
import { TableFilterByColumnData } from '../../../../../types/o-table-filter-by-column-data.type';
import { Util } from '../../../../../util/util';
import { OColumn } from '../../../column/o-column.class';

@Component({
  selector: 'o-table-filter-by-column-data-dialog',
  templateUrl: 'o-table-filter-by-column-data-dialog.component.html',
  styleUrls: ['o-table-filter-by-column-data-dialog.component.scss'],
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: {
    '[class.o-filter-by-column-dialog]': 'true'
  }
})
export class OTableFilterByColumnDataDialogComponent implements AfterViewInit {

  column: OColumn;
  preloadValues: boolean = true;
  mode: string;
  private isCustomFilterSubject = new BehaviorSubject<boolean>(false);
  isCustomFilter: Observable<boolean> = this.isCustomFilterSubject.asObservable();

  private isDefaultFilterSubject = new BehaviorSubject<boolean>(false);
  isDefaultFilter: Observable<boolean> = this.isDefaultFilterSubject.asObservable();

  fcText = new FormControl();
  fcFrom = new FormControl();
  fcTo = new FormControl();

  protected columnData: Array<TableFilterByColumnData> = [];
  protected tableData: Array<any> = [];
  protected _listData: Array<TableFilterByColumnData>;

  @ViewChild('filter', { static: false }) filter: ElementRef;
  @ViewChild('filterValueList', { static: false }) filterValueList: MatSelectionList;

  constructor(
    public dialogRef: MatDialogRef<OTableFilterByColumnDataDialogComponent>,
    @Inject(MAT_DIALOG_DATA) data: any
  ) {
    if (data.column) {
      this.column = data.column;
    }
    let previousFilter: OColumnValueFilter = {
      attr: undefined,
      operator: undefined,
      values: undefined
    };
    if (data.mode) {
      this.isDefaultFilterSubject.next(data.mode === 'default');
      this.isCustomFilterSubject.next(data.mode === 'custom');
      this.mode = data.mode;
    }

    if (data.previousFilter) {
      previousFilter = data.previousFilter;
      this.isCustomFilterSubject.next([ColumnValueFilterOperator.LESS_EQUAL, ColumnValueFilterOperator.MORE_EQUAL, ColumnValueFilterOperator.BETWEEN, ColumnValueFilterOperator.EQUAL].indexOf(previousFilter.operator) !== -1);
    }
    if (data.hasOwnProperty('preloadValues')) {
      this.preloadValues = data.preloadValues;
    }
    if (data.tableData && Array.isArray(data.tableData)) {
      this.tableData = data.tableData;
      this.getDistinctValues(data.tableData, previousFilter);
      this.initializeCustomFilterValues(previousFilter);
      this.initializeDataList(previousFilter);
    }
    if (data.mode) {
      this.mode = data.mode;
    }
  }

  ngAfterViewInit() {
    this.initializeFilterEvent();
  }

  get listData(): Array<TableFilterByColumnData> {
    return this._listData;
  }

  set listData(arg: Array<TableFilterByColumnData>) {
    this._listData = arg;
  }

  initializeDataList(filter?: OColumnValueFilter): void {
    if (this.preloadValues || (filter && filter.operator === ColumnValueFilterOperator.IN)) {
      this.listData = this.columnData.slice();
    }
  }

  initializeFilterEvent() {
    if (this.filter) {
      const self = this;
      fromEvent(this.filter.nativeElement, 'keyup')
        .pipe(debounceTime(150))
        .pipe(distinctUntilChanged())
        .subscribe(() => {
          let filterValue: string = self.filter.nativeElement.value;
          filterValue = Util.normalizeString(filterValue);
          if (filterValue.indexOf('*') !== -1) {
            self.listData = self.columnData.filter(item => new RegExp('^' + Util.normalizeString(filterValue).split('*').join('.*') + '$').test(Util.normalizeString(item.renderedValue)));
          } else {
            self.listData = self.columnData.filter(item => (Util.normalizeString(item.renderedValue).indexOf(filterValue) !== -1));
          }
        });
    }
  }

  initializeCustomFilterValues(filter: OColumnValueFilter): void {
    if (filter.operator !== ColumnValueFilterOperator.IN) {
      if (ColumnValueFilterOperator.EQUAL === filter.operator) {
        if (this.isTextType()) {
          this.fcText.setValue(filter.values);
        }
      }
      if (filter.operator === ColumnValueFilterOperator.BETWEEN) {
        if (this.isDateType()) {
          this.fcFrom.setValue(new Date(filter.values[0]));
          this.fcTo.setValue(new Date(filter.values[1]));
        } else {
          this.fcFrom.setValue(filter.values[0]);
{'fraction_non_alphanumeric': 0.1383399209486166, 'fraction_numerical': 0.0017786561264822134, 'mean_word_length': 3.714019562179786, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, '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': '4746583', 'n_tokens_mistral': 3000, 'n_tokens_neox': 2972, 'n_words': 499}