Skip to content

feat: Allow users to comment #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lms/lmsdb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ def _by_file(cls, file_id: int):
CommentText.id.alias('comment_id'), CommentText.text,
SolutionFile.id.alias('file_id'),
User.fullname.alias('author_name'),
User.role.alias('author_role'),
]
return (
cls
Expand Down
4 changes: 2 additions & 2 deletions lms/lmsweb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ def _create_comment(

return jsonify({
'success': 'true', 'text': comment_.comment.text,
'author_name': user.fullname, 'is_auto': False, 'id': comment_.id,
'line_number': line_number,
'author_name': user.fullname, 'author_role': user.role.id,
'is_auto': False, 'id': comment_.id, 'line_number': line_number,
})


Expand Down
14 changes: 12 additions & 2 deletions lms/static/comments.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const DEFAULT_COMMENTED_LINE_COLOR = '#fab3b0';
const STUDENT_COMMENTED_LINE_COLOR = '#b2eefa';
const FLAKE_COMMENTED_LINE_COLOR = '#fac4c3';
const HOVER_LINE_STYLE = '1px solid #0d0d0f';

Expand Down Expand Up @@ -27,9 +28,13 @@ function isUserGrader() {
return ['staff', 'administrator'].includes(sessionStorage.getItem('role'));
}

function isSolverComment(commentData) {
return commentData.author_name === sessionStorage.getItem('solver');
}

function formatCommentData(commentData) {
let changedCommentText = `<span class="comment-author">${commentData.author_name}:</span> ${commentData.text}`;
if (isUserGrader()) {
if (isUserGrader() || isSolverComment(commentData)) {
const deleteButton = `<i class="fa fa-trash grader-delete" aria-hidden="true" data-commentid="${commentData.id}" onclick="deleteComment(${window.fileId}, ${commentData.id});"></i>`;
changedCommentText = `${deleteButton} ${changedCommentText}`;
}
Expand Down Expand Up @@ -58,7 +63,11 @@ function addCommentToLine(line, commentData) {
if (commentData.is_auto) {
markLine(commentElement[0], FLAKE_COMMENTED_LINE_COLOR);
} else {
markLine(commentElement[0], DEFAULT_COMMENTED_LINE_COLOR);
if (commentData.author_role === 1) {
markLine(commentElement[0], STUDENT_COMMENTED_LINE_COLOR);
} else {
markLine(commentElement[0], DEFAULT_COMMENTED_LINE_COLOR);
}
commentElement[0].dataset.marked = true;
}
}
Expand Down Expand Up @@ -139,6 +148,7 @@ window.addEventListener('load', () => {
window.solutionId = codeElement.id;
window.fileId = codeElement.file;
sessionStorage.setItem('role', codeElement.role);
sessionStorage.setItem('solver', codeElement.solver);
addLineSpansToPre(document.getElementsByTagName('code'));
pullComments(window.fileId, treatComments);
});
4 changes: 2 additions & 2 deletions lms/templates/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h1>{{ _('תצוגת תרגיל') }} {{ solution['exercise']['id'] }}: {{ soluti
</div>
<div id="view-body">
<div class="code-view-container">
<div id="code-view" data-id="{{ solution['id'] }}" data-file="{{ current_file.id }}" data-exercise="{{ solution['exercise']['id'] }}" data-role="{{ role }}">
<div id="code-view" data-id="{{ solution['id'] }}" data-file="{{ current_file.id }}" data-exercise="{{ solution['exercise']['id'] }}" data-role="{{ role }}" data-solver="{{ solution['solver']['fullname'] }}">
<pre><code id="user-code" class="language-{{ current_file | language_name }} line-numbers highlight">{{- current_file.code | trim(chars=' ') | e -}}</code></pre>
</div>
<div id="copy-code">
Expand Down Expand Up @@ -115,8 +115,8 @@ <h2>{{ _('הערות בודק') }}</h2>
</div>
<script src="{{ url_for('static', filename='prism.js') }}"></script>
<script src="{{ url_for('static', filename='comments.js') }}"></script>
{%- if is_manager %}
<script src="{{ url_for('static', filename='grader.js') }}"></script>
{%- if is_manager %}
<script src="{{ url_for('static', filename='keyboard.js') }}"></script>
{% endif -%}
{% endblock %}