<commit_before>// Data Tables Helper Methods
// (C) 2017 <NAME> (<EMAIL>)

/*
 * JSON format:
 *  {
 *      // (optional) set to true to indicate an invalid request to the server, default is false.
 *      "invalidRequest": false,
 *      // (optional) an array of messages to display to the user.
 *      "messages": [
 *          {
 *              // (required) "info", "warning", "danger", "success"
 *              "type": "info",
 *              // (required) the message to display.
 *              "text": "The action was successful."
 *          }
 *      ],
 *      // (optional) an array of data to update the data table with.
 *      "data": [
 *          {
 *              // (required) the unique ID for this row.
 *              "DT_RowId": "my_model_1",
 *              // (required) the "show" path for the model.
 *              "DT_Path": "/incline/my_model/1",
 *              // (optional) "update" or "remove", default is "update".
 *              "DT_RowAction": "update",
 *              // (optional) "info", "warning", "danger", "success"
 *              "DT_RowClass": "info",
 *
 *              // then model details such as:
 *              "name": "<NAME>",
 *              "age": 35,
 *              "email": "<EMAIL>",
 *              "occupation": "Mechanic"
 *          }
 *      ]
 *  }
 */


var inclineInline = {
    action: function(path, method, post_data) {
        if (!(method)) method = 'get';
        if (path.indexOf('?') >= 0) {
            path += '&inline=1';
        } else {
            path += '?inline=1';
        }
        $.ajax({
            method: method.toUpperCase(),
            url: path,
            dataType: 'json',
            data: post_data,
            success: function (data, status, xhr) {
                inclineInline._handle_json_result(data);
            },
            error: function (xhr, status, error) {
                inclineInline._handle_error(status, error);
            }
        });
    },

    form: function(req_path, req_method) {
        if (!(req_method)) req_method = 'get';
        if (req_path.indexOf('?') >= 0) {
            req_path += '&inline=1';
        } else {
            req_path += '?inline=1';
        }

        // first request should return HTML.
        $.ajax({
            method: req_method.toUpperCase(),
            url: req_path,
            dataType: 'html',
            success: function (data, status, xhr) {
                inclineInline._handle_form_response(data, status, xhr);
            },
            error: function (xhr, status, error) {
                inclineInline._handle_error(status, error);
            }
        });
    },

    _handle_json_result: function(data) {
        var ts = Math.round((new Date().getTime() / 100) % 864000, 0);
        var i;
        if (data.invalidRequest) {
            // Should probably come up with a more informative alert.
            this._handle_error('invalid request', 'invalid request');
        } else {
            // build alerts that clear after 5 seconds.
            if (data.messages) {
                var messageCount = data.messages.length;
                var alertDiv = $('#incline_dynamic_alerts');
                for (i = 0; i < messageCount; i++) {
                    var message = data.messages[i];
                    var html = '<div id="alert-' + ts.toString() + '" class="alert alert-' + escapeHTML(message.type) + ' alert-dismissible fade in" role="alert">' +
                        '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
                        escapeHTML(message.text) +
                        '</div>';
                    var close = '$(\'#alert-' + ts.toString() + '\').alert(\'close\');';
                    alertDiv.prepend(html);
                    window.setTimeout(close, 5000);
                    ts++;
                }
            }
            // update rows in the data table.
            if (data.data) {
                var dataCount = data.data.length;
                for (i = 0; i < dataCount; i++) {
                    var item = data.data[i];
                    var row = $('#' + item.DT_RowId);
                    if (row.length > 0) {
                        var table = row.parents('table');
                        if ($.fn.dataTable.isDataTable(table))
                        {
                            var table_id = table.attr('id');
                            table = table.dataTable().api();
                            if (item.DT_RowAction === 'remove') {
                                table.row('#' + item.DT_RowId).remove();    // remove the row from the DT.
                                table.draw('page');                         // refresh the current page.
                            } else {<commit_msg>Add newlines to rendered messages.<commit_after>// Data Tables Helper Methods
// (C) 2017 <NAME> (<EMAIL>)

/*
 * JSON format:
 *  {
 *      // (optional) set to true to indicate an invalid request to the server, default is false.
 *      "invalidRequest": false,
 *      // (optional) an array of messages to display to the user.
 *      "messages": [
 *          {
 *              // (required) "info", "warning", "danger", "success"
 *              "type": "info",
 *              // (required) the message to display.
 *              "text": "The action was successful."
 *          }
 *      ],
 *      // (optional) an array of data to update the data table with.
 *      "data": [
 *          {
 *              // (required) the unique ID for this row.
 *              "DT_RowId": "my_model_1",
 *              // (required) the "show" path for the model.
 *              "DT_Path": "/incline/my_model/1",
 *              // (optional) "update" or "remove", default is "update".
 *              "DT_RowAction": "update",
 *              // (optional) "info", "warning", "danger", "success"
 *              "DT_RowClass": "info",
 *
 *              // then model details such as:
 *              "name": "<NAME>",
 *              "age": 35,
 *              "email": "<EMAIL>",
 *              "occupation": "Mechanic"
 *          }
 *      ]
 *  }
 */


var inclineInline = {
    action: function(path, method, post_data) {
        if (!(method)) method = 'get';
        if (path.indexOf('?') >= 0) {
            path += '&inline=1';
        } else {
            path += '?inline=1';
        }
        $.ajax({
            method: method.toUpperCase(),
            url: path,
            dataType: 'json',
            data: post_data,
            success: function (data, status, xhr) {
                inclineInline._handle_json_result(data);
            },
            error: function (xhr, status, error) {
                inclineInline._handle_error(status, error);
            }
        });
    },

    form: function(req_path, req_method) {
        if (!(req_method)) req_method = 'get';
        if (req_path.indexOf('?') >= 0) {
            req_path += '&inline=1';
        } else {
            req_path += '?inline=1';
        }

        // first request should return HTML.
        $.ajax({
            method: req_method.toUpperCase(),
            url: req_path,
            dataType: 'html',
            success: function (data, status, xhr) {
                inclineInline._handle_form_response(data, status, xhr);
            },
            error: function (xhr, status, error) {
                inclineInline._handle_error(status, error);
            }
        });
    },

    _handle_json_result: function(data) {
        var ts = Math.round((new Date().getTime() / 100) % 864000, 0);
        var i;
        if (data.invalidRequest) {
            // Should probably come up with a more informative alert.
            this._handle_error('invalid request', 'invalid request');
        } else {
            // build alerts that clear after 5 seconds.
            if (data.messages) {
                var messageCount = data.messages.length;
                var alertDiv = $('#incline_dynamic_alerts');
                for (i = 0; i < messageCount; i++) {
                    var message = data.messages[i];
                    var html = '<div id="alert-' + ts.toString() + '" class="alert alert-' + escapeHTML(message.type) + ' alert-dismissible fade in" role="alert">' +
                        '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
                        escapeHTML(message.text).replace(/\n/g, "<br>\n") +
                        '</div>';
                    var close = '$(\'#alert-' + ts.toString() + '\').alert(\'close\');';
                    alertDiv.prepend(html);
                    window.setTimeout(close, 5000);
                    ts++;
                }
            }
            // update rows in the data table.
            if (data.data) {
                var dataCount = data.data.length;
                for (i = 0; i < dataCount; i++) {
                    var item = data.data[i];
                    var row = $('#' + item.DT_RowId);
                    if (row.length > 0) {
                        var table = row.parents('table');
                        if ($.fn.dataTable.isDataTable(table))
                        {
                            var table_id = table.attr('id');
                            table = table.dataTable().api();
                            if (item.DT_RowAction === 'remove') {
                                table.row('#' + item.DT_RowId).remove();    // remove the row from the DT.
                                table.draw('page');                         // refresh the current page.
                            } else {
{'fraction_non_alphanumeric': 0.1433408577878104, 'fraction_numerical': 0.0065667966345167245, 'mean_word_length': 1.337410071942446, 'pattern_counts': {'":': 26, '<': 28, '<?xml version=': 0, '>': 30, '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': '4325281', 'n_tokens_mistral': 2704, 'n_tokens_neox': 2583, 'n_words': 665}