save progress
This commit is contained in:
@ -164,6 +164,7 @@ class ExercisesController < ApplicationController
|
|||||||
private :handle_file_uploads
|
private :handle_file_uploads
|
||||||
|
|
||||||
def implement
|
def implement
|
||||||
|
redirect_to_user_feedback
|
||||||
redirect_to(@exercise, alert: t('exercises.implement.no_files')) unless @exercise.files.visible.exists?
|
redirect_to(@exercise, alert: t('exercises.implement.no_files')) unless @exercise.files.visible.exists?
|
||||||
user_solved_exercise = @exercise.has_user_solved(current_user)
|
user_solved_exercise = @exercise.has_user_solved(current_user)
|
||||||
user_got_enough_interventions = UserExerciseIntervention.where(user: current_user).where("created_at >= ?", Time.zone.now.beginning_of_day).count >= max_intervention_count
|
user_got_enough_interventions = UserExerciseIntervention.where(user: current_user).where("created_at >= ?", Time.zone.now.beginning_of_day).count >= max_intervention_count
|
||||||
@ -409,4 +410,12 @@ class ExercisesController < ApplicationController
|
|||||||
redirect_to_lti_return_path
|
redirect_to_lti_return_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def redirect_to_user_feedback
|
||||||
|
if UserExerciseFeedback.find_by(exercise: @exercise, user: current_user)
|
||||||
|
redirect_to(edit_user_exercise_feedback_path(user_exercise_feedback: {exercise_id: @exercise.id}))
|
||||||
|
else
|
||||||
|
redirect_to(new_user_exercise_feedback_path(user_exercise_feedback: {exercise_id: @exercise.id}))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,15 +1,33 @@
|
|||||||
class UserExerciseFeedbackController < ApplicationController
|
class UserExerciseFeedbacksController < ApplicationController
|
||||||
include CommonBehavior
|
include CommonBehavior
|
||||||
|
|
||||||
|
before_action :set_user_exercise_feedback, only: [:edit, :update]
|
||||||
|
|
||||||
|
def comment_presets
|
||||||
|
[t('user_exercise_feedback.choose'),
|
||||||
|
t('user_exercise_feedback.easy'),
|
||||||
|
t('user_exercise_feedback.some_what_easy'),
|
||||||
|
t('user_exercise_feedback.some_what_difficult'),
|
||||||
|
t('user_exercise_feedback.difficult')]
|
||||||
|
end
|
||||||
|
|
||||||
def authorize!
|
def authorize!
|
||||||
authorize(@uef)
|
authorize(@uef)
|
||||||
end
|
end
|
||||||
private :authorize!
|
private :authorize!
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@tag = Tag.new(tag_params)
|
if validate_feedback_text(uef_params[:difficulty])
|
||||||
|
exercise = Exercise.find(uef_params[:exercise_id])
|
||||||
|
if exercise
|
||||||
|
@uef = UserExerciseFeedback.new(uef_params)
|
||||||
authorize!
|
authorize!
|
||||||
create_and_respond(object: @tag)
|
create_and_respond(object: @uef, path: proc{implement_exercise_path(exercise)})
|
||||||
|
end
|
||||||
|
else
|
||||||
|
flash[:danger] = t('shared.message_failure')
|
||||||
|
redirect_to(:back, id: uef_params[:exercise_id])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@ -17,26 +35,43 @@ class UserExerciseFeedbackController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
@texts = comment_presets
|
||||||
|
authorize!
|
||||||
end
|
end
|
||||||
|
|
||||||
def uef_params
|
def uef_params
|
||||||
params[:tag].permit(:feedback_text, :difficulty)
|
params[:user_exercise_feedback].permit(:feedback_text, :difficulty, :exercise_id).merge(user_id: current_user.id, user_type: current_user.class.name)
|
||||||
end
|
end
|
||||||
private :uef_params
|
private :uef_params
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
@texts = comment_presets
|
||||||
@uef = UserExerciseFeedback.new
|
@uef = UserExerciseFeedback.new
|
||||||
|
@exercise = Exercise.find(params[:user_exercise_feedback][:exercise_id])
|
||||||
authorize!
|
authorize!
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
|
||||||
end
|
|
||||||
|
|
||||||
def update
|
def update
|
||||||
update_and_respond(object: @UserExerciseFeedback, params: uef_params)
|
authorize!
|
||||||
|
if validate_feedback_text(uef_params[:difficulty]) && @exercise
|
||||||
|
update_and_respond(object: @uef, params: uef_params, path: implement_exercise_path(@exercise))
|
||||||
|
else
|
||||||
|
flash[:danger] = t('shared.message_failure')
|
||||||
|
redirect_to(:back, id: uef_params[:exercise_id])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_user_exercise_feedback
|
||||||
|
puts "params: #{params}"
|
||||||
|
@exercise = Exercise.find(params[:user_exercise_feedback][:exercise_id])
|
||||||
|
@uef = UserExerciseFeedback.find_by(exercise_id: params[:user_exercise_feedback][:exercise_id], user: current_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_feedback_text(difficulty_text)
|
||||||
|
return comment_presets.include? difficulty_text
|
||||||
|
end
|
||||||
end
|
end
|
@ -1,4 +1,4 @@
|
|||||||
class TagPolicy < AdminOrAuthorPolicy
|
class UserExerciseFeedbackPolicy < AdminOrAuthorPolicy
|
||||||
def author?
|
def author?
|
||||||
@user == @record.author
|
@user == @record.author
|
||||||
end
|
end
|
||||||
@ -8,6 +8,10 @@ class TagPolicy < AdminOrAuthorPolicy
|
|||||||
admin?
|
admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create?
|
||||||
|
everyone
|
||||||
|
end
|
||||||
|
|
||||||
def show?
|
def show?
|
||||||
@user.internal_user?
|
@user.internal_user?
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
= form_for(@uef) do |f|
|
= form_for(@uef) do |f|
|
||||||
= render('shared/form_errors', object: @uef)
|
= render('shared/form_errors', object: @uef)
|
||||||
|
h4
|
||||||
|
p = t('user_exercise_feedback.description')
|
||||||
.form-group
|
.form-group
|
||||||
= f.label(:feedback_text)
|
= f.text_area(:feedback_text, class: 'form-control', required: true, :rows => "10")
|
||||||
= f.text_field(:feedback_text, class: 'form-control', required: true)
|
h4 = t('user_exercise_feedback.difficulty')
|
||||||
= f.label(:difficulty)
|
= f.collection_radio_buttons :difficulty, @texts, :to_s, :to_s, html_options={class: "radio-inline"} do |b|
|
||||||
= f.text_field(:difficulty, class: 'form-control', required: true)
|
= b.label(:class => 'radio') { b.radio_button + b.text }
|
||||||
|
= f.hidden_field(:exercise_id, :value => @exercise.id)
|
||||||
.actions = render('shared/submit_button', f: f, object: @uef)
|
.actions = render('shared/submit_button', f: f, object: @uef)
|
||||||
|
0
app/views/user_exercise_feedbacks/edit.html.slim
Normal file
0
app/views/user_exercise_feedbacks/edit.html.slim
Normal file
@ -547,8 +547,12 @@ en:
|
|||||||
file_template:
|
file_template:
|
||||||
no_template_label: "Empty File"
|
no_template_label: "Empty File"
|
||||||
user_exercise_feedback:
|
user_exercise_feedback:
|
||||||
|
choose: "choose one"
|
||||||
easy: "it was easy"
|
easy: "it was easy"
|
||||||
some_what_easy: "it was somewhat easy"
|
some_what_easy: "it was somewhat easy"
|
||||||
some_what_difficult: "it was somewhat difficult"
|
some_what_difficult: "it was somewhat difficult"
|
||||||
difficult: "difficult"
|
difficult: "difficult"
|
||||||
|
done: "done"
|
||||||
|
difficulty: "Difficulty of the exercise"
|
||||||
|
description: "Here you have the chance to comment on the exercise. Feel free to give us feedback on the exercise, the description or difficulty. Did you liked the question or was it too difficult or easy?"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user