<commit_before>hqDefine("scheduling/js/conditional_alert_list", [
    'jquery',
    'hqwebapp/js/initial_page_data',
], function($, initialPageData) {
    var table = null;

    $(function() {
        var conditonalAlterListUrl = initialPageData.reverse("conditional_alert_list");

        table = $("#conditional-alert-list").dataTable({
            "lengthChange": false,
            "filter": false,
            "sort": false,
            "displayLength": 10,
            "processing": false,
            "serverSide": true,
            "ajaxSource": conditonalAlterListUrl,
            "fnServerParams": function(aoData) {
                aoData.push({"name": "action", "value": "list_conditional_alerts"});
            },
            "sDom": "rtp",
            "language": {
                "emptyTable": gettext('There are no alerts to display.'),
                "infoEmpty": gettext('There are no alerts to display.'),
                "info": gettext('Showing _START_ to _END_ of _TOTAL_ alerts'),
            },
            "columns": [
                {"data": ""},
                {"data": "name"},
                {"data": "case_type"},
                {"data": "active"},
                {"data": ""},
            ],
            "columnDefs": [
                {
                    "targets": [0],
                    "className": "text-center",
                    "render": function(data, type, row) {
                        var button_id = 'delete-button-for-' + row.id;
                        var disabled = row.locked_for_editing ? 'disabled' : '';
                        return '<button id="' + button_id + '" \
                                        class="btn btn-danger alert-delete" \
                                        data-id="'+row.id+'"\
                                        ' + disabled + '> \
                                <i class="fa fa-remove"></i></button>';
                    },
                },
                {
                    "targets": [1],
                    "render": function(data, type, row) {
                        var url = initialPageData.reverse('edit_conditional_alert', row.id);
                        return "<a href='" + url + "'>" + row.name + "</a>";
                    },
                },
                {
                    "targets": [3],
                    "render": function(data, type, row) {
                        var active_text = '';
                        if(row.active) {
                            active_text = '<span class="label label-success">' + gettext("Active") + '</span> ';
                        } else {
                            active_text = '<span class="label label-danger">' + gettext("Inactive") + '</span> ';
                        }

                        var processing_text = '';
                        if(row.locked_for_editing) {
                            processing_text = '<span class="label label-default">' + gettext("Rule is processing") + ': ' + row.progress_pct + '%</span> ';
                        }

                        return active_text + processing_text;
                    },
                },
                {
                    "targets": [4],
                    "render": function(data, type, row) {
                        var html = null;
                        var button_id = 'activate-button-for-' + row.id;
                        var disabled = (row.locked_for_editing || !row.editable) ? 'disabled' : '';
                        if(row.active) {
                            html = '<button id="' + button_id + '" \
                                            class="btn btn-default alert-activate" \
                                            data-id="'+row.id+'"\
                                            data-action="deactivate"\
                                            ' + disabled + '> \
                                   ' + gettext("Deactivate") + '</button>';
                        } else {
                            html = '<button id="' + button_id + '" + \
                                            class="btn btn-default alert-activate" + \
                                            data-action="activate"\
                                            data-id="'+row.id+'"\
                                            ' + disabled + '> \
                                   ' + gettext("Activate") + '</button>';
                        }

                        if(row.locked_for_editing) {
                            html += ' <button class="btn btn-default alert-restart" data-id="'+row.id+'" >';
                            html += '<i class="fa fa-refresh"></i> ' + gettext("Restart Rule") + '</button>';
                        }

                        return html;
                    },
                },
                {
                    "targets": [5],
                    "visible": initialPageData.get("allow_copy"),
                    "render": function(data, type, row) {
                        var disabled = (row.locked_for_editing || !row.editable) ? 'disabled' : '';
                        var html = '<input type="text" id="copy-to-project-for-' + row.id + '" placeholder="' + gettext("Project") + '" class="textinput textInput form-control" />';
                        html += ' <button ' + disabled + ' id="copy-button-for-' + row.id + '" class="btn btn-default alert-copy" data-id="' + row.id + '" >' + gettext("Copy") + '</button>';
                        return html;
                    },
                },
            ],
        });

        $(document).on('click', '.alert-delete', deleteAlert);
        $(document).on('click', '.alert-activate', activateAlert);
        $(document).on('click', '.alert-restart', restartRule);
        $(document).on('click', '.alert-copy', copyRule);

        function reloadTable() {
            table.fnDraw(false);
            setTimeout(reloadTable, 10000);
        }
<commit_msg>Don't redraw the table if someone is typing a project name in the copy input<commit_after>hqDefine("scheduling/js/conditional_alert_list", [
    'jquery',
    'hqwebapp/js/initial_page_data',
], function($, initialPageData) {
    var table = null;

    $(function() {
        var conditonalAlterListUrl = initialPageData.reverse("conditional_alert_list");

        table = $("#conditional-alert-list").dataTable({
            "lengthChange": false,
            "filter": false,
            "sort": false,
            "displayLength": 10,
            "processing": false,
            "serverSide": true,
            "ajaxSource": conditonalAlterListUrl,
            "fnServerParams": function(aoData) {
                aoData.push({"name": "action", "value": "list_conditional_alerts"});
            },
            "sDom": "rtp",
            "language": {
                "emptyTable": gettext('There are no alerts to display.'),
                "infoEmpty": gettext('There are no alerts to display.'),
                "info": gettext('Showing _START_ to _END_ of _TOTAL_ alerts'),
            },
            "columns": [
                {"data": ""},
                {"data": "name"},
                {"data": "case_type"},
                {"data": "active"},
                {"data": ""},
            ],
            "columnDefs": [
                {
                    "targets": [0],
                    "className": "text-center",
                    "render": function(data, type, row) {
                        var button_id = 'delete-button-for-' + row.id;
                        var disabled = row.locked_for_editing ? 'disabled' : '';
                        return '<button id="' + button_id + '" \
                                        class="btn btn-danger alert-delete" \
                                        data-id="'+row.id+'"\
                                        ' + disabled + '> \
                                <i class="fa fa-remove"></i></button>';
                    },
                },
                {
                    "targets": [1],
                    "render": function(data, type, row) {
                        var url = initialPageData.reverse('edit_conditional_alert', row.id);
                        return "<a href='" + url + "'>" + row.name + "</a>";
                    },
                },
                {
                    "targets": [3],
                    "render": function(data, type, row) {
                        var active_text = '';
                        if(row.active) {
                            active_text = '<span class="label label-success">' + gettext("Active") + '</span> ';
                        } else {
                            active_text = '<span class="label label-danger">' + gettext("Inactive") + '</span> ';
                        }

                        var processing_text = '';
                        if(row.locked_for_editing) {
                            processing_text = '<span class="label label-default">' + gettext("Rule is processing") + ': ' + row.progress_pct + '%</span> ';
                        }

                        return active_text + processing_text;
                    },
                },
                {
                    "targets": [4],
                    "render": function(data, type, row) {
                        var html = null;
                        var button_id = 'activate-button-for-' + row.id;
                        var disabled = (row.locked_for_editing || !row.editable) ? 'disabled' : '';
                        if(row.active) {
                            html = '<button id="' + button_id + '" \
                                            class="btn btn-default alert-activate" \
                                            data-id="'+row.id+'"\
                                            data-action="deactivate"\
                                            ' + disabled + '> \
                                   ' + gettext("Deactivate") + '</button>';
                        } else {
                            html = '<button id="' + button_id + '" + \
                                            class="btn btn-default alert-activate" + \
                                            data-action="activate"\
                                            data-id="'+row.id+'"\
                                            ' + disabled + '> \
                                   ' + gettext("Activate") + '</button>';
                        }

                        if(row.locked_for_editing) {
                            html += ' <button class="btn btn-default alert-restart" data-id="'+row.id+'" >';
                            html += '<i class="fa fa-refresh"></i> ' + gettext("Restart Rule") + '</button>';
                        }

                        return html;
                    },
                },
                {
                    "targets": [5],
                    "visible": initialPageData.get("allow_copy"),
                    "render": function(data, type, row) {
                        var disabled = (row.locked_for_editing || !row.editable) ? 'disabled' : '';
                        var html = '<input type="text" id="copy-to-project-for-' + row.id + '" placeholder="' + gettext("Project") + '" class="textinput textInput form-control copy-project-name" />';
                        html += ' <button ' + disabled + ' id="copy-button-for-' + row.id + '" class="btn btn-default alert-copy" data-id="' + row.id + '" >' + gettext("Copy") + '</button>';
                        return html;
                    },
                },
            ],
        });

        $(document).on('click', '.alert-delete', deleteAlert);
        $(document).on('click', '.alert-activate', activateAlert);
        $(document).on('click', '.alert-restart', restartRule);
        $(document).on('click', '.alert-copy', copyRule);

        function reloadTable() {
            // Don't redraw the table if someone is typing a project name in the copy input
            var canDraw = true;
            $('.copy-project-name').each(function() {
                if($(this).val()) {
                    canDraw = false;
                }
            });

            if(canDraw) {
                table.fnDraw(false);
            }

            setTimeout(reloadTable, 10000);
        }

{'fraction_non_alphanumeric': 0.14181405159824761, 'fraction_numerical': 0.0019471036832711343, 'mean_word_length': 1.063787041687594, 'pattern_counts': {'":': 68, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 46, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '681234', 'n_tokens_mistral': 3041, 'n_tokens_neox': 2822, 'n_words': 568}