<commit_before>{% block body %}
    <hr>
    <h3>{{ "page.post.show.comments.title"|trans }}</h3>
    {% if is_granted("IS_AUTHENTICATED_FULLY") %}
        {{ form_start(form, {attr: {id: "commentForm"}}) }}
        <div class="form-group">
            {{ form_widget(form.content, {'attr': {'placeholder': "page.post.show.comments.commentph"|trans}}) }}
            {{ form_errors(form.content) }}
        </div>

        {{ form_end(form) }}
    {% else %}
        <div class="alert alert-info">
            {{ "page.post.show.comments.nologin"|trans({'%url%': path('fos_user_security_login')})|raw }}
        </div>
    {% endif %}
    <div id="post-comments">
        To see comments, you need to activate Javascipt
    </div>
{% endblock %}

{% block javascripts %}

    <script>
        $(document).ready(function() {
            $('#commentForm').submit(function(e) {
                e.preventDefault();
                var formURL = "{{ path('post_comment', {"id": post.id}) }}";

                $.post({
                    url: formURL,
                    data: $(this).serialize(),
                    mimeType:"multipart/form-data",
                    success: function (data) {
                        console.log(data);
                        $('#commentForm').find('textarea').val('');
                        showComments();
                    },
                    error: function(jqXHR, textStatus, errorThrown) {
                        console.error(jqXHR);
                        console.error(textStatus);
                        console.error(errorThrown);
                    }
                });
                return false;
            });

            function showComments() {
                var url = "{{ path('post_get_comment', {"id": post.id}) }}";
                $.get({
                    url: url,
                    success: function(data) {
                        $('#post-comments').html("");

                        data.forEach(function(element) {
                            addComment(element);
                        });
                    },
                    error: function(jqXHR, textStatus, errorThrown) {
                        console.error(jqXHR);
                        console.error(textStatus);
                        console.error(errorThrown);
                    }
                });
            }

            function addComment(comment) {
                content =
                    "<div class='comment' id='comment"+ comment.id +"'>" +
                        "<div class='comment-author'>" +
                            "<img src='/{{ profile_picture_directory }}"+ comment.author.profilePicture +"'>" +
                        "</div>" +
                        "<div class='comment-content'>" +
                            "<div class='username'>" +
                                "<a href='"+ comment.author.profileUrl +"' class='label'>" + comment.author.username + "</a>" +
                                "<span class='date'>"+ comment.comment.date +"</span>" +
                                "<span class='deleteComment float-right'></span>" +
                            "</div>" +
                            comment.comment.content +
                        "</div>" +
                    "</div>";
                $('#post-comments').append(content);
                deleteState("", comment.id)
            }

            showComments();
        });

        function deleteComment(e, id) {
            e.preventDefault();
            deleteState('confirm', id);
        }

        function cancelDelete(event, id) {
            event.preventDefault();
            deleteState('', id);
        }<commit_msg>fix no profile picture<commit_after>{% block body %}
    <hr>
    <h3>{{ "page.post.show.comments.title"|trans }}</h3>
    {% if is_granted("IS_AUTHENTICATED_FULLY") %}
        {{ form_start(form, {attr: {id: "commentForm"}}) }}
        <div class="form-group">
            {{ form_widget(form.content, {'attr': {'placeholder': "page.post.show.comments.commentph"|trans}}) }}
            {{ form_errors(form.content) }}
        </div>

        {{ form_end(form) }}
    {% else %}
        <div class="alert alert-info">
            {{ "page.post.show.comments.nologin"|trans({'%url%': path('fos_user_security_login')})|raw }}
        </div>
    {% endif %}
    <div id="post-comments">
        To see comments, you need to activate Javascipt
    </div>
{% endblock %}

{% block javascripts %}

    <script>
        $(document).ready(function() {
            $('#commentForm').submit(function(e) {
                e.preventDefault();
                var formURL = "{{ path('post_comment', {"id": post.id}) }}";

                $.post({
                    url: formURL,
                    data: $(this).serialize(),
                    mimeType:"multipart/form-data",
                    success: function (data) {
                        console.log(data);
                        $('#commentForm').find('textarea').val('');
                        showComments();
                    },
                    error: function(jqXHR, textStatus, errorThrown) {
                        console.error(jqXHR);
                        console.error(textStatus);
                        console.error(errorThrown);
                    }
                });
                return false;
            });

            function showComments() {
                var url = "{{ path('post_get_comment', {"id": post.id}) }}";
                $.get({
                    url: url,
                    success: function(data) {
                        $('#post-comments').html("");

                        data.forEach(function(element) {
                            addComment(element);
                        });
                    },
                    error: function(jqXHR, textStatus, errorThrown) {
                        console.error(jqXHR);
                        console.error(textStatus);
                        console.error(errorThrown);
                    }
                });
            }

            function addComment(comment) {
                content =
                    "<div class='comment' id='comment"+ comment.id +"'>" +
                        "<div class='comment-author'>" +
                            "<img src='/{{ profile_picture_directory }}"+ (comment.author.profilePicture !== null ? comment.author.profilePicture : "default.jpg") +"'>" +
                        "</div>" +
                        "<div class='comment-content'>" +
                            "<div class='username'>" +
                                "<a href='"+ comment.author.profileUrl +"' class='label'>" + comment.author.username + "</a>" +
                                "<span class='date'>"+ comment.comment.date +"</span>" +
                                "<span class='deleteComment float-right'></span>" +
                            "</div>" +
                            comment.comment.content +
                        "</div>" +
                    "</div>";
                $('#post-comments').append(content);
                deleteState("", comment.id)
            }

            showComments();
        });

        function deleteComment(e, id) {
            e.preventDefault();
            deleteState('confirm', id);
        }

        function cancelDelete(event, id) {
            event.preventDefault();
            deleteState('', id);
        }
{'fraction_non_alphanumeric': 0.15045430251202566, 'fraction_numerical': 0.0005344735435595938, 'mean_word_length': 1.224368499257058, 'pattern_counts': {'":': 4, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2357052', 'n_tokens_mistral': 1933, 'n_tokens_neox': 1790, 'n_words': 300}