<commit_before>import { 
    Component, OnInit, OnChanges, Input, Output, ViewChild, ElementRef, ViewEncapsulation, EventEmitter, SimpleChange   
} from '@angular/core';
import { Router } from '@angular/router'

import { DatagridSettings, DatagridLangs, DatagridRoutes, DatagridFilter, RouteItem, LazyloadEvent } from './datagrid.model';
import { PaginationSettings } from '../pagination/pagination.model';
import { SelectItem, SelectSettings } from '../select/select.model';
import { PopoverComponent } from '../popover/popover.component';

import { OverwriteService } from '../../shared/services/overwrite.service';
import { HelperService } from '../../shared/services/helper.service';

@Component({ 
    moduleId: module.id,
    selector: 'fox-datagrid',
    templateUrl: 'datagrid.component.html',
    styleUrls: ['datagrid.component.css'],
    encapsulation: ViewEncapsulation.None
})
export class DatagridComponent implements OnInit, OnChanges {
    @Input() settings: DatagridSettings;
    @Input() langs: DatagridLangs;
    @Input() routes: DatagridRoutes;
    @Input() filters: any;
    @Input() rows: Array<any>;
    @Input() total: number = 0;

    @Output() lazyLoad: EventEmitter<any> = new EventEmitter();
    @Output() remove: EventEmitter<any> = new EventEmitter();
    @Output() removeSelected: EventEmitter<any> = new EventEmitter();
    @Output() rowClick: EventEmitter<any> = new EventEmitter();
    @Output() rowSelect: EventEmitter<any> = new EventEmitter();
    @Output() rowUnselect: EventEmitter<any> = new EventEmitter();
    @Output() filtersReseted: EventEmitter<any> = new EventEmitter();
    @Output() filtersSubmited: EventEmitter<any> = new EventEmitter();
    @Output() sortSubmited: EventEmitter<any> = new EventEmitter();
    
    protected totalRowsView: number;
    protected totalRowsViewOptions: Array<SelectItem> = [];
    protected paginationSettings: PaginationSettings = {
        max: 5
    }
    protected totalSettings: SelectSettings = {
        required: true
    }
    protected defaultLangs: DatagridLangs;
    protected defaultSettings: DatagridSettings;
    protected currentPage: number = 1;
    protected firstItem: number = 0;
    protected sortedField: string;
    protected sortedOrder: 'asc' | 'desc';
    protected viewedItemsCount: number = 0;
    protected totalPages: number = 1;
    protected checkedItems: Array<number> = [];
    protected filtersData: any = { };
    protected isPreloaded: boolean;

    constructor(
        private router: Router, 
        private overwriteService: OverwriteService,
        private helperService: HelperService
    ) {
        this.defaultSettings = overwriteService.getSettings('datagrid');
        this.defaultLangs = overwriteService.getLangs('datagrid');
    }

    ngOnInit() {
        this.settings = (<any>Object).assign({}, this.defaultSettings, this.settings);
        this.langs = (<any>Object).assign({}, this.defaultLangs, this.langs);
        this.sortedField = this.settings.defaultSortedField;
        this.sortedOrder = this.settings.defaultSortedOrder;

        if(this.settings.totalViewList.length) {
            for(let value in this.settings.totalViewList) {
                let total = this.settings.totalViewList[value];

                this.totalRowsViewOptions.push({
                    label: this.langs.totalRowsView + ' ' + total, 
                    value: total
                });
            }

            if(this.totalRowsViewOptions.length) {
                this.totalRowsView = this.totalRowsViewOptions[0].value;
            }
        }
        
        this.fireLazyLoadEvent();
        
        this.viewedItemsCount = this.getViewedItemsCount();
        this.totalPages = this.getTotalPages();
        this.filtersData = this.buildFiltersObject();
    }

    ngOnChanges(changes: any) {
        if(changes.rows) {
            this.stopPreloader();
        }

        if (changes.total) {
            this.changeGridData();
        }

        if(changes.settings) {
            let data = (<any>Object).assign({}, changes.settings.previousValue, changes.settings.currentValue);
            this.settings = (<any>Object).assign({}, this.defaultSettings, data);
        }<commit_msg>fix datagrid lazyload on init<commit_after>import { 
    Component, OnInit, OnChanges, Input, Output, ViewChild, ElementRef, ViewEncapsulation, EventEmitter, SimpleChange   
} from '@angular/core';
import { Router } from '@angular/router'

import { DatagridSettings, DatagridLangs, DatagridRoutes, DatagridFilter, RouteItem, LazyloadEvent } from './datagrid.model';
import { PaginationSettings } from '../pagination/pagination.model';
import { SelectItem, SelectSettings } from '../select/select.model';
import { PopoverComponent } from '../popover/popover.component';

import { OverwriteService } from '../../shared/services/overwrite.service';
import { HelperService } from '../../shared/services/helper.service';

@Component({ 
    moduleId: module.id,
    selector: 'fox-datagrid',
    templateUrl: 'datagrid.component.html',
    styleUrls: ['datagrid.component.css'],
    encapsulation: ViewEncapsulation.None
})
export class DatagridComponent implements OnInit, OnChanges {
    @Input() settings: DatagridSettings;
    @Input() langs: DatagridLangs;
    @Input() routes: DatagridRoutes;
    @Input() filters: any;
    @Input() rows: Array<any> = [];
    @Input() total: number = 0;

    @Output() lazyLoad: EventEmitter<any> = new EventEmitter();
    @Output() remove: EventEmitter<any> = new EventEmitter();
    @Output() removeSelected: EventEmitter<any> = new EventEmitter();
    @Output() rowClick: EventEmitter<any> = new EventEmitter();
    @Output() rowSelect: EventEmitter<any> = new EventEmitter();
    @Output() rowUnselect: EventEmitter<any> = new EventEmitter();
    @Output() filtersReseted: EventEmitter<any> = new EventEmitter();
    @Output() filtersSubmited: EventEmitter<any> = new EventEmitter();
    @Output() sortSubmited: EventEmitter<any> = new EventEmitter();
    
    protected totalRowsView: number;
    protected totalRowsViewOptions: Array<SelectItem> = [];
    protected paginationSettings: PaginationSettings = {
        max: 5
    }
    protected totalSettings: SelectSettings = {
        required: true
    }
    protected defaultLangs: DatagridLangs;
    protected defaultSettings: DatagridSettings;
    protected currentPage: number = 1;
    protected firstItem: number = 0;
    protected sortedField: string;
    protected sortedOrder: 'asc' | 'desc';
    protected viewedItemsCount: number = 0;
    protected totalPages: number = 1;
    protected checkedItems: Array<number> = [];
    protected filtersData: any = { };
    protected isPreloaded: boolean;

    constructor(
        private router: Router, 
        private overwriteService: OverwriteService,
        private helperService: HelperService
    ) {
        this.defaultSettings = overwriteService.getSettings('datagrid');
        this.defaultLangs = overwriteService.getLangs('datagrid');
    }

    ngOnInit() {
        this.settings = (<any>Object).assign({}, this.defaultSettings, this.settings);
        this.langs = (<any>Object).assign({}, this.defaultLangs, this.langs);
        this.sortedField = this.settings.defaultSortedField;
        this.sortedOrder = this.settings.defaultSortedOrder;

        if(this.settings.totalViewList.length) {
            for(let value in this.settings.totalViewList) {
                let total = this.settings.totalViewList[value];

                this.totalRowsViewOptions.push({
                    label: this.langs.totalRowsView + ' ' + total, 
                    value: total
                });
            }

            if(this.totalRowsViewOptions.length) {
                this.totalRowsView = this.totalRowsViewOptions[0].value;
            }
        }
        
        if(!this.rows.length) {
        	this.fireLazyLoadEvent();
        } else {
        	this.stopPreloader();
        }
        
        this.viewedItemsCount = this.getViewedItemsCount();
        this.totalPages = this.getTotalPages();
        this.filtersData = this.buildFiltersObject();
    }

    ngOnChanges(changes: any) {
        if(changes.rows) {
            this.stopPreloader();
        }

        if (changes.total) {
            this.changeGridData();
        }

        if(changes.settings) {
            let data = (<any>Object).assign({}, changes.settings.previousValue, changes.settings.currentValue);
            this.settings = (<any>Object).assign({}, this.defaultSettings, data);
        }
{'fraction_non_alphanumeric': 0.12076617612707312, 'fraction_numerical': 0.001635131978509694, 'mean_word_length': 3.0486997635933806, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, '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': '2226521', 'n_tokens_mistral': 2407, 'n_tokens_neox': 2390, 'n_words': 507}