diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index beea602fe..34a5c9266 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -14,7 +14,6 @@ class PeopleController < CrudController [:language, :level, :certificate, :id, :_destroy] }] layout 'person', only: [:show] - helper_method :sorted_people def index return flash[:alert] = I18n.t('errors.messages.profile-not-found') if params[:alert].present? @@ -59,18 +58,9 @@ def export disposition: content_disposition('attachment', filename) end - def sorted_people - people_for_select.sort_by { |e| e.first.downcase } - end - - private - def people_for_select - Person.all.map { |p| [p.name, person_path(p)] } - end - def fetch_entries Person.includes(:company).list end diff --git a/app/helpers/person_helper.rb b/app/helpers/person_helper.rb index 6d2bcd6b3..61b6ccca9 100644 --- a/app/helpers/person_helper.rb +++ b/app/helpers/person_helper.rb @@ -76,4 +76,12 @@ def not_rated_default_skills(person) certificate: false, core_competence: false }) end end + + def sorted_people + people_for_select.sort_by { |e| e.first.downcase } + end + + def people_for_select + Person.all.map { |p| [p.name, person_path(p)] } + end end diff --git a/app/helpers/select_helper.rb b/app/helpers/select_helper.rb index 0e3e933fb..ea71548fb 100644 --- a/app/helpers/select_helper.rb +++ b/app/helpers/select_helper.rb @@ -15,4 +15,8 @@ def skills_dropdown_options skills = Skill.list.map { |s| [s.title, s.id, { 'data-category-id': s.category.id }] } add_default_option(skills, { 'data-placeholder': true }) end + + def model_path_or_nil(model) + polymorphic_path(model) if model + end end diff --git a/app/views/people/_search.html.haml b/app/views/people/_search.html.haml index faf26fa72..f2e06a0ed 100644 --- a/app/views/people/_search.html.haml +++ b/app/views/people/_search.html.haml @@ -1,7 +1,8 @@ %div.d-flex.align-items-center.justify-content-between %div.d-flex.col-9.gap-3 %span.col-6{"data-controller": "dropdown"} - = select :person_id, :person, options_for_select(sorted_people, select_when_available(person)), {prompt: person.nil?}, {data:{"dropdown-target": "dropdown" , action: "change->dropdown#handleChange"}} + - selected_path = model_path_or_nil(person) + = select :person_id, :person, options_for_select(sorted_people, select_when_available(selected_path)), {prompt: person.nil?}, {data:{"dropdown-target": "dropdown" , action: "change->dropdown#handleChange"}} %div.d-flex.align-items-center.text-gray = "#{t '.updated_at'}: #{@person&.last_updated_at.strftime("%d.%m.%Y")}" if @person&.last_updated_at %a.d-flex.justify-content-between#new-person-button diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index d8d10d318..5af5ac052 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -80,7 +80,6 @@ config.include(PersonRelationsHelpers, type: :feature) config.include(SlimselectHelpers, type: :feature) config.include(PeopleSkillsHelpers, type: :feature) - config.include(PeopleSkillsHelpers, type: :feature) config.include(UtilitiesHelpers) config.infer_spec_type_from_file_location!