Skip to content

Commit

Permalink
Add link to the specific error trace in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vmordan committed Nov 29, 2023
1 parent 0dd93c5 commit 1f2bd26
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 112 deletions.
1 change: 1 addition & 0 deletions web/marks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class Meta:

class MarkUnsafeComment(models.Model):
mark = models.ForeignKey(MarkUnsafe, models.CASCADE, related_name='comments')
report = models.ForeignKey(ReportUnsafe, models.SET_NULL, null=True)
date = models.DateTimeField()
author = models.ForeignKey(User, models.SET_NULL, null=True, related_name='+')
description = models.TextField()
Expand Down
217 changes: 109 additions & 108 deletions web/marks/static/marks/js/comments.js
Original file line number Diff line number Diff line change
@@ -1,108 +1,109 @@
/*
* CVV is a continuous verification visualizer.
* Copyright (c) 2023 ISP RAS (http://www.ispras.ru)
* Ivannikov Institute for System Programming of the Russian Academy of Sciences
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* ee the License for the specific language governing permissions and
* limitations under the License.
*/

function clear_reply_form(mark_id) {
let previous_comment = document.getElementById('edit_comment_id_' + mark_id);
if (previous_comment.value) {
document.getElementById("comment_text_" + previous_comment.value).style.background = "#ffffff";
}
previous_comment.value = "";
}

function show_comments(mark_id) {
$('.comment.collapsed').each(function () { !$(this).toggleClass("collapsed")});
$('#show_comments_btn_' + mark_id).modal('hide');
}

function reply_comment(comment_id, username, mark_id) {
const orig_text = document.getElementById("comment_text_" + comment_id).innerHTML;
document.getElementById('new_comment_field_' + mark_id).value = username + ":<blockquote>" + orig_text + "</blockquote>\n";
$("#new_comment_field_" + mark_id).focus();
clear_reply_form(mark_id);
}

function edit_comment(comment_id, mark_id) {
const orig_text = document.getElementById("comment_text_" + comment_id).innerHTML;
document.getElementById('new_comment_field_' + mark_id).value = orig_text;
$("#new_comment_field_" + mark_id).focus();
clear_reply_form(mark_id);
document.getElementById('edit_comment_id_' + mark_id).value = comment_id;
document.getElementById("comment_text_" + comment_id).style.background = "#f9f9f9";
}

function new_comment(mark_id) {
let comment_id = document.getElementById('edit_comment_id_' + mark_id).value;
var desc = $('#new_comment_field_' + mark_id).val();
if (!desc) {
return;
}
const root_comment = $('#comments_root_' + mark_id);

var cmt_data = {
description: desc, mark_id: mark_id, comment_id: comment_id
};

$.post('/marks/create-comment/', cmt_data, function (data) {
if (data.error) {
err_notify(data.error);
return false;
}
if (comment_id) {
// Edit comment
document.getElementById("comment_text_" + comment_id).innerHTML = desc;
} else {
// New comment
const user_name = data['user_name'];
const user_id = data['user_id'];
comment_id = data['comment_id'];
let new_comment = document.createElement('div');
new_comment.className = 'comment';
new_comment.innerHTML = `
<div id="comment_${comment_id}" class="content">
<a href="/users/profile/${user_id}" class="author">${user_name}</a>
<div class="metadata">
<span class="date">Now</span>
</div>
<div id="comment_text_${comment_id}" class="text">${desc}</div>
<div class="actions">
<a class="reply" onclick="reply_comment('${comment_id}', '${user_name}', '${mark_id}')">Reply</a>
<a class="edit" onclick="edit_comment(${comment_id}, ${mark_id})">Edit</a>
<a class="delete" onclick="delete_comment(${comment_id}, ${mark_id})">Delete</a>
</div>
</div>`;
root_comment.prepend(new_comment);
}
clear_reply_form(mark_id);
document.getElementById('new_comment_field_' + mark_id).value = "";
});
}

function delete_comment(comment_id, mark_id) {
var cmt_data = {
comment_id: comment_id
};
$.post('/marks/delete-comment/', cmt_data, function (data) {
if (data.error) {
err_notify(data.error);
return false;
}
clear_reply_form(mark_id);
let removed_comment = document.getElementById("comment_" + comment_id);
removed_comment.parentNode.removeChild(removed_comment);
});
}
/*
* CVV is a continuous verification visualizer.
* Copyright (c) 2023 ISP RAS (http://www.ispras.ru)
* Ivannikov Institute for System Programming of the Russian Academy of Sciences
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* ee the License for the specific language governing permissions and
* limitations under the License.
*/

function clear_reply_form(mark_id) {
let previous_comment = document.getElementById('edit_comment_id_' + mark_id);
if (previous_comment.value) {
document.getElementById("comment_text_" + previous_comment.value).style.background = "#ffffff";
}
previous_comment.value = "";
}

function show_comments(mark_id) {
$('.comment.collapsed').each(function () { !$(this).toggleClass("collapsed")});
$('#show_comments_btn_' + mark_id).modal('hide');
}

function reply_comment(comment_id, username, mark_id) {
const orig_text = document.getElementById("comment_text_" + comment_id).innerHTML;
document.getElementById('new_comment_field_' + mark_id).value = username + ":<blockquote>" + orig_text + "</blockquote>\n";
$("#new_comment_field_" + mark_id).focus();
clear_reply_form(mark_id);
}

function edit_comment(comment_id, mark_id) {
const orig_text = document.getElementById("comment_text_" + comment_id).innerHTML;
document.getElementById('new_comment_field_' + mark_id).value = orig_text;
$("#new_comment_field_" + mark_id).focus();
clear_reply_form(mark_id);
document.getElementById('edit_comment_id_' + mark_id).value = comment_id;
document.getElementById("comment_text_" + comment_id).style.background = "#f9f9f9";
}

function new_comment(mark_id) {
let comment_id = document.getElementById('edit_comment_id_' + mark_id).value;
var desc = $('#new_comment_field_' + mark_id).val();
if (!desc) {
return;
}
const root_comment = $('#comments_root_' + mark_id);
const report_id = $('#report_pk').val();

var cmt_data = {
description: desc, mark_id: mark_id, comment_id: comment_id, report_id: report_id
};

$.post('/marks/create-comment/', cmt_data, function (data) {
if (data.error) {
err_notify(data.error);
return false;
}
if (comment_id) {
// Edit comment
document.getElementById("comment_text_" + comment_id).innerHTML = desc;
} else {
// New comment
const user_name = data['user_name'];
const user_id = data['user_id'];
comment_id = data['comment_id'];
let new_comment = document.createElement('div');
new_comment.className = 'comment';
new_comment.innerHTML = `
<div id="comment_${comment_id}" class="content">
<a href="/users/profile/${user_id}" class="author">${user_name}</a>
<div class="metadata">
<span class="date">Now</span>
</div>
<div id="comment_text_${comment_id}" class="text">${desc}</div>
<div class="actions">
<a class="reply" onclick="reply_comment('${comment_id}', '${user_name}', '${mark_id}')">Reply</a>
<a class="edit" onclick="edit_comment(${comment_id}, ${mark_id})">Edit</a>
<a class="delete" onclick="delete_comment(${comment_id}, ${mark_id})">Delete</a>
</div>
</div>`;
root_comment.prepend(new_comment);
}
clear_reply_form(mark_id);
document.getElementById('new_comment_field_' + mark_id).value = "";
});
}

function delete_comment(comment_id, mark_id) {
var cmt_data = {
comment_id: comment_id
};
$.post('/marks/delete-comment/', cmt_data, function (data) {
if (data.error) {
err_notify(data.error);
return false;
}
clear_reply_form(mark_id);
let removed_comment = document.getElementById("comment_" + comment_id);
removed_comment.parentNode.removeChild(removed_comment);
});
}
3 changes: 3 additions & 0 deletions web/marks/templates/marks/Comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ <h4 class="ui top left attached gray label">{% trans 'Comments' %}</h4>
</div>
<div id="comment_text_{{comment.3}}" class="text">{{comment.2|safe}}</div>
<div class="actions" style="align-items: left">
{% if comment.6 %}
<a class="show" href="{% url 'reports:unsafe' comment.6.id %}">{% trans 'Show original report' %}</a>
{% endif %}
<a class="reply" onclick="reply_comment('{{comment.3}}', '{{comment.0.username}}', '{{mark_id}}')">{% trans 'Reply' %}</a>
{% if comment.4 %}
<a class="edit" onclick="edit_comment({{comment.3}}, {{mark_id}})">{% trans 'Edit' %}</a>
Expand Down
2 changes: 1 addition & 1 deletion web/marks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def get_mark_comments(comments, user):
counter = 0
for m in comments.order_by('-id'):
is_edit = m.author == user or user.is_staff
results.append((m.author, m.date, m.description, m.id, is_edit, counter < 3))
results.append((m.author, m.date, m.description, m.id, is_edit, counter < 3, m.report))
counter += 1
return results

Expand Down
7 changes: 6 additions & 1 deletion web/marks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ def get_context_data(self, **kwargs):
description = self.request.POST['description']
mark_id = self.request.POST['mark_id']
comment_id = self.request.POST['comment_id']
report_id = self.request.POST.get('report_id', None)
context = {}
if comment_id:
# Edit comment
Expand All @@ -725,10 +726,14 @@ def get_context_data(self, **kwargs):
else:
# Create new comment
mark = MarkUnsafe.objects.get(id=mark_id)
if report_id:
report = ReportUnsafe.objects.get(id=report_id)
else:
report = None
try:
mark_comment = MarkUnsafeComment.objects.create(
mark=mark, description=description,
author=self.request.user, date=now()
author=self.request.user, date=now(), report=report
)
context['comment_id'] = mark_comment.id
context['user_name'] = self.request.user.username
Expand Down
8 changes: 6 additions & 2 deletions web/users/templates/users/showComments.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{% block body_block %}
<div class="ui basic segment">
<h1>{% trans 'Comments to unsafe marks' %}</h1>
<table class="ui celled compact gray selectable table sort-table show-min">
<table class="ui celled compact gray selectable table sort-table show-max">
<thead>
<tr style="text-align: center">
<th width="1%">#</th>
Expand All @@ -49,7 +49,11 @@ <h1>{% trans 'Comments to unsafe marks' %}</h1>
<td>{{ comment.date }}</td>
<td><a href="{% url 'users:show_profile' comment.author.id %}">{{ comment.author.username }}</a></td>
<td><a href="{% url 'marks:mark' 'unsafe' comment.mark.id %}">{{ comment.mark.id }}</a></td>
<td><a href="{% url 'reports:unsafe' comment.mark.report.id %}">{{ comment.mark.report.id }}</a></td>
{% if comment.report %}
<td><a href="{% url 'reports:unsafe' comment.report.id %}">{% trans 'Specific' %}</a></td>
{% else %}
<td><a href="{% url 'reports:unsafe' comment.mark.report.id %}">{% trans 'Original' %}</a></td>
{% endif %}
<td><a href="{% url 'jobs:job' comment.mark.report.root.job.id %}">{{comment.mark.report.root.job.name}}</a></td>
<td style="text-align: left">{{ comment.description|safe }}</td>
</tr>
Expand Down

0 comments on commit 1f2bd26

Please sign in to comment.