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]
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')]
[[0,t('user_exercise_feedback.difficulty_easy')],
[1,t('user_exercise_feedback.difficulty_some_what_easy')],
[2,t('user_exercise_feedback.difficulty_ok')],
[3,t('user_exercise_feedback.difficulty_some_what_difficult')],
[4,t('user_exercise_feedback.difficult_too_difficult')]]
end
def authorize!
@@ -17,16 +17,16 @@ class UserExerciseFeedbacksController < ApplicationController
private :authorize!
def create
if validate_feedback_text(uef_params[:difficulty])
exercise = Exercise.find(uef_params[:exercise_id])
if exercise
@uef = UserExerciseFeedback.new(uef_params)
exercise = Exercise.find(uef_params[:exercise_id])
if exercise
@uef = UserExerciseFeedback.new(uef_params)
if validate_inputs(uef_params)
authorize!
create_and_respond(object: @uef, path: proc{implement_exercise_path(exercise)})
else
flash[:danger] = t('shared.message_failure')
redirect_to(:back, id: uef_params[:exercise_id])
end
else
flash[:danger] = t('shared.message_failure')
redirect_to(:back, id: uef_params[:exercise_id])
end
end
@@ -35,7 +35,7 @@ class UserExerciseFeedbacksController < ApplicationController
end
def edit
@texts = comment_presets
@texts = comment_presets.to_a
authorize!
end
@@ -45,7 +45,7 @@ class UserExerciseFeedbacksController < ApplicationController
private :uef_params
def new
@texts = comment_presets
@texts = comment_presets.to_a
@uef = UserExerciseFeedback.new
@exercise = Exercise.find(params[:user_exercise_feedback][:exercise_id])
authorize!
@@ -53,7 +53,7 @@ class UserExerciseFeedbacksController < ApplicationController
def update
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))
else
flash[:danger] = t('shared.message_failure')
@@ -66,12 +66,13 @@ class UserExerciseFeedbacksController < ApplicationController
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)
@selectedDifficulty = @uef.difficulty
end
def validate_feedback_text(difficulty_text)
return comment_presets.include? difficulty_text
def validate_inputs(uef_params)
(uef_params[:difficulty].to_i >= 0 && uef_params[:difficulty].to_i < comment_presets.size) rescue false
end
end

View File

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

View File

@@ -1,11 +1,11 @@
= form_for(@uef) do |f|
= render('shared/form_errors', object: @uef)
h4
p = t('user_exercise_feedback.description')
== t('user_exercise_feedback.description')
.form-group
= f.text_area(:feedback_text, class: 'form-control', required: true, :rows => "10")
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 }
= f.hidden_field(:exercise_id, :value => @exercise.id)
.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')