Fixes all management bi issues except filtering by geozone

This commit is contained in:
kikito
2016-12-07 16:35:27 +01:00
parent 2760e751e7
commit b3be1633af
11 changed files with 59 additions and 26 deletions

View File

@@ -6,8 +6,8 @@ class Management::Budgets::InvestmentsController < Management::BaseController
before_action :only_verified_users, except: :print
def index
@investments = apply_filters_and_search(@investments).order(cached_votes_up: :desc).page(params[:page]).for_render
@investment_ids = @investments.pluck(:id)
@investments = apply_filters_and_search(@investments).page(params[:page])
set_investment_votes(@investments)
end
def new
@@ -26,10 +26,12 @@ class Management::Budgets::InvestmentsController < Management::BaseController
end
def show
set_investment_votes(@investment)
end
def vote
@investment.register_vote(managed_user, 'yes')
@investment.register_selection(managed_user)
set_investment_votes(@investment)
end
def print
@@ -39,6 +41,10 @@ class Management::Budgets::InvestmentsController < Management::BaseController
private
def set_investment_votes(investments)
@investment_votes = managed_user ? managed_user.budget_investment_votes(investments) : {}
end
def load_budget
@budget = Budget.find(params[:budget_id])
end

View File

@@ -10,7 +10,7 @@ class Management::BudgetsController < Management::BaseController
end
def support_investments
@budgets = Budget.accepting.order(created_at: :desc).page(params[:page])
@budgets = Budget.selecting.order(created_at: :desc).page(params[:page])
end
def print_investments

View File

@@ -21,6 +21,15 @@ module BudgetsHelper
end
end
def namespaced_budget_investment_vote_path(investment, options={})
case namespace
when "management::budgets"
vote_management_budget_investment_path(investment.budget, investment, options)
else
vote_budget_investment_path(investment.budget, investment, options)
end
end
def display_budget_countdown?(budget)
budget.balloting?
end

View File

@@ -14,11 +14,14 @@ class Budget < ActiveRecord::Base
has_many :groups, dependent: :destroy
has_many :headings, through: :groups
scope :current, -> { where.not(phase: "finished") }
scope :finished, -> { where(phase: "finished") }
scope :valuating, -> { where(valuating: true) }
scope :on_hold, -> { where(phase: "on_hold") }
scope :accepting, -> { where(phase: "accepting") }
scope :selecting, -> { where(phase: "selecting") }
scope :balloting, -> { where(phase: "balloting") }
scope :finished, -> { where(phase: "finished") }
scope :current, -> { where.not(phase: "finished") }
scope :valuating, -> { where(valuating: true) }
def on_hold?
phase == "on_hold"

View File

@@ -190,9 +190,7 @@ class Budget
end
def should_show_aside?
(budget.selecting? && !investment.unfeasible?) ||
(budget.balloting? && investment.feasible?) ||
budget.on_hold?
(budget.selecting? && !unfeasible?) || (budget.balloting? && feasible?) || budget.on_hold?
end
def should_show_votes?

View File

@@ -51,7 +51,7 @@
<%= render partial: '/budgets/investments/votes', locals: {
investment: investment,
investment_votes: investment_votes,
vote_url: vote_budget_investment_path(investment.budget, investment, value: 'yes')
vote_url: namespaced_budget_investment_vote_path(investment, value: 'yes')
} %>
</div>

View File

@@ -63,7 +63,7 @@
vote_url: vote_budget_investment_path(investment.budget, investment, value: 'yes')
} %>
</div>
<% elseif investment.sould_show_ballots? %>
<% elsif investment.should_show_ballots? %>
<div id="<%= dom_id(investment) %>_ballot">
<%= render 'ballot', investment: investment %>
</div>

View File

@@ -1 +1,4 @@
$("#<%= dom_id(@investment) %>_votes").html('<%= j render("budgets/investments/votes", investment: @investment, vote_url: vote_budget_investment_path(@budget, @investment, value: "yes")) %>');
$("#<%= dom_id(@investment) %>_votes").html('<%= j render("/budgets/investments/votes",
investment: @investment,
investment_votes: @budget_investment_votes,
vote_url: namespaced_budget_investment_vote_path(@investment, value: 'yes')) %>');

View File

@@ -2,4 +2,7 @@
<%= render '/shared/print' %>
<%= render partial: '/budgets/investments/investment_show', locals: { investment: @investment, investment_votes: @investment_votes } %>
<%= render partial: '/budgets/investments/investment_show', locals: {
investment: @investment,
investment_votes: @investment_votes
} %>

View File

@@ -1 +1,4 @@
<%= render template: 'budgets/investments/vote' %>
$("#<%= dom_id(@investment) %>_votes").html('<%= j render("/budgets/investments/votes",
investment: @investment,
investment_votes: @investment_votes,
vote_url: namespaced_budget_investment_vote_path(@investment, value: 'yes')) %>');

View File

@@ -4,12 +4,13 @@ feature 'Budget Investments' do
background do
login_as_manager
@budget = create(:budget, phase: 'accepting', name: "2016")
group = create(:budget_group, budget: @budget, name: 'Whole city')
@heading = create(:budget_heading, group: group, name: "Health")
@budget = create(:budget, phase: 'selecting', name: "2016")
@group = create(:budget_group, budget: @budget, name: 'Whole city')
@heading = create(:budget_heading, group: @group, name: "Health")
end
context "Create" do
before { @budget.update(phase: 'accepting') }
scenario 'Creating budget investments on behalf of someone, selecting a budget' do
user = create(:user, :level_two)
@@ -59,6 +60,7 @@ feature 'Budget Investments' do
end
context "Searching" do
scenario "by title" do
budget_investment1 = create(:budget_investment, budget: @budget, title: "Show me what you got")
budget_investment2 = create(:budget_investment, budget: @budget, title: "Get Schwifty")
@@ -67,6 +69,7 @@ feature 'Budget Investments' do
login_managed_user(user)
click_link "Support Budget Investments"
expect(page).to have_content(@budget.name)
within "#budget_#{@budget.id}" do
click_link "Support Budget Investments"
end
@@ -91,6 +94,7 @@ feature 'Budget Investments' do
login_managed_user(user)
click_link "Support Budget Investments"
expect(page).to have_content(@budget.name)
within "#budget_#{@budget.id}" do
click_link "Support Budget Investments"
end
@@ -116,6 +120,7 @@ feature 'Budget Investments' do
login_managed_user(user)
click_link "Support Budget Investments"
expect(page).to have_content(@budget.name)
within "#budget_#{@budget.id}" do
click_link "Support Budget Investments"
end
@@ -145,11 +150,11 @@ feature 'Budget Investments' do
login_managed_user(user)
click_link "Support Budget Investments"
expect(page).to have_content(@budget.name)
within "#budget_#{@budget.id}" do
click_link "Support Budget Investments"
end
save_and_open_page
expect(page).to have_content(budget_investment.title)
within("#budget-investments") do
find('.js-in-favor a').click
@@ -166,6 +171,7 @@ feature 'Budget Investments' do
login_managed_user(user)
click_link "Support Budget Investments"
expect(page).to have_content(@budget.name)
within "#budget_#{@budget.id}" do
click_link "Support Budget Investments"
end
@@ -194,9 +200,10 @@ feature 'Budget Investments' do
context "Printing" do
scenario 'Printing budget investments' do
16.times { create(:budget_investment, budget: @budget, geozone_id: nil) }
16.times { create(:budget_investment, budget: @budget) }
click_link "Print budget investments"
expect(page).to have_content(@budget.name)
within "#budget_#{@budget.id}" do
click_link "Support Budget Investments"
end
@@ -206,16 +213,17 @@ feature 'Budget Investments' do
end
scenario "Filtering budget investments by geozone to be printed", :js do
district_9 = create(:geozone, name: "District Nine")
create(:budget_investment, budget: @budget, title: 'Change district 9', geozone: district_9, cached_votes_up: 10)
create(:budget_investment, budget: @budget, title: 'Destroy district 9', geozone: district_9, cached_votes_up: 100)
create(:budget_investment, budget: @budget, title: 'Nuke district 9', geozone: district_9, cached_votes_up: 1)
create(:budget_investment, budget: @budget, title: 'Add new districts to the city', geozone_id: nil)
district_9 = create(:budget_heading, group: @group, name: "District Nine")
create(:budget_investment, budget: @budget, title: 'Change district 9', heading: district_9, cached_votes_up: 10)
create(:budget_investment, budget: @budget, title: 'Destroy district 9', heading: district_9, cached_votes_up: 100)
create(:budget_investment, budget: @budget, title: 'Nuke district 9', heading: district_9, cached_votes_up: 1)
create(:budget_investment, budget: @budget, title: 'Add new districts to the city', heading: @heading)
user = create(:user, :level_two)
login_managed_user(user)
click_link "Print budget investments"
expect(page).to have_content(@budget.name)
within "#budget_#{@budget.id}" do
click_link "Support Budget Investments"
end