diff --git a/app/controllers/concerns/decidim/budgeting_pipeline/projects_controller_extensions.rb b/app/controllers/concerns/decidim/budgeting_pipeline/projects_controller_extensions.rb index 40e8bf7..046a11e 100644 --- a/app/controllers/concerns/decidim/budgeting_pipeline/projects_controller_extensions.rb +++ b/app/controllers/concerns/decidim/budgeting_pipeline/projects_controller_extensions.rb @@ -26,6 +26,8 @@ def show raise ActionController::RoutingError, "Not Found" unless project end + def index; end + def default_filter_params { search_text_cont: "", diff --git a/app/packs/src/decidim/budgeting_pipeline/projects.js b/app/packs/src/decidim/budgeting_pipeline/projects.js index 98bf987..6283c69 100644 --- a/app/packs/src/decidim/budgeting_pipeline/projects.js +++ b/app/packs/src/decidim/budgeting_pipeline/projects.js @@ -17,7 +17,7 @@ // placeHolder.style.height = `${ordersSummary.offsetHeight}px`; // console.log(ordersSummary.offsetHeight); - document.addEventListener("scroll", (event) => { + document.addEventListener("scroll", () => { if (window.scrollY > stickPosition.offsetTop) { if (!ordersSummary.classList.contains("is-stuck")) { placeHolder.style.height = `${ordersSummary.offsetHeight}px`; @@ -27,6 +27,8 @@ if (ordersSummary.classList.contains("is-stuck")) { ordersSummary.classList.remove("is-stuck"); placeHolder.style.height = 0; + } else { + return; } } }); @@ -70,12 +72,21 @@ window.initializeProjects = () => { const loadingProjects = []; document.querySelectorAll("[data-project-selector] input[type='checkbox']").forEach((el) => { + el.addEventListener("change", () => { + let requestType; + + if (el.checked) { + requestType = "POST"; + } else { + requestType = "DELETE"; + } + loadingProjects.push(el.value); document.body.classList.add("loading"); Rails.ajax({ url: el.dataset.selectUrl, - type: el.checked ? "POST" : "DELETE", + type: requestType, success: () => { loadingProjects.shift(); if (loadingProjects.length < 1) { @@ -108,6 +119,8 @@ } clickableArea.addEventListener("click", clickHandler); + + // eslint-disable-next-line no-undef button.addEventListener("keydown", (ev) => { if (ev.code === "Enter" || ev.code === "Space") { buttonClickHandler(ev); diff --git a/spec/system/explore_projects_spec.rb b/spec/system/explore_projects_spec.rb index a6b2d24..809d9e8 100644 --- a/spec/system/explore_projects_spec.rb +++ b/spec/system/explore_projects_spec.rb @@ -20,7 +20,7 @@ it "can filter based on keywords" do within "form.new_filter" do - find(%(input[name="filter[search_text_cont]"])).set(translated(budget1_projects.first.title)) + find(%(input[name="filter[search_text_cont]"])).set(translated(budget_one_projects.first.title)) click_on "Search" end @@ -29,7 +29,7 @@ it "can filter based on the area" do within "form.new_filter" do - find(%(select[name="filter[decidim_budgets_budget_id_eq]"])).find(%(option[value="#{budget1.id}"])).select_option + find(%(select[name="filter[decidim_budgets_budget_id_eq]"])).find(%(option[value="#{budget_one.id}"])).select_option click_on "Search" end @@ -51,7 +51,7 @@ end describe "show" do - let(:project) { budget1_projects.first } + let(:project) { budget_one_projects.first } before do visit_project(project) @@ -69,7 +69,7 @@ let(:category) { create(:category, participatory_space: component.participatory_space, parent: parent_category) } let(:parent_category) { create(:category, participatory_space: component.participatory_space) } - let!(:project) { create(:budgeting_pipeline_project, budget: budget1, category:) } + let!(:project) { create(:budgeting_pipeline_project, budget: budget_one, category:) } it "displays the category and its parent category" do expect(page).to have_content(translated(parent_category.name)) @@ -81,7 +81,7 @@ before do component.step_settings = { component.participatory_space.active_step.id => { votes: "finished", show_votes: true, show_selected_status: true } } component.save - budget1_projects.first.update(selected_at: Time.current) + budget_one_projects.first.update(selected_at: Time.current) end it "renders status selection" do diff --git a/spec/system/voting_spec.rb b/spec/system/voting_spec.rb index 8f319a9..006f5e3 100644 --- a/spec/system/voting_spec.rb +++ b/spec/system/voting_spec.rb @@ -69,14 +69,14 @@ describe "start" do before { login_as user, scope: :user } - let(:project1) { budget1.projects.first } + let(:project1) { budget_one.projects.first } it "allows selecting a budget" do visit_voting page.scroll_to find("h2", text: "Select the area where you want to vote") - find("h2", text: translated(budget1.title)).click + find("h2", text: translated(budget_one.title)).click find("input[name='filter[selected]']").click find("label[for=project_selector_#{project1.id}]").click @@ -85,7 +85,7 @@ end describe "projects" do - let(:budget) { budget1 } + let(:budget) { budget_one } before do login_as user, scope: :user @@ -155,11 +155,11 @@ end describe "preview" do - let(:budget) { budget1 } - let!(:order) { create(:order, budget: budget1, user:) } + let(:budget) { budget_one } + let!(:order) { create(:order, budget: budget_one, user:) } before do - order.projects << budget1_projects.first + order.projects << budget_one_projects.first order.save! login_as user, scope: :user @@ -171,16 +171,16 @@ it "shows the vote preview page" do expect(page).to have_content("Maximum amount of proposals to be selected in the area: 5") - expect(page).to have_content(translated(budget1_projects.first.title)) + expect(page).to have_content(translated(budget_one_projects.first.title)) end end describe "create" do - let(:budget) { budget1 } - let!(:order) { create(:order, budget: budget1, user:) } + let(:budget) { budget_one } + let!(:order) { create(:order, budget: budget_one, user:) } before do - order.projects << budget1_projects.first + order.projects << budget_one_projects.first order.save! login_as user, scope: :user