From cc0987d8ff234c53088147d1cc3f026ce4337bbb Mon Sep 17 00:00:00 2001 From: Yanick Minder Date: Fri, 5 Jul 2024 17:43:56 +0200 Subject: [PATCH] fix search --- .../people_skills/filter_form_controller.rb | 10 +--------- app/controllers/people_skills/filter_params.rb | 2 +- .../people_skills/filter_form/_index.html.haml | 11 ----------- .../people_skills/filter_form/index.html.haml | 14 +++++++++++++- app/views/people_skills/index.html.haml | 12 +++++++++++- spec/features/people_skill_search_spec.rb | 4 +++- spec/features/skills_controller_spec.rb | 1 - 7 files changed, 29 insertions(+), 25 deletions(-) delete mode 100644 app/views/people_skills/filter_form/_index.html.haml diff --git a/app/controllers/people_skills/filter_form_controller.rb b/app/controllers/people_skills/filter_form_controller.rb index b677f1026..56c1a65b6 100644 --- a/app/controllers/people_skills/filter_form_controller.rb +++ b/app/controllers/people_skills/filter_form_controller.rb @@ -1,18 +1,10 @@ # frozen_string_literal: true -class PeopleSkills::FilterFormController < CrudController +class PeopleSkills::FilterFormController < ApplicationController include ParamConverters helper_method :filter_params - def self.model_class - PeopleSkill - end - - def self.controller_path - 'people_skills/filter_form' - end - private def filter_params diff --git a/app/controllers/people_skills/filter_params.rb b/app/controllers/people_skills/filter_params.rb index aeda8004a..13b8c66af 100644 --- a/app/controllers/people_skills/filter_params.rb +++ b/app/controllers/people_skills/filter_params.rb @@ -20,7 +20,7 @@ def interests end def rows - [@params[:rows].to_i, 1].max + @params[:rows].to_i end def rows_count diff --git a/app/views/people_skills/filter_form/_index.html.haml b/app/views/people_skills/filter_form/_index.html.haml deleted file mode 100644 index dcb75b691..000000000 --- a/app/views/people_skills/filter_form/_index.html.haml +++ /dev/null @@ -1,11 +0,0 @@ -%turbo-frame{id: "search-filters"} - = form_with(url: people_skills_path, method: :get, class: "filter-form", data: {"people-skills-filter-target": "form"}) do |form| - - filter_params.rows.times do |i| - %div.d-flex.flex-row.align-items-center{"data-people-skills-filter-target": "filter", id: "filter-row-#{i+ 1}"} - %div.filter-container.me-1 - = render("people_skills/search_form", form: form, row_number: i + 1) - = close_action_link "#", data: {action: "click->people-skills-filter#remove", "people-skills-filter-id-param": i, id: "remove-row-#{i+1}"} - - if filter_params.rows < 4 - - path = filter_form_people_skills_path(rows: filter_params.rows + 1) + "&#{filter_params.query_params}" - = add_action_link path, data: {"turbo-frame": "search-filters"}, id: "add-row-button" - \ No newline at end of file diff --git a/app/views/people_skills/filter_form/index.html.haml b/app/views/people_skills/filter_form/index.html.haml index 9be656400..70a0e849c 100644 --- a/app/views/people_skills/filter_form/index.html.haml +++ b/app/views/people_skills/filter_form/index.html.haml @@ -1 +1,13 @@ -= render "people_skills/filter_form/index" \ No newline at end of file +%turbo-frame{id: "search-filters"} + %div{"data-controller": "people-skills-filter"} + = form_with(url: people_skills_path, method: :get, class: "filter-form", data: {"people-skills-filter-target": "form"}) do |form| + %div.filter-container.me-1#filter-row-0 + = render("people_skills/search_form", form: form, row_number: 0, filter_params: filter_params) + - filter_params.rows.times do |i| + %div.d-flex.flex-row.align-items-center{"data-people-skills-filter-target": "filter", id: "filter-row-#{i+ 1}"} + %div.filter-container.me-1 + = render("people_skills/search_form", form: form, row_number: i + 1) + = close_action_link "#", {data: {action: "click->people-skills-filter#remove", "people-skills-filter-id-param": i}, id: "remove-row-#{i+1}"} + - if filter_params.rows < 4 + - path = filter_form_people_skills_path(rows: filter_params.rows + 1) + "&#{filter_params.query_params}" + = add_action_link path, {}, {data: {"turbo-frame": "search-filters"}, id: "add-row-button"} \ No newline at end of file diff --git a/app/views/people_skills/index.html.haml b/app/views/people_skills/index.html.haml index d4555cbf1..c27ee7d40 100644 --- a/app/views/people_skills/index.html.haml +++ b/app/views/people_skills/index.html.haml @@ -1,5 +1,15 @@ %div.mt-3{"data-controller": "people-skills-filter"} - = render "people_skills/filter_form/index" + %turbo-frame{id: "search-filters"} + = form_with(url: people_skills_path, method: :get, class: "filter-form", data: {"people-skills-filter-target": "form"}) do |form| + - filter_params.rows_count.times do |i| + %div.d-flex.flex-row.align-items-center{"data-people-skills-filter-target": "filter", id: "filter-row-#{i}"} + %div.filter-container.me-1 + = render("search_form", form: form, row_number: i, filter_params: filter_params) + - if i != 0 + = close_action_link "#", {data: {action: "click->people-skills-filter#remove", "people-skills-filter-id-param": i}, id: "remove-row-#{i+1}"} + - if filter_params.rows_count < 5 + - path = filter_form_people_skills_path(rows: filter_params.rows + 1) + "&#{filter_params.query_params}" + = add_action_link path, {}, {data: {"turbo-frame": "search-filters"}, id: "add-row-button"} %div.profile-header.mw-100.border-bottom.mt-4.fw-normal = ti "search.search_results" %turbo-frame{id: "search-results"} diff --git a/spec/features/people_skill_search_spec.rb b/spec/features/people_skill_search_spec.rb index 1278e57d0..8c17c7099 100644 --- a/spec/features/people_skill_search_spec.rb +++ b/spec/features/people_skill_search_spec.rb @@ -33,6 +33,7 @@ visit(people_skills_path) fill_out_row("JUnit", 5, 3) add_and_fill_out_row("Rails", 4, 5) + require 'pry'; binding.pry # rubocop:disable Style/Semicolon,Lint/Debugger add_and_fill_out_row("ember", 5, 4) add_and_fill_out_row("Bash", 5, 2) add_and_fill_out_row("cunit", 5, 2) @@ -66,7 +67,8 @@ # remove skill filter - page.find('#remove-row-1').click + require 'pry'; binding.pry # rubocop:disable Style/Semicolon,Lint/Debugger + page.find('#remove-row-2').click expect(page).to have_text("Alice Mante") expect(page).to have_text("Wally Allround") expect(page).to have_text("Hope Sunday") diff --git a/spec/features/skills_controller_spec.rb b/spec/features/skills_controller_spec.rb index 47dbc4fbc..120c5224c 100644 --- a/spec/features/skills_controller_spec.rb +++ b/spec/features/skills_controller_spec.rb @@ -32,7 +32,6 @@ def fill_out_form it 'can save edited skill' do visit skills_path - require 'pry'; binding.pry # rubocop:disable Style/Semicolon,Lint/Debugger page.all('.icon.icon-pencil')[1].click fill_out_form save_button = page.find("input[type='image']")