-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Modify old search controller to not send json and add view with non-functional searchbar & routes for this new cv search controller * Add message if there are no results and make searchbar functional * Style search results to make them look like in the old version of skills * Make search results display name and found in value and change oninput to onchange * Reload serach-results via turboframe and change onchange to oninput * Create stimulus controller to add a short timeout before submitting, use this controller in the cv-search search-field and update stimulus manifest * Add translations for cv search and implement translation of results in view * Filter results from cv-search that have nil values as found_in and convert translation keys in cv search index view to snake case * Change translation key from camel to snake case in de.yml * Add link to cv search to header * Make clicking on search result preserve query params and implement highlighting of search results * Remove unnecessary stimulus controller action and write same functionality directly in view * Shorten filter method that filters out nil values for found_in in people_search controller * Make cv search form only submit if value length > 3 * Write cv search specs, add new missing translations and make search result link not trigger turbo-frame * Move logic that excludes results for searches with length < 3 to view * Add spec that asserts that results are only displayed with a search text length > 3 * Replace hardcoded route with path helper in header entry of cv search * Instead of not showing results for queries with length < 3 just return empty array in controller * Nest hover styles into normal styles * Move logic that decides wether or not to do cv search from controller to concern * Move logic that translates the found_in value and the one that creates a person link with search query from cv search view to a new helper * Reduce timeout in cv search from 400ms to 100ms * Populate value from query-params in cv search field on reload * Resolve rubocop offence * Move should search method from concern to controller
- Loading branch information
1 parent
3827898
commit a695968
Showing
13 changed files
with
195 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class CvSearchController < ApplicationController | ||
def index | ||
@cv_search_results = should_search ? [] : search_results | ||
end | ||
|
||
private | ||
|
||
def search_results | ||
PeopleSearch.new(query).entries | ||
end | ||
|
||
def query | ||
params[:q] | ||
end | ||
|
||
def should_search | ||
query.nil? || query.length < 3 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module CvSearchHelper | ||
def translate_found_in(result) | ||
I18n.t("cv_search.#{result[:found_in].split('#')[0].underscore}") | ||
end | ||
|
||
def person_path_with_query(result) | ||
"#{person_path(result[:person][:id])}?q=#{params[:q]}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
export default class extends Controller { | ||
connect() { | ||
const params = new URLSearchParams(window.location.search); | ||
if(params.has("q")) { | ||
window.find(params.get("q")) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
export default class extends Controller { | ||
|
||
connect() { | ||
const params = new URLSearchParams(window.location.search); | ||
if(params.has("q")) { | ||
document.getElementById("cv_search_field").value = params.get("q"); | ||
} | ||
} | ||
|
||
timeout; | ||
submitWithTimeout(e) { | ||
const form = e.target.parentElement; | ||
clearTimeout(this.timeout); | ||
this.timeout = setTimeout(() => { | ||
form.requestSubmit(); | ||
}, 100) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
%div.mt-2 | ||
%form{data: {"turbo-frame": "search-results", "turbo-action": "advance"}, "data-controller": "search"} | ||
%input{class: 'form-control w-75', placeholder: 'CVs durchsuchen...', name: 'q', "data-action": "search#submitWithTimeout", id: "cv_search_field"} | ||
%div.profile-header.mw-100.border-bottom.mt-2.mb-2 | ||
Suchresultate | ||
%turbo-frame{id: "search-results"} | ||
- if @cv_search_results.blank? | ||
Keine Resultate | ||
- else | ||
- @cv_search_results.each do |result| | ||
%div.w-50.d-flex | ||
= link_to result[:person][:name], person_path(result[:person][:id]), {class: "bg-skills-green w-50 text-decoration-none text-white ps-1 p-2 rounded-1", "data-turbo": "false"} | ||
%div.w-50.d-flex.justify-content-end.align-items-center | ||
%div.me-1 gefunden in: | ||
= link_to translate_found_in(result), person_path_with_query(result), {class: "bg-skills-search-result-blue w-50 text-decoration-none text-white ps-1 p-2 rounded-1 text-center", "data-turbo": "false"} | ||
%br |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require 'rails_helper' | ||
|
||
|
||
describe 'Advanced Trainings', type: :feature, js:true do | ||
let(:person) { people(:bob) } | ||
|
||
before(:each) do | ||
sign_in auth_users(:admin) | ||
visit("/cv_search") | ||
end | ||
|
||
describe 'Search' do | ||
it 'should find correct results' do | ||
fill_in 'cv_search_field', with: person.name | ||
check_search_results(I18n.t("cv_search.name")) | ||
fill_in 'cv_search_field', with: person.projects.first.technology | ||
check_search_results(I18n.t("cv_search.projects")) | ||
fill_in 'cv_search_field', with: person.title | ||
check_search_results(I18n.t("cv_search.title")) | ||
fill_in 'cv_search_field', with: person.roles.first.name | ||
check_search_results(I18n.t("cv_search.roles")) | ||
fill_in 'cv_search_field', with: person.department.name | ||
check_search_results(I18n.t("cv_search.department")) | ||
fill_in 'cv_search_field', with: person.competence_notes.split.first | ||
check_search_results(I18n.t("cv_search.competence_notes")) | ||
fill_in 'cv_search_field', with: person.advanced_trainings.first.description | ||
check_search_results(I18n.t("cv_search.advanced_trainings")) | ||
fill_in 'cv_search_field', with: person.educations.first.location | ||
check_search_results(I18n.t("cv_search.educations")) | ||
fill_in 'cv_search_field', with: person.activities.first.description | ||
check_search_results(I18n.t("cv_search.activities")) | ||
fill_in 'cv_search_field', with: person.projects.first.description | ||
check_search_results(I18n.t("cv_search.projects")) | ||
end | ||
|
||
it 'should open person when clicking result' do | ||
fill_in 'cv_search_field', with: person.projects.first.technology | ||
check_search_results(I18n.t("cv_search.projects")) | ||
click_link(person.name) | ||
expect(page).to have_current_path(person_path(person)) | ||
|
||
visit("/cv_search") | ||
education_location = person.educations.first.location | ||
fill_in 'cv_search_field', with: education_location | ||
check_search_results(I18n.t("cv_search.educations")) | ||
click_link(I18n.t("cv_search.educations")) | ||
expect(page).to have_current_path("#{person_path(person)}?q=#{education_location}") | ||
end | ||
|
||
it 'should only display results when length of search-text is > 3' do | ||
fill_in 'cv_search_field', with: person.name.slice(0, 2) | ||
expect(page).not_to have_content(person.name) | ||
fill_in 'cv_search_field', with: person.name.slice(0, 3) | ||
expect(page).to have_content(person.name) | ||
end | ||
end | ||
end | ||
|
||
def check_search_results(field_name) | ||
within('turbo-frame#search-results') { | ||
expect(page).to have_content(person.name) | ||
expect(page).to have_content(field_name) | ||
} | ||
end |