<commit_before>import {
    Bean,
    PostConstruct,
    Autowired,
    Context,
    PreDestroy,
    IRowModel,
    RowNode,
    Constants,
    GridOptionsWrapper,
    EventService,
    Events,
    SelectionController,
    IViewportDatasource,
    RowBounds,
    GridApi,
    ColumnApi,
    ModelUpdatedEvent,
    RowRenderer,
    _
} from "@ag-grid-community/core";

@Bean('rowModel')
export class ViewportRowModel implements IRowModel {

    @Autowired('gridOptionsWrapper') private gridOptionsWrapper: GridOptionsWrapper;
    @Autowired('eventService') private eventService: EventService;
    @Autowired('selectionController') private selectionController: SelectionController;
    @Autowired('context') private context: Context;
    @Autowired('gridApi') private gridApi: GridApi;
    @Autowired('columnApi') private columnApi: ColumnApi;
    @Autowired('rowRenderer') private rowRenderer: RowRenderer;

    // rowRenderer tells us these
    private firstRow = -1;
    private lastRow = -1;

    // datasource tells us this
    private rowCount = -1;

    private rowNodesByIndex: {[index: number]: RowNode} = {};

    private rowHeight: number;

    private viewportDatasource: IViewportDatasource;

    private events: (() => void)[] = [];

    // we don't implement as lazy row heights is not supported in this row model
    public ensureRowHeightsValid(startPixel: number, endPixel: number, startLimitIndex: number, endLimitIndex: number): boolean { return false; }

    @PostConstruct
    private init(): void {
        this.rowHeight = this.gridOptionsWrapper.getRowHeightAsNumber();
        this.events = [
            this.eventService.addEventListener(Events.EVENT_VIEWPORT_CHANGED, this.onViewportChanged.bind(this))
        ]
    }

    public start(): void {
        if (this.gridOptionsWrapper.getViewportDatasource()) {
            this.setViewportDatasource(this.gridOptionsWrapper.getViewportDatasource());
        }
    }

    public isLastRowFound(): boolean {
        return true;
    }

    @PreDestroy
    private destroyDatasource(): void {
        if (this.viewportDatasource) {
            if (this.viewportDatasource.destroy) {
                this.viewportDatasource.destroy();
            }
            this.rowRenderer.datasourceChanged();
            this.firstRow = -1;
            this.lastRow = -1;
        }

        if (this.events.length) {
            this.events.forEach(func => func());
            this.events = [];
        }
    }

    private calculateFirstRow(firstRenderedRow: number): number {
        const bufferSize = this.gridOptionsWrapper.getViewportRowModelBufferSize();
        const pageSize = this.gridOptionsWrapper.getViewportRowModelPageSize();
        const afterBuffer = firstRenderedRow - bufferSize;

        if (afterBuffer < 0) {
            return 0;
        } else {
            return Math.floor(afterBuffer / pageSize) * pageSize;
        }
    }

    private calculateLastRow(lastRenderedRow: number): number {
        if (lastRenderedRow === -1) {
            return lastRenderedRow;
        }
        const bufferSize = this.gridOptionsWrapper.getViewportRowModelBufferSize();
        const pageSize = this.gridOptionsWrapper.getViewportRowModelPageSize();
        const afterBuffer = lastRenderedRow + bufferSize;

        const result = Math.ceil(afterBuffer / pageSize) * pageSize;
        const lastRowIndex = this.rowCount - 1;
        return Math.min(result, lastRowIndex);
    }
<commit_msg>RTI-99 - fixed regression defect that prevents Viewport Row Model rendering rows.<commit_after>import {
    Bean,
    PostConstruct,
    Autowired,
    Context,
    PreDestroy,
    IRowModel,
    RowNode,
    Constants,
    GridOptionsWrapper,
    EventService,
    Events,
    SelectionController,
    IViewportDatasource,
    RowBounds,
    GridApi,
    ColumnApi,
    ModelUpdatedEvent,
    RowRenderer,
    _
} from "@ag-grid-community/core";

@Bean('rowModel')
export class ViewportRowModel implements IRowModel {

    @Autowired('gridOptionsWrapper') private gridOptionsWrapper: GridOptionsWrapper;
    @Autowired('eventService') private eventService: EventService;
    @Autowired('selectionController') private selectionController: SelectionController;
    @Autowired('context') private context: Context;
    @Autowired('gridApi') private gridApi: GridApi;
    @Autowired('columnApi') private columnApi: ColumnApi;
    @Autowired('rowRenderer') private rowRenderer: RowRenderer;

    // rowRenderer tells us these
    private firstRow = -1;
    private lastRow = -1;

    // datasource tells us this
    private rowCount = -1;

    private rowNodesByIndex: {[index: number]: RowNode} = {};

    private rowHeight: number;

    private viewportDatasource: IViewportDatasource;

    // we don't implement as lazy row heights is not supported in this row model
    public ensureRowHeightsValid(startPixel: number, endPixel: number, startLimitIndex: number, endLimitIndex: number): boolean { return false; }

    @PostConstruct
    private init(): void {
        this.rowHeight = this.gridOptionsWrapper.getRowHeightAsNumber();
        this.eventService.addEventListener(Events.EVENT_VIEWPORT_CHANGED, this.onViewportChanged.bind(this));
    }

    public start(): void {
        if (this.gridOptionsWrapper.getViewportDatasource()) {
            this.setViewportDatasource(this.gridOptionsWrapper.getViewportDatasource());
        }
    }

    public isLastRowFound(): boolean {
        return true;
    }

    @PreDestroy
    private destroyDatasource(): void {
        if (this.viewportDatasource) {
            if (this.viewportDatasource.destroy) {
                this.viewportDatasource.destroy();
            }
            this.rowRenderer.datasourceChanged();
            this.firstRow = -1;
            this.lastRow = -1;
        }
    }

    private calculateFirstRow(firstRenderedRow: number): number {
        const bufferSize = this.gridOptionsWrapper.getViewportRowModelBufferSize();
        const pageSize = this.gridOptionsWrapper.getViewportRowModelPageSize();
        const afterBuffer = firstRenderedRow - bufferSize;

        if (afterBuffer < 0) {
            return 0;
        } else {
            return Math.floor(afterBuffer / pageSize) * pageSize;
        }
    }

    private calculateLastRow(lastRenderedRow: number): number {
        if (lastRenderedRow === -1) {
            return lastRenderedRow;
        }
        const bufferSize = this.gridOptionsWrapper.getViewportRowModelBufferSize();
        const pageSize = this.gridOptionsWrapper.getViewportRowModelPageSize();
        const afterBuffer = lastRenderedRow + bufferSize;

        const result = Math.ceil(afterBuffer / pageSize) * pageSize;
        const lastRowIndex = this.rowCount - 1;
        return Math.min(result, lastRowIndex);
    }

{'fraction_non_alphanumeric': 0.09269869252240341, 'fraction_numerical': 0.002938151902453357, 'mean_word_length': 2.9126436781609195, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3439445', 'n_tokens_mistral': 1878, 'n_tokens_neox': 1849, 'n_words': 413}