From 290f9665cf22ce8550d0d85a357462e606428b2b Mon Sep 17 00:00:00 2001 From: Andreas Maierhofer Date: Wed, 27 Mar 2024 11:29:06 +0100 Subject: [PATCH] Reload trainings form when event kind changes (#262) --- .../external_trainings_controller.rb | 4 ++++ .../_event_kind_field_with_info.html.haml | 11 +++++++++++ app/views/external_trainings/_form.html.haml | 8 ++++++-- .../_qualification_infos.html.haml | 0 spec/features/external_training_model_spec.rb | 18 +++++++++++++++++- 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 app/views/external_trainings/_event_kind_field_with_info.html.haml create mode 100644 app/views/external_trainings/_qualification_infos.html.haml diff --git a/app/controllers/external_trainings_controller.rb b/app/controllers/external_trainings_controller.rb index ca8f1e45e..b16d29a28 100644 --- a/app/controllers/external_trainings_controller.rb +++ b/app/controllers/external_trainings_controller.rb @@ -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)) @@ -36,4 +37,7 @@ def build_entry @person.external_trainings.build end + def load_event_kinds + @event_kinds ||= Event::Kind.list + end end diff --git a/app/views/external_trainings/_event_kind_field_with_info.html.haml b/app/views/external_trainings/_event_kind_field_with_info.html.haml new file mode 100644 index 000000000..de7def51d --- /dev/null +++ b/app/views/external_trainings/_event_kind_field_with_info.html.haml @@ -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: 'element#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 diff --git a/app/views/external_trainings/_form.html.haml b/app/views/external_trainings/_form.html.haml index 301bb865d..92735a4bb 100644 --- a/app/views/external_trainings/_form.html.haml +++ b/app/views/external_trainings/_form.html.haml @@ -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: :element }) 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 diff --git a/app/views/external_trainings/_qualification_infos.html.haml b/app/views/external_trainings/_qualification_infos.html.haml new file mode 100644 index 000000000..e69de29bb diff --git a/spec/features/external_training_model_spec.rb b/spec/features/external_training_model_spec.rb index f253600ca..13d6b5c5e 100644 --- a/spec/features/external_training_model_spec.rb +++ b/spec/features/external_training_model_spec.rb @@ -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