{"size": 7754, "ext": "js", "max_stars_repo_path": "src/RepoCat.Portal/wwwroot/js/site/projectsTable-declaration.js", "max_stars_repo_name": "bartosz-jarmuz/RepoCat", "max_stars_repo_stars_event_min_datetime": "2019-09-05T09:13:04.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-19T01:58:47.000Z", "max_issues_repo_path": "src/RepoCat.Portal/wwwroot/js/site/projectsTable-declaration.js", "max_issues_repo_name": "bartosz-jarmuz/RepoCat", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/RepoCat.Portal/wwwroot/js/site/projectsTable-declaration.js", "max_forks_repo_name": "bartosz-jarmuz/RepoCat", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.5798319328, "max_line_length": 147, "alphanum_fraction": 0.5145731235}
﻿function getProjectsTable(activeColumnsCookie, isSearchResult) {

    let t0 = performance.now();

    let showRepositoryColumn = $('#ResultsTableData').data('showrepositorycolumn');
    let numberOfExtraColumns = 0; 
    if (activeColumnsCookie) {
        numberOfExtraColumns = showColumnsFromCookies(activeColumnsCookie);
    } else {
        numberOfExtraColumns = parseInt($('#ResultsTableData').attr('data-numberofextracolumns'));
    }
    let ordering;
    if (isSearchResult) {
        ordering = [[0, 'desc']]; 

    } else {
        ordering = [[3, 'asc']];
    }
    var table = $('#ResultsTable').DataTable({
        pageLength: 50,
        stateSave: false,
        "autoWidth": true,
        "processing": true,
        "lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
        order: ordering,
         
        // @ts-ignore
        "columnDefs": [
            {
                "targets": [0],
                "visible": true,
                "searchable": false,
                "width": "2%",
                render: function (data, type, full, meta) {
                    if (type === "sort") {
                        // @ts-ignore
                        var api = new $.fn.dataTable.Api(meta.settings);
                        var td = api.cell({ row: meta.row, column: meta.col }).node(); // the td of the row
                        data = $(td).attr('data-order'); // the data it should be sorted by
                    }
                    return data;
                }
            },
            {
                "targets": [1],
                "visible": false, 
            },
            { 
                "targets": [2],
                "visible": (showRepositoryColumn.toUpperCase() == 'TRUE'),
            },
            {
                "targets": [3],
                "width": "25%"

            },
            {
                "targets": [4],
                "width": "2%" 
            },
        ],

        columns: getColumns(numberOfExtraColumns, isSearchResult),
        
        dom: "R"  
            + "<'#TopButtonsRow.row'<'col-md-1 first'l><'col-md-2 table-filter'><'col-md-8 restore-columns-row'><'col-md-1 third'if>>"
            + "<rtip> ",
         
    });

    if (isSearchResult) {
        $('td.expand-table-row').each(function () {
            $(this).html(
                '<span class="accuracy-score" data-toggle="tooltip" title="This score indicates how relevant is this project to the search query.'+
                '\r\nThe higher the better - there is no maximum defined.">' +
                '<i class="far fa-star d-inline"></i>'+
                Number($(this).data('order')).toFixed(2)
                + '</span>'
            );
        });
    }

    setupHideButtons(table);

    alignSearchPanel();

    hideDefaultColumnsFromCookies(table);
    setupSearchHighlights();

    let t1 = performance.now();
    console.log("Drawing table: " + (t1 - t0) + " milliseconds.");

    return table;

}

function setupSearchHighlights() {
    let timeout = null;
    $('.table-search').on('input', function () {
        clearTimeout(timeout);
        timeout = setTimeout(function () {
            markSearchPhrases();
        }, 250);

    });
}

function markSearchPhrases() {
    // @ts-ignore
    $('.projects-table-card').unmark({
        done: function () {
            // @ts-ignore
            $('.projects-table-card').mark($('.table-search').val(), {
                className: 'search-mark',
                element: 'span'
            });
            // @ts-ignore
            $('.projects-table-card').mark($('#searchQuery').val(), {
                className: 'search-mark',
                element: 'span'
            });
        }
    });
    redrawStripes();
}

function setupTableFeatures(table) {
    setupRowExpanding(table);

    setupFiltering(table);

    alignTopButtonsRow();

    setupAddingColumns(table);
}

function setupRowExpanding(table) {
    $('#ResultsTable tbody').off('click.rc.rows');
    $('#ResultsTable tbody').on('click.rc.rows', '.expand-table-row', function () {
        function getProjectDetails(d) {
            var arr = Object.values(d); 
            return $(arr[0]); 
        }
        let $expandButton = $($(this).clone());
        let tr = $(this).closest('tr').not('.child-row-shown'); 
        if (!tr || tr.length == 0) {
            tr = $(this).closest('tr').prev('tr');
        }
        var row = table.row(tr);
        if (row.child.isShown()) {
            $('div.slider', row.child()).fadeOut();
            row.child.hide();
            $(tr).fadeIn();   
            
        }
        else { 
            let details = getProjectDetails(row.data());
            row.child(details.html()).show(); 
            let childRow = $(tr).next('tr');
            childRow.prepend($expandButton);  
            childRow.addClass('child-row-shown');
            $('div.slider', row.child()).fadeIn();   
            $(tr).hide();
            markSearchPhrases();
        }

        redrawStripes();
    });
}

function redrawStripes() {
    $('#ResultsTable tbody tr:visible').each(function (index) {
        if (index % 2 == 0) {
            $(this).css('background-color', '#f2f2f2');
        } else {
            $(this).css('background-color', '#ffffff');
        }
    });
}

function alignTopButtonsRow() {
    $('#TopButtonsRow').children('.first').attr('style', 'margin-right: 10px;');
    $('#TopButtonsRow').children('.third').attr('style', 'margin-left: -10px;');
}

function alignSearchPanel() {
  
    var input = $('#ResultsTable_filter label input').appendTo($('.table-filter')).wrap(
        "<div class='col'></div>"
    );
    $('#ResultsTable_filter label').remove();  
    $(input).attr('style', 'width: 11rem; display: inline;');
    $(input).addClass('table-search');
    $(input).after("<i class='far fa-question-circle d-inline m-2' style='cursor: help;' data-toggle='tooltip'" +
        "title='Filtering is a basic method for searching within a table.\r\n" +
        "It simply shows only the rows which contain a given search string anywhere in the content.\r\n" +
        "Contrary to the repository Search function:\r\n" +
        "  - filtering does not take into account the \"weights\" of matches\r\n" +
        "  - filtering does not change the table sorting.\r\n" +
        "For example, if looking for \"Miss Universe\", a project with name \"Miss Universe\" is more relevant than\r\n" +
        "a project which description states something like \"This project is missing a universal template\"\r\n" +
        "The search function will order the results so that more \"relevant\" matches are shown on the top of the list." +
        "'></i>");
     
    $(input).attr('placeholder', 'Type to filter the table'); 
}

function showOverlay() {
    var overlay = $('#ResultsTable').closest('.card').find('.overlay');
    $(overlay).show().fadeIn();
}

function hideOverlay() {
    var overlay = $('#ResultsTable').closest('.card').find('.overlay');
    $(overlay).fadeOut();
}

function getRepositoriesKey() {
    return $('#ResultsTableData').attr('data-repositories');
} 

function showShareButton() {
    setTimeout(function () {

        if ($('.table-header .share-link').length == 0) {
            var button = '<a tabindex="0" class="btn btn-warning share-link" ><i class="fas fa-share-square"></i>&nbsp;Share</div>';
            $('.table-header').append($(button).hide().fadeIn());

            // @ts-ignore
            $('.share-link').tooltip({
                placement: 'top',
                trigger: 'hover',
                delay: { "show": 900, "hide": 100 }, 
                title: 'Get the URL of this results set'
            })    
        }
    }, 500);
}