<commit_before>    $(function() {
    'use strict';

        function changeText(text, field) {
            $(field).fadeOut(200, function() {
                $(field).html(text).fadeIn(500);
            });
        }

        function setErrorMessage(type, message) {
            $('#messages').html('<div class="alert alert-' + type + '">' + message + '</div>').find('div').show().delay(2500).slideUp(500);
        }

        // set the correct, current amount of bands
        $('.bandsAmount').html($('#bandsTable').find('tbody tr').length + ' Bands');


        function ajaxFunction(self, event, success) {
            event.preventDefault();

            $.ajax({
                url: $(self).attr('href')
            }).done(function( data ) {
                if (data.success) {
                    success(data, self);

                    if (data.message) {
                        setErrorMessage('success', data.message);
                    }
                } else {
                    if (data.message) {
                        setErrorMessage('danger', data.message);
                    }
                }
            });
        }


        $('a.access').on('click', function(event) {
            ajaxFunction(this, event, function(data, self) {
                var accessCol = $(self).parent().parent().find('td:nth-child(2)');
                if (data.active) {
                    changeText('deaktivieren', self);
                    changeText('Benutzer', accessCol);
                } else {
                    changeText('aktivieren', self);
                    changeText('Inaktiv', accessCol);
                }
            });
        });

        $('a.mod').on('click', function(event) {
            ajaxFunction(this, event, function(data, self) {
                var accessCol = $(self).parent().parent().find('td:nth-child(2)');
                if (data.mod) {
                    changeText('degradieren', self);
                    changeText('Moderator', accessCol);
                } else {
                    changeText('befördern', self);
                    changeText('Benutzer', accessCol);
                }
            });
        });


        $('a.bandState').on('click', function(event) {
            ajaxFunction(this, event, function(data, self) {
                var stateCol = $(self).parent().parent().parent().parent().parent().find('td:nth-child(10)');
                changeText(data.state, stateCol);
            });
        });



        $('a.voteState').on('click', function(event) {
            ajaxFunction(this, event, function(data, self) {
                var stateCol = $(self).parent().parent().parent().parent().parent().find('td:nth-child(10)');
                var stateDotCol = $(self).parent().parent().parent().parent().parent().find('td:nth-child(1) div.dot');
                if (data.state) {
                    changeText('Aus dem Voting nehmen', self);
                    changeText('Im Voting', stateCol);
                    stateDotCol.fadeOut(200, function() {stateDotCol.removeClass('dot-yellow').addClass('dot-green').fadeIn(500);});
                } else {
                    changeText('Ins Voting nehmen', self);
                    changeText('Aus Voting genommen', stateCol);
                    stateDotCol.fadeOut(200, function() {stateDotCol.removeClass('dot-green').addClass('dot-yellow').fadeIn(500);});
                }
            });
        });

        $('a.voteStateDetail').on('click', function(event) {
            ajaxFunction(this, event, function(data, self) {
                var stateCol = $('#voteState');
                console.log(stateCol);
                if (data.state) {
                    changeText('Aus dem Voting nehmen', self);
                    changeText('Im Voting', stateCol);
                } else {
                    changeText('Ins Voting nehmen', self);
                    changeText('Aus Voting genommen', stateCol);
                }
            });
        });


        $('a.distance').on('click', function(event) {
            ajaxFunction(this, event, function(data, self) {
                if (data.distance) {
                    changeText(data.distance + ' km', self);
                }
            });
        });

        $('a.comment-rm').on('click', function(event) {

            if (confirm('Kommentar wirklich löschen?')) {
            ajaxFunction(this, event, function(data, self) {
                $(self).parent().parent().slideUp(function() {
                    this.remove();
                });
            });
            } else {
                event.preventDefault();
            }

        });


        /* Sort Users */
        var order = 2;

        /**
         * Generic handler for sorting a table by clicking on the column
         *
         * @param string table the id of the table
         * @param string elem the id of the elem the onclick-Listener should be registered on
         * @param int num the order-number (0,2,4, ...)
         * @param int col the nth-col (0,1,2,...)
         * @param bool desc whether the column should be ordered desc by default
         *
         * @return void
         * */
        function sortLinkHandler(table, elem, num, col, desc) {
            $(elem).on('click', function (event) {
                event.preventDefault();

                if (desc && order !== num && order !== num-1) {
                    // default: desc
                    order = num;
                } else if (order !== num && order !== num-1) {
                    // default: asc
                    order = num-1;

                } else {
                    order = (order < num) ? num : (num - 1);
                }
                sortTable(col, order, table);
            });
        }

        /** Sort users */
        sortLinkHandler('#usersTable', '#sortLogin', 2, 0, 0);
        sortLinkHandler('#usersTable', '#sortAccess', 4, 1, 0);
        sortLinkHandler('#usersTable', '#sortVotes', 6, 4, 1);
        sortLinkHandler('#usersTable', '#sortVotesLatest', 8, 5, 1);
        sortLinkHandler('#usersTable', '#sortVoteAverage', 10, 6, 1);
        sortLinkHandler('#usersTable', '#sortVoteVariance', 12, 7, 1);


        function sortBandTable(elem, num, col, desc) {
            sortLinkHandler('#bandsTable', elem, num, col, desc);
        }

        sortBandTable('#sortName', 2, 0, 0);
        sortBandTable('#sortMembers', 4, 1, 0);
        sortBandTable('#sortCity', 6, 2, 0);
        sortBandTable('#sortDistance', 8, 3, 0);
        sortBandTable('#sortCount', 12, 5, 1);
        sortBandTable('#sortAverage', 14, 6, 1);
        sortBandTable('#sortVariance', 16, 7, 1);
        sortBandTable('#sortDeviation', 18, 8, 1);
        sortBandTable('#sortState', 10, 9, 1);<commit_msg>Correct sorting<commit_after>    $(function() {
    'use strict';

        function changeText(text, field) {
            $(field).fadeOut(200, function() {
                $(field).html(text).fadeIn(500);
            });
        }

        function setErrorMessage(type, message) {
            $('#messages').html('<div class="alert alert-' + type + '">' + message + '</div>').find('div').show().delay(2500).slideUp(500);
        }

        // set the correct, current amount of bands
        $('.bandsAmount').html($('#bandsTable').find('tbody tr').length + ' Bands');


        function ajaxFunction(self, event, success) {
            event.preventDefault();

            $.ajax({
                url: $(self).attr('href')
            }).done(function( data ) {
                if (data.success) {
                    success(data, self);

                    if (data.message) {
                        setErrorMessage('success', data.message);
                    }
                } else {
                    if (data.message) {
                        setErrorMessage('danger', data.message);
                    }
                }
            });
        }


        $('a.access').on('click', function(event) {
            ajaxFunction(this, event, function(data, self) {
                var accessCol = $(self).parent().parent().find('td:nth-child(2)');
                if (data.active) {
                    changeText('deaktivieren', self);
                    changeText('Benutzer', accessCol);
                } else {
                    changeText('aktivieren', self);
                    changeText('Inaktiv', accessCol);
                }
            });
        });

        $('a.mod').on('click', function(event) {
            ajaxFunction(this, event, function(data, self) {
                var accessCol = $(self).parent().parent().find('td:nth-child(2)');
                if (data.mod) {
                    changeText('degradieren', self);
                    changeText('Moderator', accessCol);
                } else {
                    changeText('befördern', self);
                    changeText('Benutzer', accessCol);
                }
            });
        });


        $('a.bandState').on('click', function(event) {
            ajaxFunction(this, event, function(data, self) {
                var stateCol = $(self).parent().parent().parent().parent().parent().find('td:nth-child(10)');
                changeText(data.state, stateCol);
            });
        });



        $('a.voteState').on('click', function(event) {
            ajaxFunction(this, event, function(data, self) {
                var stateCol = $(self).parent().parent().parent().parent().parent().find('td:nth-child(10)');
                var stateDotCol = $(self).parent().parent().parent().parent().parent().find('td:nth-child(1) div.dot');
                if (data.state) {
                    changeText('Aus dem Voting nehmen', self);
                    changeText('Im Voting', stateCol);
                    stateDotCol.fadeOut(200, function() {stateDotCol.removeClass('dot-yellow').addClass('dot-green').fadeIn(500);});
                } else {
                    changeText('Ins Voting nehmen', self);
                    changeText('Aus Voting genommen', stateCol);
                    stateDotCol.fadeOut(200, function() {stateDotCol.removeClass('dot-green').addClass('dot-yellow').fadeIn(500);});
                }
            });
        });

        $('a.voteStateDetail').on('click', function(event) {
            ajaxFunction(this, event, function(data, self) {
                var stateCol = $('#voteState');
                console.log(stateCol);
                if (data.state) {
                    changeText('Aus dem Voting nehmen', self);
                    changeText('Im Voting', stateCol);
                } else {
                    changeText('Ins Voting nehmen', self);
                    changeText('Aus Voting genommen', stateCol);
                }
            });
        });


        $('a.distance').on('click', function(event) {
            ajaxFunction(this, event, function(data, self) {
                if (data.distance) {
                    changeText(data.distance + ' km', self);
                }
            });
        });

        $('a.comment-rm').on('click', function(event) {

            if (confirm('Kommentar wirklich löschen?')) {
            ajaxFunction(this, event, function(data, self) {
                $(self).parent().parent().slideUp(function() {
                    this.remove();
                });
            });
            } else {
                event.preventDefault();
            }

        });


        /* Sort Users */
        var order = 2;

        /**
         * Generic handler for sorting a table by clicking on the column
         *
         * @param string table the id of the table
         * @param string elem the id of the elem the onclick-Listener should be registered on
         * @param int num the order-number (0,2,4, ...)
         * @param int col the nth-col (0,1,2,...)
         * @param bool desc whether the column should be ordered desc by default
         *
         * @return void
         * */
        function sortLinkHandler(table, elem, num, col, desc) {
            $(elem).on('click', function (event) {
                event.preventDefault();

                if (desc && order !== num && order !== num-1) {
                    // default: desc
                    order = num;
                } else if (order !== num && order !== num-1) {
                    // default: asc
                    order = num-1;

                } else {
                    order = (order < num) ? num : (num - 1);
                }
                sortTable(col, order, table);
            });
        }

        /** Sort users */
        sortLinkHandler('#usersTable', '#sortLogin', 2, 0, 0);
        sortLinkHandler('#usersTable', '#sortAccess', 4, 1, 0);
        sortLinkHandler('#usersTable', '#sortVotes', 6, 5, 1);
        sortLinkHandler('#usersTable', '#sortVotesLatest', 8, 6, 1);
        sortLinkHandler('#usersTable', '#sortVoteAverage', 10, 7, 1);
        sortLinkHandler('#usersTable', '#sortVoteVariance', 12, 8, 1);


        function sortBandTable(elem, num, col, desc) {
            sortLinkHandler('#bandsTable', elem, num, col, desc);
        }

        sortBandTable('#sortName', 2, 0, 0);
        sortBandTable('#sortMembers', 4, 1, 0);
        sortBandTable('#sortCity', 6, 2, 0);
        sortBandTable('#sortDistance', 8, 3, 0);
        sortBandTable('#sortCount', 12, 5, 1);
        sortBandTable('#sortAverage', 14, 6, 1);
        sortBandTable('#sortVariance', 16, 7, 1);
        sortBandTable('#sortDeviation', 18, 8, 1);
        sortBandTable('#sortState', 10, 9, 1);
{'fraction_non_alphanumeric': 0.15419667793620462, 'fraction_numerical': 0.013964427458474203, 'mean_word_length': 1.5519504876219055, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '1661785', 'n_tokens_mistral': 3872, 'n_tokens_neox': 3495, 'n_words': 754}