<commit_before>$(function () {
    var server = io.connect(window.location.href);

    $('table').tablesort();
    $("thead th:contains('Date')").data('sortBy', function (th, td, tablesort) {
        var dateString = td.find('span.data').text();
        var date = new Date(dateString);
        if (date == 'Invalid Date'){
            date = new Date(0);
        }
        return date;
    });

    $('#table').click(function (e) {
        e.stopPropagation();
    });
    var updateCell = function (e) {
        e.preventDefault();
        var $td = $('td.active');
        var existingVal = $td.find('span.data').text();
        var val = $('#cell-edit').find('input').val();
        if (val !== existingVal) {
            var key = $td.parent().attr('data-key');
            var col = $td.closest('table').find('th').eq($td.index()).html();
            var data = {key: key, col: col, val: val};
            var dataJSON = JSON.stringify(data);
            console.log("sending 'update table cell' " + dataJSON);
            server.emit('update table cell', dataJSON);
        }
    };
    $('#cell-form').submit(updateCell);
    $('#cell-edit').find('input')[0].oninput = updateCell;
    $('body').click(function (e) {
        $('td').removeClass('active');
        $('#cell-edit').addClass('disabled').find('input').val('');
        $('#cell-ok').addClass('disabled');
    });
    $('#new-row').click(function (e) {
        var row = {};
        $('th').each(function () {
            var thText = $(this).html();
            if (thText.length > 0) {
                row[thText] = "";
            }
        });
        var rowJSON = JSON.stringify(row);
        console.log("sending 'new table row' " + rowJSON);
        server.emit('new table row', rowJSON);
    });

    var tdOnClick = function (e) {
        $('td').removeClass('active');
        $(this).addClass('active');
        $('#cell-edit').removeClass('disabled').find('input').focus().val($(this).find('span.data').html()).select();
        $('#cell-ok').removeClass('disabled');
    };

    var trashOnClick = function (e) {
        var key = $(this).parent().attr('data-key');
        var dataJSON = JSON.stringify({key: key});
        console.log("sending 'delete row' " + dataJSON);
        server.emit('delete row', dataJSON);
    };

    server.on('connect', function () {
        console.log('established new connection to server, clearing local table');
        $('tbody').html('');
        console.log("sending 'request all' to server");
        server.emit("request all");
    });
    server.on('title', function(dataJSON){
        $('.title').html(JSON.parse(dataJSON).title);
    });
    server.on('update table cell', function (dataJSON) {
        console.log("received 'update table cell' " + dataJSON);
        var data = JSON.parse(dataJSON);
        var index = $('th:contains(' + data.col + ')').index();
        $('tr[data-key="' + data.key + '"]').find('td').eq(index).find('span.data').html(data.val);
    });
    server.on('delete row', function (dataJSON) {
        console.log("received 'delete row' " + dataJSON);
        var data = JSON.parse(dataJSON);
        $('tr[data-key="' + data.key + '"]').remove();
    });
    server.on('new table row', function (rowJSON) {
        console.log("received 'new table row' " + rowJSON);
        var row = JSON.parse(rowJSON);
        var $tr = $('<tr data-key="' + row.key + '"></tr>');
        var $smallTrashIcon = $('<i class="smallDisplay ui left aligned trash outline icon"></i>');
        var $largeTrashIcon = $('<i class="largeDisplay ui center aligned trash outline icon"></i>');
        $trashTd = $('<td class="ui collapsing"></td>');
        $trashTd.append($smallTrashIcon).append($largeTrashIcon);
        $trashTd.click(trashOnClick);
        $tr.append($trashTd);
        $('th').each(function () {
            var thText = $(this).html();
            if (thText.length > 0) {
                var $td = $('<td>');
                var $span1 = $('<span class="header smallDisplay">' + thText + ': </span>');
                var $span2 = $('<span class="data">' + row.data[thText] + '</span>');
                $td.click(tdOnClick);
                $td.append($span1).append($span2);
                $tr.append($td);
            }
        });
        $('table').append($tr);
    });
});<commit_msg>resorts the table whenever data changes<commit_after>$(function () {
    var server = io.connect(window.location.href);

    var $table = $('table');
    $table.tablesort();
    $("thead th:contains('Date')").data('sortBy', function (th, td, tablesort) {
        var dateString = td.find('span.data').text();
        var date = new Date(dateString);
        if (date == 'Invalid Date') {
            date = new Date(0);
        }
        return date;
    });

    $('#table').click(function (e) {
        e.stopPropagation();
    });
    var updateCell = function (e) {
        e.preventDefault();
        var $td = $('td.active');
        var existingVal = $td.find('span.data').text();
        var val = $('#cell-edit').find('input').val();
        if (val !== existingVal) {
            var key = $td.parent().attr('data-key');
            var col = $td.closest('table').find('th').eq($td.index()).html();
            var data = {key: key, col: col, val: val};
            var dataJSON = JSON.stringify(data);
            console.log("sending 'update table cell' " + dataJSON);
            server.emit('update table cell', dataJSON);
        }
    };
    $('#cell-form').submit(updateCell);
    $('#cell-edit').find('input')[0].oninput = updateCell;
    $('body').click(function (e) {
        $('td').removeClass('active');
        $('#cell-edit').addClass('disabled').find('input').val('');
        $('#cell-ok').addClass('disabled');
    });
    $('#new-row').click(function (e) {
        var row = {};
        $('th').each(function () {
            var thText = $(this).html();
            if (thText.length > 0) {
                row[thText] = "";
            }
        });
        var rowJSON = JSON.stringify(row);
        console.log("sending 'new table row' " + rowJSON);
        server.emit('new table row', rowJSON);
    });

    var tdOnClick = function (e) {
        $('td').removeClass('active');
        $(this).addClass('active');
        $('#cell-edit').removeClass('disabled').find('input').focus().val($(this).find('span.data').html()).select();
        $('#cell-ok').removeClass('disabled');
    };

    var trashOnClick = function (e) {
        var key = $(this).parent().attr('data-key');
        var dataJSON = JSON.stringify({key: key});
        console.log("sending 'delete row' " + dataJSON);
        server.emit('delete row', dataJSON);
    };
    var sortTable = function () {
        var $th = $table.find('th.sorted');
        if ($th.hasClass('descending')) {
            $table.data('tablesort').sort($th, 'desc');
        } else if ($th.hasClass('ascending')) {
            $table.data('tablesort').sort($th, 'asc');
        }
    };

    server.on('connect', function () {
        console.log('established new connection to server, clearing local table');
        $('tbody').html('');
        console.log("sending 'request all' to server");
        server.emit("request all");
    });
    server.on('title', function (dataJSON) {
        $('.title').html(JSON.parse(dataJSON).title);
    });
    server.on('update table cell', function (dataJSON) {
        console.log("received 'update table cell' " + dataJSON);
        var data = JSON.parse(dataJSON);
        var index = $('th:contains(' + data.col + ')').index();
        $('tr[data-key="' + data.key + '"]').find('td').eq(index).find('span.data').html(data.val);
        sortTable();
    });
    server.on('delete row', function (dataJSON) {
        console.log("received 'delete row' " + dataJSON);
        var data = JSON.parse(dataJSON);
        $('tr[data-key="' + data.key + '"]').remove();
    });
    server.on('new table row', function (rowJSON) {
        console.log("received 'new table row' " + rowJSON);
        var row = JSON.parse(rowJSON);
        var $tr = $('<tr data-key="' + row.key + '"></tr>');
        var $smallTrashIcon = $('<i class="smallDisplay ui left aligned trash outline icon"></i>');
        var $largeTrashIcon = $('<i class="largeDisplay ui center aligned trash outline icon"></i>');
        $trashTd = $('<td class="ui collapsing"></td>');
        $trashTd.append($smallTrashIcon).append($largeTrashIcon);
        $trashTd.click(trashOnClick);
        $tr.append($trashTd);
        $('th').each(function () {
            var thText = $(this).html();
            if (thText.length > 0) {
                var $td = $('<td>');
                var $span1 = $('<span class="header smallDisplay">' + thText + ': </span>');
                var $span2 = $('<span class="data">' + row.data[thText] + '</span>');
                $td.click(tdOnClick);
                $td.append($span1).append($span2);
                $tr.append($td);
            }
        });
        $('table').append($tr);
        sortTable();
    });
});
{'fraction_non_alphanumeric': 0.21007479102507698, 'fraction_numerical': 0.0017597888253409592, 'mean_word_length': 2.344244207429202, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 33, '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': '2071060', 'n_tokens_mistral': 2748, 'n_tokens_neox': 2718, 'n_words': 546}