diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb index b9fa19ca9..c26fa0a69 100644 --- a/app/controllers/admin/budget_investments_controller.rb +++ b/app/controllers/admin/budget_investments_controller.rb @@ -2,16 +2,18 @@ class Admin::BudgetInvestmentsController < Admin::BaseController include FeatureFlags feature_flag :budgets - before_action :load_budget - before_action :load_investment, only: [:show, :edit, :update] - before_action :load_ballot, only: [:show, :index] + has_filters(%w{valuation_open without_admin managed valuating valuation_finished + valuation_finished_feasible selected all}, + only: [:index, :toggle_selection]) + + before_action :load_budget + before_action :load_investment, only: [:show, :edit, :update, :toggle_selection] + before_action :load_ballot, only: [:show, :index] + before_action :load_investments, only: [:index, :toggle_selection] + - has_filters %w{valuation_open without_admin managed valuating valuation_finished all}, only: :index def index - @investments = Budget::Investment.scoped_filter(params, @current_filter) - .order(cached_votes_up: :desc, created_at: :desc) - .page(params[:page]) end def show @@ -35,8 +37,19 @@ class Admin::BudgetInvestmentsController < Admin::BaseController end end + def toggle_selection + @investment.toggle :selected + @investment.save + end + private + def load_investments + @investments = Budget::Investment.scoped_filter(params, @current_filter) + .order(cached_votes_up: :desc, created_at: :desc) + .page(params[:page]) + end + def budget_investment_params params.require(:budget_investment) .permit(:title, :description, :external_url, :heading_id, :administrator_id, :tag_list, valuator_ids: []) diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 037289226..8d7694b32 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -45,7 +45,7 @@ module Abilities can [:index, :read, :new, :create, :update, :destroy], Budget can [:read, :create, :update, :destroy], Budget::Group can [:read, :create, :update, :destroy], Budget::Heading - can [:hide, :update], Budget::Investment + can [:hide, :update, :toggle_selection], Budget::Investment can :valuate, Budget::Investment, budget: { valuating: true } can :create, Budget::ValuatorAssignment diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 14109ba93..3487e8a66 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -34,17 +34,18 @@ class Budget scope :sort_by_price, -> { reorder(price: :desc, confidence_score: :desc, id: :desc) } scope :sort_by_random, -> { reorder("RANDOM()") } - scope :valuation_open, -> { where(valuation_finished: false) } - scope :without_admin, -> { valuation_open.where(administrator_id: nil) } - scope :managed, -> { valuation_open.where(valuator_assignments_count: 0).where("administrator_id IS NOT ?", nil) } - scope :valuating, -> { valuation_open.where("valuator_assignments_count > 0 AND valuation_finished = ?", false) } - scope :valuation_finished, -> { where(valuation_finished: true) } - scope :feasible, -> { where(feasibility: "feasible") } - scope :unfeasible, -> { where(feasibility: "unfeasible") } - scope :not_unfeasible, -> { where.not(feasibility: "unfeasible") } - scope :undecided, -> { where(feasibility: "undecided") } - scope :with_supports, -> { where('cached_votes_up > 0') } - scope :selected, -> { where(selected: true) } + scope :valuation_open, -> { where(valuation_finished: false) } + scope :without_admin, -> { valuation_open.where(administrator_id: nil) } + scope :managed, -> { valuation_open.where(valuator_assignments_count: 0).where("administrator_id IS NOT ?", nil) } + scope :valuating, -> { valuation_open.where("valuator_assignments_count > 0 AND valuation_finished = ?", false) } + scope :valuation_finished, -> { where(valuation_finished: true) } + scope :valuation_finished_feasible, -> { where(valuation_finished: true, feasibility: "feasible") } + scope :feasible, -> { where(feasibility: "feasible") } + scope :unfeasible, -> { where(feasibility: "unfeasible") } + scope :not_unfeasible, -> { where.not(feasibility: "unfeasible") } + scope :undecided, -> { where(feasibility: "undecided") } + scope :with_supports, -> { where('cached_votes_up > 0') } + scope :selected, -> { where(selected: true) } scope :by_group, -> (group_id) { where(group_id: group_id) } scope :by_heading, -> (heading_id) { where(heading_id: heading_id) } diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/views/admin/budget_investments/_investments.html.erb new file mode 100644 index 000000000..c82b0044a --- /dev/null +++ b/app/views/admin/budget_investments/_investments.html.erb @@ -0,0 +1,77 @@ +

<%= page_entries_info @investments %>

+ + + + + + + + + + + + + + + + <% @investments.each do |investment| %> + + + + + + + + + + + <% end %> +
<%= t("admin.budget_investments.index.table_id") %><%= t("admin.budget_investments.index.table_title") %><%= t("admin.budget_investments.index.table_admin") %><%= t("admin.budget_investments.index.table_valuator") %><%= t("admin.budget_investments.index.table_geozone") %><%= t("admin.budget_investments.index.table_feasibility") %><%= t("admin.budget_investments.index.table_valuation_finished") %><%= t("admin.budget_investments.index.table_selection") %>
+ <%= investment.id %> + + <%= link_to investment.title, admin_budget_budget_investment_path(budget_id: @budget.id, id: investment.id, params: Budget::Investment.filter_params(params)) %> + + <% if investment.administrator.present? %> + <%= investment.administrator.name %> + <% else %> + <%= t("admin.budget_investments.index.no_admin_assigned") %> + <% end %> + + <% if investment.valuators.size == 0 %> + <%= t("admin.budget_investments.index.no_valuators_assigned") %> + <% else %> + <%= investment.valuators.collect(&:description_or_name).join(', ') %> + <% end %> + + <%= investment.heading.name %> + + <%= t("admin.budget_investments.index.feasibility.#{investment.feasibility}", + price: investment.formatted_price) + %> + + <%= investment.valuation_finished? ? t('shared.yes'): t('shared.no') %> + + <% if investment.selected? %> + <%= link_to toggle_selection_admin_budget_budget_investment_path(@budget, + investment, + filter: params[:filter], + page: params[:page]), + method: :patch, + remote: true, + class: "button small expanded" do %> + <%= t("admin.budget_investments.index.selected") %> + <% end %> + <% elsif investment.feasible? && investment.valuation_finished? %> + <%= link_to toggle_selection_admin_budget_budget_investment_path(@budget, + investment, + filter: params[:filter], + page: params[:page]), + method: :patch, + remote: true, + class: "button small hollow expanded" do %> + <%= t("admin.budget_investments.index.select") %> + <% end %> + <% end %> +
+ +<%= paginate @investments %> diff --git a/app/views/admin/budget_investments/index.html.erb b/app/views/admin/budget_investments/index.html.erb index 5aff40115..126a933b7 100644 --- a/app/views/admin/budget_investments/index.html.erb +++ b/app/views/admin/budget_investments/index.html.erb @@ -36,41 +36,9 @@ <% end %> -<%= render 'shared/filter_subnav', i18n_namespace: "admin.budget_investments.index" %> +<%= render '/shared/filter_subnav', i18n_namespace: "admin.budget_investments.index" %> -

<%= page_entries_info @investments %>

+
+ <%= render '/admin/budget_investments/investments' %> +
- - <% @investments.each do |investment| %> - - - - - - - - - <% end %> -
- <%= investment.id %> - - <%= link_to investment.title, admin_budget_budget_investment_path(budget_id: @budget.id, id: investment.id, params: Budget::Investment.filter_params(params)) %> - - <% if investment.administrator.present? %> - <%= investment.administrator.name %> - <% else %> - <%= t("admin.budget_investments.index.no_admin_assigned") %> - <% end %> - - <% if investment.valuators.size == 0 %> - <%= t("admin.budget_investments.index.no_valuators_assigned") %> - <% else %> - <%= investment.valuators.collect(&:description_or_name).join(', ') %> - <% end %> - - <%= investment.heading.name %> - - <%= t("admin.budget_investments.index.feasibility.#{investment.feasibility}", price: investment.price) %> -
- -<%= paginate @investments %> \ No newline at end of file diff --git a/app/views/admin/budget_investments/toggle_selection.js.erb b/app/views/admin/budget_investments/toggle_selection.js.erb new file mode 100644 index 000000000..dc3a8d67a --- /dev/null +++ b/app/views/admin/budget_investments/toggle_selection.js.erb @@ -0,0 +1 @@ +$("#investments").html('<%= j render("admin/budget_investments/investments") %>'); diff --git a/app/views/shared/_filter_subnav.html.erb b/app/views/shared/_filter_subnav.html.erb index 51a745b09..80767f4a7 100644 --- a/app/views/shared/_filter_subnav.html.erb +++ b/app/views/shared/_filter_subnav.html.erb @@ -1,4 +1,4 @@ -