Skip to content

Commit

Permalink
Feature/603 notes core competences (#629)
Browse files Browse the repository at this point in the history
* begin with template implementation of core competences

* implement icon and corresponding text

* finish template and inline form

* fix cancel button by removing unnecessary modal class

* implement test helper and adjust rows of textarea

* use partial to display competence-notes

* use css class to dipslay line breaks instead of helper

* write feature specs

* use default functionality of crud controller to update competence notes

* rename id of field

* rename partial and increase width of text area

* implement group.by helper function and use it in template view

* write tests and modify fixtures to check whether feature works as expected

* revert changes on capybara and resolve rubocop offenses

* move logic of grouping entities to helper class

* use scope to filter people_skills which are core_competences

* make rubocop happy again

* clean up code by implementing helpers

* adjust rows of textarea

* add wait in test

* increase wait time

* change title of test data to avoid line break

* Add word break for non space containing competence strings

* Cleanup competence show hash looping

* create partials for profile view

---------

Co-authored-by: Robin Steiner <[email protected]>
  • Loading branch information
MarcEgliP and Robin481 authored Mar 25, 2024
1 parent f1257df commit a525e7f
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 74 deletions.
19 changes: 18 additions & 1 deletion app/assets/stylesheets/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pzsh-topbar {
}


.person-profile-header {
.profile-header {
background: $skills-gray;
height: 3.25rem;
padding: 12px 20px 12px 20px;
Expand All @@ -81,4 +81,21 @@ pzsh-topbar {
.fixed-table {
table-layout: fixed;
width: 100%;
}

.persisted-line-breaks {
white-space: pre-wrap;
overflow-wrap: break-word;
overflow: hidden;
}

#competence-notes {
width: 100% !important;
}

.circle-divider {
width: 8px;
height: 8px;
border-radius: 50%;
background-color: #69b978
}
8 changes: 8 additions & 0 deletions app/controllers/people/competence_notes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

class People::CompetenceNotesController < CrudController

def self.model_class
Person
end
end
2 changes: 1 addition & 1 deletion app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def show
end

def update
if false?(params['has_nationality2']['checked'])
if params.include?('has_nationality2') && false?(params['has_nationality2']['checked'])
params['person']['nationality2'] = nil
end
super
Expand Down
5 changes: 5 additions & 0 deletions app/helpers/person_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ def country_alpha2_translation_map
def avatar_cached?(picture)
picture&.file&.file&.include? 'tmp'
end

def group_person_skills_by_category(person)
PeopleSkill.core_competence.where(person_id: person.id)
.group_by { |ps| ps.skill.category.parent }
end
end
1 change: 1 addition & 0 deletions app/models/people_skill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ class PeopleSkill < ApplicationRecord
'mehrmals ausgewählt werden' }

scope :list, -> { order(:person_id, :skill_id) }
scope :core_competence, -> { where('core_competence = true') }
end
15 changes: 15 additions & 0 deletions app/views/people/_core_competences.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%div.border.border-secondary-subtle.border-1.d-flex.flex-column
%div.profile-header.mw-100.border-bottom
Kernkompetenzen
%div.d-flex.flex-column.ms-5.mt-3.mb-3
- group_person_skills_by_category(@person).each do |parent_skill, children_skills|
%div.d-flex.flex-row.align-items-center.border-bottom.border-1.pb-3.pt-3.core-competence
%span.text-gray.w-25= parent_skill.title
- children_skills.each do | person_skill |
%span= person_skill.skill.title
- if person_skill != children_skills.last
%div.circle-divider.ms-2.me-2
%div.d-flex.flex-row.border-bottom.border-1.pb-3.pt-3
%span.text-gray.w-25 Notizen Member
%span.w-75.d-flex.align-items-center
= render('people/competence_notes/show')
64 changes: 64 additions & 0 deletions app/views/people/_profile.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
%div
=render partial:"people/search", :locals => {person: @person}
%div.profile-header.mw-100.border-bottom
Personalien
%div.mt-4
%turbo-frame{id: "#{dom_id @person}"}
%div.d-flex.flex-xl-row.flex-column
%div.col-xl-3.col-12
%img.rounded-circle{src: "/people/#{@person.id}/picture?#{Time.now.to_f}", width: '141', height: '141'}
%div.mt-3= link_to "Bearbeiten", edit_person_path, id: "edit-button"
%div.pe-5.col-xl-3.col-12
%table.fixed-table
%tbody
%th.fw-normal.text-gray Name
%tr
%td.text-break.pb-1= @person.name
%th.fw-normal.text-gray Email
%tr
%td.text-break.pb-1= @person.email
%th.fw-normal.text-gray Abschluss
%tr
%td.text-break.pb-1= @person.title
%th.fw-normal.text-gray Funktion
- unless @person.person_roles.empty?
- @person.person_roles.each do |person_role|
%tr
%td.pb-1= person_role_string(person_role)
- else
%tr
%td -
%th.fw-normal.text-gray Organisationseinheit
%tr
%td.pb-1= @person.department.nil? ? '-' : @person.department.name
%th.fw-normal.text-gray Firma
%tr
%td= @person.company.name
%div.pe-5.col-xl-3.col-12
%table.fixed-table
%tbody
%th.fw-normal.text-gray Geburtsdatum
%tr
%td.pb-1= @person.birthdate.to_date.strftime('%d.%m.%Y')
%th.fw-normal.text-gray Nationalität
%tr
%td.text-break.pb-1= nationality_string(@person.nationality, @person.nationality2)
%th.fw-normal.text-gray Wohnort (Stadt)
%tr
%td.text-break.pb-1= @person.location
%th.fw-normal.text-gray Zivilstand
%tr
%td.pb-1= t("marital_statuses.#{@person.marital_status}")
%th.fw-normal.text-gray Kürzel
%tr
%td= @person.shortname.blank? ? '-' : @person.shortname

%div.col-xl-3.col-12
%div.fw-normal.text-gray Sprachen
%div.border.border-dark-subtle.mt-1.p-2.rounded
- @person.language_skills.each do |language|
%div.mb-1= "#{language.language}: #{language.level} - #{language.certificate}"
= link_to "Show all", people_path, {"data-turbo"=>false}

%div.d-flex.justify-content-end
=link_to image_tag("plus-lg.svg", class: "text-primary")+ "Export", export_cv_person_path(@person), class: "btn text-primary", data: { turbo_frame: "remote_modal" }
6 changes: 6 additions & 0 deletions app/views/people/competence_notes/_show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%turbo-frame{id: "competence-notes"}
%div.d-flex
%div.persisted-line-breaks= @person.competence_notes
%div.d-flex.flex-row
= link_to image_tag("pencil-square.svg", class: "text-primary me-2 ms-0 d-flex align-items-center", width: '16', height: '16')+ "Bearbeiten",
competence_notes_person_path(@person), class: "d-flex align-items-center", id: "edit-link"
8 changes: 8 additions & 0 deletions app/views/people/competence_notes/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
%turbo-frame{id: "competence-notes"}
= form_with model: @person do |f|
.mb-4.w-100
= f.text_area :competence_notes, class: "form-control w-75", value: @person.competence_notes,
rows: @person.competence_notes.lines.count
.mb-1.mt-4
= f.button "Speichern", class:"btn btn-primary","aria-label":"Close", id: 'save'
= link_to "Abbrechen", person_path(@person), class: "btn btn-outline-secondary", id: 'cancel'
1 change: 1 addition & 0 deletions app/views/people/competence_notes/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= render('people/competence_notes/show')
65 changes: 2 additions & 63 deletions app/views/people/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,64 +1,3 @@
%div
=render partial:"people/search", :locals => {person: @person}
%div.person-profile-header.mw-100.border-bottom
Personalien
%div.mt-4
%turbo-frame{id: "#{dom_id @person}"}
%div.d-flex.flex-xl-row.flex-column
%div.col-xl-3.col-12
%img.rounded-circle{src: "/people/#{@person.id}/picture?#{Time.now.to_f}", width: '141', height: '141'}
%div.mt-3= link_to "Bearbeiten", edit_person_path, id: "edit-button"
%div.pe-5.col-xl-3.col-12
%table.fixed-table
%tbody
%th.fw-normal.text-gray Name
%tr
%td.text-break.pb-1= @person.name
%th.fw-normal.text-gray Email
%tr
%td.text-break.pb-1= @person.email
%th.fw-normal.text-gray Abschluss
%tr
%td.text-break.pb-1= @person.title
%th.fw-normal.text-gray Funktion
- unless @person.person_roles.empty?
- @person.person_roles.each do |person_role|
%tr
%td.pb-1= person_role_string(person_role)
- else
%tr
%td -
%th.fw-normal.text-gray Organisationseinheit
%tr
%td.pb-1= @person.department.nil? ? '-' : @person.department.name
%th.fw-normal.text-gray Firma
%tr
%td= @person.company.name
%div.pe-5.col-xl-3.col-12
%table.fixed-table
%tbody
%th.fw-normal.text-gray Geburtsdatum
%tr
%td.pb-1= @person.birthdate.to_date.strftime('%d.%m.%Y')
%th.fw-normal.text-gray Nationalität
%tr
%td.text-break.pb-1= nationality_string(@person.nationality, @person.nationality2)
%th.fw-normal.text-gray Wohnort (Stadt)
%tr
%td.text-break.pb-1= @person.location
%th.fw-normal.text-gray Zivilstand
%tr
%td.pb-1= t("marital_statuses.#{@person.marital_status}")
%th.fw-normal.text-gray Kürzel
%tr
%td= @person.shortname.blank? ? '-' : @person.shortname
= render('profile')
= render('core_competences')

%div.col-xl-3.col-12
%div.fw-normal.text-gray Sprachen
%div.border.border-dark-subtle.mt-1.p-2.rounded
- @person.language_skills.each do |language|
%div.mb-1= "#{language.language}: #{language.level} - #{language.certificate}"
= link_to "Show all", people_path, {"data-turbo"=>false}

%div.d-flex.justify-content-end
=link_to image_tag("plus-lg.svg", class: "text-primary")+ "Export", export_cv_person_path(@person), class: "btn text-primary", data: { turbo_frame: "remote_modal" }
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
put 'picture', to: 'people/picture#update'
get 'picture', to: 'people/picture#show'
get 'export', to: 'people#export'
get 'competence-notes', to: 'people/competence_notes#edit'
post 'competence-notes', to: 'people/competence_notes#update'
end

end
Expand Down
12 changes: 6 additions & 6 deletions spec/domain/people_skills_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
levels = filteredPeopleSkills.pluck(:level)
interests = filteredPeopleSkills.pluck(:interest)

expect(filteredPeopleSkills.count).to eq(15)
expect(levels).to eq([3, 1, 0, 0, 1, 5, 4, 5, 5, 5, 5, 1, 1, 1, 1])
expect(interests).to eq([5, 4, 0, 0, 2, 4, 5, 3, 2, 2, 4, 5, 3, 2, 4])
expect(filteredPeopleSkills.count).to eq(16)
expect(levels).to eq([3, 1, 0, 1, 0, 1, 5, 4, 5, 5, 5, 5, 1, 1, 1, 1])
expect(interests).to eq([5, 4, 0, 4, 0, 2, 4, 5, 3, 2, 2, 4, 5, 3, 2, 4])
end

it 'filters rated people skills' do
Expand All @@ -20,9 +20,9 @@
levels = filteredPeopleSkills.pluck(:level)
interests = filteredPeopleSkills.pluck(:interest)

expect(filteredPeopleSkills.count).to eq(13)
expect(levels).to eq([3, 1, 1, 5, 4, 5, 5, 5, 5, 1, 1, 1, 1])
expect(interests).to eq([5, 4, 2, 4, 5, 3, 2, 2, 4, 5, 3, 2, 4])
expect(filteredPeopleSkills.count).to eq(14)
expect(levels).to eq([3, 1, 1, 1, 5, 4, 5, 5, 5, 5, 1, 1, 1, 1])
expect(interests).to eq([5, 4, 4, 2, 4, 5, 3, 2, 2, 4, 5, 3, 2, 4])
end

it 'it filters unrated people skills' do
Expand Down
47 changes: 47 additions & 0 deletions spec/features/core_competences_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require 'rails_helper'

describe "Core competences" do
before(:each) do
sign_in auth_users(:user), scope: :auth_user
visit root_path
end

it 'should display core competences' do
visit person_path(people(:bob))
expect(page).to have_selector('.core-competence', count: 1)
expect(page).to have_text('Software-Engineering')
expect(page).to have_text('Rails')
end

it 'should display competence notes and edit link correctly' do
visit person_path(people(:alice))
expect(page).to have_text('LaTex\n Puppet\n Bash')
expect(page).to have_selector('#edit-link')
end

it 'should update competence notes' do
visit person_path(people(:alice))
page.find('#edit-link').click
expect(page).to have_selector('.form-control')

fill_in 'person_competence_notes', with: 'Hello World here'
page.find('#save').click
expect(page).to have_text('Hello World here')
end

it 'should not update competence notes when clicking cancel button' do
visit person_path(people(:alice))
page.find('#edit-link').click
expect(page).to have_selector('.form-control')

fill_in 'person_competence_notes', with: 'Hello World here'
page.find('#cancel').click
expect(page).to have_text('LaTex\n Puppet\n Bash')
end

it 'should display skill with same parent category in same row with divider' do
visit person_path(people(:alice))
expect(page).to have_selector('.circle-divider')
expect(page).to have_selector('.core-competence', count: 1, text: "Software-Engineering\nRails\nember")
end
end
4 changes: 2 additions & 2 deletions spec/features/skills_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
end

it 'creates the skill when the form is submitted' do
fill_in 'skill_title', with: 'New Skill Title'
fill_in 'skill_title', with: 'New Skill'
select @category.title, from: 'skill_category_id'
select @radar, from: 'skill_radar'
select @portfolio, from: 'skill_portfolio'
Expand All @@ -24,7 +24,7 @@
expect(page).to have_content('ember')
expect(page).to have_content('JUnit')
expect(page).to have_content('Rails')
expect(page).to have_content('New Skill Title')
expect(page).to have_content('New Skill')
end

it 'displays error messages when present' do
Expand Down
10 changes: 9 additions & 1 deletion spec/fixtures/people_skills.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ alice_rails:
level: 0
interest: 0
certificate: false
core_competence: false
core_competence: true

alice_ember:
skill: ember
person: alice
level: 1
interest: 4
certificate: true
core_competence: true

alice_bash:
skill: bash
Expand Down

0 comments on commit a525e7f

Please sign in to comment.