<commit_before>import parser, {recognizedDomEvents} from './vanilla-src-parser';

function removeFunction(code) {
    return code.replace(/^function /, '');
}

function convertFunctionToMethod(code, methodName) {
    return methodName + removeFunction(code);
}

function onGridReadyTemplate(readyCode: string, resizeToFit: boolean, data: { url: string, callback: string }) {
    let resize = '', getData = '';

    if (!readyCode) {
        readyCode = '';
    }

    if (resizeToFit) {
        resize = `params.api.sizeColumnsToFit();`;
    }

    if (data) {
       getData = `this.http.get(${data.url}).subscribe( data => ${data.callback});`
    }

    return `
    onGridReady(params) {
        this.gridApi = params.api;
        this.gridColumnApi = params.columnApi;

        ${getData}
        ${resize}
        ${readyCode.trim().replace(/^\{|\}$/g, '')}
    }`;
}

const toInput = property => `[${property.name}]="${property.name}"`;
const toConst = property => `[${property.name}]="${property.value}"`;

const toOutput = event => `(${event.name})="${event.handlerName}($event)"`;

const toMember = property => `private ${property.name};`;

const toAssignment = property => `this.${property.name} = ${property.value}`;

function appComponentTemplate(bindings) {
    const diParams = [];
    const imports = [];
    const additional = [];

    if (bindings.data) {
        imports.push('import { HttpClient } from "@angular/common/http";');
        diParams.push('private http: HttpClient');
    }

    if (bindings.gridSettings.enterprise) {
        imports.push('import "ag-grid-enterprise";');
    }

    const propertyAttributes =[];
    const propertyVars =[];
    const propertyAssignments =[];

    bindings.properties.forEach( property => {
        if (property.value === 'null') {
            return;
        }
        if (property.value === 'true' || property.value === 'false') {
            propertyAttributes.push(toConst(property));
        } else {
            propertyAttributes.push(toInput(property));
            propertyVars.push(toMember(property));
            propertyAssignments.push(toAssignment(property));
        }
    });

    const eventAttributes = bindings.eventHandlers.filter(event => event.name != 'onGridReady').map(toOutput);

    const eventHandlers = bindings.eventHandlers.map(event => event.handler).map(removeFunction);

    if (bindings.onGridReady || bindings.resizeToFit || bindings.data) {
        eventAttributes.push('(gridReady)="onGridReady($event)"');
        additional.push(onGridReadyTemplate(bindings.onGridReady, bindings.resizeToFit, bindings.data));
    }<commit_msg>We need gridReady at all times<commit_after>import parser, {recognizedDomEvents} from './vanilla-src-parser';

function removeFunction(code) {
    return code.replace(/^function /, '');
}

function convertFunctionToMethod(code, methodName) {
    return methodName + removeFunction(code);
}

function onGridReadyTemplate(readyCode: string, resizeToFit: boolean, data: { url: string, callback: string }) {
    let resize = '', getData = '';

    if (!readyCode) {
        readyCode = '';
    }

    if (resizeToFit) {
        resize = `params.api.sizeColumnsToFit();`;
    }

    if (data) {
       getData = `this.http.get(${data.url}).subscribe( data => ${data.callback});`
    }

    return `
    onGridReady(params) {
        this.gridApi = params.api;
        this.gridColumnApi = params.columnApi;

        ${getData}
        ${resize}
        ${readyCode.trim().replace(/^\{|\}$/g, '')}
    }`;
}

const toInput = property => `[${property.name}]="${property.name}"`;
const toConst = property => `[${property.name}]="${property.value}"`;

const toOutput = event => `(${event.name})="${event.handlerName}($event)"`;

const toMember = property => `private ${property.name};`;

const toAssignment = property => `this.${property.name} = ${property.value}`;

function appComponentTemplate(bindings) {
    const diParams = [];
    const imports = [];
    const additional = [];

    if (bindings.data) {
        imports.push('import { HttpClient } from "@angular/common/http";');
        diParams.push('private http: HttpClient');
    }

    if (bindings.gridSettings.enterprise) {
        imports.push('import "ag-grid-enterprise";');
    }

    const propertyAttributes =[];
    const propertyVars =[];
    const propertyAssignments =[];

    bindings.properties.forEach( property => {
        if (property.value === 'null') {
            return;
        }
        if (property.value === 'true' || property.value === 'false') {
            propertyAttributes.push(toConst(property));
        } else {
            propertyAttributes.push(toInput(property));
            propertyVars.push(toMember(property));
            propertyAssignments.push(toAssignment(property));
        }
    });

    const eventAttributes = bindings.eventHandlers.filter(event => event.name != 'onGridReady').map(toOutput);

    const eventHandlers = bindings.eventHandlers.map(event => event.handler).map(removeFunction);

    eventAttributes.push('(gridReady)="onGridReady($event)"');
    additional.push(onGridReadyTemplate(bindings.onGridReady, bindings.resizeToFit, bindings.data));
{'fraction_non_alphanumeric': 0.16416474210931487, 'fraction_numerical': 0.0, 'mean_word_length': 3.291494632535095, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '6527619', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1502, 'n_words': 265}