From 6e6c9143cdd8156dcb1956a375e60260c59f4591 Mon Sep 17 00:00:00 2001 From: Ralf Teusner Date: Thu, 11 Aug 2016 18:13:33 +0200 Subject: [PATCH 1/4] Some tidy up in request for comments (bugfix: removed leftover parts of requested_at attribute, some UI changes in comment dialog) Redirect to open rfc if an exercise has been solved --- app/assets/javascripts/editor.js.erb | 4 +-- app/controllers/exercises_controller.rb | 29 +++++++++++++++++-- app/models/request_for_comment.rb | 6 +--- .../_comment_dialogcontent.html.slim | 6 ++-- app/views/request_for_comments/_form.html.erb | 4 --- .../request_for_comments/index.json.jbuilder | 2 +- app/views/request_for_comments/show.html.erb | 7 +++-- .../request_for_comments/show.json.jbuilder | 2 +- config/locales/de.yml | 3 +- config/locales/en.yml | 3 +- 10 files changed, 43 insertions(+), 23 deletions(-) diff --git a/app/assets/javascripts/editor.js.erb b/app/assets/javascripts/editor.js.erb index 2d73bbf0..1a38e685 100644 --- a/app/assets/javascripts/editor.js.erb +++ b/app/assets/javascripts/editor.js.erb @@ -153,8 +153,8 @@ $(function() { // This is the case, since it is set via a call to ancestor_id on the model, which returns either file_id if set, or id if it is not set. // therefore the else part is not needed any longer... - // if we have an file_id set (the file is a copy of a teacher supplied given file) - if (file_id_old != null){ + // if we have an file_id set (the file is a copy of a teacher supplied given file) and the new file-ids are present in the response + if (file_id_old != null && data.files){ // if we find file_id_old (this is the reference to the base file) in the submission, this is the match for(var j = 0; j< data.files.length; j++){ if(data.files[j].file_id == file_id_old){ diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 45fd04d9..cbd5266a 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -224,7 +224,7 @@ class ExercisesController < ApplicationController if lti_outcome_service? transmit_lti_score else - redirect_to_lti_return_path + redirect_after_submit end end @@ -232,7 +232,7 @@ class ExercisesController < ApplicationController ::NewRelic::Agent.add_custom_parameters({ submission: @submission.id, normalized_score: @submission.normalized_score }) response = send_score(@submission.normalized_score) if response[:status] == 'success' - redirect_to_lti_return_path + redirect_after_submit else respond_to do |format| format.html { redirect_to(implement_exercise_path(@submission.exercise)) } @@ -245,4 +245,29 @@ class ExercisesController < ApplicationController def update update_and_respond(object: @exercise, params: exercise_params) end + + def redirect_after_submit + Rails.logger.error('Score ' + @submission.normalized_score.to_s) + if @submission.normalized_score == 1.0 + # if user has an own rfc, redirect to it and message him to clean up and accept the answer. + + # else: show open rfc for same exercise + if rfc = RequestForComment.unsolved.where(exercise_id: @submission.exercise).order("RANDOM()").first + Rails.logger.error('rfc: ' + rfc.to_s) + + # set a message that informs the user that his score was perfect and help in RFC is greatly appreciated. + flash[:notice] = I18n.t('exercises.submit.full_score_redirect_to_rfc') + flash.keep(:notice) + + respond_to do |format| + format.html { redirect_to(rfc) } + format.json { render(json: {redirect: url_for(rfc)}) } + end + + return + end + end + redirect_to_lti_return_path + end + end diff --git a/app/models/request_for_comment.rb b/app/models/request_for_comment.rb index 63d932fc..4be7d325 100644 --- a/app/models/request_for_comment.rb +++ b/app/models/request_for_comment.rb @@ -4,16 +4,12 @@ class RequestForComment < ActiveRecord::Base belongs_to :exercise belongs_to :file, class_name: 'CodeOcean::File' - before_create :set_requested_timestamp + scope :unsolved, -> { where(solved: [false, nil]) } def self.last_per_user(n = 5) from("(#{row_number_user_sql}) as request_for_comments").where("row_number <= ?", n) end - def set_requested_timestamp - self.requested_at = Time.now - 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 diff --git a/app/views/exercises/_comment_dialogcontent.html.slim b/app/views/exercises/_comment_dialogcontent.html.slim index b14c988f..0d89bea3 100644 --- a/app/views/exercises/_comment_dialogcontent.html.slim +++ b/app/views/exercises/_comment_dialogcontent.html.slim @@ -1,9 +1,9 @@ -h5 =t('exercises.implement.comment.others') -pre#other-comments - h5 =t('exercises.implement.comment.addyours') textarea.form-control(style='resize:none;') +#otherComments + h5 =t('exercises.implement.comment.others') + pre#otherCommentsTextfield p = '' button#addCommentButton.btn.btn-block.btn-primary(type='button') =t('exercises.implement.comment.addComment') button#removeAllButton.btn.btn-block.btn-warning(type='button') =t('exercises.implement.comment.removeAllOnLine') \ No newline at end of file diff --git a/app/views/request_for_comments/_form.html.erb b/app/views/request_for_comments/_form.html.erb index 4d4494ce..81f6ed65 100644 --- a/app/views/request_for_comments/_form.html.erb +++ b/app/views/request_for_comments/_form.html.erb @@ -23,10 +23,6 @@ <%= f.label :file_id %>
<%= f.number_field :file_id %> -
- <%= f.label :requested_at %>
- <%= f.datetime_select :requested_at %> -
<%= f.label :user_type %>
<%= f.text_field :user_type %> diff --git a/app/views/request_for_comments/index.json.jbuilder b/app/views/request_for_comments/index.json.jbuilder index 94bc95fd..eaf4293a 100644 --- a/app/views/request_for_comments/index.json.jbuilder +++ b/app/views/request_for_comments/index.json.jbuilder @@ -1,4 +1,4 @@ json.array!(@request_for_comments) do |request_for_comment| - json.extract! request_for_comment, :id, :user_id, :exercise_id, :file_id, :requested_at, :user_type + json.extract! request_for_comment, :id, :user_id, :exercise_id, :file_id, :user_type json.url request_for_comment_url(request_for_comment, format: :json) end diff --git a/app/views/request_for_comments/show.html.erb b/app/views/request_for_comments/show.html.erb index 4089d878..5ad78b58 100644 --- a/app/views/request_for_comments/show.html.erb +++ b/app/views/request_for_comments/show.html.erb @@ -8,7 +8,7 @@ <%= user.displayname %> | <%= @request_for_comment.created_at.localtime %>

- <%= t('activerecord.attributes.exercise.description') %>: "<%= render_markdown(@request_for_comment.exercise.description) %>" + <%= t('activerecord.attributes.exercise.description') %>: <%= render_markdown(@request_for_comment.exercise.description) %>
@@ -162,9 +162,10 @@ also, all settings from the rails model needed for the editor configuration in t if (hasCommentsInRow(editor, row)) { var rowComments = getCommentsForRow(editor, row); var comments = _.pluck(rowComments, 'text').join('\n'); - commentModal.find('#other-comments').text(comments); + commentModal.find('#otherComments').show(); + commentModal.find('#otherCommentsTextfield').text(comments); } else { - commentModal.find('#other-comments').text('none'); + commentModal.find('#otherComments').hide(); } commentModal.find('#addCommentButton').off('click'); diff --git a/app/views/request_for_comments/show.json.jbuilder b/app/views/request_for_comments/show.json.jbuilder index fd9ffe0c..443ce0fb 100644 --- a/app/views/request_for_comments/show.json.jbuilder +++ b/app/views/request_for_comments/show.json.jbuilder @@ -1 +1 @@ -json.extract! @request_for_comment, :id, :user_id, :exercise_id, :file_id, :requested_at, :created_at, :updated_at, :user_type, :solved +json.extract! @request_for_comment, :id, :user_id, :exercise_id, :file_id, :created_at, :updated_at, :user_type, :solved diff --git a/config/locales/de.yml b/config/locales/de.yml index 4905f929..a57b2c04 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -246,7 +246,7 @@ de: comment: a_comment: Kommentar line: Zeile - dialogtitle: Kommentieren Sie diese Zeile! + dialogtitle: Kommentar hinzufügen others: Andere Kommentare auf dieser Zeile addyours: Fügen Sie Ihren Kommentar hinzu addComment: Kommentieren @@ -273,6 +273,7 @@ de: external_user: Externe Nutzer submit: failure: Beim Übermitteln Ihrer Punktzahl ist ein Fehler aufgetreten. Bitte versuchen Sie es später erneut. + full_score_redirect_to_rfc: Herzlichen Glückwunsch! Sie haben die maximale Punktzahl für diese Aufgabe an den Kurs übertragen. Ein anderer Teilnehmer hat eine Frage zu der von Ihnen gelösten Aufgabe. Er würde sich sicherlich sehr über ihre Hilfe und Kommentare freuen. external_users: statistics: no_data_available: Keine Daten verfügbar. diff --git a/config/locales/en.yml b/config/locales/en.yml index eaf88018..691dfe72 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -246,7 +246,7 @@ en: comment: a_comment: comment line: line - dialogtitle: Comment on this line! + dialogtitle: Comment on this line others: Other comments on this line addyours: Add your comment addComment: Comment this @@ -273,6 +273,7 @@ en: external_users: External Users submit: failure: An error occured while transmitting your score. Please try again later. + full_score_redirect_to_rfc: Congratulations! You achieved and submitted the highest possible score for this exercise. Another participant has a question concerning the exercise you just solved. Your help and comments will be greatly appreciated! external_users: statistics: no_data_available: No data available. From 99f1fe45a3dacae62d8e0f783468c0d2738669ef Mon Sep 17 00:00:00 2001 From: Ralf Teusner Date: Fri, 2 Sep 2016 15:05:48 +0200 Subject: [PATCH 2/4] Allow to specify a branch to deploy for staging --- config/deploy/staging.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb index 4cdc5169..5093b58e 100644 --- a/config/deploy/staging.rb +++ b/config/deploy/staging.rb @@ -1,2 +1,3 @@ server '10.210.0.50', roles: [:app, :db, :puma_nginx, :web], user: 'debian' set :rails_env, "staging" +set :branch, ENV['BRANCH'] if ENV['BRANCH'] From e45426635dc19e0d60bec4ef9d1664bf6af27906 Mon Sep 17 00:00:00 2001 From: Ralf Teusner Date: Fri, 2 Sep 2016 15:06:11 +0200 Subject: [PATCH 3/4] rename application from Code Ocean to CodeOcean --- app/helpers/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f11da84b..844a87c4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,5 @@ module ApplicationHelper - APPLICATION_NAME = 'Code Ocean' + APPLICATION_NAME = 'CodeOcean' def application_name APPLICATION_NAME From e67f1f78c43b2723f5d903a5d9dd9b74e04e01f9 Mon Sep 17 00:00:00 2001 From: Ralf Teusner Date: Fri, 9 Sep 2016 14:11:38 +0200 Subject: [PATCH 4/4] cleanup logging statements. --- app/controllers/exercises_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index cbd5266a..75451eb3 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -247,13 +247,12 @@ class ExercisesController < ApplicationController end def redirect_after_submit - Rails.logger.error('Score ' + @submission.normalized_score.to_s) + Rails.logger.debug('Score ' + @submission.normalized_score.to_s) if @submission.normalized_score == 1.0 # if user has an own rfc, redirect to it and message him to clean up and accept the answer. # else: show open rfc for same exercise if rfc = RequestForComment.unsolved.where(exercise_id: @submission.exercise).order("RANDOM()").first - Rails.logger.error('rfc: ' + rfc.to_s) # set a message that informs the user that his score was perfect and help in RFC is greatly appreciated. flash[:notice] = I18n.t('exercises.submit.full_score_redirect_to_rfc')