some cleanup of request for comments. Work in progress.

Noticed a flaw when fetching the last submission, which is caused by timezone differences. First step to solve this.
Existing Request for Comments still need to be updated with their current submissionId, the SQL to do that is not yet finished.
This commit is contained in:
Ralf Teusner
2016-07-04 17:44:22 +02:00
parent 6e7c250ad1
commit 223df2ffa8
7 changed files with 57 additions and 33 deletions

View File

@ -1160,6 +1160,8 @@ $(function() {
var file_id = $('.editor').data('id') var file_id = $('.editor').data('id')
var question = $('#question').val(); var question = $('#question').val();
var createRequestForComments = function(submission) {
console.log(submission);
$.ajax({ $.ajax({
method: 'POST', method: 'POST',
url: '/request_for_comments', url: '/request_for_comments',
@ -1167,18 +1169,17 @@ $(function() {
request_for_comment: { request_for_comment: {
exercise_id: exercise_id, exercise_id: exercise_id,
file_id: file_id, file_id: file_id,
question: question, submission_id: submission.id,
"requested_at(1i)": 2015, // these are the timestamp values that the request handler demands question: question
"requested_at(2i)":3, // they could be random here, because the timestamp is updated on serverside anyway
"requested_at(3i)":27,
"requested_at(4i)":17,
"requested_at(5i)":06
} }
} }
}).done(function() { }).done(function() {
hideSpinner(); hideSpinner();
$.flash.success({ text: $('#askForCommentsButton').data('message-success') }) $.flash.success({ text: $('#askForCommentsButton').data('message-success') });
}).error(ajaxError); }).error(ajaxError);
}
createSubmission($('.requestCommentsButton'), null, createRequestForComments);
$('#comment-modal').modal('hide'); $('#comment-modal').modal('hide');
var button = $('.requestCommentsButton'); var button = $('.requestCommentsButton');

View File

@ -82,6 +82,6 @@ class RequestForCommentsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
def request_for_comment_params def request_for_comment_params
params.require(:request_for_comment).permit(:exercise_id, :file_id, :question, :requested_at, :solved).merge(user_id: current_user.id, user_type: current_user.class.name) params.require(:request_for_comment).permit(:exercise_id, :file_id, :question, :requested_at, :solved, :submission_id).merge(user_id: current_user.id, user_type: current_user.class.name)
end end
end end

View File

@ -25,6 +25,35 @@ class RequestForComment < ActiveRecord::Base
limit 1").first limit 1").first
end end
def last_submission_before_creation
submission1 = 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 def comments_count
submission.files.map { |file| file.comments.size}.sum submission.files.map { |file| file.comments.size}.sum
end end

View File

@ -2,7 +2,7 @@ class Submission < ActiveRecord::Base
include Context include Context
include Creation include Creation
CAUSES = %w(assess download file render run save submit test autosave) CAUSES = %w(assess download file render run save submit test autosave requestComments)
FILENAME_URL_PLACEHOLDER = '{filename}' FILENAME_URL_PLACEHOLDER = '{filename}'
belongs_to :exercise belongs_to :exercise

View File

@ -14,6 +14,6 @@
.editor-content.hidden data-file-id=file.ancestor_id = file.content .editor-content.hidden data-file-id=file.ancestor_id = file.content
.editor data-file-id=file.ancestor_id data-indent-size=file.file_type.indent_size data-mode=file.file_type.editor_mode data-read-only=file.read_only data-id=file.id .editor data-file-id=file.ancestor_id data-indent-size=file.file_type.indent_size data-mode=file.file_type.editor_mode data-read-only=file.read_only data-id=file.id
button.btn.btn-primary.requestCommentsButton type='button' button.btn.btn-primary.requestCommentsButton type='button' id="requestComments"
i.fa.fa-comment-o i.fa.fa-comment
= t('exercises.editor.requestComments') = t('exercises.editor.requestComments')

View File

@ -3,19 +3,12 @@
<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 submission = @request_for_comment.last_submission_before_creation
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.displayname %> | <%= @request_for_comment.requested_at %> <%= user.displayname %> | <%= @request_for_comment.requested_at.localtime %>
</p> </p>
<h5> <h5>
<u><%= t('activerecord.attributes.exercise.instructions') %>:</u> "<%= @request_for_comment.exercise.description %>" <u><%= t('activerecord.attributes.exercise.description') %>:</u> "<%= render_markdown(@request_for_comment.exercise.description) %>"
</h5> </h5>
<h5> <h5>

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160624130951) do ActiveRecord::Schema.define(version: 20160630154310) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -191,6 +191,7 @@ ActiveRecord::Schema.define(version: 20160624130951) do
t.string "user_type" t.string "user_type"
t.text "question" t.text "question"
t.boolean "solved" t.boolean "solved"
t.integer "submission_id"
end end
create_table "submissions", force: true do |t| create_table "submissions", force: true do |t|