From e146a7f4a01f700076f29e5d7a22f7a2b2170b5d Mon Sep 17 00:00:00 2001 From: Yanick Minder Date: Fri, 2 Aug 2024 10:25:57 +0200 Subject: [PATCH] use options_for_select in people_search --- app/controllers/people_controller.rb | 13 +++++++++++-- app/models/person.rb | 4 ---- app/views/people/_search.html.haml | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 6d4e6de63..beea602fe 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -8,14 +8,13 @@ class PeopleController < CrudController self.permitted_attrs = [:birthdate, :location, :marital_status, :updated_by, :name, :nationality, :nationality2, :title, :competence_notes, :company_id, :email, :department_id, :shortname, :picture, :picture_cache, - { person_roles_attributes: [:role_id, :person_role_level_id, - :percent, :id, :_destroy] }, { person_roles_attributes: [:role_id, :person_role_level_id, :percent, :id, :_destroy] }, { language_skills_attributes: [: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? @@ -60,8 +59,18 @@ 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/models/person.rb b/app/models/person.rb index 44847a0f3..2659f951a 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -100,10 +100,6 @@ def to_s name end - def path - Rails.application.routes.url_helpers.person_path(self, locale: I18n.locale) - end - private def picture_size diff --git a/app/views/people/_search.html.haml b/app/views/people/_search.html.haml index 8f97cd2a5..faf26fa72 100644 --- a/app/views/people/_search.html.haml +++ b/app/views/people/_search.html.haml @@ -1,7 +1,7 @@ %div.d-flex.align-items-center.justify-content-between %div.d-flex.col-9.gap-3 %span.col-6{"data-controller": "dropdown"} - = collection_select :person_id, :person, Person.all.sort_by {|p| p.name.downcase }, :path, :name, select_when_available(person&.path), {data:{"dropdown-target": "dropdown" , action: "change->dropdown#handleChange"}} + = select :person_id, :person, options_for_select(sorted_people, select_when_available(person)), {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