Commit 078dfa0f authored by Jiri Strojil's avatar Jiri Strojil
Browse files

Added new semester process form

parent 18ce0850
Pipeline #28926 passed with stage
in 58 minutes and 21 seconds
......@@ -13,6 +13,14 @@ class SemesterProcessesController < ApplicationController
@semester_process = SemesterProcess.new(semester: @selected_semester)
@semester_process.build_semester_volunteers(@volunteers)
authorize @semester_process
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])
else
redirect_to new_email_template_path,
notice: 'Sie müssen eine aktive E-Mailvorlage haben,
bevor Sie eine Halbjahres Erinnerung erstellen können.'
end
end
def edit; end
......@@ -22,6 +30,11 @@ class SemesterProcessesController < ApplicationController
@semester_process.creator = current_user
authorize @semester_process
@semester_process.assign_attributes(
mail_body_template: semester_process_params[:body],
mail_subject_template: semester_process_params[:subject]
)
@semester_process.build_semester_volunteers(@volunteers, selected_volunteers)
@semester_process.build_volunteers_hours_feedbacks_and_mails
......@@ -69,6 +82,9 @@ class SemesterProcessesController < ApplicationController
def semester_process_params
params.require(:semester_process).permit(
:semester,
:kind,
:subject,
:body,
semester_process_volunteers_attributes: [
:volunteer_id, :selected
]
......
class EmailTemplate < ApplicationRecord
before_save :ensure_exactly_one_active_per_kind
enum kind: { signup: 0, trial: 1, half_year: 3, termination: 2 }
enum kind: { signup: 0, trial: 1, half_year: 3, termination: 2, half_year_process_email: 4, half_year_process_overdue: 5 }
validates :kind, presence: true
scope :order_by_active, -> { order(active: :desc) }
......@@ -33,7 +33,9 @@ class EmailTemplate < ApplicationRecord
assignment: [:Anrede, :Name, :EinsatzTitel, :FeedbackLink],
trial: ReminderMailing::TEMPLATE_VARNAMES,
half_year: ReminderMailing::TEMPLATE_VARNAMES,
termination: ReminderMailing::TEMPLATE_VARNAMES
termination: ReminderMailing::TEMPLATE_VARNAMES,
half_year_process_email: ReminderMailing::TEMPLATE_VARNAMES + [:Semester],
half_year_process_overdue: ReminderMailing::TEMPLATE_VARNAMES + [:Semester]
}
end
......
......@@ -25,7 +25,7 @@ class ReminderMailing < ApplicationRecord
source_type: 'GroupAssignment'
has_many :process_submitters, through: :reminder_mailing_volunteers, source: :process_submitted_by
enum kind: { half_year: 0, trial_period: 1, termination: 2 }
enum kind: { half_year: 0, trial_period: 1, termination: 2, half_year_process_email: 3, half_year_process_overdue: 4 }
ransacker :kind, formatter: ->(value) { kinds[value] }
validates :subject, presence: true
......
......@@ -24,6 +24,30 @@ class SemesterProcess < ApplicationRecord
semester_process_mails.where(kind: 'reminder')
end
def mail?
self.mail_subject_template && self.mail_body_template
end
def reminder?
self.reminder_mail_subject_template && self.reminder_mail_body_template
end
def kind
if self.mail?
return :mail
elsif self.reminder?
return :reminder
end
end
def subject
self.mail_subject_template || self.reminder_mail_subject_template
end
def body
self.mail_body_template || self.reminder_mail_body_template
end
# will only return an array, not a AD-result
delegate :missions, to: :semester_process_volunteers
......
......@@ -6,4 +6,73 @@ class SemesterProcessMail < ApplicationRecord
scope :mail, -> { where(kind: 'mail') }
scope :reminder, -> { where(kind: 'reminder') }
delegate :volunteer, to: :semester_process_volunteer
delegate :semester_process, to: :semester_process_volunteer
def self.template_varnames
{
mail: EmailTemplate::template_varnames[:half_year_process_email],
reminder: EmailTemplate::template_varnames[:half_year_process_overdue]
}
end
def process_template
{
subject: replace_ruby_template(self.subject),
body: replace_ruby_template(self.body)
}
end
def replace_ruby_template(template)
template % template_variables
end
def template_variables
template_variables = SemesterProcessMail::template_varnames[self.kind.to_sym].map do |varname|
[varname, send(varname.to_s.underscore)]
end.to_h
template_variables.default = ''
template_variables
end
def anrede
I18n.t("salutation.#{volunteer.salutation}")
end
def name
volunteer.contact.natural_name
end
def semester
"#{ 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
def email_absender
"[#{reminder_mailing_creator_name}](mailto:"\
"#{semester_process.creator.email})"
end
def reminder_mailing_creator_name
semester_process.creator.profile&.contact&.natural_name ||
semester_process.creator.email
end
def feedback_link
"[Halbjahres-Rapport erstellen](#{feedback_url})"
end
def feedback_url(options = {})
''
end
end
......@@ -57,6 +57,8 @@ class SemesterProcessVolunteer < ApplicationRecord
missions.each do |mission|
hours << mission.hours.date_between_inclusion(:meeting_date, semester.begin, semester.end)
end
semester_process_mails << SemesterProcessMail.new(kind: :mail, sent_by: creator)
semester_process_mails << SemesterProcessMail.new(kind: :mail, sent_by: creator,
subject: semester_process.mail_subject_template,
body: semester_process.mail_body_template)
end
end
......@@ -9,4 +9,4 @@ fieldset
'Text
abbr title="notwendig"
' *
= f.input :body, label_html: { class: 'sr-only' }
= f.input :body, as: :text, label_html: { class: 'sr-only' }, input_html: { class: 'text-bg-body' }
......@@ -13,6 +13,4 @@ nav.navbar.section-navigation
- (0..11).to_a.reverse.map { |count| Time.zone.today.months_ago(count).beginning_of_month }.each do |date|
li class=('bg-success' if pre_selected == date)
= link_to "#{I18n.t('date.month_names')[date.month]} #{date.year}", new_half_year_reminder_mailings_path(submitted_since: date)
= render 'form'
= simple_form_for(@semester_process, html: { class: 'form-ignore-changes' }) do |f|
= simple_error_notice f
= f.input_field :kind, value: @semester_process.kind, as: :hidden
.row:.col-xs-12.col-md-4
= f.input :semester, collection: @semester.collection, selected: params[:semester], input_html: { class: 'semester-selector' }
.row
.col-xs-12.col-md-4
= render 'email_templates/explain_panel', template_varnames: SemesterProcessMail::template_varnames[:mail]
.col-xs-12.col-md-8
= render 'email_templates/subject_body_inputs', f: f
fieldset
legend Freiwillige auswählen
.table-responsive.table-scrollable
......
......@@ -69,6 +69,8 @@ de:
trial: Probezeit
half_year: Halbjährlich
termination: Beendigung
half_year_process_email: 'Half year process email'
half_year_process_overdue: 'Half year process overdue'
index:
<<: *id-kinds-template
show:
......
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