diff --git a/app/controllers/advanced_trainings_controller.rb b/app/controllers/advanced_trainings_controller.rb index 0d849f190..2d1485f39 100644 --- a/app/controllers/advanced_trainings_controller.rb +++ b/app/controllers/advanced_trainings_controller.rb @@ -2,5 +2,4 @@ class AdvancedTrainingsController < People::PersonRelationsController self.permitted_attrs = %i[description year_to month_to year_from month_from person_id] - self.nesting = Person end diff --git a/app/controllers/educations_controller.rb b/app/controllers/educations_controller.rb new file mode 100644 index 000000000..42ad28ddd --- /dev/null +++ b/app/controllers/educations_controller.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class EducationsController < People::PersonRelationsController + self.permitted_attrs = %i[location title month_to year_to month_from year_from person_id] +end diff --git a/app/controllers/people/person_relations_controller.rb b/app/controllers/people/person_relations_controller.rb index ce99994e0..75d0c68aa 100644 --- a/app/controllers/people/person_relations_controller.rb +++ b/app/controllers/people/person_relations_controller.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class People::PersonRelationsController < CrudController + self.nesting = Person def index redirect_to person_path(entry.person) @@ -12,9 +13,13 @@ def show def create super do |format, success| - if success && params.key?(:render_new_after_save) - remove_instance_variable(model_ivar_name) - format.turbo_stream { render('save_and_new') } + if success + if params.key?(:render_new_after_save) + remove_instance_variable(model_ivar_name) + format.turbo_stream { render('save_and_new') } + else + format.turbo_stream { render('refresh_after_new') } + end end end end diff --git a/app/views/educations/_education.html.haml b/app/views/educations/_education.html.haml new file mode 100644 index 000000000..6eb262c4c --- /dev/null +++ b/app/views/educations/_education.html.haml @@ -0,0 +1,10 @@ +%div.border-top + %turbo-frame{id: dom_id(education)} + = link_to edit_person_education_path(@person, education), data:{turbo_prefetch: :false}, class: "text-decoration-none text-dark bg-hover-gray d-block" do + %div.d-flex.row.pt-3.pb-5 + %span.col-3.ps-5 + = date_range_label education + %span.col.d-flex.flex-column + %span.fw-bolder + = education.title + = education.location \ No newline at end of file diff --git a/app/views/educations/_form.html.haml b/app/views/educations/_form.html.haml new file mode 100644 index 000000000..9daf46859 --- /dev/null +++ b/app/views/educations/_form.html.haml @@ -0,0 +1,7 @@ += form_with model: ([entry.person, entry]) do |f| + = render('people/person_relations/form', form: f) do + - content_for :input do + = t "activerecord.attributes.education.title" + = f.text_area :title, placeholder: "Description", class: "form-control w-100" + = t "activerecord.attributes.education.location" + = f.text_area :location, placeholder: "Ein Ausbildungsort", class: "form-control w-100" diff --git a/app/views/people/_cv.html.haml b/app/views/people/_cv.html.haml index d8fa55a75..3bc11c833 100644 --- a/app/views/people/_cv.html.haml +++ b/app/views/people/_cv.html.haml @@ -1,3 +1,4 @@ = render('profile') = render('core_competences') -= render('people/person_relations/index', list: @person.advanced_trainings) += render('people/person_relations/index', list: @person.advanced_trainings.list) += render('people/person_relations/index', list: @person.educations.list) diff --git a/app/views/people/person_relations/refresh_after_new.turbo_stream.haml b/app/views/people/person_relations/refresh_after_new.turbo_stream.haml new file mode 100644 index 000000000..9a5022c01 --- /dev/null +++ b/app/views/people/person_relations/refresh_after_new.turbo_stream.haml @@ -0,0 +1,4 @@ += turbo_stream.remove dom_id(entry.class.new) + += turbo_stream.update name_of_obj(entry) do + = render entries diff --git a/config/locales/de.yml b/config/locales/de.yml index 884b31a3a..aeb36d0a0 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -4,12 +4,22 @@ de: cancel: Abbrechen delete: Löschen save-and-new: Speichern & Neu + + attributes: + year_from: Jahr von + year_to: Jahr bis + month_from: Monat von + month_to: Monat bis activerecord: models: advanced_training: Weiterbildung + education: Ausbildung attributes: advanced_training: description: Beschreibung + education: + title: Ausbildung + location: Ausbildungsort skills: table: skill: Skill diff --git a/config/routes.rb b/config/routes.rb index 389198e07..9e6ca98f4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,6 +21,7 @@ resources :people do resources :advanced_trainings + resources :educations member do get 'export-cv', to: 'people/export_cv#show' put 'picture', to: 'people/picture#update' diff --git a/spec/features/advanced_trainings_spec.rb b/spec/features/advanced_trainings_spec.rb index 8c596b8bc..bafccb802 100644 --- a/spec/features/advanced_trainings_spec.rb +++ b/spec/features/advanced_trainings_spec.rb @@ -21,6 +21,7 @@ click_link(href: new_person_advanced_training_path(person)) within('turbo-frame#new_advanced_training') do fill_in 'advanced_training_description', with: description + select '2020', from: 'advanced_training_year_from' click_default_submit end expect(page).to have_content(description) @@ -99,7 +100,7 @@ click_default_submit end - expect(page).to have_css(".alert.alert-danger", text: "Year from muss ausgefüllt werden") + expect(page).to have_css(".alert.alert-danger", text: "Jahr von muss ausgefüllt werden") end it 'Update entry and clear description' do @@ -121,7 +122,7 @@ select '2010', from: 'advanced_training_year_to' click_default_submit end - expect(page).to have_css(".alert.alert-danger", text: "Year from muss vor \"Datum bis\" sein") + expect(page).to have_css(".alert.alert-danger", text: "Jahr von muss vor \"Datum bis\" sein") end end diff --git a/spec/features/educations_spec.rb b/spec/features/educations_spec.rb new file mode 100644 index 000000000..8c9298b6c --- /dev/null +++ b/spec/features/educations_spec.rb @@ -0,0 +1,95 @@ +require 'rails_helper' + +describe 'Educations', type: :feature, js:true do + let(:person) { people(:bob) } + + before(:each) do + sign_in auth_users(:admin) + visit person_path(person) + end + + describe 'Crud actions' do + it 'shows all' do + within('turbo-frame#education') do + person.educations.each do |education| + expect(page).to have_content(education.title) + expect(page).to have_content(education.location) + end + end + end + + it 'creates and saves new education' do + title = 'Döner-Verkäufer' + new_location = 'Dönerbude' + + click_link(href: new_person_education_path(person)) + + within('turbo-frame#new_education') do + select '2024', from: 'education_year_from' + fill_in 'education_title', with: title + fill_in 'education_location', with: new_location + click_default_submit + end + + expect(page).to have_content(title) + expect(page).to have_content(new_location) + end + + it 'updates education' do + updated_location = 'Dönerbude des Vertrauens' + + education = person.educations.first + within("turbo-frame#education_#{education.id}") do + find("[href=\"#{edit_person_education_path(person, education)}\"]").all("*").first.click + fill_in 'education_location', with: updated_location + click_default_submit + end + expect(page).to have_content(updated_location) + end + + it 'cancels without saving' do + education = person.educations.first + old_location = education.location + updated_location = 'Dönerbude des Vertrauens' + + within("turbo-frame#education_#{education.id}") do + find("[href=\"#{edit_person_education_path(person, education)}\"]").all("*").first.click + fill_in 'education_location', with: updated_location + find('a', text: 'Abbrechen').click + end + expect(person.educations.first.location).to eq(old_location) + end + end + + describe 'Error handling' do + it 'create new education without title and location' do + click_link(href: new_person_education_path(person)) + + within('turbo-frame#new_education') do + click_default_submit + end + expect(page).to have_css(".alert.alert-danger", text: "Ausbildung muss ausgefüllt werden") + expect(page).to have_css(".alert.alert-danger", text: "Ausbildungsort muss ausgefüllt werden") + end + + it 'Update entry and clear title & description' do + education = person.educations.first + within("turbo-frame#education_#{education.id}") do + find("[href=\"#{edit_person_education_path(person, education)}\"]").all("*").first.click + fill_in 'education_title', with: "" + fill_in 'education_location', with: "" + click_default_submit + end + expect(page).to have_css(".alert.alert-danger", text: "Ausbildung muss ausgefüllt werden") + expect(page).to have_css(".alert.alert-danger", text: "Ausbildungsort muss ausgefüllt werden") + end + end + + def click_default_submit + find("button[type='submit'][name='save']").click + end + + def click_save_and_new_submit + find("button[type='submit'][name='render_new_after_save']").click + end +end