Commit 3ca749fb authored by Jiri Strojil's avatar Jiri Strojil
Browse files

Tmp

parent 4be1564d
...@@ -6,30 +6,23 @@ class SemesterProcessVolunteersController < ApplicationController ...@@ -6,30 +6,23 @@ class SemesterProcessVolunteersController < ApplicationController
include SemesterProcessVolunteerHelper include SemesterProcessVolunteerHelper
def review_semester def review_semester; end
@hour = Hour.new
end
def submit_review def submit_review
assign_reviewed_attributes
set_reviewed set_reviewed
assign_reviewed_attributes
@semester_process_volunteer.volunteer.validate_waive_and_bank = true @semester_process_volunteer.volunteer.validate_waive_and_bank = true
begin @semester_process_volunteer.missions.each { |m| m.semester_feedback.build }
ActiveRecord::Base.transaction do @semester_process_volunteer.missions.each { |m| m.hours.build }
@semester_process_volunteer.semester_feedbacks << @feedback if @semester_process_volunteer.save && @volunteer.save
@hour.save! unless @hour.hours == 0 || @hour.hours.blank?
@semester_process_volunteer.save!
@volunteer.save!
end
redirect_to( redirect_to(
review_semester_semester_process_volunteer_path(@semester_process_volunteer), review_semester_semester_process_volunteer_path(@semester_process_volunteer),
notice: 'Successfully reviewed.' notice: 'Successfully reviewed.'
) )
rescue ActiveRecord::RecordInvalid => exception else
null_reviewed null_reviewed
@hours.reload errors = @semester_process_volunteer.errors.full_messages + @volunteer.errors.full_messages
render :review_semester, notice: exception render :review_semester, notice: errors
end end
end end
...@@ -56,17 +49,17 @@ class SemesterProcessVolunteersController < ApplicationController ...@@ -56,17 +49,17 @@ class SemesterProcessVolunteersController < ApplicationController
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])
@hours = @semester_process_volunteer.hours #@hours = @semester_process_volunteer.hours
@volunteer = @semester_process_volunteer.volunteer @volunteer = @semester_process_volunteer.volunteer
@mission = @semester_process_volunteer.missions.first @missions = @semester_process_volunteer.missions
authorize @semester_process_volunteer authorize @semester_process_volunteer
end end
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: [:goals, :achievements, :future, :comments, :conversation], semester_feedback: [:mission, :goals, :achievements, :future, :comments, :conversation],
hour: [:hours]) hour_attributes: [:hours])
end end
def set_semester_process_volunteer def set_semester_process_volunteer
......
...@@ -85,6 +85,12 @@ class SemesterProcessesController < ApplicationController ...@@ -85,6 +85,12 @@ 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
] ]
......
...@@ -10,16 +10,8 @@ module SemesterProcessVolunteerHelper ...@@ -10,16 +10,8 @@ module SemesterProcessVolunteerHelper
end end
def assign_reviewed_attributes def assign_reviewed_attributes
@hour = Hour.new(
volunteer: @volunteer,
hourable: @mission,
semester_process_volunteer: @semester_process_volunteer,
meeting_date: Time.zone.now,
)
@hour.assign_attributes(review_params[:hour])
@volunteer.assign_attributes(review_params[:volunteer_attributes] @volunteer.assign_attributes(review_params[:volunteer_attributes]
.slice(:waive, :bank, :iban)) .slice(:waive, :bank, :iban))
@feedback.assign_attributes(review_params[:semester_feedback])
end end
def null_reviewed def null_reviewed
......
...@@ -8,6 +8,8 @@ module MissionEitherOneRelation ...@@ -8,6 +8,8 @@ module MissionEitherOneRelation
validate :validate_group_assignment_or_assignment_present validate :validate_group_assignment_or_assignment_present
attr_accessor :mission_id
def mission=(mission) def mission=(mission)
if mission.class.name == 'Assignment' if mission.class.name == 'Assignment'
self.assignment = mission self.assignment = mission
......
...@@ -27,7 +27,7 @@ class SemesterProcessVolunteer < ApplicationRecord ...@@ -27,7 +27,7 @@ class SemesterProcessVolunteer < ApplicationRecord
has_many :reminders, -> { where(kind: 'reminder') }, class_name: 'SemesterProcessMail', has_many :reminders, -> { where(kind: 'reminder') }, class_name: 'SemesterProcessMail',
foreign_key: 'semester_process_volunteer_id', inverse_of: 'semester_process_volunteer' foreign_key: 'semester_process_volunteer_id', inverse_of: 'semester_process_volunteer'
accepts_nested_attributes_for :hours, :volunteer, :semester_feedbacks accepts_nested_attributes_for :group_assignments, :assignments , :semester_process_volunteer_missions , :hours, :volunteer, :semester_feedbacks
validates_associated :hours, :semester_feedbacks, :volunteer validates_associated :hours, :semester_feedbacks, :volunteer
......
...@@ -3,23 +3,17 @@ ...@@ -3,23 +3,17 @@
= 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}
h2.m-b-20.m-t-30 = f.simple_fields_for :missions, @semester_process_volunteer.semester_process_volunteer_missions do |mf|
'Einsatz - mf.object.each do |mission|
= link_to @mission.to_label, polymorphic_path([@mission.volunteer, @mission.polymorph_url_object]), target: '_blank' h2.m-b-20.m-t-30
'Einsatz
= link_to mission.mission.to_label, polymorphic_path([mission.mission.volunteer, mission.mission.polymorph_url_object]), target: '_blank'
= f.simple_fields_for @feedback do |ff| = mf.simple_fields_for :semester_feedback, @semester_process_volunteer.semester_feedbacks.select {|feedback| feedback.mission == mission}.first do |ff|
- [:goals, :achievements, :future, :comments, :conversation].each do |field| = ff.input :id, type: :hidden
.row - [:goals, :achievements, :future, :comments, :conversation].each do |field|
.col-xs-12= ff.input field .row
.col-xs-12= ff.input field
- if @hours.any?
h3 Stunden
= render 'hours/last_submitted_hours', hours: @hours
= f.simple_fields_for @hour do |hf|
.row
.col-xs-2= hf.input :hours, label: 'Restliche Stunden in diesem Semester',
required: false, input_html: { value: f.object.hours == 0 ? '' : f.object.hours}
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