-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exercise feedback page for pair programming study
- Loading branch information
1 parent
fc38653
commit a54001e
Showing
15 changed files
with
261 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
app/controllers/pair_programming_exercise_feedbacks_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# frozen_string_literal: true | ||
|
||
class PairProgrammingExerciseFeedbacksController < ApplicationController | ||
include CommonBehavior | ||
include RedirectBehavior | ||
|
||
before_action :set_presets, only: %i[new create] | ||
|
||
def comment_presets | ||
[[0, t('pair_programming_exercise_feedback.difficulty_easy')], | ||
[1, t('pair_programming_exercise_feedback.difficulty_some_what_easy')], | ||
[2, t('pair_programming_exercise_feedback.difficulty_ok')], | ||
[3, t('pair_programming_exercise_feedback.difficulty_some_what_difficult')], | ||
[4, t('pair_programming_exercise_feedback.difficult_too_difficult')]] | ||
end | ||
|
||
def time_presets | ||
[[0, t('pair_programming_exercise_feedback.estimated_time_less_5')], | ||
[1, t('pair_programming_exercise_feedback.estimated_time_5_to_10')], | ||
[2, t('pair_programming_exercise_feedback.estimated_time_10_to_20')], | ||
[3, t('pair_programming_exercise_feedback.estimated_time_20_to_30')], | ||
[4, t('pair_programming_exercise_feedback.estimated_time_more_30')]] | ||
end | ||
|
||
def new | ||
exercise_id = if params[:pair_programming_exercise_feedback].nil? | ||
params[:exercise_id] | ||
else | ||
params[:pair_programming_exercise_feedback][:exercise_id] | ||
end | ||
@exercise = Exercise.find(exercise_id) | ||
|
||
@submission = Submission.find(params[:pair_programming_exercise_feedback][:submission_id]) | ||
authorize(@submission, :show?) | ||
|
||
@uef = PairProgrammingExerciseFeedback.new(user: current_user, exercise: @exercise, programming_group:, submission: @submission) | ||
authorize! | ||
end | ||
|
||
def create | ||
Sentry.set_extras(params: uef_params) | ||
|
||
@exercise = Exercise.find(uef_params[:exercise_id]) | ||
|
||
if @exercise | ||
@uef = PairProgrammingExerciseFeedback.new(exercise: @exercise, programming_group:, study_group_id: current_user.current_study_group_id) | ||
@uef.update(uef_params) | ||
authorize! | ||
if validate_inputs(uef_params) && @uef.save | ||
redirect_after_submit | ||
else | ||
flash.now[:danger] = t('shared.message_failure') | ||
redirect_back fallback_location: pair_programming_exercise_feedback_path(@uef) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def authorize! | ||
authorize(@uef || @uefs) | ||
end | ||
|
||
def set_presets | ||
@texts = comment_presets.to_a | ||
@times = time_presets.to_a | ||
end | ||
|
||
def uef_params | ||
return if params[:pair_programming_exercise_feedback].blank? | ||
|
||
@submission = Submission.find(params[:pair_programming_exercise_feedback][:submission_id]) | ||
|
||
authorize(@submission, :show?) | ||
|
||
params[:pair_programming_exercise_feedback] | ||
.permit(:difficulty, :user_estimated_worktime, :exercise_id) | ||
.merge(user: current_user, | ||
submission: @submission, | ||
normalized_score: @submission&.normalized_score) | ||
end | ||
|
||
def validate_inputs(uef_params) | ||
if uef_params[:difficulty].to_i.negative? || uef_params[:difficulty].to_i >= comment_presets.size | ||
false | ||
else | ||
!(uef_params[:user_estimated_worktime].to_i.negative? || uef_params[:user_estimated_worktime].to_i >= time_presets.size) | ||
end | ||
rescue StandardError | ||
false | ||
end | ||
|
||
def programming_group | ||
current_contributor if current_contributor.programming_group? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
class PairProgrammingExerciseFeedback < ApplicationRecord | ||
include Creation | ||
|
||
belongs_to :exercise | ||
belongs_to :submission | ||
belongs_to :study_group | ||
belongs_to :programming_group, optional: true | ||
has_one :execution_environment, through: :exercise | ||
|
||
scope :intermediate, -> { where.not(normalized_score: 1.00) } | ||
scope :final, -> { where(normalized_score: 1.00) } | ||
|
||
def to_s | ||
'Pair Programming Exercise Feedback' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class PairProgrammingExerciseFeedbackPolicy < AdminOnlyPolicy | ||
def create? | ||
everyone | ||
end | ||
|
||
def new? | ||
everyone | ||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
app/views/pair_programming_exercise_feedbacks/_form.html.slim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
= form_for(@uef) do |f| | ||
div | ||
h1 id="exercise-headline" | ||
= t('activerecord.models.user_exercise_feedback.one') + " " + @exercise.title | ||
= render('shared/form_errors', object: @uef) | ||
p | ||
== t('pair_programming_exercise_feedback.description') | ||
.mb-3 | ||
h5.mt-4 = t('pair_programming_exercise_feedback.difficulty') | ||
= f.collection_radio_buttons :difficulty, @texts, :first, :last do |b| | ||
.form-check | ||
label.form-check-label | ||
= b.radio_button(class: 'form-check-input') | ||
= b.text | ||
h5.mt-4 = t('pair_programming_exercise_feedback.working_time') | ||
= f.collection_radio_buttons :user_estimated_worktime, @times, :first, :last do |b| | ||
.form-check | ||
label.form-check-label | ||
= b.radio_button(class: 'form-check-input') | ||
= b.text | ||
= f.hidden_field(:exercise_id, :value => @exercise.id) | ||
= f.hidden_field(:submission_id, :value => @submission.id) | ||
.actions = render('shared/submit_button', f: f, object: @uef) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
= render('form') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
db/migrate/20230905190519_add_pair_programming_exercise_feedbacks.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddPairProgrammingExerciseFeedbacks < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :pair_programming_exercise_feedbacks do |t| | ||
t.references :exercise, null: false, index: true, foreign_key: true | ||
t.references :submission, null: false, index: true, foreign_key: true | ||
t.references :user, polymorphic: true, null: false, index: true | ||
t.references :programming_group, null: true, index: {name: 'pp_feedback_programming_group'}, foreign_key: true | ||
t.references :study_group, null: false, index: true, foreign_key: true | ||
t.integer :difficulty | ||
t.integer :user_estimated_worktime | ||
t.integer :reason_work_alone | ||
t.float :normalized_score | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters