Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
aoz-003
Commits
078dfa0f
Commit
078dfa0f
authored
Oct 17, 2018
by
Jiri Strojil
Browse files
Added new semester process form
parent
18ce0850
Pipeline
#28926
passed with stage
in 58 minutes and 21 seconds
Changes
10
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/controllers/semester_processes_controller.rb
View file @
078dfa0f
...
...
@@ -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
]
...
...
app/models/email_template.rb
View file @
078dfa0f
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
...
...
app/models/reminder_mailing.rb
View file @
078dfa0f
...
...
@@ -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
...
...
app/models/semester_process.rb
View file @
078dfa0f
...
...
@@ -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
...
...
app/models/semester_process_mail.rb
View file @
078dfa0f
...
...
@@ -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
app/models/semester_process_volunteer.rb
View file @
078dfa0f
...
...
@@ -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
app/views/email_templates/_subject_body_inputs.html.slim
View file @
078dfa0f
...
...
@@ -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'
}
app/views/reminder_mailings/new_half_year.html.slim
View file @
078dfa0f
...
...
@@ -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'
app/views/semester_processes/_form.html.slim
View file @
078dfa0f
=
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
...
...
config/locales/de.yml
View file @
078dfa0f
...
...
@@ -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
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment