Merge pull request #134 from openHPI/user_exercise_feedback_backend

User exercise feedback backend UI
This commit is contained in:
rteusner
2017-11-15 14:19:04 +01:00
committed by GitHub
14 changed files with 182 additions and 29 deletions

View File

@@ -24,7 +24,6 @@ class ExercisesController < ApplicationController
3
end
def java_course_token
"702cbd2a-c84c-4b37-923a-692d7d1532d0"
end
@@ -387,10 +386,13 @@ class ExercisesController < ApplicationController
# otherwise an internal user could be shown a false rfc here, since current_user.id is polymorphic, but only makes sense for external users when used with rfcs.)
# redirect 10 percent pseudorandomly to the feedback page
if current_user.respond_to? :external_id
if ((current_user.id + @submission.exercise.created_at.to_i) % 10 == 1)
if @submission.redirect_to_feedback?
redirect_to_user_feedback
return
elsif rfc = RequestForComment.unsolved.where(exercise_id: @submission.exercise, user_id: current_user.id).first
end
rfc = @submission.own_unsolved_rfc
if rfc
# set a message that informs the user that his own RFC should be closed.
flash[:notice] = I18n.t('exercises.submit.full_score_redirect_to_own_rfc')
flash.keep(:notice)
@@ -400,24 +402,30 @@ class ExercisesController < ApplicationController
format.json { render(json: {redirect: url_for(rfc)}) }
end
return
end
# else: show open rfc for same exercise if available
elsif rfc = RequestForComment.unsolved.where(exercise_id: @submission.exercise).where.not(question: nil).order("RANDOM()").find { | rfc_element |(rfc_element.comments_count < 5) }
rfc = @submission.unsolved_rfc
unless rfc.nil?
# 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)}) }
format.html {redirect_to(rfc)}
format.json {render(json: {redirect: url_for(rfc)})}
end
return
end
end
else
# redirect to feedback page if score is less than 100 percent
redirect_to_user_feedback
return
if @exercise.needs_more_feedback?
redirect_to_user_feedback
else
redirect_to_lti_return_path
end
return
end
redirect_to_lti_return_path
end

View File

@@ -2,6 +2,7 @@ class UserExerciseFeedbacksController < ApplicationController
include CommonBehavior
before_action :set_user_exercise_feedback, only: [:edit, :update]
before_action :set_user_exercise_feedback_by_id, only: [:show, :destroy]
def comment_presets
[[0,t('user_exercise_feedback.difficulty_easy')],
@@ -19,10 +20,15 @@ class UserExerciseFeedbacksController < ApplicationController
[4,t('user_exercise_feedback.estimated_time_more_30')]]
end
def authorize!
authorize(@uef)
def index
@search = UserExerciseFeedback.all.search params[:q]
@uefs = @search.result.includes(:execution_environment).order(:id).paginate(page: params[:page])
authorize!
end
def show
authorize!
end
private :authorize!
def create
@exercise = Exercise.find(uef_params[:exercise_id])
@@ -49,7 +55,8 @@ class UserExerciseFeedbacksController < ApplicationController
end
def destroy
destroy_and_respond(object: @tag)
authorize!
destroy_and_respond(object: @uef)
end
def edit
@@ -58,11 +65,6 @@ class UserExerciseFeedbacksController < ApplicationController
authorize!
end
def uef_params
params[:user_exercise_feedback].permit(:feedback_text, :difficulty, :exercise_id, :user_estimated_worktime).merge(user_id: current_user.id, user_type: current_user.class.name)
end
private :uef_params
def new
@texts = comment_presets.to_a
@times = time_presets.to_a
@@ -89,6 +91,12 @@ class UserExerciseFeedbacksController < ApplicationController
end
end
private
def authorize!
authorize(@uef || @uefs)
end
def to_s
name
end
@@ -98,6 +106,14 @@ class UserExerciseFeedbacksController < ApplicationController
@uef = UserExerciseFeedback.find_by(exercise_id: params[:user_exercise_feedback][:exercise_id], user: current_user)
end
def set_user_exercise_feedback_by_id
@uef = UserExerciseFeedback.find(params[:id])
end
def uef_params
params[:user_exercise_feedback].permit(:feedback_text, :difficulty, :exercise_id, :user_estimated_worktime).merge(user_id: current_user.id, user_type: current_user.class.name)
end
def validate_inputs(uef_params)
begin
if uef_params[:difficulty].to_i < 0 || uef_params[:difficulty].to_i >= comment_presets.size
@@ -112,4 +128,4 @@ class UserExerciseFeedbacksController < ApplicationController
end
end
end
end