Commit 8d231538 authored by Chrysanthi Lagodimou's avatar Chrysanthi Lagodimou

Merge branch 'features/editable-semester-process' into 'develop'

Features/editable semester process

See merge request !851
parents c3720adb aec79283
Pipeline #31181 failed with stage
in 76 minutes and 22 seconds
......@@ -38,8 +38,9 @@ class SemesterProcessVolunteersController < ApplicationController
def index
authorize SemesterProcessVolunteer
@q = SemesterProcessVolunteer.index(Semester.parse(params[:semester])).ransack(params[:q])
semester = Semester.parse(params[:semester])
@semester_process = SemesterProcess.find_by_semester(semester).last
@q = SemesterProcessVolunteer.index(semester).ransack(params[:q])
@q.sorts = ['volunteer_contact_last_name asc'] if @q.sorts.empty?
@spvs = @q.result.paginate(page: params[:page])
set_responsibles
......
......@@ -11,9 +11,32 @@ class SemesterProcessesController < ApplicationController
def new
@semester_process = SemesterProcess.new(semester: @selected_semester)
@semester_process.build_semester_volunteers(@volunteers)
new_or_edit
end
def edit
new_or_edit
end
def create
@semester_process = SemesterProcess.new(semester_process_params.slice(:semester))
update_or_create
end
def update
update_or_create
end
private
def new_or_edit
authorize @semester_process
@spvs_sorted = @semester_process.semester_process_volunteers.sort { |spv1, spv2| spv1.volunteer.contact.full_name <=> spv2.volunteer.contact.full_name}
@volunteers = Volunteer.semester_process_eligible(@semester_process.semester)
@semester_process.build_semester_volunteers(@volunteers, nil, false)
@spvs_sorted = @semester_process.new_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])
......@@ -24,19 +47,17 @@ class SemesterProcessesController < ApplicationController
end
end
def edit; end
def create
@semester_process = SemesterProcess.new(semester_process_params.slice(:semester))
@semester_process.creator = current_user
def update_or_create
authorize @semester_process
@semester_process.creator = current_user
@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)
@volunteers = Volunteer.semester_process_eligible(@semester_process.semester)
@semester_process.build_semester_volunteers(@volunteers, selected_volunteers, true)
@semester_process.build_volunteers_hours_feedbacks_and_mails
if @semester_process.save
......@@ -46,16 +67,6 @@ class SemesterProcessesController < ApplicationController
end
end
def update
if @semester_process.update(semester_process_params)
redirect_to @semester_process, notice: 'Semester process was successfully updated.'
else
render :edit
end
end
private
def set_semester_process
@semester_process = SemesterProcess.find(params[:id])
authorize @semester_process
......@@ -69,9 +80,6 @@ class SemesterProcessesController < ApplicationController
@selected_semester = @semester.previous
params[:semester] = Semester.to_s(@selected_semester)
end
semester_form_param = Semester.parse(params[:semester_process]&.fetch(:semester))
@volunteers = Volunteer.semester_process_eligible(semester_form_param || @selected_semester)
end
def selected_volunteers
......
......@@ -16,6 +16,12 @@ class SemesterProcess < ApplicationRecord
has_many :semester_process_mails, through: :semester_process_volunteers
attr_accessor :new_semester_process_volunteers
scope :find_by_semester, lambda { |semester = nil|
where('semester && daterange(?,?)', semester.begin, semester.end)
}
def mails
semester_process_mails.where(kind: 'mail')
end
......@@ -68,16 +74,19 @@ class SemesterProcess < ApplicationRecord
Semester.period(semester)
end
def build_semester_volunteers(volunteers, selected = nil)
volunteers = volunteers.select{ |volunteer| selected.include? volunteer.id } if selected && selected.any?
semester_process_volunteers << volunteers.to_a.map do |volunteer|
spv = SemesterProcessVolunteer.new(volunteer: volunteer, selected: false)
def build_semester_volunteers(volunteers, selected, save_record = true)
volunteers = volunteers.select{ |volunteer| selected.include? volunteer.id } if selected && selected.any?
@new_semester_process_volunteers = []
@new_semester_process_volunteers = volunteers.to_a.map do |volunteer|
spv = SemesterProcessVolunteer.new(volunteer: volunteer, semester_process: self, selected: false)
spv.build_missions(semester)
spv.save if save_record
spv
end
end
def build_volunteers_hours_feedbacks_and_mails
semester_process_volunteers.map(&:build_hours_and_mails)
@new_semester_process_volunteers.map(&:build_hours_and_mails)
end
end
......@@ -4,6 +4,9 @@ nav.navbar.section-navigation
li= clear_filter_button
li= button_link 'Neuen Semester Prozess erstellen', new_semester_process_path, dimension: 'sm'
li= render 'semester_filter'
- if @semester_process
li= button_link 'Semester Prozess bearbeiten', edit_semester_process_path(@semester_process), dimension: 'sm'
= custom_filter_dropdown('Übernommen',
{ q: :responsible_id_null, text: 'Offen', value: 'true' },
{ q: :responsible_id_not_null, text: 'Übernommen', value: 'true' },
......
......@@ -3,7 +3,8 @@
= 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' }
= f.input :semester, collection: @semester&.collection || [Semester.i18n_t(@semester_process.semester, short: false)],
selected: params[:semester], input_html: { class: 'semester-selector' }, disabled: !@semester
.row
.col-xs-12.col-md-4
......
......@@ -2,5 +2,4 @@ h1= t_title(:edit)
= render 'form'
= form_navigation_btn :show
= form_navigation_btn :back
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