improved texts of feedback, added ok button

This commit is contained in:
Thomas Hille
2017-04-12 10:13:23 +02:00
parent e4d28452bf
commit 8ca944558c
7 changed files with 46 additions and 29 deletions

View File

@ -4,11 +4,11 @@ class UserExerciseFeedbacksController < ApplicationController
before_action :set_user_exercise_feedback, only: [:edit, :update] before_action :set_user_exercise_feedback, only: [:edit, :update]
def comment_presets def comment_presets
[t('user_exercise_feedback.choose'), [[0,t('user_exercise_feedback.difficulty_easy')],
t('user_exercise_feedback.easy'), [1,t('user_exercise_feedback.difficulty_some_what_easy')],
t('user_exercise_feedback.some_what_easy'), [2,t('user_exercise_feedback.difficulty_ok')],
t('user_exercise_feedback.some_what_difficult'), [3,t('user_exercise_feedback.difficulty_some_what_difficult')],
t('user_exercise_feedback.difficult')] [4,t('user_exercise_feedback.difficult_too_difficult')]]
end end
def authorize! def authorize!
@ -17,25 +17,25 @@ class UserExerciseFeedbacksController < ApplicationController
private :authorize! private :authorize!
def create def create
if validate_feedback_text(uef_params[:difficulty])
exercise = Exercise.find(uef_params[:exercise_id]) exercise = Exercise.find(uef_params[:exercise_id])
if exercise if exercise
@uef = UserExerciseFeedback.new(uef_params) @uef = UserExerciseFeedback.new(uef_params)
if validate_inputs(uef_params)
authorize! authorize!
create_and_respond(object: @uef, path: proc{implement_exercise_path(exercise)}) create_and_respond(object: @uef, path: proc{implement_exercise_path(exercise)})
end
else else
flash[:danger] = t('shared.message_failure') flash[:danger] = t('shared.message_failure')
redirect_to(:back, id: uef_params[:exercise_id]) redirect_to(:back, id: uef_params[:exercise_id])
end end
end end
end
def destroy def destroy
destroy_and_respond(object: @tag) destroy_and_respond(object: @tag)
end end
def edit def edit
@texts = comment_presets @texts = comment_presets.to_a
authorize! authorize!
end end
@ -45,7 +45,7 @@ class UserExerciseFeedbacksController < ApplicationController
private :uef_params private :uef_params
def new def new
@texts = comment_presets @texts = comment_presets.to_a
@uef = UserExerciseFeedback.new @uef = UserExerciseFeedback.new
@exercise = Exercise.find(params[:user_exercise_feedback][:exercise_id]) @exercise = Exercise.find(params[:user_exercise_feedback][:exercise_id])
authorize! authorize!
@ -53,7 +53,7 @@ class UserExerciseFeedbacksController < ApplicationController
def update def update
authorize! authorize!
if validate_feedback_text(uef_params[:difficulty]) && @exercise if @exercise && validate_inputs(uef_params)
update_and_respond(object: @uef, params: uef_params, path: implement_exercise_path(@exercise)) update_and_respond(object: @uef, params: uef_params, path: implement_exercise_path(@exercise))
else else
flash[:danger] = t('shared.message_failure') flash[:danger] = t('shared.message_failure')
@ -66,12 +66,13 @@ class UserExerciseFeedbacksController < ApplicationController
end end
def set_user_exercise_feedback def set_user_exercise_feedback
puts "params: #{params}"
@exercise = Exercise.find(params[:user_exercise_feedback][:exercise_id]) @exercise = Exercise.find(params[:user_exercise_feedback][:exercise_id])
@uef = UserExerciseFeedback.find_by(exercise_id: params[:user_exercise_feedback][:exercise_id], user: current_user) @uef = UserExerciseFeedback.find_by(exercise_id: params[:user_exercise_feedback][:exercise_id], user: current_user)
@selectedDifficulty = @uef.difficulty
end end
def validate_feedback_text(difficulty_text) def validate_inputs(uef_params)
return comment_presets.include? difficulty_text (uef_params[:difficulty].to_i >= 0 && uef_params[:difficulty].to_i < comment_presets.size) rescue false
end end
end end

View File

@ -5,4 +5,7 @@ class UserExerciseFeedback < ActiveRecord::Base
validates :user_id, uniqueness: { scope: [:exercise_id, :user_type] } validates :user_id, uniqueness: { scope: [:exercise_id, :user_type] }
def to_s
"User Exercise Feedback"
end
end end

View File

@ -1,11 +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 h4
p = t('user_exercise_feedback.description') == t('user_exercise_feedback.description')
.form-group .form-group
= f.text_area(:feedback_text, class: 'form-control', required: true, :rows => "10") = f.text_area(:feedback_text, class: 'form-control', required: true, :rows => "10")
h4 = t('user_exercise_feedback.difficulty') h4 = t('user_exercise_feedback.difficulty')
= f.collection_radio_buttons :difficulty, @texts, :to_s, :to_s, html_options={class: "radio-inline"} do |b| = f.collection_radio_buttons :difficulty, @texts, :first, :last, html_options={class: "radio-inline"} do |b|
= b.label(:class => 'radio') { b.radio_button + b.text } = b.label(:class => 'radio') { b.radio_button + b.text }
= f.hidden_field(:exercise_id, :value => @exercise.id) = 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)

View File

@ -0,0 +1 @@
= render('form')

View File

@ -1,3 +1 @@
h1 = t('shared.new_model', model: UserExerciseFeedback.model_name.human)
= render('form') = render('form')

View File

@ -152,6 +152,9 @@ de:
submission: submission:
one: Abgabe one: Abgabe
other: Abgaben other: Abgaben
user_exercise_feedback:
one: Feedback
other: Feedback
errors: errors:
messages: messages:
together: 'muss zusammen mit %{attribute} definiert werden' together: 'muss zusammen mit %{attribute} definiert werden'
@ -525,3 +528,12 @@ de:
previous_label: '&#8592; Vorherige Seite' previous_label: '&#8592; Vorherige Seite'
file_template: file_template:
no_template_label: "Leere Datei" no_template_label: "Leere Datei"
user_exercise_feedback:
difficulty_easy: "es war zu einfach"
difficulty_some_what_easy: "es war etwas zu einfach"
difficulty_ok: "es war ok"
difficulty_some_what_difficult: "es war etwas zu schwer"
difficult_too_difficult: "es war zu schwer"
difficulty: "Schwierigkeit der Aufgabe"
description: "Wir freuen uns, wenn Sie uns hier Feedback zur Aufgabe zu geben.<br>Bitte beschreiben Sie, was Ihnen an der Aufgabe gefallen hat und was nicht. Gabs Schwierigkeiten bei der Aufgabe? War die Aufgabe zu leicht oder zu schwer?<br>Wir freuen uns über jedes Feedback."

View File

@ -173,6 +173,9 @@ en:
submission: submission:
one: Submission one: Submission
other: Submissions other: Submissions
user_exercise_feedback:
one: Feedback
other: Feedback
errors: errors:
messages: messages:
together: 'has to be set along with %{attribute}' together: 'has to be set along with %{attribute}'
@ -548,11 +551,10 @@ en:
no_template_label: "Empty File" no_template_label: "Empty File"
user_exercise_feedback: user_exercise_feedback:
choose: "choose one" choose: "choose one"
easy: "it was easy" difficulty_easy: "it was too easy"
some_what_easy: "it was somewhat easy" difficulty_some_what_easy: "it was somewhat easy"
some_what_difficult: "it was somewhat difficult" difficulty_ok: "it was just right"
difficult: "difficult" difficulty_some_what_difficult: "it was somewhat difficult"
done: "done" difficult_too_difficult: "it was too difficult"
difficulty: "Difficulty of the exercise" 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?" 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?"