diff --git a/app/assets/javascripts/editor/participantsupport.js.erb b/app/assets/javascripts/editor/participantsupport.js.erb index 91e9f0d1..63787f4a 100644 --- a/app/assets/javascripts/editor/participantsupport.js.erb +++ b/app/assets/javascripts/editor/participantsupport.js.erb @@ -59,8 +59,6 @@ CodeOceanEditorCodePilot = { } }; -//Request for comments does currently not work on staging platform (no relative root_url used here). -//To fix this rely on ruby routes CodeOceanEditorRequestForComments = { requestComments: function () { var user_id = $('#editor').data('user-id'); @@ -83,6 +81,8 @@ CodeOceanEditorRequestForComments = { }).done(function () { this.hideSpinner(); $.flash.success({text: $('#askForCommentsButton').data('message-success')}); + // trigger a run + this.runSubmission.call(this, submission); }.bind(this)).error(this.ajaxError.bind(this)); }; diff --git a/app/assets/javascripts/editor/submissions.js.erb b/app/assets/javascripts/editor/submissions.js.erb index 20d8cd10..21250f7e 100644 --- a/app/assets/javascripts/editor/submissions.js.erb +++ b/app/assets/javascripts/editor/submissions.js.erb @@ -142,19 +142,21 @@ CodeOceanEditorSubmissions = { * Execution-Logic */ runCode: function(event) { - event.preventDefault(); - if ($('#run').is(':visible')) { - this.createSubmission('#run', null, function(response) { - //Run part starts here - $('#stop').data('url', response.stop_url); - this.running = true; - this.showSpinner($('#run')); - $('#score_div').addClass('hidden'); - this.toggleButtonStates(); - var url = response.run_url.replace(this.FILENAME_URL_PLACEHOLDER, this.active_file.filename.replace(/#$/,'')); // remove # if it is the last character, this is not part of the filename and just an anchor - this.initializeSocketForRunning(url); - }.bind(this)); - } + event.preventDefault(); + if ($('#run').is(':visible')) { + this.createSubmission('#run', null, this.runSubmission.bind(this)); + } + }, + + runSubmission: function (submission) { + //Run part starts here + $('#stop').data('url', submission.stop_url); + this.running = true; + this.showSpinner($('#run')); + $('#score_div').addClass('hidden'); + this.toggleButtonStates(); + var url = submission.run_url.replace(this.FILENAME_URL_PLACEHOLDER, this.active_file.filename.replace(/#$/,'')); // remove # if it is the last character, this is not part of the filename and just an anchor + this.initializeSocketForRunning(url); }, saveCode: function(event) { diff --git a/app/assets/stylesheets/request-for-comments.css.scss b/app/assets/stylesheets/request-for-comments.css.scss index e4b56e2e..2cad6446 100644 --- a/app/assets/stylesheets/request-for-comments.css.scss +++ b/app/assets/stylesheets/request-for-comments.css.scss @@ -1,7 +1,98 @@ -#commentitor { - margin-bottom: 2rem; - height: 600px; - background-color:#f9f9f9 +.rfc { + + h5 { + color: #008CBA; + } + + .text { + font-size: larger; + } + + .text.collapsed { + max-height: 50px; + overflow-y: hidden; + } + + .collapse-button { + position: relative; + float: right; + margin-top: 5px; + margin-right: 5px; + cursor: pointer; + } + + .description { + + .text { + padding: 5px; + background-color: #FAFAFA; + border: 1px solid #CCCCCC; + } + + } + + .question { + + .text { + font-weight: bold; + } + + } + + .testruns { + + .text { + padding: 5px; + background-color: #FAFAFA; + border: 1px solid #CCCCCC; + } + + pre { + background-color: inherit; + border: none; + } + } + +} + +.testrun-assess-results { + + display: flex; + + .result { + margin-right: 10px; + width: 10px; + height: 10px; + } + + .passed { + border-radius: 50%; + background-color: #8efa00; + -webkit-box-shadow: 0 0 11px 1px rgba(44,222,0,1); + -moz-box-shadow: 0 0 11px 1px rgba(44,222,0,1); + box-shadow: 0 0 11px 1px rgba(44,222,0,1); + } + + .unknown { + border-radius: 50%; + background-color: #ffca00; + -webkit-box-shadow: 0 0 11px 1px rgb(255, 202, 0); + -moz-box-shadow: 0 0 11px 1px rgb(255, 202, 0); + box-shadow: 0 0 11px 1px rgb(255, 202, 0); + } + + .failed { + border-radius: 50%; + background-color: #ff2600; + -webkit-box-shadow: 0 0 11px 1px rgba(222,0,0,1); + -moz-box-shadow: 0 0 11px 1px rgba(222,0,0,1); + box-shadow: 0 0 11px 1px rgba(222,0,0,1); + } + +} + +#mark-as-solved-button { + margin-top: 20px; } #thank-you-container { @@ -11,6 +102,10 @@ border: solid lightgrey 1px; background-color: rgba(20, 180, 20, 0.2); border-radius: 4px; + + button { + margin-right: 10px; + } } #thank-you-note { @@ -18,6 +113,12 @@ height: 200px; } +#commentitor { + margin-bottom: 2rem; + height: 600px; + background-color:#f9f9f9 +} + .ace_tooltip { display: none !important; } diff --git a/app/assets/stylesheets/statistics.css.scss b/app/assets/stylesheets/statistics.css.scss index f656cd9a..a5ea4430 100644 --- a/app/assets/stylesheets/statistics.css.scss +++ b/app/assets/stylesheets/statistics.css.scss @@ -42,6 +42,14 @@ div.positive-result { box-shadow: 0px 0px 11px 1px rgba(44,222,0,1); } +div.unknown-result { + border-radius: 50%; + background-color: #ffca00; + -webkit-box-shadow: 0px 0px 11px 1px rgb(255, 202, 0); + -moz-box-shadow: 0px 0px 11px 1px rgb(255, 202, 0); + box-shadow: 0px 0px 11px 1px rgb(255, 202, 0); +} + div.negative-result { border-radius: 50%; background-color: #ff2600; diff --git a/app/controllers/concerns/submission_scoring.rb b/app/controllers/concerns/submission_scoring.rb index 16f1f061..41f9ff26 100644 --- a/app/controllers/concerns/submission_scoring.rb +++ b/app/controllers/concerns/submission_scoring.rb @@ -9,7 +9,7 @@ module SubmissionScoring assessment = assessor.assess(output) passed = ((assessment[:passed] == assessment[:count]) and (assessment[:score] > 0)) testrun_output = passed ? nil : output[:stderr] - Testrun.new(submission: submission, file: file, passed: passed, output: testrun_output).save + Testrun.new(submission: submission, cause: 'assess', file: file, passed: passed, output: testrun_output).save output.merge!(assessment) output.merge!(filename: file.name_with_extension, message: feedback_message(file, output[:score]), weight: file.weight) end diff --git a/app/controllers/request_for_comments_controller.rb b/app/controllers/request_for_comments_controller.rb index 8ef8f866..4fd19a92 100644 --- a/app/controllers/request_for_comments_controller.rb +++ b/app/controllers/request_for_comments_controller.rb @@ -1,4 +1,5 @@ class RequestForCommentsController < ApplicationController + include SubmissionScoring before_action :set_request_for_comment, only: [:show, :edit, :update, :destroy, :mark_as_solved, :set_thank_you_note] skip_after_action :verify_authorized @@ -107,6 +108,10 @@ class RequestForCommentsController < ApplicationController @request_for_comment = RequestForComment.new(request_for_comment_params) respond_to do |format| if @request_for_comment.save + # create thread here and execute tests. A run is triggered from the frontend and does not need to be handled here. + Thread.new do + score_submission(@request_for_comment.submission) + end format.json { render :show, status: :created, location: @request_for_comment } else format.html { render :new } diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 9b37fde0..4dfa182c 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -13,8 +13,12 @@ class SubmissionsController < ApplicationController before_action :set_mime_type, only: [:download_file, :render_file] skip_before_action :verify_authenticity_token, only: [:download_file, :render_file] - def max_message_buffer_size - 500 + def max_run_output_buffer_size + if(@submission.cause == 'requestComments') + 5000 + else + 500 + end end def authorize! @@ -196,7 +200,7 @@ class SubmissionsController < ApplicationController end def handle_message(message, tubesock, container) - @message_buffer ||= "" + @run_output ||= "" # Handle special commands first if (/^#exit/.match(message)) # Just call exit_container on the docker_client. @@ -205,19 +209,19 @@ class SubmissionsController < ApplicationController # kill_socket is called in the "on close handler" of the websocket to the container @docker_client.exit_container(container) elsif /^#timeout/.match(message) - @message_buffer = 'timeout: ' + @message_buffer # add information that this run timed out to the buffer + @run_output = 'timeout: ' + @run_output # add information that this run timed out to the buffer else # Filter out information about run_command, test_command, user or working directory run_command = @submission.execution_environment.run_command % command_substitutions(params[:filename]) test_command = @submission.execution_environment.test_command % command_substitutions(params[:filename]) if !(/root|workspace|#{run_command}|#{test_command}/.match(message)) - @message_buffer += message if @message_buffer.size <= max_message_buffer_size parse_message(message, 'stdout', tubesock) end end end def parse_message(message, output_stream, socket, recursive = true) + parsed = ''; begin parsed = JSON.parse(message) if(parsed.class == Hash && parsed.key?('cmd')) @@ -256,13 +260,16 @@ class SubmissionsController < ApplicationController socket.send_data JSON.dump(parsed) Rails.logger.info('parse_message sent: ' + JSON.dump(parsed)) end + ensure + # save the data that was send to the run_output if there is enough space left. this will be persisted as a testrun with cause "run" + @run_output += JSON.dump(parsed) if @run_output.size <= max_run_output_buffer_size end end def save_run_output - if !@message_buffer.blank? - @message_buffer = @message_buffer[(0..max_message_buffer_size-1)] # trim the string to max_message_buffer_size chars - Testrun.create(file: @file, submission: @submission, output: @message_buffer) + if !@run_output.blank? + @run_output = @run_output[(0..max_run_output_buffer_size-1)] # trim the string to max_message_buffer_size chars + Testrun.create(file: @file, cause: 'run', submission: @submission, output: @run_output) end end diff --git a/app/views/exercises/external_users/statistics.html.slim b/app/views/exercises/external_users/statistics.html.slim index 313a19b0..8b5c3b30 100644 --- a/app/views/exercises/external_users/statistics.html.slim +++ b/app/views/exercises/external_users/statistics.html.slim @@ -54,8 +54,10 @@ h1 = "#{@exercise} (external user #{@external_user})" -submission_or_intervention.testruns.each do |run| - if run.passed .unit-test-result.positive-result title=run.output - - else + - elsif run.failed .unit-test-result.negative-result title=run.output + - else + .unit-test-result.unknown-result title=run.output td = Time.at(deltas[1..index].inject(:+)).utc.strftime("%H:%M:%S") if index > 0 -working_times_until.push((Time.at(deltas[1..index].inject(:+)).utc.strftime("%H:%M:%S") if index > 0)) - elsif submission_or_intervention.is_a? UserExerciseIntervention diff --git a/app/views/request_for_comments/_admin_menu.html.slim b/app/views/request_for_comments/_admin_menu.html.slim new file mode 100644 index 00000000..3f71b2ed --- /dev/null +++ b/app/views/request_for_comments/_admin_menu.html.slim @@ -0,0 +1,9 @@ +br +h4 Admin Menu +h5 + ul + li = link_to "User's current status of this exercise", statistics_external_user_exercise_path(id: @request_for_comment.exercise_id, external_user_id: @request_for_comment.user_id) + li = link_to "All exercises of this user", statistics_external_user_path(id: @request_for_comment.user_id) + ul + li = link_to "Implement the exercise yourself", implement_exercise_path(id: @request_for_comment.exercise_id) + li = link_to "Show the exercise", exercise_path(id: @request_for_comment.exercise_id) diff --git a/app/views/request_for_comments/_mark_as_solved.html.slim b/app/views/request_for_comments/_mark_as_solved.html.slim new file mode 100644 index 00000000..b3df57fd --- /dev/null +++ b/app/views/request_for_comments/_mark_as_solved.html.slim @@ -0,0 +1,7 @@ +button.btn.btn-primary#mark-as-solved-button = t('request_for_comments.mark_as_solved') + +#thank-you-container + p = t('request_for_comments.write_a_thank_you_node') + textarea#thank-you-note + button.btn.btn-primary#send-thank-you-note = t('request_for_comments.send_thank_you_note') + button.btn.btn-default#cancel-thank-you-note = t('request_for_comments.cancel_thank_you_note') diff --git a/app/views/request_for_comments/show.html.erb b/app/views/request_for_comments/show.html.erb index 83741a87..eb88caf1 100644 --- a/app/views/request_for_comments/show.html.erb +++ b/app/views/request_for_comments/show.html.erb @@ -1,6 +1,6 @@
- <%= t('request_for_comments.write_a_thank_you_node') %> -
- - - -<%= testrun.try(:output) or t('request_for_comments.no_output') %>+ <% end %> +