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

Fix conflict

parent ed9f8bd0
......@@ -32,6 +32,7 @@ class SemesterProcessVolunteersController < ApplicationController
authorize SemesterProcessVolunteer
@spvs = SemesterProcessVolunteer.index(Semester.parse(params[:semester])).page(params[:page])
@spvs_sorted = @spvs.sort { |spv1, spv2| spv1.volunteer.contact.full_name <=> spv2.volunteer.contact.full_name}
end
def show; end
......@@ -76,6 +77,7 @@ class SemesterProcessVolunteersController < ApplicationController
volunteer_attributes: [:id ,:waive, :iban, :bank],
semester_feedbacks_attributes: [[semester_feedback: [:mission, :goals, :achievements, :future, :comments, :conversation, :spv_mission_id]],
[hour: [:hours, :spv_mission_id ]]])
end
def set_semester_process_volunteer
......
......@@ -13,6 +13,7 @@ class SemesterProcessesController < ApplicationController
@semester_process = SemesterProcess.new(semester: @selected_semester)
@semester_process.build_semester_volunteers(@volunteers)
authorize @semester_process
@spvs_sorted = @semester_process.semester_process_volunteers.sort { |spv1, spv2| spv1.volunteer.contact.full_name <=> spv2.volunteer.contact.full_name}
if EmailTemplate.half_year_process_email.active.any?
template = EmailTemplate.half_year_process_email.active.first.slice(:subject, :body)
@semester_process.assign_attributes(mail_body_template: template[:body], mail_subject_template: template[:subject])
......@@ -35,11 +36,11 @@ class SemesterProcessesController < ApplicationController
mail_subject_template: semester_process_params[:subject]
)
@semester_process.build_semester_volunteers(@volunteers, selected_volunteers)
@semester_process.build_semester_volunteers(@volunteers, selected_volunteers: selected_volunteers)
@semester_process.build_volunteers_hours_feedbacks_and_mails
if @semester_process.save
redirect_to semester_process_volunteers_path, notice: 'Semester process was successfully created.'
redirect_to semester_process_volunteers_path, notice: 'Semester process was successfully created and emails delivered.'
else
render :new
end
......
......@@ -37,4 +37,10 @@ class VolunteerMailer < ApplicationMailer
reminder_mailing_volunteer.update(email_sent: true)
mail(to: @volunteer.contact.primary_email, subject: @subject)
end
def half_year_process_email(semester_process_mail)
@volunteer = semester_process_mail.volunteer
@subject, @body = semester_process_mail.process_template.values_at(:subject, :body)
mail(to: @volunteer.contact.primary_email, subject: @subject)
end
end
......@@ -34,8 +34,8 @@ class EmailTemplate < ApplicationRecord
trial: ReminderMailing::TEMPLATE_VARNAMES,
half_year: ReminderMailing::TEMPLATE_VARNAMES,
termination: ReminderMailing::TEMPLATE_VARNAMES,
half_year_process_email: ReminderMailing::TEMPLATE_VARNAMES + [:Semester],
half_year_process_overdue: ReminderMailing::TEMPLATE_VARNAMES + [:Semester]
half_year_process_email: SemesterProcessMail.template_varnames[:mail],
half_year_process_overdue: SemesterProcessMail.template_varnames[:reminder]
}
end
......
......@@ -7,7 +7,8 @@ class ReminderMailing < ApplicationRecord
:Einsatz,
:EinsatzStart,
:FeedbackLink,
:EmailAbsender
:EmailAbsender,
:OnlinePlattformUrl
].freeze
belongs_to :creator, -> { with_deleted }, class_name: 'User', inverse_of: 'reminder_mailings'
......
......@@ -121,4 +121,8 @@ class ReminderMailingVolunteer < ApplicationRecord
def feedback_link
"[Halbjahres-Rapport erstellen](#{feedback_url})"
end
def online_plattform_url
"[Online-Plattform Url](#{Rails.application.routes.url_helpers.root_path})"
end
end
......@@ -64,10 +64,14 @@ class SemesterProcess < ApplicationRecord
Semester.i18n_t(semester, short: short)
end
def semester_period
Semester.period(semester)
end
def build_semester_volunteers(volunteers, selected = nil)
volunteers = volunteers.where(id: selected) if selected
semester_process_volunteers << volunteers.to_a.map do |volunteer|
spv = SemesterProcessVolunteer.new(volunteer: volunteer, selected: true)
spv = SemesterProcessVolunteer.new(volunteer: volunteer, selected: false)
spv.build_missions(semester)
spv
end
......
......@@ -2,6 +2,8 @@ class SemesterProcessMail < ApplicationRecord
belongs_to :semester_process_volunteer
belongs_to :sent_by, class_name: 'User', inverse_of: 'semester_process_mails'
after_create :send_email
enum kind: { mail: 0, reminder: 1 }
scope :mail, -> { where(kind: 'mail') }
......@@ -10,10 +12,21 @@ class SemesterProcessMail < ApplicationRecord
delegate :volunteer, to: :semester_process_volunteer
delegate :semester_process, to: :semester_process_volunteer
TEMPLATE_VARNAMES = [
:Anrede,
:Name,
:Einsatz,
:FeedbackLink,
:EmailAbsender,
:Semester,
:OnlinePlattformUrl
].freeze
def self.template_varnames
{
mail: EmailTemplate::template_varnames[:half_year_process_email],
reminder: EmailTemplate::template_varnames[:half_year_process_overdue]
mail: TEMPLATE_VARNAMES,
reminder: TEMPLATE_VARNAMES
}
end
......@@ -48,11 +61,6 @@ class SemesterProcessMail < ApplicationRecord
"#{ I18n.l(semester_process.semester.begin)} - #{I18n.l(semester_process.semester.end)}"
end
def einsatz_start
#I18n.l(reminder_mailable.period_start) if reminder_mailable.period_start
''
end
def einsatz
''
end
......@@ -72,7 +80,22 @@ class SemesterProcessMail < ApplicationRecord
end
def feedback_url(options = {})
''
action = :review_semester
path = semester_process_volunteer
Rails.application.routes.url_helpers.polymorphic_url(
path,
ActionMailer::Base.default_url_options.merge(action: action)
)
end
def online_plattform_url
"[Online-Plattform Url](#{Rails.application.routes.url_helpers.root_path})"
end
private
def send_email
VolunteerMailer.half_year_process_email(self).deliver
self.update(sent_at: Time.zone.now)
end
end
......@@ -5,6 +5,7 @@ class SemesterProcessVolunteer < ApplicationRecord
belongs_to :semester_process
delegate :semester, to: :semester_process
delegate :semester_t, to: :semester_process
delegate :semester_period, to: :semester_process
delegate :creator, to: :semester_process
belongs_to :responsible, -> { with_deleted }, class_name: 'User',
......@@ -43,6 +44,7 @@ class SemesterProcessVolunteer < ApplicationRecord
end
}
def semester_feedback_with_mission(mission)
self.semester_feedbacks.order(:created_at).select{|sf| sf.mission == mission}.last
end
......
......@@ -172,21 +172,18 @@ class Volunteer < ApplicationRecord
.where('assignments.period_start IS NOT NULL OR group_assignments.period_start IS NOT NULL')
}
scope :active_semester_mission, lambda { |semester|
have_mission.where(
'assignments.period_start < :prob OR group_assignments.period_start < :prob',
prob: semester.end.advance(weeks: -4)
).where(
'(assignments.period_end IS NULL OR group_assignments.period_end IS NULL) OR '\
'(assignments.period_end > :begin OR group_assignments.period_end > :begin)',
begin: semester.begin
)
}
def self.semester_process_eligible(semester)
joins(:contact).where.not(id: have_semester_process(semester).ids)
.active_semester_mission(semester)
.group('volunteers.id')
end
def unsubmitted_semester_feedbacks
semester_process_volunteers.where(commited_at: nil)
end
def unsubmitted_semester_feedbacks?
return false if unsubmitted_semester_feedbacks.blank?
true
end
## Activness Scopes
......@@ -239,6 +236,18 @@ class Volunteer < ApplicationRecord
scope :need_refunds, (-> { where(waive: false) })
def self.active_semester_mission(semester)
volunteers = Volunteer.have_mission
prob = semester.end.advance(weeks: -4)
sem_start = semester.begin
vol_with_missions = volunteers.select do |v|
[v.assignments, v.group_assignments].detect do |mission|
mission.where("period_start < ?", prob).where("period_end > ? OR period_end IS NULL", sem_start).any?
end
end
vol_with_missions
end
def self.with_billable_hours(date = nil)
date = billable_semester_date(date)
need_refunds.left_joins(:contact, :hours, :billing_expenses)
......
......@@ -8,8 +8,8 @@ class SemesterProcessVolunteerPolicy < ApplicationPolicy
# Actions
alias_method :index?, :superadmin?
alias_method :review_semester?, :superadmin?
alias_method :submit_review?, :superadmin?
alias_method :review_semester?, :superadmin_or_volunteer_related?
alias_method :submit_review?, :superadmin_or_volunteer_related?
alias_method :new?, :superadmin?
alias_method :show?, :superadmin?
alias_method :edit?, :superadmin?
......
......@@ -60,6 +60,10 @@ class Semester
end
end
def period(semester)
I18n.t(:semester_period, begin: I18n.l(semester.begin.to_date), end: I18n.l(semester.end.to_date))
end
def semester_start_time(date_time)
date_time = date_time.to_date
if (6..11).cover?(date_time.month)
......
- if current_user.volunteer? && current_user.volunteer.unsubmitted_semester_feedbacks?
- current_user.volunteer.unsubmitted_semester_feedbacks.each do |spv|
- message = 'Sie haben einen ausstehenden Halbjahres-Rapport für dieses Semester.'
- message << "<a href='#{review_semester_semester_process_volunteer_path(spv)}'>Bitte klicken Sie hier um diesen zu bestätigen.</a>".html_safe
= notification_warning_bubble(message)
= render 'unsubmitted_semester_feedback_notification'
......@@ -2,4 +2,5 @@ nav.navbar.section-navigation
hr
ul.list-inline
li= button_link 'Neuen Semester Prozess erstellen', new_semester_process_path, dimension: 'sm'
li= render 'semester_filter'
hr
.btn-group
button.btn.btn-default.dropdown-toggle type='button' data-toggle='dropdown' aria-label="Semester" aria-haspopup='true' aria-expanded='false' class="btn-md"
= "Semester: "
= params[:semester] || @semester
= ' '
span.caret aria-hidden='true'
ul.dropdown-menu
li
-@semester.collection.each do |name, semester_code|
li= link_to name[0..15], semester_process_volunteers_path(semester: semester_code)
......@@ -9,27 +9,28 @@ h1= t_title(:index)
thead
tr
th.hidden-print Aktionen
th= t_attr(:full_name, Volunteer)
th= t_attr(:semester)
th Status
th Freiwilige/r
th Einsätze
th Missions
th= t_attr(:commited_by)
th= t_attr(:commited_at)
th= t_attr(:creator)
th= t_attr(:created_at)
th Letzte Bestätigung
tbody
- @spvs.each do |spv|
- @spvs_sorted.each do |spv|
tr
td.index-action-cell.hidden-print
= link_to t_action(:show), spv
= link_to t_action(:edit), edit_semester_process_volunteer_path(spv)
= button_link icon_span(:edit), review_semester_semester_process_volunteer_path(spv), title: 'Bearbeiten'
td
- if spv.commited_at.present?
.label.label-success Bestätigt
- else
.label.label-warning Unbestätigt
td= link_to_if policy(Volunteer).edit?, spv.volunteer.contact.full_name, edit_volunteer_path(spv.volunteer)
td= spv.semester_t
td= render_missions(spv)
td= spv.commited_by
td= spv.commited_at && l(spv.commited_at)
td= spv.creator
td= l(spv.created_at)
= bootstrap_paginate(@spvs)
......
......@@ -27,6 +27,7 @@
.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
= f.simple_fields_for :volunteer, @volunteer do |vf|
.row.text-left#volunteer-update-waive-and-iban
......
......@@ -16,12 +16,12 @@
.table-responsive.table-scrollable
table.table.table-striped
thead:tr
th
th Name
th.limit-width= select_all_rows
th Freiwilliger/r
th Einsatz
tbody
= f.simple_fields_for :semester_process_volunteers do |fv|
tr
= f.simple_fields_for :semester_process_volunteers, @spvs_sorted do |fv|
tr.table-row-selectable
td= fv.input :selected, as: :boolean, label: false
td= link_to fv.object.volunteer.contact.full_name, fv.object.volunteer
td.index-action-cell
......
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