Skip to content

Commit

Permalink
use options_for_select in people_search
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Aug 2, 2024
1 parent cbdc90f commit e146a7f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
13 changes: 11 additions & 2 deletions app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/people/_search.html.haml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit e146a7f

Please sign in to comment.