Skip to content

Commit

Permalink
Feature/711 people skill filter (#713)
Browse files Browse the repository at this point in the history
* add filter for people-skills

* add filter controller

* refactor backend logic

* Fix tests

* implement reveiw

* Remove unnecessary linebreak

* add translation for filter

---------

Co-authored-by: Robin Steiner <[email protected]>
  • Loading branch information
kcinay055679 and Robin481 authored May 24, 2024
1 parent 3ea4cfb commit c6798eb
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 15 deletions.
24 changes: 24 additions & 0 deletions app/controllers/people/people_skills_create_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ class People::PeopleSkillsCreateController < CrudController
{ skill_attributes:
[:id, :title, :radar, :portfolio, :default_set, :category_id] }]
self.nesting = Person
helper_method :people_skills_of_category
layout 'person'

def index
return super if params[:rating].present?

redirect_to url_for(request.params.merge(rating: 0))
end

def show
redirect_to person_people_skills_path(@person)
end
Expand All @@ -22,7 +29,24 @@ def self.model_class
PeopleSkill
end

def list_entries
return super if params[:rating].blank?

filter_by_rating(super, params[:rating])
end

def filter_by_rating(people_skills, rating)
return people_skills.where('level > ?', 0) if rating == '0'
return people_skills.where(level: 0) if rating == '-1'

people_skills
end

def self.controller_path
'people/people_skills'
end

def people_skills_of_category(category)
@people_skills.where(skill_id: category.skills.ids)
end
end
14 changes: 14 additions & 0 deletions app/javascript/controllers/filter_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Controller } from "@hotwired/stimulus"

// Connects to data-controller="skillset-selected"
export default class extends Controller {

submit() {
const form = this.element;
const formData = new FormData(form);

const params = new URLSearchParams(formData);
const newUrl = `${form.action}?${params.toString()}`;
history.pushState({}, "", newUrl);
}
}
3 changes: 3 additions & 0 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ application.register("scroll", ScrollController)

import SkillsetSelectedController from "./skillset_selected_controller"
application.register("skillset-selected", SkillsetSelectedController)

import FilterController from "./filter_controller"
application.register("filter", FilterController)
38 changes: 27 additions & 11 deletions app/views/people/people_skills/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,30 @@
%p.d-flex.align-items-center.profile-header
Skills
="(#{@person.people_skills.count})"
- Category.all_parents.each do |category|
%div.profile-header.mw-100.border-bottom.mt-4{id: category.title, "data-scroll-target": "scrollItem"}
= category.title
- ([category] + category.children.to_a).each do |category_child|
%div.white-header.mw-100.border-bottom.text-gray
=category_child.title + " (#{people_skills_of_category(@person, category_child).count})"
- people_skills_of_category(@person, category_child).each do |person_skill|
- @person_skill = person_skill
%div.mw-100.border-bottom.text-black.ps-5.border
%div.d-flex.flex-row.align-items-center.mt-3.mb-3
= render("people_skills/person_skill", {person_skill: @person_skill})
%div.ms-3
= form_with(url: person_people_skills_path(@person), method: :get, data: {controller: "filter", turbo_frame: "people-skills"}) do |f|
%span.btn-group
- rating = request.query_parameters[:rating]
= f.radio_button :rating, 1, class: "btn-check", checked: rating == "1",
onClick: "this.form.requestSubmit()", data: {action: "change->filter#submit"}
= f.label :rating, t("people-skills.filter.all"), value: 1, class: "btn btn-outline-primary"

= f.radio_button :rating, 0, class: "btn-check", checked: rating == "0",
onClick: "this.form.requestSubmit()", data: {action: "change->filter#submit"}
= f.label :rating, t("people-skills.filter.rated"), value: 0, class: "btn btn-outline-primary"

= f.radio_button :rating, -1, class: "btn-check", checked: rating == "-1",
onClick: "this.form.requestSubmit()", data: {action: "change->filter#submit"}
= f.label :rating, t("people-skills.filter.unrated"), value: -1, class: "btn btn-outline-primary"
= turbo_frame_tag 'people-skills' do
- Category.all_parents.each do |category|
%div.profile-header.mw-100.border-bottom.mt-4{id: category.title, "data-scroll-target": "scrollItem"}
= category.title
- ([category] + category.children.to_a).each do |category_child|
%div.white-header.mw-100.border-bottom.text-gray
- @people_skills_of_category = people_skills_of_category(category_child)
=category_child.title + " (#{@people_skills_of_category.count})"
- @people_skills_of_category.each do |person_skill|
%div.mw-100.border-bottom.text-black.ps-5.border
%div.d-flex.flex-row.align-items-center.mt-3.mb-3
= render("people_skills/person_skill", {person_skill: person_skill})
4 changes: 4 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ de:
interest: Interesse
certificate: Zertifikat
core-competence: Kernkompetenz
filter:
all: Alle
rated: Bewertet
unrated: Nicht bewertet
date_range_picker:
from: Von
to: Bis
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ en:
interest: Interest
certificate: Certificate
core-competence: Core Competence
filter:
all: ALl
rated: Rated
unrated: Unrated
date_range_picker:
from: From
to: To
Expand Down
6 changes: 2 additions & 4 deletions spec/features/edit_people_skills_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
it 'should show amount of skills' do
# Switch to PeopleSkills tab
alice = people(:alice)
visit person_people_skills_path(alice)
visit person_people_skills_path(alice, rating: 1)
expect(page).to have_content('Ruby (2)')
expect(page).to have_content('Java (1)')
expect(page).to have_content('c (0)')
Expand All @@ -76,10 +76,8 @@
it 'should display unweighted label if level is 0' do
# Switch to PeopleSkills tab
alice = people(:alice)
visit person_people_skills_path(alice)
visit person_people_skills_path(alice, rating: 1)

expect(page).to have_css('.nav-link', text: 'Skills', count: 2)
page.all('.nav-link', text: 'Skills')[1].click
expect(page).to have_content('Unweighted', count: 2)
end
end
Expand Down

0 comments on commit c6798eb

Please sign in to comment.