Add support for comments on multiple files per exercise
This commit is contained in:
@ -2,9 +2,15 @@
|
|||||||
<h4 class="list-group-item-heading"><%= Exercise.find(@request_for_comment.exercise_id) %></h4>
|
<h4 class="list-group-item-heading"><%= Exercise.find(@request_for_comment.exercise_id) %></h4>
|
||||||
<p class="list-group-item-text">
|
<p class="list-group-item-text">
|
||||||
<%
|
<%
|
||||||
|
|
||||||
user = @request_for_comment.user
|
user = @request_for_comment.user
|
||||||
|
submission_id = ActiveRecord::Base.connection.execute("select id from submissions
|
||||||
|
where exercise_id =
|
||||||
|
#{@request_for_comment.exercise_id} AND
|
||||||
|
user_id = #{@request_for_comment.user_id} AND
|
||||||
|
'#{@request_for_comment.created_at}' > created_at
|
||||||
|
order by created_at desc
|
||||||
|
limit 1").first['id'].to_i
|
||||||
|
submission = Submission.find(submission_id)
|
||||||
%>
|
%>
|
||||||
<%= user %> | <%= @request_for_comment.requested_at %>
|
<%= user %> | <%= @request_for_comment.requested_at %>
|
||||||
</p>
|
</p>
|
||||||
@ -13,36 +19,34 @@
|
|||||||
<!--
|
<!--
|
||||||
do not put a carriage return in the line below. it will be present in the presentation of the source code, otherwise.
|
do not put a carriage return in the line below. it will be present in the presentation of the source code, otherwise.
|
||||||
-->
|
-->
|
||||||
<div id='commentitor' class='editor' data-read-only='true' data-file-id='<%=@request_for_comment.file_id%>'><%= CodeOcean::File.find(@request_for_comment.file_id).content %>
|
<% submission.files.each do |file| %>
|
||||||
</div>
|
<%= (file.path or "") + "/" + file.name + file.file_type.file_extension %>
|
||||||
|
<div id='commentitor' class='editor' data-read-only='true' data-file-id='<%=file.id%>'><%= file.content %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
//(function() {
|
//(function() {
|
||||||
var commentitor = $('#commentitor');
|
var commentitor = $('.editor');
|
||||||
var userid = commentitor.data('user-id');
|
var userid = commentitor.data('user-id');
|
||||||
var fileid = commentitor.data('file-id');
|
|
||||||
|
commentitor.each(function (index, editor) {
|
||||||
|
currentEditor = ace.edit(editor);
|
||||||
|
currentEditor.setReadOnly(true);
|
||||||
|
|
||||||
|
setAnnotations(currentEditor, $(editor).data('file-id'));
|
||||||
|
});
|
||||||
|
|
||||||
|
function setAnnotations(editor, fileid) {
|
||||||
|
var session = editor.getSession()
|
||||||
|
|
||||||
var inputHtml = ''
|
var inputHtml = ''
|
||||||
//inputHtml += '<form class="form">'
|
|
||||||
//inputHtml += '<div class="form-group">'
|
|
||||||
//inputHtml += '<p style="display:inline-block"><%= t("exercises.implement.comment.line") %></p>'
|
|
||||||
//inputHtml += '<input type="number" class="form-control" id="lineInput" placeholder="1" required>'
|
|
||||||
//inputHtml += '</div>'
|
|
||||||
inputHtml += '<div class="input-group">'
|
inputHtml += '<div class="input-group">'
|
||||||
//inputHtml += '<p style="display:inline-block"><%= t("exercises.implement.comment.a_comment") %></p>'
|
inputHtml += '<input type="text" class="form-control" id="commentInput' + fileid + '" '
|
||||||
inputHtml += '<input type="text" class="form-control" id="commentInput" placeholder="I\'d suggest a variable here" required>'
|
inputHtml += 'placeholder="I\'d suggest a variable here" required>'
|
||||||
inputHtml += '<span class="input-group-btn"><button id="submitComment" class="btn btn-default"><%= t("exercises.implement.comment.addComment") %>!</button></span>'
|
inputHtml += '<span class="input-group-btn"><button id="submitComment' + fileid + '" '
|
||||||
|
inputHtml += 'class="btn btn-default"><%= t("exercises.implement.comment.addComment") %>!</button></span>'
|
||||||
inputHtml += '</div>'
|
inputHtml += '</div>'
|
||||||
//inputHtml +='</form>'
|
|
||||||
|
|
||||||
|
|
||||||
commentitor = ace.edit(commentitor[0]);
|
|
||||||
commentitor.setReadOnly(true);
|
|
||||||
|
|
||||||
setAnnotations();
|
|
||||||
|
|
||||||
function setAnnotations() {
|
|
||||||
var session = commentitor.getSession()
|
|
||||||
|
|
||||||
var jqrequest = $.ajax({
|
var jqrequest = $.ajax({
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
@ -60,28 +64,26 @@ do not put a carriage return in the line below. it will be present in the presen
|
|||||||
comment.text = comment.username + ": " + comment.text
|
comment.text = comment.username + ": " + comment.text
|
||||||
})
|
})
|
||||||
|
|
||||||
commentitor.getSession().setAnnotations(response)
|
editor.getSession().setAnnotations(response)
|
||||||
|
|
||||||
//$('.ace_gutter-layer').data('container', '.ui-front')
|
$(editor.container).find('.ace_gutter-cell').popover({
|
||||||
$('.ace_gutter-cell').popover({
|
|
||||||
title: 'Add a comment',
|
title: 'Add a comment',
|
||||||
html: true,
|
html: true,
|
||||||
content: inputHtml,
|
content: inputHtml,
|
||||||
position: 'right',
|
position: 'right',
|
||||||
trigger: 'focus click'
|
trigger: 'focus click'
|
||||||
}).on('shown.bs.popover', function() {
|
}).on('shown.bs.popover', function() {
|
||||||
$('#commentInput').focus()
|
$('#commentInput' + fileid).focus()
|
||||||
$('#submitComment').click(addComment);
|
$('#submitComment' + fileid).click(_.partial(addComment, editor, fileid));
|
||||||
console.log($(this).text())
|
$('#commentInput' + fileid).data('line', $(this).text())
|
||||||
$('#commentInput').data('line', $(this).text())
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function addComment() {
|
function addComment(editor, fileid) {
|
||||||
var commentInput = $('#commentInput');
|
var commentInput = $('#commentInput' + fileid);
|
||||||
var comment = commentInput.val()
|
var comment = commentInput.val()
|
||||||
var line = $('#commentInput').data('line')
|
var line = $('#commentInput' + fileid).data('line')
|
||||||
|
|
||||||
if (line == '' || comment == '') {
|
if (line == '' || comment == '') {
|
||||||
return
|
return
|
||||||
@ -102,7 +104,7 @@ do not put a carriage return in the line below. it will be present in the presen
|
|||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: "/comments"
|
url: "/comments"
|
||||||
}).done(setAnnotations)
|
}).done(setAnnotations(editor, fileid))
|
||||||
|
|
||||||
$('.ace_gutter-cell').popover('hide')
|
$('.ace_gutter-cell').popover('hide')
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user