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

Basic fnc done

parent be681047
......@@ -171,3 +171,7 @@ h5.small {
.fixed-width-lg {
width: 600px;
}
.float-right {
float: right;
}
class SemesterProcessVolunteersController < ApplicationController
before_action :skip_authorization #TODO add auth
before_action :set_mission, only: [:show, :edit, :update, :destroy, :review_semester, :submit_review]
before_action :initialize_feedback, only: [:review_semester, :submit_review]
include SemesterProcessVolunteerHelper
def review_semester
@volunteer = @semester_process_volunteer.volunteer
@hour = Hour.new
end
def submit_review
@volunteer = @semester_process_volunteer.volunteer
assign_reviewed_attributes
set_reviewed
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
redirect_to(
review_semester_semester_process_volunteer_path(@semester_process_volunteer),
notice: 'Successfully reviewed.'
)
rescue ActiveRecord::RecordInvalid => exception
null_reviewed
render :review_semester, notice: exception
end
end
private
def set_mission
# careful cuz mission id can be present in both missions
@semester_process_volunteer = SemesterProcessVolunteer.find(params[:id])
@mission = @semester_process_volunteer.missions.first
# TODO auths
end
def review_params
params.require(:semester_process_volunteer).permit(
volunteer_attributes: [:waive, :iban, :bank],
semester_feedback: [:goals, :achievements, :future, :comments, :conversation],
hour: [:hours])
end
end
module SemesterProcessVolunteerHelper
def initialize_feedback
@feedback = SemesterFeedback.new(mission: @mission, semester_process_volunteer: @semester_process_volunteer,
author: current_user)
end
def set_reviewed
@semester_process_volunteer.reviewed_by = current_user
@semester_process_volunteer.reviewed_at = Time.zone.now
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
@semester_process_volunteer.reviewed_by = nil
@semester_process_volunteer.reviewed_at = nil
end
end
......@@ -26,6 +26,10 @@ 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
validates_associated :hours, :semester_feedbacks, :volunteer
# will only return an array, not a AD-result
def missions
semester_process_volunteer_missions.map(&:mission)
......
......@@ -82,6 +82,7 @@ class Volunteer < ApplicationRecord
#
validates :contact, presence: true
validates_presence_of :iban, :bank, unless: :waive?
validates :salutation, presence: true
validates_attachment :avatar, content_type: {
content_type: /\Aimage\/.*\z/
......
class SemesterProcessVolunteerPolicy < ApplicationPolicy
class Scope < ApplicationScope
def resolve
return all if superadmin?
none
end
end
# Actions
alias_method :index?, :superadmin?
alias_method :review_semester?, :superadmin?
alias_method :new?, :superadmin?
alias_method :show?, :superadmin?
alias_method :edit?, :superadmin?
alias_method :create?, :superadmin?
alias_method :update?, :superadmin?
alias_method :destroy?, :superadmin?
end
= simple_form_for(@semester_process_volunteer, html: { class: 'col-xs-12 '},
url: submit_review_semester_process_volunteer_path(@semester_process_volunteer)) do |f|
= simple_error_notice f
h1 Zuletzt übermittelte Stunden und Halbjahres-Rapporte
h2.m-b-20.m-t-30
'Einsatz
= link_to @mission.to_label, polymorphic_path([@mission.volunteer, @mission.polymorph_url_object]), target: '_blank'
h3 Halbjahres-Rapporte
= f.simple_fields_for @feedback do |ff|
- [:goals, :achievements, :future, :comments, :conversation].each do |field|
.row
.col-xs-12= ff.input field
h3 Stunden
= render 'hours/last_submitted_hours', hours: @semester_process_volunteer.hours
= f.simple_fields_for :hour, @hour do |hf|
.row
.col-xs-2.float-right= hf.input :hours, required: false, input_html: { value: f.object.hours == 0 ? '' : f.object.hours}
h3 Spesen
= f.simple_fields_for :volunteer, @volunteer do |vf|
.row.text-left#volunteer-update-waive-and-iban
.col-xs-12
= vf.input_field :id, type: :hidden
= checkbox_toggle_collapse(vf, :waive, '#not-waive-expenses', check_shows: false)
.col-xs-12#not-waive-expenses
.row
.col-xs-4= vf.input :iban
.col-xs-4= vf.input :bank
.submit-box
.col-xs-12
p Ich bestätige, dass ich alle meine Stunden und Halbjahres-Rapporte bis zum heutigen Datum erfasst habe.
- if @semester_process_volunteer.reviewed_at.present?
p.text-danger Bestätigt am #{l(@semester_process_volunteer.reviewed_at.to_date)} durch #{profile_link(@semester_process_volunteer.reviewed_by)}
- else
= f.submit 'Bestätigen', class: 'btn btn-lg-accepted'
......@@ -97,6 +97,10 @@ Rails.application.routes.draw do
end
resources :semester_processes
resources :semester_process_volunteers do
get :review_semester, on: :member
patch :submit_review, on: :member
end
resources :volunteer_applications, only: [:new, :create] do
get :thanks, on: :collection
......
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