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:
@ -1160,6 +1160,8 @@ $(function() {
|
||||
var file_id = $('.editor').data('id')
|
||||
var question = $('#question').val();
|
||||
|
||||
var createRequestForComments = function(submission) {
|
||||
console.log(submission);
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: '/request_for_comments',
|
||||
@ -1167,18 +1169,17 @@ $(function() {
|
||||
request_for_comment: {
|
||||
exercise_id: exercise_id,
|
||||
file_id: file_id,
|
||||
question: question,
|
||||
"requested_at(1i)": 2015, // these are the timestamp values that the request handler demands
|
||||
"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
|
||||
submission_id: submission.id,
|
||||
question: question
|
||||
}
|
||||
}
|
||||
}).done(function() {
|
||||
hideSpinner();
|
||||
$.flash.success({ text: $('#askForCommentsButton').data('message-success') })
|
||||
$.flash.success({ text: $('#askForCommentsButton').data('message-success') });
|
||||
}).error(ajaxError);
|
||||
}
|
||||
|
||||
createSubmission($('.requestCommentsButton'), null, createRequestForComments);
|
||||
|
||||
$('#comment-modal').modal('hide');
|
||||
var button = $('.requestCommentsButton');
|
||||
|
@ -82,6 +82,6 @@ class RequestForCommentsController < ApplicationController
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
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
|
||||
|
@ -25,6 +25,35 @@ class RequestForComment < ActiveRecord::Base
|
||||
limit 1").first
|
||||
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
|
||||
submission.files.map { |file| file.comments.size}.sum
|
||||
end
|
||||
|
@ -2,7 +2,7 @@ class Submission < ActiveRecord::Base
|
||||
include Context
|
||||
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}'
|
||||
|
||||
belongs_to :exercise
|
||||
|
@ -14,6 +14,6 @@
|
||||
.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
|
||||
|
||||
button.btn.btn-primary.requestCommentsButton type='button'
|
||||
i.fa.fa-comment-o
|
||||
button.btn.btn-primary.requestCommentsButton type='button' id="requestComments"
|
||||
i.fa.fa-comment
|
||||
= t('exercises.editor.requestComments')
|
@ -3,19 +3,12 @@
|
||||
<p class="list-group-item-text">
|
||||
<%
|
||||
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)
|
||||
submission = @request_for_comment.last_submission_before_creation
|
||||
%>
|
||||
<%= user.displayname %> | <%= @request_for_comment.requested_at %>
|
||||
<%= user.displayname %> | <%= @request_for_comment.requested_at.localtime %>
|
||||
</p>
|
||||
<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>
|
||||
|
@ -11,7 +11,7 @@
|
||||
#
|
||||
# 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
|
||||
enable_extension "plpgsql"
|
||||
@ -191,6 +191,7 @@ ActiveRecord::Schema.define(version: 20160624130951) do
|
||||
t.string "user_type"
|
||||
t.text "question"
|
||||
t.boolean "solved"
|
||||
t.integer "submission_id"
|
||||
end
|
||||
|
||||
create_table "submissions", force: true do |t|
|
||||
|
Reference in New Issue
Block a user