diff --git a/.gitignore b/.gitignore index 0413aaa36..865001781 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ public/sitemap.xml public/system/ /public/ckeditor_assets/ + diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/views/admin/budget_investments/_investments.html.erb index a3a512366..81b46f9d3 100644 --- a/app/views/admin/budget_investments/_investments.html.erb +++ b/app/views/admin/budget_investments/_investments.html.erb @@ -57,87 +57,7 @@ <% @investments.each do |investment| %> - - <%= investment.id %> - - - <%= link_to investment.title, - admin_budget_budget_investment_path(budget_id: @budget.id, - id: investment.id, - params: Budget::Investment.filter_params(params)), - target: "_blank" %> - - - <%= investment.total_votes %> - - - <% if investment.administrator.present? %> - "> - <%= investment.administrator.name %> - - <% else %> - <%= t("admin.budget_investments.index.no_admin_assigned") %> - <% end %> - - - <% no_valuation_groups = t("admin.budget_investments.index.no_valuation_groups") %> - <%= investment.assigned_valuation_groups || no_valuation_groups %> -
- <% no_valuators_assigned = t("admin.budget_investments.index.no_valuators_assigned") %> - <%= investment.assigned_valuators || no_valuators_assigned %> - - - <%= investment.heading.name %> - - - <%= t("admin.budget_investments.index.feasibility.#{investment.feasibility}", - price: investment.formatted_price) %> - - - <%= investment.valuation_finished? ? t("shared.yes"): t("shared.no") %> - - - <%= form_for [:admin, investment.budget, investment], remote: true do |f| %> - <%= f.check_box :visible_to_valuators, - label: false, - class: "js-submit-on-change", - id: "budget_investment_visible_to_valuators" %> - <% end %> - - - <% if investment.selected? %> - <%= link_to_unless investment.budget.finished?, - t("admin.budget_investments.index.selected"), - toggle_selection_admin_budget_budget_investment_path(@budget, - investment, - filter: params[:filter], - sort_by: params[:sort_by], - min_total_supports: params[:min_total_supports], - advanced_filters: params[:advanced_filters], - page: params[:page]), - method: :patch, - remote: true, - class: "button small expanded" %> - <% elsif investment.feasible? && investment.valuation_finished? %> - <%= link_to_unless investment.budget.finished?, - t("admin.budget_investments.index.select"), - toggle_selection_admin_budget_budget_investment_path(@budget, - investment, - filter: params[:filter], - sort_by: params[:sort_by], - min_total_supports: params[:min_total_supports], - advanced_filters: params[:advanced_filters], - page: params[:page]), - method: :patch, - remote: true, - class: "button small hollow expanded" %> - <% end %> - - <% if params[:filter] == "selected" %> - - <%= investment.incompatible? ? t("shared.yes"): t("shared.no") %> - - <% end %> + <%= render '/admin/budget_investments/select_investment', investment: investment %> <% end %> diff --git a/app/views/admin/budget_investments/_select_investment.html.erb b/app/views/admin/budget_investments/_select_investment.html.erb new file mode 100644 index 000000000..12bb5c5c8 --- /dev/null +++ b/app/views/admin/budget_investments/_select_investment.html.erb @@ -0,0 +1,81 @@ + + <%= investment.id %> + + + <%= link_to investment.title, + admin_budget_budget_investment_path(budget_id: @budget.id, + id: investment.id, + params: Budget::Investment.filter_params(params)), + target: "_blank" %> + + + <%= investment.total_votes %> + + + <% if investment.administrator.present? %> + "> + <%= investment.administrator.name %> + + <% else %> + <%= t("admin.budget_investments.index.no_admin_assigned") %> + <% end %> + + + <% no_valuation_groups = t("admin.budget_investments.index.no_valuation_groups") %> + <%= investment.assigned_valuation_groups || no_valuation_groups %> +
+ <% no_valuators_assigned = t("admin.budget_investments.index.no_valuators_assigned") %> + <%= investment.assigned_valuators || no_valuators_assigned %> + + + <%= investment.heading.name %> + + + <%= t("admin.budget_investments.index.feasibility.#{investment.feasibility}", + price: investment.formatted_price) %> + + + <%= investment.valuation_finished? ? t("shared.yes"): t("shared.no") %> + + + <%= form_for [:admin, investment.budget, investment], remote: true do |f| %> + <%= f.check_box :visible_to_valuators, + label: false, + class: "js-submit-on-change", + id: "budget_investment_visible_to_valuators" %> + <% end %> + + + <% if investment.selected? %> + <%= link_to_unless investment.budget.finished?, + t("admin.budget_investments.index.selected"), + toggle_selection_admin_budget_budget_investment_path(@budget, + investment, + filter: params[:filter], + sort_by: params[:sort_by], + min_total_supports: params[:min_total_supports], + advanced_filters: params[:advanced_filters], + page: params[:page]), + method: :patch, + remote: true, + class: "button small expanded" %> + <% elsif investment.feasible? && investment.valuation_finished? %> + <%= link_to_unless investment.budget.finished?, + t("admin.budget_investments.index.select"), + toggle_selection_admin_budget_budget_investment_path(@budget, + investment, + filter: params[:filter], + sort_by: params[:sort_by], + min_total_supports: params[:min_total_supports], + advanced_filters: params[:advanced_filters], + page: params[:page]), + method: :patch, + remote: true, + class: "button small hollow expanded" %> + <% end %> + +<% if params[:filter] == "selected" %> + + <%= investment.incompatible? ? t("shared.yes"): t("shared.no") %> + +<% end %> diff --git a/app/views/admin/budget_investments/toggle_selection.js.erb b/app/views/admin/budget_investments/toggle_selection.js.erb index dc3a8d67a..3074847d6 100644 --- a/app/views/admin/budget_investments/toggle_selection.js.erb +++ b/app/views/admin/budget_investments/toggle_selection.js.erb @@ -1 +1 @@ -$("#investments").html('<%= j render("admin/budget_investments/investments") %>'); +$("#<%= dom_id(@investment) %>").html('<%= j render("select_investment", investment: @investment) %>'); diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index d58263d2a..67805f013 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -1079,6 +1079,7 @@ feature 'Admin budget investments' do click_link('Selected') end + click_button('Filter') expect(page).not_to have_content(selected_bi.title) expect(page).to have_content('There is 1 investment') @@ -1089,6 +1090,20 @@ feature 'Admin budget investments' do expect(page).not_to have_link('Selected') end end + + scenario "Pagination after unselecting an investment", :js do + create_list(:budget_investment, 30, budget: budget) + + visit admin_budget_budget_investments_path(budget) + + within("#budget_investment_#{selected_bi.id}") do + click_link('Selected') + end + + click_link('Next') + + expect(page).to have_link('Previous') + end end context "Mark as visible to valuators" do