<commit_before>window.charts = window.charts || {};

charts.graphUrl; // /v1/users/... without query params
charts.date;

var getEventsFor = function (type, typeId, objectTags, actionTags, operation, period, shareToken) {
    return $.ajax({
        url: "/v1/" + type + "/" + typeId + "/events/" + objectTags + "/" + actionTags + "/" + operation + "/" + period + "/" + "type/json",
        data: {
            shareToken: shareToken
        },
        headers: {
            "Accept": "application/json",
            "Authorization": $.cookie("_eun")
        }
    });
};

var plotChart = function (events) {
    if (renderType === "barchart") {
        charts.plotBarChart("#chart", events, null, null);
    }
};

charts.addComment = function () {
    var commentText = $("#commentText").val();
    var comment = {
        text: commentText,
        timestamp: new Date(),
        user: username
    };
    var graph = {
        graphUrl: charts.graphUrl,
        username: graphOwner,
        objectTags: objectTags,
        actionTags: actionTags,
        operation: operation,
        period: period,
        renderType: renderType,
        comment: comment
    };
    $.ajax({
        url: "/v1/comments",
        method: "POST",
        data: graph,
        headers: {
            "Accept": "application/json",
            "Authorization": $.cookie("_eun")
        }
    }).done(function (data) {
        $(".commentList").append("<li><div class='commenter'>" + comment.user + "</div>" +
            "<div class='commentText'><p>" + comment.text + "</p>" +
            "<sub><span class='commentTimestamp'>" + moment(comment.timestamp).format("DD MMM YYYY HH:mm") + "</span></sub></div></li>");
        console.info("awesome. comment added." + JSON.stringify(comment));
        $("#commentText").val("");
        $("#addCommentInput").hide();
    });
};

$("#addCommentInput").keyup(function (e) {
    if (e.keyCode == 13) {
        charts.addComment();
    }
});

var handleAddComment = function () {
    if (isUserLoggedIn) {
        $("#addCommentInput").show();
    }
    else {
        $("#loginModal").modal({show: true});
    }
};

var handleShareGraph = function () {
    var unregisteredUserOnStreamsPage = function () {
        return !isUserLoggedIn && (window.location.pathname.search("streams") !== -1)
    };

    if (isUserLoggedIn) {
        $("#shareModal").modal({show: true});
    } else if (unregisteredUserOnStreamsPage()) {
        $("#shareLoginModal").modal({show: true});
    } else {
        $("#loginModal").modal({show: true});
    }
};

var showChartTitle = function () {
    $("#chartTitle").html(chartTitle);
    if (isUserLoggedIn || (!isUserLoggedIn && !(_.isEmpty(shareToken)))) {
        $.when(getEventsFor("users", graphOwner, objectTags, actionTags, operation, period, shareToken))
            .done(plotChart)
            .fail();
    } else {
        $.when(getEventsFor("streams", streamId, objectTags, actionTags, operation, period, shareToken))
            .done(plotChart)
            .fail();
    }
};

var submitShare = function () {
    var emailId = $("#emailId").val();
    var graphShare = {
        toEmailId: emailId,
        graphUrl: window.location.pathname
    };
    $.ajax({
        url: "/v1/share_graph",
        method: "POST",
        data: graphShare,
        success: function () {
            alert("Graph shared successfully.");
        },
        error: function () {
            alert("some problem. Please try again later.");
        }
    });
};

charts.showComments = function () {
    $.ajax({
        url: "/v1/comments?graphUrl=" + charts.graphUrl,
        headers: {
            "Accept": "application/json",
            "Authorization": $.cookie("_eun")
        }
    }).done(function (comments) {
        var commentsDiv = $(".commentList");
        commentsDiv.empty();
        comments.forEach(function (comment) {
            commentsDiv.append("<li><div class='commenter'>" + comment.user + "</div>" +
                "<div class='commentText'><p>" + comment.text + "</p>" +
                "<sub><span class='commentTimestamp'>" + moment(comment.timestamp).format("DD MMM YYYY HH:mm") + "</span></sub></div></li><hr>");
        });
    });
};

$(document).ready(function () {
    showChartTitle();
    $("#shareSubmit").click(submitShare);
});<commit_msg>-- Showing avatarUrl for the comments now<commit_after>window.charts = window.charts || {};

charts.graphUrl; // /v1/users/... without query params
charts.date;

var getEventsFor = function (type, typeId, objectTags, actionTags, operation, period, shareToken) {
    return $.ajax({
        url: "/v1/" + type + "/" + typeId + "/events/" + objectTags + "/" + actionTags + "/" + operation + "/" + period + "/" + "type/json",
        data: {
            shareToken: shareToken
        },
        headers: {
            "Accept": "application/json",
            "Authorization": $.cookie("_eun")
        }
    });
};

var plotChart = function (events) {
    if (renderType === "barchart") {
        charts.plotBarChart("#chart", events, null, null);
    }
};

charts.addComment = function () {
    var commentText = $("#commentText").val();
    var comment = {
        text: commentText,
        timestamp: new Date(),
        user: username,
        avatarUrl: avatarUrl
    };
    var graph = {
        graphUrl: charts.graphUrl,
        username: graphOwner,
        objectTags: objectTags,
        actionTags: actionTags,
        operation: operation,
        period: period,
        renderType: renderType,
        comment: comment
    };
    $.ajax({
        url: "/v1/comments",
        method: "POST",
        data: graph,
        headers: {
            "Accept": "application/json",
            "Authorization": $.cookie("_eun")
        }
    }).done(function (data) {
        $(".commentList").append("<li><div class='commenter'><img src='" + comment.avatarUrl + "'&size=100' width='100' height='100'/></div>" +
            "<div class='commentText'><p>" + comment.text + "</p>" +
            "<sub><span class='commentTimestamp'>" + moment(comment.timestamp).format("DD MMM YYYY HH:mm") + "</span></sub></div></li>");
        console.info("awesome. comment added." + JSON.stringify(comment));
        $("#commentText").val("");
        $("#addCommentInput").hide();
    });
};

$("#addCommentInput").keyup(function (e) {
    if (e.keyCode == 13) {
        charts.addComment();
    }
});

var handleAddComment = function () {
    if (isUserLoggedIn) {
        $("#addCommentInput").show();
    }
    else {
        $("#loginModal").modal({show: true});
    }
};

var handleShareGraph = function () {
    var unregisteredUserOnStreamsPage = function () {
        return !isUserLoggedIn && (window.location.pathname.search("streams") !== -1)
    };

    if (isUserLoggedIn) {
        $("#shareModal").modal({show: true});
    } else if (unregisteredUserOnStreamsPage()) {
        $("#shareLoginModal").modal({show: true});
    } else {
        $("#loginModal").modal({show: true});
    }
};

var showChartTitle = function () {
    $("#chartTitle").html(chartTitle);
    if (isUserLoggedIn || (!isUserLoggedIn && !(_.isEmpty(shareToken)))) {
        $.when(getEventsFor("users", graphOwner, objectTags, actionTags, operation, period, shareToken))
            .done(plotChart)
            .fail();
    } else {
        $.when(getEventsFor("streams", streamId, objectTags, actionTags, operation, period, shareToken))
            .done(plotChart)
            .fail();
    }
};

var submitShare = function () {
    var emailId = $("#emailId").val();
    var graphShare = {
        toEmailId: emailId,
        graphUrl: window.location.pathname
    };
    $.ajax({
        url: "/v1/share_graph",
        method: "POST",
        data: graphShare,
        success: function () {
            alert("Graph shared successfully.");
        },
        error: function () {
            alert("some problem. Please try again later.");
        }
    });
};

charts.showComments = function () {
    $.ajax({
        url: "/v1/comments?graphUrl=" + charts.graphUrl,
        headers: {
            "Accept": "application/json",
            "Authorization": $.cookie("_eun")
        }
    }).done(function (comments) {
        var commentsDiv = $(".commentList");
        commentsDiv.empty();
        comments.forEach(function (comment) {
            commentsDiv.append("<li><div class='commenter'><img src='" + comment.avatarUrl + "'&size=100' width='100' height='100'/></div>" +
                "<div class='commentText'><p>" + comment.text + "</p>" +
                "<sub><span class='commentTimestamp'>" + moment(comment.timestamp).format("DD MMM YYYY HH:mm") + "</span></sub></div></li><hr>");
        });
    });
};

$(document).ready(function () {
    showChartTitle();
    $("#shareSubmit").click(submitShare);
});
{'fraction_non_alphanumeric': 0.18346136466335292, 'fraction_numerical': 0.0038409399005874378, 'mean_word_length': 2.4036908881199537, 'pattern_counts': {'":': 12, '<': 55, '<?xml version=': 0, '>': 55, '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': '1975212', 'n_tokens_mistral': 2598, 'n_tokens_neox': 2589, 'n_words': 512}