Commit e5c2f19b authored by Jiri Strojil's avatar Jiri Strojil
Browse files

Multiple assignments added (hours validations missing)

parent 3ca749fb
Pipeline #30690 failed with stage
in 35 minutes and 43 seconds
...@@ -10,20 +10,26 @@ class SemesterProcessVolunteersController < ApplicationController ...@@ -10,20 +10,26 @@ class SemesterProcessVolunteersController < ApplicationController
def submit_review def submit_review
set_reviewed set_reviewed
assign_reviewed_attributes assign_volunteer_attributes
@semester_process_volunteer.volunteer.validate_waive_and_bank = true @semester_process_volunteer.volunteer.validate_waive_and_bank = true
@semester_process_volunteer.missions.each { |m| m.semester_feedback.build }
@semester_process_volunteer.missions.each { |m| m.hours.build } build_nested_objects
if @semester_process_volunteer.save && @volunteer.save
redirect_to( ActiveRecord::Base.transaction do
review_semester_semester_process_volunteer_path(@semester_process_volunteer), @semester_process_volunteer.save!
notice: 'Successfully reviewed.' @volunteer.save!
) @feedbacks.each(&:save!)
else @hours.each(&:save!)
null_reviewed
errors = @semester_process_volunteer.errors.full_messages + @volunteer.errors.full_messages
render :review_semester, notice: errors
end end
redirect_to(
review_semester_semester_process_volunteer_path(@semester_process_volunteer),
notice: 'Successfully reviewed.'
)
rescue ActiveRecord::RecordInvalid => exception
puts "ERROR!"
puts exception.message
null_reviewed
render :review_semester, notice: exception.message, errors: exception.message
end end
def index def index
...@@ -46,6 +52,15 @@ class SemesterProcessVolunteersController < ApplicationController ...@@ -46,6 +52,15 @@ class SemesterProcessVolunteersController < ApplicationController
private private
def build_nested_objects
@feedbacks, @hours = [], []
review_params[:semester_feedbacks_attributes].each do |_i, hash|
@feedbacks << SemesterFeedback.new(hash[:semester_feedback]
.merge({ author: current_user, semester_process_volunteer: @semester_process_volunteer }))
@hours << Hour.new(hash[:hour])
end
end
def prepare_review def prepare_review
# careful cuz mission id can be present in both missions # careful cuz mission id can be present in both missions
@semester_process_volunteer = SemesterProcessVolunteer.find(params[:id]) @semester_process_volunteer = SemesterProcessVolunteer.find(params[:id])
...@@ -58,8 +73,8 @@ class SemesterProcessVolunteersController < ApplicationController ...@@ -58,8 +73,8 @@ class SemesterProcessVolunteersController < ApplicationController
def review_params def review_params
params.require(:semester_process_volunteer).permit( params.require(:semester_process_volunteer).permit(
volunteer_attributes: [:waive, :iban, :bank], volunteer_attributes: [:waive, :iban, :bank],
semester_feedback: [:mission, :goals, :achievements, :future, :comments, :conversation], semester_feedbacks_attributes: [[semester_feedback: [:mission, :goals, :achievements, :future, :comments, :conversation, :spv_mission_id]],
hour_attributes: [:hours]) [hour: [:hours, :spv_mission_id ]]])
end end
def set_semester_process_volunteer def set_semester_process_volunteer
......
...@@ -85,12 +85,6 @@ class SemesterProcessesController < ApplicationController ...@@ -85,12 +85,6 @@ class SemesterProcessesController < ApplicationController
:kind, :kind,
:subject, :subject,
:body, :body,
:semester_feedbacks: [
:
]
:hours_attributes: [
:hours
],
semester_process_volunteers_attributes: [ semester_process_volunteers_attributes: [
:volunteer_id, :selected :volunteer_id, :selected
] ]
......
...@@ -9,7 +9,7 @@ module SemesterProcessVolunteerHelper ...@@ -9,7 +9,7 @@ module SemesterProcessVolunteerHelper
@semester_process_volunteer.commited_at = Time.zone.now @semester_process_volunteer.commited_at = Time.zone.now
end end
def assign_reviewed_attributes def assign_volunteer_attributes
@volunteer.assign_attributes(review_params[:volunteer_attributes] @volunteer.assign_attributes(review_params[:volunteer_attributes]
.slice(:waive, :bank, :iban)) .slice(:waive, :bank, :iban))
end end
......
...@@ -45,6 +45,12 @@ class Hour < ApplicationRecord ...@@ -45,6 +45,12 @@ class Hour < ApplicationRecord
group_offer.where(hourable_id: group_offer_ids) group_offer.where(hourable_id: group_offer_ids)
} }
attr_reader :spv_mission_id
def spv_mission_id= id
self.hourable = SemesterProcessVolunteerMission.find(id).mission
end
def assignment? def assignment?
hourable_type == 'Assignment' hourable_type == 'Assignment'
end end
......
...@@ -5,4 +5,10 @@ class SemesterFeedback < ApplicationRecord ...@@ -5,4 +5,10 @@ class SemesterFeedback < ApplicationRecord
belongs_to :semester_process_volunteer belongs_to :semester_process_volunteer
has_one :semester_process, through: :semester_process_volunteer has_one :semester_process, through: :semester_process_volunteer
has_one :volunteer, through: :semester_process_volunteer has_one :volunteer, through: :semester_process_volunteer
attr_reader :spv_mission_id
def spv_mission_id= id
self.mission = SemesterProcessVolunteerMission.find(id).mission
end
end end
...@@ -43,6 +43,9 @@ class SemesterProcessVolunteer < ApplicationRecord ...@@ -43,6 +43,9 @@ class SemesterProcessVolunteer < ApplicationRecord
end end
} }
def semester_feedback_with_mission(mission)
self.semester_feedbacks.select{|sf| sf.mission == mission}.last
end
# will only return an array, not a AD-result # will only return an array, not a AD-result
def missions def missions
......
...@@ -2,4 +2,10 @@ class SemesterProcessVolunteerMission < ApplicationRecord ...@@ -2,4 +2,10 @@ class SemesterProcessVolunteerMission < ApplicationRecord
include MissionEitherOneRelation include MissionEitherOneRelation
belongs_to :semester_process_volunteer belongs_to :semester_process_volunteer
attr_accessor :hour
def hour
@hour || Hour.new
end
end end
...@@ -3,17 +3,29 @@ ...@@ -3,17 +3,29 @@
= simple_error_notice f = simple_error_notice f
h1 Halbjahres-Rapporte #{@semester_process_volunteer.semester_t} für #{@semester_process_volunteer.volunteer.contact.full_name} h1 Halbjahres-Rapporte #{@semester_process_volunteer.semester_t} für #{@semester_process_volunteer.volunteer.contact.full_name}
= f.simple_fields_for :missions, @semester_process_volunteer.semester_process_volunteer_missions do |mf| = f.simple_fields_for :semester_feedbacks, @semester_process_volunteer.semester_process_volunteer_missions do |spvm|
- mf.object.each do |mission| - mission= spvm.object.mission
h2.m-b-20.m-t-30 h2.m-b-20.m-t-30
'Einsatz 'Einsatz
= link_to mission.mission.to_label, polymorphic_path([mission.mission.volunteer, mission.mission.polymorph_url_object]), target: '_blank' = link_to mission.to_label,
url: polymorphic_path([mission.volunteer, mission.polymorph_url_object]),
target: '_blank'
= mf.simple_fields_for :semester_feedback, @semester_process_volunteer.semester_feedbacks.select {|feedback| feedback.mission == mission}.first do |ff| = spvm.simple_fields_for :semester_feedback, @semester_process_volunteer.semester_feedback_with_mission(mission) do |ff|
= ff.input :id, type: :hidden = ff.input :spv_mission_id, as: :hidden, input_html: { value: spvm.object.id }
- [:goals, :achievements, :future, :comments, :conversation].each do |field| - [:goals, :achievements, :future, :comments, :conversation].each do |field|
.row .row
.col-xs-12= ff.input field .col-xs-12= ff.input field
- if mission.hours.any?
h3 Stunden
= render 'hours/last_submitted_hours', hours: mission.hours
= spvm.simple_fields_for :hour, Hour.new do |hf|
= hf.input :spv_mission_id, as: :hidden, input_html: { value: spvm.object.id}
.row
.col-xs-2= hf.input :hours, label: 'Restliche Stunden in diesem Semester',
input_html: { value: f.object.hours == 0 ? '' : f.object.hours, min: 0}
h3 Spesen h3 Spesen
= f.simple_fields_for :volunteer, @volunteer do |vf| = f.simple_fields_for :volunteer, @volunteer do |vf|
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment