<commit_before>/*jshint jquery: true */
(function ($) {
    'use strict';

    // String used to separate values in select2 fields.
    var VALUES_SEPARATOR = '|||';

    /**
     * Create a new dynamic form or run an action on an existing form.
     *
     * Actions:
     *     newLine - Add a new line to this dynamic form
     *     getParams - Return an object with the content of this dynamic form
     *     setParams - Change the content of this dynamic form
     *
     * If `action` is none of those values, create a new dynamic form where
     * the first argument is the URL of the JSON file describing the fields
     * and the optional second argument is an object containing the initial
     * form values.
     */
    function dynamicForm(action, initialParams, containerId, onReadyCallback, sortFuntion) {
        var form = this;
        var dynamic = form.data('dynamic');
        var lines = [];
        var container = form;

        if (dynamic) {
            lines = dynamic.lines;
            container = dynamic.container;
        }

        initialParams = initialParams || null;
        containerId = containerId || null;

        if (action === 'newLine' || action === 'getParams' || action === 'setParams') {
            if (!dynamic) {
                throw new Error('Impossible to call ' + action + ' on an object that was not initialized first');
            }

            if (action === 'newLine') {
                if (initialParams) {
                    // there is some data, this should not be a blank line
                    return dynamic.createLine(
                        initialParams.field,
                        initialParams.operator,
                        initialParams.value
                    );
                }
                return dynamic.newLine();
            }
            else if (action === 'getParams') {
                return dynamic.getParams();
            }
            else if (action === 'setParams') {
                return dynamic.setParams(initialParams);
            }
        }

        var fieldsURL = action;
        var fields = {};
        var sortedFieldNames = [];
        var lastFieldLineId = 0;

        if (containerId) {
            container = $(containerId, form);
        }

        // first display a loader while the fields data is being downloaded
        container.append($('<div>', {'class': 'loader'}));

        $.getJSON(
            fieldsURL,
            function(data) {
                $('.loader', container).remove();
                fields = data;
                sortedFieldNames = Object.keys(fields).sort();
                if (initialParams) {
                    setParams(initialParams);
                }
                else {
                    newLine();
                }

                if (onReadyCallback) {
                    onReadyCallback();
                }
            }
        );

        var OPERATORS = {
            'has': 'has terms',
            '!': 'does not have terms',
            '=': 'is',
            '!=': 'is not',
            '~': 'contains',
            '!~': 'does not contain',
            '$': 'starts with',
            '!$': 'does not start with',
            '^': 'ends with',
            '!^': 'does not end with',
            '>': '>',
            '>=': '>=',
            '<': '<',
            '<=': '<=',
            '__null__': 'does not exist',
            '!__null__': 'exists',
            '__true__': 'is true',
            '!__true__': 'is false'
        };

        // Order matters here, the first operator will be used as the default
        // value when no operator is passed for a field.
        var OPERATORS_BASE = ['has', '!'];
        var OPERATORS_RANGE = ['>', '>=', '<', '<='];
        var OPERATORS_REGEX = ['~', '=', '$', '^', '!=', '!~', '!$', '!^'];
        var OPERATORS_EXISTENCE = ['__null__', '!__null__'];
        var OPERATORS_BOOLEAN = ['__true__', '!__true__'];

        var OPERATORS_ENUM = OPERATORS_BASE;
        var OPERATORS_NUMBER = OPERATORS_BASE.concat(OPERATORS_RANGE);
        var OPERATORS_DATE = OPERATORS_RANGE;
        var OPERATORS_STRING = OPERATORS_REGEX.concat(OPERATORS_EXISTENCE);

        var OPERATORS_NO_VALUE = OPERATORS_EXISTENCE.concat(OPERATORS_BOOLEAN);

        /**
         * Get the list of operators for a field.
         * @param field Field object extracted from the fields list.
         * @return object A dictionary of options, key is the option name, value is
         *                the option value to use in the select box.
         */
        function getOperatorsForField(field) {
            var options = OPERATORS_BASE;

            if (field.valueType === 'number') {
                options = OPERATORS_NUMBER;
            }
            else if (field.valueType === 'date') {
                options = OPERATORS_DATE;
            }
            else if (field.valueType === 'bool') {
                options = OPERATORS_BOOLEAN;
            }
            else if (field.valueType === 'flag') {
                options = OPERATORS_EXISTENCE;
            }
            else if (field.valueType === 'string') {
                options = OPERATORS_STRING;
            }
            else {  // type 'enum' or unknown type
                options = OPERATORS_ENUM;
            }<commit_msg>Fixes bug 1164062 - Added "has terms" operator to string fields.<commit_after>/*jshint jquery: true */
(function ($) {
    'use strict';

    // String used to separate values in select2 fields.
    var VALUES_SEPARATOR = '|||';

    /**
     * Create a new dynamic form or run an action on an existing form.
     *
     * Actions:
     *     newLine - Add a new line to this dynamic form
     *     getParams - Return an object with the content of this dynamic form
     *     setParams - Change the content of this dynamic form
     *
     * If `action` is none of those values, create a new dynamic form where
     * the first argument is the URL of the JSON file describing the fields
     * and the optional second argument is an object containing the initial
     * form values.
     */
    function dynamicForm(action, initialParams, containerId, onReadyCallback, sortFuntion) {
        var form = this;
        var dynamic = form.data('dynamic');
        var lines = [];
        var container = form;

        if (dynamic) {
            lines = dynamic.lines;
            container = dynamic.container;
        }

        initialParams = initialParams || null;
        containerId = containerId || null;

        if (action === 'newLine' || action === 'getParams' || action === 'setParams') {
            if (!dynamic) {
                throw new Error('Impossible to call ' + action + ' on an object that was not initialized first');
            }

            if (action === 'newLine') {
                if (initialParams) {
                    // there is some data, this should not be a blank line
                    return dynamic.createLine(
                        initialParams.field,
                        initialParams.operator,
                        initialParams.value
                    );
                }
                return dynamic.newLine();
            }
            else if (action === 'getParams') {
                return dynamic.getParams();
            }
            else if (action === 'setParams') {
                return dynamic.setParams(initialParams);
            }
        }

        var fieldsURL = action;
        var fields = {};
        var sortedFieldNames = [];
        var lastFieldLineId = 0;

        if (containerId) {
            container = $(containerId, form);
        }

        // first display a loader while the fields data is being downloaded
        container.append($('<div>', {'class': 'loader'}));

        $.getJSON(
            fieldsURL,
            function(data) {
                $('.loader', container).remove();
                fields = data;
                sortedFieldNames = Object.keys(fields).sort();
                if (initialParams) {
                    setParams(initialParams);
                }
                else {
                    newLine();
                }

                if (onReadyCallback) {
                    onReadyCallback();
                }
            }
        );

        var OPERATORS = {
            'has': 'has terms',
            '!': 'does not have terms',
            '=': 'is',
            '!=': 'is not',
            '~': 'contains',
            '!~': 'does not contain',
            '$': 'starts with',
            '!$': 'does not start with',
            '^': 'ends with',
            '!^': 'does not end with',
            '>': '>',
            '>=': '>=',
            '<': '<',
            '<=': '<=',
            '__null__': 'does not exist',
            '!__null__': 'exists',
            '__true__': 'is true',
            '!__true__': 'is false'
        };

        // Order matters here, the first operator will be used as the default
        // value when no operator is passed for a field.
        var OPERATORS_BASE = ['has', '!'];
        var OPERATORS_RANGE = ['>', '>=', '<', '<='];
        var OPERATORS_REGEX = ['~', '=', '$', '^', '!=', '!~', '!$', '!^'];
        var OPERATORS_EXISTENCE = ['__null__', '!__null__'];
        var OPERATORS_BOOLEAN = ['__true__', '!__true__'];

        var OPERATORS_ENUM = OPERATORS_BASE;
        var OPERATORS_NUMBER = OPERATORS_BASE.concat(OPERATORS_RANGE);
        var OPERATORS_DATE = OPERATORS_RANGE;
        var OPERATORS_STRING = OPERATORS_BASE.concat(OPERATORS_REGEX).concat(OPERATORS_EXISTENCE);

        var OPERATORS_NO_VALUE = OPERATORS_EXISTENCE.concat(OPERATORS_BOOLEAN);

        /**
         * Get the list of operators for a field.
         * @param field Field object extracted from the fields list.
         * @return object A dictionary of options, key is the option name, value is
         *                the option value to use in the select box.
         */
        function getOperatorsForField(field) {
            var options = OPERATORS_BASE;

            if (field.valueType === 'number') {
                options = OPERATORS_NUMBER;
            }
            else if (field.valueType === 'date') {
                options = OPERATORS_DATE;
            }
            else if (field.valueType === 'bool') {
                options = OPERATORS_BOOLEAN;
            }
            else if (field.valueType === 'flag') {
                options = OPERATORS_EXISTENCE;
            }
            else if (field.valueType === 'string') {
                options = OPERATORS_STRING;
            }
            else {  // type 'enum' or unknown type
                options = OPERATORS_ENUM;
            }
{'fraction_non_alphanumeric': 0.11584342963653309, 'fraction_numerical': 0.0010251630941286113, 'mean_word_length': 1.500232991612302, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1222397', 'n_tokens_mistral': 2888, 'n_tokens_neox': 2796, 'n_words': 813}