diff --git a/app/controllers/user_exercise_feedbacks_controller.rb b/app/controllers/user_exercise_feedbacks_controller.rb index 6a835a37..4052fbb5 100644 --- a/app/controllers/user_exercise_feedbacks_controller.rb +++ b/app/controllers/user_exercise_feedbacks_controller.rb @@ -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 \ No newline at end of file diff --git a/app/models/user_exercise_feedback.rb b/app/models/user_exercise_feedback.rb index d3ec09d5..4ff9626e 100644 --- a/app/models/user_exercise_feedback.rb +++ b/app/models/user_exercise_feedback.rb @@ -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 \ No newline at end of file diff --git a/app/views/user_exercise_feedbacks/_form.html.slim b/app/views/user_exercise_feedbacks/_form.html.slim index 2d6cfd54..ebea7859 100644 --- a/app/views/user_exercise_feedbacks/_form.html.slim +++ b/app/views/user_exercise_feedbacks/_form.html.slim @@ -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) diff --git a/app/views/user_exercise_feedbacks/edit.html.slim b/app/views/user_exercise_feedbacks/edit.html.slim index e69de29b..7e5cfff1 100644 --- a/app/views/user_exercise_feedbacks/edit.html.slim +++ b/app/views/user_exercise_feedbacks/edit.html.slim @@ -0,0 +1 @@ += render('form') diff --git a/app/views/user_exercise_feedbacks/new.html.slim b/app/views/user_exercise_feedbacks/new.html.slim index 7abfbd34..7e5cfff1 100644 --- a/app/views/user_exercise_feedbacks/new.html.slim +++ b/app/views/user_exercise_feedbacks/new.html.slim @@ -1,3 +1 @@ -h1 = t('shared.new_model', model: UserExerciseFeedback.model_name.human) - = render('form') diff --git a/config/locales/de.yml b/config/locales/de.yml index 80f88c2a..f6480823 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -152,6 +152,9 @@ de: submission: one: Abgabe other: Abgaben + user_exercise_feedback: + one: Feedback + other: Feedback errors: messages: together: 'muss zusammen mit %{attribute} definiert werden' @@ -525,3 +528,12 @@ de: previous_label: '← Vorherige Seite' file_template: 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.
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?
Wir freuen uns über jedes Feedback." + diff --git a/config/locales/en.yml b/config/locales/en.yml index 99d11c32..90ba7d10 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -173,6 +173,9 @@ en: submission: one: Submission other: Submissions + user_exercise_feedback: + one: Feedback + other: Feedback errors: messages: together: 'has to be set along with %{attribute}' @@ -548,11 +551,10 @@ en: no_template_label: "Empty File" user_exercise_feedback: choose: "choose one" - easy: "it was easy" - some_what_easy: "it was somewhat easy" - some_what_difficult: "it was somewhat difficult" - difficult: "difficult" - done: "done" + difficulty_easy: "it was too easy" + difficulty_some_what_easy: "it was somewhat easy" + difficulty_ok: "it was just right" + difficulty_some_what_difficult: "it was somewhat difficult" + difficult_too_difficult: "it was too difficult" 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?" \ No newline at end of file