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

View File

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

View File

@@ -21,6 +21,15 @@ module BudgetsHelper
end end
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) def display_budget_countdown?(budget)
budget.balloting? budget.balloting?
end end

View File

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

View File

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

View File

@@ -51,7 +51,7 @@
<%= render partial: '/budgets/investments/votes', locals: { <%= render partial: '/budgets/investments/votes', locals: {
investment: investment, investment: investment,
investment_votes: investment_votes, 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> </div>

View File

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