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

Minor fixes

parent e5c2f19b
Pipeline #30757 failed with stage
in 36 minutes and 3 seconds
class SemesterProcessVolunteersController < ApplicationController class SemesterProcessVolunteersController < ApplicationController
before_action :prepare_review, only: [:review_semester, :submit_review] before_action :prepare_review, only: [:review_semester, :submit_review]
before_action :initialize_feedback, only: [:review_semester, :submit_review]
before_action :set_semester_process_volunteer, only: [:show, :edit, :update] before_action :set_semester_process_volunteer, only: [:show, :edit, :update]
before_action :set_semester, only: [:index] before_action :set_semester, only: [:index]
...@@ -21,15 +20,12 @@ class SemesterProcessVolunteersController < ApplicationController ...@@ -21,15 +20,12 @@ class SemesterProcessVolunteersController < ApplicationController
@feedbacks.each(&:save!) @feedbacks.each(&:save!)
@hours.each(&:save!) @hours.each(&:save!)
end end
redirect_to(
review_semester_semester_process_volunteer_path(@semester_process_volunteer), redirect_to review_semester_semester_process_volunteer_path(@semester_process_volunteer), notice: t('.success')
notice: 'Successfully reviewed.'
)
rescue ActiveRecord::RecordInvalid => exception rescue ActiveRecord::RecordInvalid => exception
puts "ERROR!"
puts exception.message
null_reviewed null_reviewed
render :review_semester, notice: exception.message, errors: exception.message render :review_semester
end end
def index def index
...@@ -54,25 +50,31 @@ class SemesterProcessVolunteersController < ApplicationController ...@@ -54,25 +50,31 @@ class SemesterProcessVolunteersController < ApplicationController
def build_nested_objects def build_nested_objects
@feedbacks, @hours = [], [] @feedbacks, @hours = [], []
review_params[:semester_feedbacks_attributes].each do |_i, hash| review_params[:semester_feedbacks_attributes].each do |_key, hash|
@feedbacks << SemesterFeedback.new(hash[:semester_feedback] @feedbacks << SemesterFeedback.new(hash[:semester_feedback]
.merge({ author: current_user, semester_process_volunteer: @semester_process_volunteer })) .merge({ author: current_user, semester_process_volunteer: @semester_process_volunteer }))
@hours << Hour.new(hash[:hour]) if hash[:hour][:hours]&.to_i.positive?
spv_mission = SemesterProcessVolunteerMission.find(hash[:hour][:spv_mission_id])
@hours << Hour.new(hash[:hour].merge({
hourable: spv_mission.mission.group_assignment? ? spv_mission.mission.group_offer : spv_mission.mission,
volunteer: spv_mission.volunteer,
meeting_date: Time.zone.now,
semester_process_volunteer: @semester_process_volunteer
}))
end
end end
end end
def prepare_review def prepare_review
# 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 authorize @semester_process_volunteer
@volunteer = @semester_process_volunteer.volunteer @volunteer = @semester_process_volunteer.volunteer
@missions = @semester_process_volunteer.missions @missions = @semester_process_volunteer.missions
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: [:id ,:waive, :iban, :bank],
semester_feedbacks_attributes: [[semester_feedback: [:mission, :goals, :achievements, :future, :comments, :conversation, :spv_mission_id]], semester_feedbacks_attributes: [[semester_feedback: [:mission, :goals, :achievements, :future, :comments, :conversation, :spv_mission_id]],
[hour: [:hours, :spv_mission_id ]]]) [hour: [:hours, :spv_mission_id ]]])
end end
......
module SemesterProcessVolunteerHelper module SemesterProcessVolunteerHelper
def initialize_feedback
@feedback = SemesterFeedback.new(mission: @mission, semester_process_volunteer: @semester_process_volunteer,
author: current_user)
end
def set_reviewed def set_reviewed
@semester_process_volunteer.commited_by = current_user @semester_process_volunteer.commited_by = current_user
......
...@@ -44,7 +44,7 @@ class SemesterProcessVolunteer < ApplicationRecord ...@@ -44,7 +44,7 @@ class SemesterProcessVolunteer < ApplicationRecord
} }
def semester_feedback_with_mission(mission) def semester_feedback_with_mission(mission)
self.semester_feedbacks.select{|sf| sf.mission == mission}.last self.semester_feedbacks.order(:created_at).select{|sf| sf.mission == mission}.last
end end
# will only return an array, not a AD-result # will only return an array, not a AD-result
......
class SemesterProcessVolunteerMission < ApplicationRecord class SemesterProcessVolunteerMission < ApplicationRecord
include MissionEitherOneRelation include MissionEitherOneRelation
delegate :volunteer, to: :semester_process_volunteer
belongs_to :semester_process_volunteer belongs_to :semester_process_volunteer
attr_accessor :hour attr_accessor :hour
......
...@@ -192,6 +192,8 @@ de: ...@@ -192,6 +192,8 @@ de:
semester_process_volunteers: semester_process_volunteers:
show: show:
title: 'Semester Prozess %{semester} von %{name}' title: 'Semester Prozess %{semester} von %{name}'
submit_review:
success: Erfolgreich überprüft
salutation: &id-salutations salutation: &id-salutations
all: Alle all: Alle
family: Familie family: Familie
......
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