Merge remote-tracking branch 'origin/master' into error-info
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
li = link_to(t('internal_users.show.link'), current_user)
|
||||
li = link_to(t('request_for_comments.index.all'), request_for_comments_path)
|
||||
li = link_to(t('request_for_comments.index.get_my_comment_requests'), my_request_for_comments_path)
|
||||
li = link_to(t('request_for_comments.index.get_my_rfc_activity'), my_rfc_activity_path)
|
||||
- if current_user.internal_user?
|
||||
li = link_to(t('sessions.destroy.link'), sign_out_path, method: :delete)
|
||||
- else
|
||||
|
@@ -1,4 +1,4 @@
|
||||
json.array!(@comments) do |comment|
|
||||
json.extract! comment, :id, :user_id, :file_id, :row, :column, :text, :username
|
||||
json.extract! comment, :id, :user_id, :file_id, :row, :column, :text, :username, :date, :updated
|
||||
json.url comment_url(comment, format: :json)
|
||||
end
|
||||
|
@@ -20,6 +20,7 @@ h1 = RequestForComment.model_name.human(count: 2)
|
||||
i class="fa fa-comment" aria-hidden="true" title = t('request_for_comments.comments') align="center"
|
||||
th = t('activerecord.attributes.request_for_comments.username')
|
||||
th = t('activerecord.attributes.request_for_comments.requested_at')
|
||||
th = t('activerecord.attributes.request_for_comments.last_update')
|
||||
tbody
|
||||
- @request_for_comments.each do |request_for_comment|
|
||||
tr data-id=request_for_comment.id
|
||||
@@ -36,5 +37,6 @@ h1 = RequestForComment.model_name.human(count: 2)
|
||||
td = request_for_comment.comments_count
|
||||
td = request_for_comment.user.displayname
|
||||
td = t('shared.time.before', time: distance_of_time_in_words_to_now(request_for_comment.created_at))
|
||||
td = t('shared.time.before', time: distance_of_time_in_words_to_now(request_for_comment.last_comment.nil? ? request_for_comment.updated_at : request_for_comment.last_comment))
|
||||
|
||||
= render('shared/pagination', collection: @request_for_comments)
|
@@ -64,6 +64,8 @@
|
||||
</h5>
|
||||
</div>
|
||||
<hr>
|
||||
|
||||
<div class="hidden sanitizer"></div>
|
||||
<!--
|
||||
do not put a carriage return in the line below. it will be present in the presentation of the source code, otherwise.
|
||||
also, all settings from the rails model needed for the editor configuration in the JavaScript are attached to the editor as data attributes here.
|
||||
@@ -134,11 +136,24 @@ also, all settings from the rails model needed for the editor configuration in t
|
||||
currentEditor.setReadOnly(true);
|
||||
// set editor mode (used for syntax highlighting
|
||||
currentEditor.getSession().setMode($(editor).data('mode'));
|
||||
currentEditor.getSession().setOption("useWorker", false);
|
||||
|
||||
setAnnotations(currentEditor, $(editor).data('file-id'));
|
||||
currentEditor.on("guttermousedown", handleSidebarClick);
|
||||
});
|
||||
|
||||
function cleanupPopovers() {
|
||||
// remove all possible popovers
|
||||
$('.editor > .ace_gutter > .ace_gutter-layer > .ace_gutter-cell').popover('destroy');
|
||||
}
|
||||
|
||||
function preprocess(commentText) {
|
||||
// sanitize comments to deal with XSS attacks:
|
||||
commentText = $('div.sanitizer').text(commentText).html();
|
||||
// display original line breaks:
|
||||
return commentText.replace(/\n/g, '<br>');
|
||||
}
|
||||
|
||||
function setAnnotations(editor, fileid) {
|
||||
var session = editor.getSession();
|
||||
|
||||
@@ -152,18 +167,65 @@ also, all settings from the rails model needed for the editor configuration in t
|
||||
});
|
||||
|
||||
jqrequest.done(function(response){
|
||||
$.each(response, function(index, comment) {
|
||||
comment.className = "code-ocean_comment";
|
||||
// comments need to be sorted to cluster them per line
|
||||
var comments = response.slice().sort(function (a, b) {
|
||||
return a.row - b.row;
|
||||
});
|
||||
while (comments.length > 0) {
|
||||
// new cluster of comments
|
||||
var cluster = [];
|
||||
var clusterRow = comments[0].row;
|
||||
// now collect all comments on this line
|
||||
while (comments.length > 0 && comments[0].row === clusterRow) {
|
||||
cluster.push(comments.shift());
|
||||
}
|
||||
// sort the comments by creation date
|
||||
cluster = cluster.sort(function (a, b) {
|
||||
return a.id - b.id;
|
||||
});
|
||||
|
||||
// build the markup for the current line's popover
|
||||
var popupContent = '';
|
||||
cluster.forEach(function(comment, index) {
|
||||
if (index !== 0) {
|
||||
popupContent += '<div class="popover-divider"></div>'
|
||||
}
|
||||
popupContent += '<p class="comment">';
|
||||
popupContent += '<div class="popover-header">' +
|
||||
'<div class="popover-username">' + preprocess(comment.username) + '</div>' +
|
||||
'<div class="popover-date">' + comment.date + '</div>';
|
||||
if (comment.updated) {
|
||||
popupContent += '<div class="popover-updated">' +
|
||||
'<i class="fa fa-pencil" aria-hidden="true"></i>' +
|
||||
'<%= t('request_for_comments.comment_edited') %>' +
|
||||
'</div>'
|
||||
}
|
||||
popupContent += '</div>';
|
||||
popupContent += '<div class="popover-comment">' + preprocess(comment.text) + '</div>';
|
||||
popupContent += '</p>';
|
||||
});
|
||||
|
||||
// attach the popover to the ace sidebar (where the comment icon is displayed)
|
||||
var icon = $('*[data-file-id="' + fileid + '"]') // the editor for this file
|
||||
.find('.ace_gutter > .ace_gutter-layer') // the sidebar
|
||||
.find('div:nth-child(' + (clusterRow + 1) + ')'); // the correct line
|
||||
icon.popover({
|
||||
content: popupContent,
|
||||
html: true, // necessary to style comments. XSS is not possible due to comment pre-processing (sanitizing)
|
||||
trigger: 'hover',
|
||||
container: 'body'
|
||||
});
|
||||
}
|
||||
|
||||
$.each(response, function(index, comment) {
|
||||
comment.className = 'code-ocean_comment';
|
||||
// if we have tabs or carriage returns in the comment, just add the name and leave it as it is. otherwise: format!
|
||||
if(comment.text.includes("\n") || comment.text.includes("\t")){
|
||||
comment.text = comment.username + ": " + comment.text;
|
||||
} else {
|
||||
comment.text = comment.username + ": " + stringDivider(comment.text, 80, "\n\t\t");
|
||||
comment.text = comment.username + ": " + stringDivider(comment.text, 80, "\n");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
session.setAnnotations(response);
|
||||
})
|
||||
}
|
||||
@@ -181,6 +243,7 @@ also, all settings from the rails model needed for the editor configuration in t
|
||||
}
|
||||
|
||||
function deleteComment(file_id, row, editor) {
|
||||
cleanupPopovers();
|
||||
var jqxhr = $.ajax({
|
||||
type: 'DELETE',
|
||||
url: "/comments",
|
||||
@@ -195,6 +258,7 @@ also, all settings from the rails model needed for the editor configuration in t
|
||||
}
|
||||
|
||||
function createComment(file_id, row, editor, commenttext){
|
||||
cleanupPopovers();
|
||||
var jqxhr = $.ajax({
|
||||
data: {
|
||||
comment: {
|
||||
|
Reference in New Issue
Block a user