diff --git a/app/assets/javascripts/editor.js.erb b/app/assets/javascripts/editor.js.erb index 480f6580..658ff3cd 100644 --- a/app/assets/javascripts/editor.js.erb +++ b/app/assets/javascripts/editor.js.erb @@ -1215,7 +1215,6 @@ $(function() { var question = $('#question').val(); var createRequestForComments = function(submission) { - console.log(submission); $.ajax({ method: 'POST', url: '/request_for_comments', diff --git a/app/models/request_for_comment.rb b/app/models/request_for_comment.rb index 1343f5b3..cd57c5c2 100644 --- a/app/models/request_for_comment.rb +++ b/app/models/request_for_comment.rb @@ -17,6 +17,8 @@ class RequestForComment < ActiveRecord::Base Submission.find(file.context_id) end + # not used right now, finds the last submission for the respective user and exercise. + # might be helpful to check whether the exercise has been solved in the meantime. def last_submission Submission.find_by_sql(" select * from submissions where exercise_id = #{exercise_id} AND @@ -25,33 +27,15 @@ class RequestForComment < ActiveRecord::Base limit 1").first end + # not used any longer, since we directly saved the submission_id now. + # Was used before that to determine the submission belonging to the request_for_comment. def last_submission_before_creation - submission1 = Submission.find_by_sql(" select * from submissions + Submission.find_by_sql(" select * from submissions where exercise_id = #{exercise_id} AND user_id = #{user_id} AND '#{created_at.localtime}' > created_at order by created_at desc limit 1").first - submission2 = Submission.find_by_sql(" select * from submissions - where exercise_id = #{exercise_id} AND - user_id = #{user_id} AND - '#{created_at}' > created_at - order by created_at desc - limit 1").first - submission3 = Submission.find_by_sql(" select * from submissions - where exercise_id = #{exercise_id} AND - user_id = #{user_id} AND - '#{created_at.strftime('%Y-%m-%d %H:%M:%S.%N')}' > created_at - order by created_at desc - limit 1").first - submission4 = Submission.find_by_sql(" select * from submissions - where exercise_id = #{exercise_id} AND - user_id = #{user_id} AND - '#{created_at.localtime.strftime('%Y-%m-%d %H:%M:%S.%N')}' > created_at - order by created_at desc - limit 1").first - binding.pry - submission1 end def comments_count @@ -64,6 +48,6 @@ class RequestForComment < ActiveRecord::Base private def self.row_number_user_sql - select("id, user_id, exercise_id, file_id, question, requested_at, created_at, updated_at, user_type, solved, row_number() OVER (PARTITION BY user_id ORDER BY created_at DESC) as row_number").to_sql + select("id, user_id, exercise_id, file_id, question, created_at, updated_at, user_type, solved, submission_id, row_number() OVER (PARTITION BY user_id ORDER BY created_at DESC) as row_number").to_sql end end diff --git a/app/views/request_for_comments/index.html.slim b/app/views/request_for_comments/index.html.slim index 3bdbe6d0..b7ada0a2 100644 --- a/app/views/request_for_comments/index.html.slim +++ b/app/views/request_for_comments/index.html.slim @@ -27,6 +27,6 @@ h1 = RequestForComment.model_name.human(count: 2) td = '-' 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.requested_at)) + td = t('shared.time.before', time: distance_of_time_in_words_to_now(request_for_comment.created_at)) = render('shared/pagination', collection: @request_for_comments) \ No newline at end of file diff --git a/app/views/request_for_comments/show.html.erb b/app/views/request_for_comments/show.html.erb index 8e52150c..c1d71672 100644 --- a/app/views/request_for_comments/show.html.erb +++ b/app/views/request_for_comments/show.html.erb @@ -1,11 +1,11 @@
<% user = @request_for_comment.user submission = @request_for_comment.last_submission_before_creation %> - <%= user.displayname %> | <%= @request_for_comment.requested_at.localtime %> + <%= user.displayname %> | <%= @request_for_comment.created_at.localtime %>