function showContributionsTable()

in ignite-tc-helper-web/src/main/webapp/js/prs-1.2.js [61:204]


function showContributionsTable(result, srvId, suiteId) {
    let tableId = 'serverContributions-' + srvId;
    let tableForSrv = $('#' + tableId);

    tableForSrv.dataTable().fnDestroy();

    if (isDefinedAndFilled(result) && result.length > 0)
        $("#expandAllButton-"+ srvId).html("<button class='more green' id='expandAll'>Expand all</button>");

    var table = tableForSrv.DataTable({
        order: [[1, 'desc']],
        data: result,
        "iDisplayLength": 30, //rows to be shown by default
        //"dom": '<lf<t>ip>',
        //"dom": '<"wrapper"flipt>',
        stateSave: true,
        columnDefs: [
            {
                targets: 1,
                className: 'dt-body-center'
            }
        ],
        columns: [
            {
                "className": 'details-control',
                //"orderable":      false,
                "data": null,
                "title": "",
                "defaultContent": "",
                "render": function (data, type, row, meta) {
                    if (type === 'display') {
                        return "<button class='more full green' type='button' id='button_" + row.prNumber +"'>" +
                            "<b>ᴍᴏʀᴇ</b><i class='fas fa-caret-down'></i></button>";
                    }
                }
            },
            {
                "data": "prTimeUpdate",
                title: "Update Time",
                "render": function (data, type, row, meta) {
                    if (type === 'display' && isDefinedAndFilled(data) && data.length >0) {
                        let date = new Date(data);

                        data = normalizeDateNum(date.getFullYear()) + '-' + normalizeDateNum(date.getMonth() + 1) +
                            '-' + normalizeDateNum(date.getDate()) + "<br>" + normalizeDateNum(date.getHours()) +
                            ':' + normalizeDateNum(date.getMinutes()) + ":" + normalizeDateNum(date.getSeconds());
                    }

                    return data;
                }
            },
            {
                "data": "prHtmlUrl",
                title: "PR Number",
                "render": function (data, type, row, meta) {
                    if (type === 'display' && row.prNumber > 0) {
                        data = "<a href='" + data + "'>#" + row.prNumber + "</a>";

                        if (type === 'display' && isDefinedAndFilled(row.prHeadCommit)) {
                            data += " (" + row.prHeadCommit + ")";
                        }
                    }

                    return data;
                }
            }
            , {
                "data": "prTitle",
                title: "Title"
            },
            {
                "data": "prAuthor",
                title: "Author",
                "render": function (data, type, row, meta) {
                    if (type === 'display' && isDefinedAndFilled(row.prAuthorAvatarUrl) && row.prAuthorAvatarUrl.length >0) {
                        data = "<img src='" + row.prAuthorAvatarUrl + "' width='20px' height='20px'> " + data + "";
                    }

                    return data;
                }

            },
            {
                "data": "jiraIssueId",
                title: "JIRA Issue",
                "render": function (data, type, row, meta) {
                    if (type === 'display') {
                        if (data != null && row.jiraIssueUrl != null)
                            data = "<a href='" + row.jiraIssueUrl + "'>" + data + "</a>";
                    }

                    return data;
                }
            },
            {
                "data": "jiraStatusName",
                title: "JIRA Status",
                "render": function (data, type, row, meta) {
                    if (type === 'display') {
                        if (data != null && row.jiraIssueUrl != null)
                            data = "<a href='" + row.jiraIssueUrl + "'>" + data + "</a>";
                    }

                    return data;
                }
            },
            {
                "data": "tcBranchName",
                title: "Resolved Branch Name",
                "render": function (data, type, row, meta) {
                    let prId = data;
                    if (type === 'display' && isDefinedAndFilled(data)) {
                        data = " " + data + "";
                    }

                    return data;
                }
            }
        ]
    });

    $('#expandAll').on('click', function () {
        $('.details-control').click();
    });

    // Add event listener for opening and closing details, enable to only btn   'td.details-control'
    $('#' + tableId + ' tbody').on('click', 'td.details-control', function () {
        var tr = $(this).closest('tr');
        var row = table.row(tr);

        if (row.child.isShown()) {
            // This row is already open - close it
            row.child.hide();
            $("#button_" + row.data().prNumber).html("<b>ᴍᴏʀᴇ</b><i class='fas fa-caret-down'></i>");
            tr.removeClass('shown');
        }
        else {
            // Open this row
            row.child(formatContributionDetails(row.data(), srvId, suiteId)).show();
            $("#button_" + row.data().prNumber).html("<b>ʟᴇss&nbsp;</b><i class='fas fa-caret-up'></i>");
            tr.addClass('shown');
        }
    });
}