Skip to content

Commit

Permalink
clean up people search
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Aug 2, 2024
1 parent e146a7f commit 7df7e6e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
10 changes: 0 additions & 10 deletions app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/person_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions app/helpers/select_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion app/views/people/_search.html.haml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down

0 comments on commit 7df7e6e

Please sign in to comment.