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

Tmp

parent 4be1564d
......@@ -6,30 +6,23 @@ class SemesterProcessVolunteersController < ApplicationController
include SemesterProcessVolunteerHelper
def review_semester
@hour = Hour.new
end
def review_semester; end
def submit_review
assign_reviewed_attributes
set_reviewed
assign_reviewed_attributes
@semester_process_volunteer.volunteer.validate_waive_and_bank = true
begin
ActiveRecord::Base.transaction do
@semester_process_volunteer.semester_feedbacks << @feedback
@hour.save! unless @hour.hours == 0 || @hour.hours.blank?
@semester_process_volunteer.save!
@volunteer.save!
end
@semester_process_volunteer.missions.each { |m| m.semester_feedback.build }
@semester_process_volunteer.missions.each { |m| m.hours.build }
if @semester_process_volunteer.save && @volunteer.save
redirect_to(
review_semester_semester_process_volunteer_path(@semester_process_volunteer),
notice: 'Successfully reviewed.'
)
rescue ActiveRecord::RecordInvalid => exception
null_reviewed
@hours.reload
render :review_semester, notice: exception
else
null_reviewed
errors = @semester_process_volunteer.errors.full_messages + @volunteer.errors.full_messages
render :review_semester, notice: errors
end
end
......@@ -56,17 +49,17 @@ class SemesterProcessVolunteersController < ApplicationController
def prepare_review
# careful cuz mission id can be present in both missions
@semester_process_volunteer = SemesterProcessVolunteer.find(params[:id])
@hours = @semester_process_volunteer.hours
#@hours = @semester_process_volunteer.hours
@volunteer = @semester_process_volunteer.volunteer
@mission = @semester_process_volunteer.missions.first
@missions = @semester_process_volunteer.missions
authorize @semester_process_volunteer
end
def review_params
params.require(:semester_process_volunteer).permit(
volunteer_attributes: [:waive, :iban, :bank],
semester_feedback: [:goals, :achievements, :future, :comments, :conversation],
hour: [:hours])
semester_feedback: [:mission, :goals, :achievements, :future, :comments, :conversation],
hour_attributes: [:hours])
end
def set_semester_process_volunteer
......
......@@ -85,6 +85,12 @@ class SemesterProcessesController < ApplicationController
:kind,
:subject,
:body,
:semester_feedbacks: [
:
]
:hours_attributes: [
:hours
],
semester_process_volunteers_attributes: [
:volunteer_id, :selected
]
......
......@@ -10,16 +10,8 @@ module SemesterProcessVolunteerHelper
end
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]
.slice(:waive, :bank, :iban))
@feedback.assign_attributes(review_params[:semester_feedback])
end
def null_reviewed
......
......@@ -8,6 +8,8 @@ module MissionEitherOneRelation
validate :validate_group_assignment_or_assignment_present
attr_accessor :mission_id
def mission=(mission)
if mission.class.name == 'Assignment'
self.assignment = mission
......
......@@ -27,7 +27,7 @@ class SemesterProcessVolunteer < ApplicationRecord
has_many :reminders, -> { where(kind: 'reminder') }, class_name: 'SemesterProcessMail',
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
......
......@@ -3,23 +3,17 @@
= simple_error_notice f
h1 Halbjahres-Rapporte #{@semester_process_volunteer.semester_t} für #{@semester_process_volunteer.volunteer.contact.full_name}
h2.m-b-20.m-t-30
'Einsatz
= link_to @mission.to_label, polymorphic_path([@mission.volunteer, @mission.polymorph_url_object]), target: '_blank'
= f.simple_fields_for :missions, @semester_process_volunteer.semester_process_volunteer_missions do |mf|
- mf.object.each do |mission|
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|
- [:goals, :achievements, :future, :comments, :conversation].each do |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}
= mf.simple_fields_for :semester_feedback, @semester_process_volunteer.semester_feedbacks.select {|feedback| feedback.mission == mission}.first do |ff|
= ff.input :id, type: :hidden
- [:goals, :achievements, :future, :comments, :conversation].each do |field|
.row
.col-xs-12= ff.input field
h3 Spesen
= f.simple_fields_for :volunteer, @volunteer do |vf|
......
Markdown is supported
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