Skip to content

Commit

Permalink
Reload trainings form when event kind changes (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
amaierhofer committed Mar 28, 2024
1 parent 4a6b9be commit c08b885
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/controllers/external_trainings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ExternalTrainingsController < CrudController

# load parents before authorization
prepend_before_action :parent
before_render_form :load_event_kinds

def create
super(location: history_group_person_path(@group, @person))
Expand All @@ -36,4 +37,7 @@ def build_entry
@person.external_trainings.build
end

def load_event_kinds
@event_kinds ||= Event::Kind.list
end
end
11 changes: 11 additions & 0 deletions app/views/external_trainings/_event_kind_field_with_info.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- id = :event_kind_turbo_frame
- form_action = new_group_person_external_training_path(@group, @person)
- prolonging_qualis = entry.kind&.qualification_kinds(%w(qualification prolongation), 'participant')

= turbo_frame_tag(id) do
= f.labeled_input_fields :event_kind_id, data: { action: 'forwarder#click' }
- if entry.kind && entry.qualification_date && prolonging_qualis.present?
%p.col-md-9.offset-md-3.offset-xl-2.mb-2
= entry.kind.decorate.issued_qualifications_info_for_participants(entry.qualification_date)

= render 'shared/hidden_submit', label: 'Load qualification info', formaction: form_action, turbo_frame: id
8 changes: 6 additions & 2 deletions app/views/external_trainings/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
= entry_form(cancel_url: history_group_person_path(@group, @person)) do |f|
= f.labeled_input_fields :event_kind_id, :name, :provider, :start_at, :finish_at, :training_days, :link, :remarks
= entry_form(cancel_url: history_group_person_path(@group, @person), data: { controller: :forwarder }) do |f|
= f.labeled_input_fields :name, :provider
= f.labeled_input_field :start_at
= f.labeled_input_field :finish_at
= render 'event_kind_field_with_info', f: f
= f.labeled_input_fields :training_days, :link, :remarks
Empty file.
18 changes: 17 additions & 1 deletion spec/features/external_training_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,26 @@
fill_in 'Link', with: 'https://wasser.example.com'
fill_in 'Bemerkung', with: 'Bla'
all('button', text: 'Speichern').first.click

expect(page).to have_css('.alert-success', text: "Schwimmkurs wurde erfolgreich erstellt.")

within('#external_trainings') { click_on 'Löschen' }
accept_alert
expect(page).to have_css('.alert-success', text: "Externe Ausbildung Schwimmkurs wurde erfolgreich gelöscht.")
expect(page).to have_css('.alert-success',
text: "Externe Ausbildung Schwimmkurs wurde erfolgreich gelöscht.")
end

it "reloads qualification infos", js: true do
sign_in(admin)
visit history_group_person_path(group_id: mitglieder, id: mitglied)
click_on 'Erstellen'
fill_in 'Name', with: 'Skikurs'
fill_in 'Startdatum', with: '01.03.2024'
fill_in 'Enddatum', with: '06.03.2024'
select 'Dummy', from: 'external_training_event_kind_id'
expect(page).to have_css 'turbo-frame p', text: 'Verlängert existierende Qualifikation ' \
'Ski Leiter unmittelbar per 06.03.2024 (letztes Kursdatum).'
select '(keine)', from: 'external_training_event_kind_id'
expect(page).not_to have_css 'turbo-frame p'
end
end

0 comments on commit c08b885

Please sign in to comment.