<commit_before>"use strict";

(function($) {
    $.fn.autofilter = function() {
        // setup the filter modal dialog
        var filterWidgetId = "_jquery_autofilter_modal";
        var filterWidget = $("#" + filterWidgetId);
        if (filterWidget.length == 0) { // not created yet
            var filterWidgetCode = "" +
"<div style='display: none'>" +
    "<div id='" + filterWidgetId + "' class='modal'>" +
    "    <span class='filter-button-reset'>Select all</span> - <span class='filter-button-reset'>Clear</span>" +
    "    <input class='filter-input'></input>" +
    "    <div id='filter-list'>" +
    "    </div>" +
    "</div>" +
"</div>";
            $("body").append(filterWidgetCode);

            filterWidget = $("#" + filterWidgetId);
        }

        //<form id="login-form" class="widget">
        //...
        //</form>
        this.each(function() {
            // TODO: check if is a table

            // get table data
            var body = $(this).find("tbody");
            var rows = [];
            body.find("tr").each(function(index) {
                var rowValues = [];
                $(this).find("td").each(function(index) {
                    rowValues.push($(this).text());
                });
                rows.push(rowValues);
            });
            //console.log(rows);

            // add filter element to all top tds
            var header = $(this).find("thead");
            
            //console.log(header);
            var headers = header.find("td");
            headers.each(function(columnIndex) {
                $(this).append("<div class='filter-icon-wrapper'><div class='filter-icon'></div></div>");
                var filter = $(this).find(".filter-icon-wrapper");
                filter.click(function() {
                    var columnFilters = $(this).attr("data-filters");
                    if (columnFilters == undefined) {
                        console.log("creating filters");
                        // get all the filterable values
                        var filterable = {};
                        var filterableList = [];

                        for (var rowIndex = 0; rowIndex < rows.length; rowIndex++) {
                            var data = rows[rowIndex][columnIndex];
                            if (!(data in filterable)) {
                                filterable[data] = true;
                                filterableList.push({
                                    "label" : data,
                                    "checked" : true
                                });
                            }
                        }
                        columnFilters = filterableList;
                        $(this).attr("data-filters", JSON.stringify(columnFilters));
                    } else {
                        columnFilters = JSON.parse(columnFilters);
                    }

                    $("#filter-list").html("");
                    for (var filterIndex = 0; filterIndex < columnFilters.length; filterIndex++) {
                        var filter = columnFilters[filterIndex];
                        var checkId = "autofilter_check" + filterIndex;
                        var checkedStr = filter["checked"] ? " checked" : "";
                        $("#filter-list").append("<input id='" + checkId + "' type='checkbox'" + checkedStr + "><label>" + filter["label"] + "</label><br/>");
                    }
                    
                    filterWidget.modal();
                    filterWidget.one($.modal.BEFORE_CLOSE, function(event, modal) {
                        console.log("closed");

                        // save off check changes
                        for (var filterIndex = 0; filterIndex < columnFilters.length; filterIndex++) {
                            var filter = columnFilters[filterIndex];
                            var checkId = "autofilter_check" + filterIndex;
                            columnFilters[filterIndex]["checked"] = $("#" + checkId).is(':checked');
                        }
                        console.log(columnFilters);
                        $(this).attr("data-filters", JSON.stringify(columnFilters));

                        // update the table visibility
                    });
                });
            });
        });
    }
}(jQuery));<commit_msg>changed storage to use closures, hiding rows<commit_after>"use strict";

(function($) {
    $.fn.autofilter = function() {
        // setup the filter modal dialog
        var filterWidgetId = "_jquery_autofilter_modal";
        var filterWidget = $("#" + filterWidgetId);
        if (filterWidget.length == 0) { // not created yet
            var filterWidgetCode = "" +
"<div style='display: none'>" +
    "<div id='" + filterWidgetId + "' class='modal'>" +
    "    <span class='filter-button-reset'>Select all</span> - <span class='filter-button-reset'>Clear</span>" +
    "    <input class='filter-input'></input>" +
    "    <div id='filter-list'>" +
    "    </div>" +
    "</div>" +
"</div>";
            $("body").append(filterWidgetCode);

            filterWidget = $("#" + filterWidgetId);
        }

        this.each(function() {
            // TODO: check if is a table

            // get table data
            var body = $(this).find("tbody");
            var rows = [];
            body.find("tr").each(function(index) {
                var rowValues = [];
                $(this).find("td").each(function(index) {
                    rowValues.push($(this).text());
                });
                rows.push(rowValues);
            });

            // add filter element to all top tds
            var headerRow = $(this).find("thead");
            
            var allColumnFilters = [];

            var headers = headerRow.find("td");
            headers.each(function(columnIndex) {
                var header = $(this);
                header.append("<div class='filter-icon-wrapper'><div class='filter-icon'></div></div>");
                var filter = header.find(".filter-icon-wrapper");

                // add to the create the data model
                let filterable = {};
                let filterableList = [];
                for (var rowIndex = 0; rowIndex < rows.length; rowIndex++) {
                    let data = rows[rowIndex][columnIndex];
                    if (!(data in filterable)) {
                        filterable[data] = true;
                        filterableList.push({
                            "label" : data,
                            "checked" : true
                        });
                    }
                }
                allColumnFilters.push(filterableList);

                filter.click(function() {
                    // empty the list and put in the filters for this column
                    $("#filter-list").html("");
                    var columnFilters = allColumnFilters[columnIndex];
                    for (var filterIndex = 0; filterIndex < columnFilters.length; filterIndex++) {
                        var filter = columnFilters[filterIndex];
                        var checkId = "autofilter_check" + filterIndex;
                        var checkedStr = filter["checked"] ? " checked" : "";
                        $("#filter-list").append("<input id='" + checkId + "' type='checkbox'" + checkedStr + "><label>" + filter["label"] + "</label><br/>");
                    }
                    
                    filterWidget.modal();
                    filterWidget.one($.modal.BEFORE_CLOSE, function(event, modal) {
                        // save off check changes
                        for (var filterIndex = 0; filterIndex < columnFilters.length; filterIndex++) {
                            var filter = columnFilters[filterIndex];
                            var checkId = "autofilter_check" + filterIndex;
                            columnFilters[filterIndex]["checked"] = $("#" + checkId).is(':checked');
                        }

                        // build the check set
                        var allColumnFilterSets = allColumnFilters.map(function(columnFilters) {
                            return new Set(columnFilters.filter(function(filter) {
                                return filter["checked"];
                            }).map(function(filter){ 
                                return filter["label"];
                            }));
                        });

                        // update the table visibility
                        body.find("tr").each(function(rowIndex) {
                            var rowVisible = true;
                            $(this).find("td").each(function(cellColumnIndex) {
                                var cellValue = $(this).text();
                                rowVisible = rowVisible && allColumnFilterSets[cellColumnIndex].has(cellValue);
                            });
                            if (rowVisible) {
                                $(this).show();
                            } else {
                                $(this).hide();
                            }
                        });
                    });
                });
            });
        });
    }
}(jQuery));
{'fraction_non_alphanumeric': 0.13442197469449552, 'fraction_numerical': 0.0008651454525792149, 'mean_word_length': 1.2262879152623978, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7357899', 'n_tokens_mistral': 2202, 'n_tokens_neox': 2109, 'n_words': 431}