Skip to content

Commit

Permalink
Feature/585 CV export (#614)
Browse files Browse the repository at this point in the history
* create controller method to load correct picture path, add uploads to assets path, move cancel button on edit view and fix view not loading when department name missing

* add default avatar to public directory

* make view display nil properties of person as -, create picture controller and remove picture_path method from people_controller, use new picture controller to load pictures correctly in view

* start working on updating roles by renaming the params in the form and overriding the update method in the controller

* Implement first yet not usable version of modal

* Implement second version of CV export with working modal

* implement view of cv-export modal

* implement cv export and its modal

* transform values of query parameters to string

* fix template issue by using andpercent operator

* implement feature specs to check modal

* use before each block in describe to sign in as user

* resolve rubocop offenses

* remove duplicated update method

* modify validation method

* make rubocop happy

* delete unnecessary test files

---------

Co-authored-by: Jannik Pulfer <[email protected]>
Co-authored-by: megli2 <[email protected]>
  • Loading branch information
3 people authored Mar 18, 2024
1 parent 3f6c69b commit 8d78715
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 24 deletions.
7 changes: 7 additions & 0 deletions app/controllers/people/export_cv_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class People::ExportCvController < ApplicationController
def show
render 'show'
end
end
29 changes: 13 additions & 16 deletions app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ class PeopleController < CrudController
:percent, :id, :_destroy] }]

def show
if format_odt?
export
return
end
return export if format_odt?

@person = Person.includes(projects: :project_technologies,
person_roles: [:role, :person_role_level]).find(params.fetch(:id))
super
Expand All @@ -27,20 +25,9 @@ def update
super
end

private

def fetch_entries
Person.includes(:company).list
end

def person
@person ||= Person.find(params[:person_id])
end

def export
anon = params[:anon].presence || 'false'
odt_file = Odt::Cv.new(entry, params).export
filename = if anon == 'true'
filename = if true?(params[:anon])
'CV_Puzzle_ITC_anonymized.odt'
else
filename(entry.name, 'CV_Puzzle_ITC')
Expand All @@ -50,4 +37,14 @@ def export
type: 'application/vnd.oasis.opendocument.text',
disposition: content_disposition('attachment', filename)
end

private

def fetch_entries
Person.includes(:company).list
end

def person
@person ||= Person.find(params[:person_id])
end
end
8 changes: 8 additions & 0 deletions app/controllers/picture_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

class PictureController < ApplicationController
def show
picture_url = @person.picture.file.nil? ? default_avatar_path : @person.picture.url
send_file(picture_url, disposition: 'inline')
end
end
7 changes: 4 additions & 3 deletions app/exporters/odt/cv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module Odt
# rubocop:disable Metrics/ClassLength
class Cv
include ParamConverters

def initialize(person, params)
@person = person
Expand Down Expand Up @@ -33,15 +34,15 @@ def export
private

def anon?
@params[:anon].presence == 'true'
true?(@params[:anon])
end

def include_core_competences_and_skills?
@params[:includeCS].presence == 'true'
true?(@params[:includeCS])
end

def include_skills_by_level?
@params[:skillsByLevel].presence == 'true'
true?(@params[:skillsByLevel])
end

def skill_level_value
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/picture_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

module PictureHelper
end
3 changes: 3 additions & 0 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ application.register("person-roles", PersonRolesController)
import RemoteModalController from "./remote_modal_controller"
application.register("remote-modal", RemoteModalController)

import SkillsFilterController from "./skills_filter_controller"
application.register("skills-filter", SkillsFilterController)

import DropdownLinksController from "./dropdown_controller"
application.register("dropdown", DropdownLinksController)

20 changes: 20 additions & 0 deletions app/javascript/controllers/skills_filter_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {Controller} from "@hotwired/stimulus"

export default class extends Controller {
static targets = ['container', 'switch', 'label']
levels = {"1": "Trainee", "2": "Junior", "3": "Professional", "4": "Senior", "5": "Expert"}
showSwitch = false;

connect() {
this.toggleSwitch();
}

toggleSwitch() {
this.containerTarget.style.display = !this.showSwitch ? 'none' : 'block';
this.showSwitch = !this.showSwitch
}

toggleLevel() {
this.labelTarget.textContent = this.levels[this.switchTarget.value]
}
}
19 changes: 19 additions & 0 deletions app/views/people/export_cv/_export_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
= form_with(url: person_path(format: 'odt'), method: 'get', data: {controller: "skills-filter"}) do |f|
.mb-2.w-100
= f.label 'Niederlassung (für Footer):', class: "form-label w-100"
= f.collection_select :location, BranchAdress.all, :id, :short_name, {}, class: "form-select w-100"
.mb-2.w-100.form-check.form-switch
= f.check_box :includeCS, class: "form-check-input"
= f.label 'Kernkompetenzen - Skills', class: "form-check-label w-100"
.mb-2.w-100.form-check.form-switch
= f.check_box :skillsByLevel, class: "form-check-input", "data-action": "click->skills-filter#toggleSwitch"
= f.label "Skills nach Level", class: "form-check-label w-100"
%div{"data-skills-filter-target": "container"}
= f.label "trainee", "data-skills-filter-target": "label", class: "w-100"
= f.range_field :levelValue, min: 1, max: 5, value: 1, class: "form-range w-25", "data-action": "change->skills-filter#toggleLevel", "data-skills-filter-target": "switch"
.mb-2.w-100.form-check.form-switch
= f.check_box :anon, class: "form-check-input"
= f.label "Anonymisierter CV", class: "form-check-label w-100"
.mb-1.mt-4
= f.button "Herunterladen", class:"btn btn-primary","aria-label":"Close"
= link_to "Cancel", skills_path, class: "btn btn-outline-secondary", "data-bs-dismiss":"modal"
2 changes: 2 additions & 0 deletions app/views/people/export_cv/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
= render "remote_modal", title: "CV-Export" do
= render "export_form"
5 changes: 4 additions & 1 deletion app/views/people/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@
%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}
= 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" }
7 changes: 3 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
delete 'sign_out', :to => 'devise/sessions#destroy', :as => :destroy_auth_user_session
end

resources :people
resources :skills


# Status
scope 'status' do
get 'health', to: 'status#health'
Expand All @@ -23,9 +19,12 @@

resources :people do
member do
get 'export-cv', to: 'people/export_cv#show'
put 'picture', to: 'people/picture#update'
get 'picture', to: 'people/picture#show'
get 'export', to: 'people#export'
end

end
resources :skills

Expand Down
28 changes: 28 additions & 0 deletions spec/features/cv_export_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'rails_helper'

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

describe 'CV-Export', type: :feature, js: true do
it 'should display range after switch was clicked' do
visit person_path(people(:bob))
page.find('a', text: 'Export').click

expect(page).not_to have_field('levelValue')
page.first('#skillsByLevel').click
expect(page).to have_field('levelValue')
end

it 'should display correct label when range increased' do
visit person_path(people(:bob))
page.find('a', text: 'Export').click

page.first('#skillsByLevel').click
page.find('#levelValue').set(5)
expect(page).to have_text('Expert')
end
end
end

0 comments on commit 8d78715

Please sign in to comment.