Starts fixing management budget investments
This commit is contained in:
@@ -2,11 +2,11 @@ class Management::BudgetInvestmentsController < Management::BaseController
|
|||||||
|
|
||||||
before_action :only_verified_users, except: :print
|
before_action :only_verified_users, except: :print
|
||||||
before_action :set_budget_investment, only: [:vote, :show]
|
before_action :set_budget_investment, only: [:vote, :show]
|
||||||
before_action :load_budget
|
before_action :load_accepting_headings, only: [:new, :create]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@budget_investments = apply_filters_and_search(Budget::Investment).order(cached_votes_up: :desc).page(params[:page]).for_render
|
@investments = apply_filters_and_search(Budget::Investment).order(cached_votes_up: :desc).page(params[:page]).for_render
|
||||||
set_budget_investment_votes(@budget_investments)
|
set_budget_investment_votes(@investments)
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@@ -14,39 +14,40 @@ class Management::BudgetInvestmentsController < Management::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@budget_investment = Budget::Investment.new(budget_investment_params)
|
@investment = Budget::Investment.new(budget_investment_params)
|
||||||
@budget_investment.author = managed_user
|
@investment.terms_of_service = "1"
|
||||||
|
@investment.author = managed_user
|
||||||
|
|
||||||
if @budget_investment.save
|
if @investment.save
|
||||||
redirect_to management_budget_investment_path(@budget_investment), notice: t('flash.actions.create.notice', resource_name: t("activerecord.models.budget_investment", count: 1))
|
redirect_to management_budget_investment_path(@investment), notice: t('flash.actions.create.notice', resource_name: Budget::Investment.model_name.human, count: 1)
|
||||||
else
|
else
|
||||||
render :new
|
render :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
set_budget_investment_votes(@budget_investment)
|
set_budget_investment_votes(@investment)
|
||||||
end
|
end
|
||||||
|
|
||||||
def vote
|
def vote
|
||||||
@budget_investment.register_vote(managed_user, 'yes')
|
@investment.register_vote(managed_user, 'yes')
|
||||||
set_budget_investment_votes(@budget_investment)
|
set_budget_investment_votes(@investment)
|
||||||
end
|
end
|
||||||
|
|
||||||
def print
|
def print
|
||||||
params[:geozone] ||= 'all'
|
params[:geozone] ||= 'all'
|
||||||
@budget_investments = apply_filters_and_search(Budget::Investment).order(cached_votes_up: :desc).for_render.limit(15)
|
@investments = apply_filters_and_search(Budget::Investment).order(cached_votes_up: :desc).for_render.limit(15)
|
||||||
set_budget_investment_votes(@budget_investments)
|
set_budget_investment_votes(@investments)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_budget_investment
|
def set_budget_investment
|
||||||
@budget_investment = Budget::Investment.find(params[:id])
|
@investment = Budget::Investment.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def budget_investment_params
|
def budget_investment_params
|
||||||
params.require(:budget_investment).permit(:title, :description, :external_url, :geozone_id, :terms_of_service)
|
params.require(:budget_investment).permit(:title, :description, :external_url, :geozone_id, :heading_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def only_verified_users
|
def only_verified_users
|
||||||
@@ -55,7 +56,7 @@ class Management::BudgetInvestmentsController < Management::BaseController
|
|||||||
|
|
||||||
# This should not be necessary. Maybe we could create a specific show view for managers.
|
# This should not be necessary. Maybe we could create a specific show view for managers.
|
||||||
def set_budget_investment_votes(budget_investments)
|
def set_budget_investment_votes(budget_investments)
|
||||||
@budget_investment_votes = managed_user ? managed_user.budget_investment_votes(budget_investments) : {}
|
@investment_votes = managed_user ? managed_user.budget_investment_votes(budget_investments) : {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_geozone_name
|
def set_geozone_name
|
||||||
@@ -76,4 +77,10 @@ class Management::BudgetInvestmentsController < Management::BaseController
|
|||||||
target
|
target
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def load_accepting_headings
|
||||||
|
accepting_budget_ids = Budget.accepting.pluck(:id)
|
||||||
|
accepting_budget_group_ids = Budget::Group.where(budget_id: accepting_budget_ids).pluck(:id)
|
||||||
|
@headings = Budget::Heading.where(group_id: accepting_budget_group_ids).order(:group_id, :name).includes(:group => :budget)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
class Management::BudgetsController < Management::BaseController
|
class Management::BudgetsController < Management::BaseController
|
||||||
include FeatureFlags
|
include FeatureFlags
|
||||||
|
include HasFilters
|
||||||
feature_flag :budgets
|
feature_flag :budgets
|
||||||
|
|
||||||
has_filters %w{open finished}, only: :index
|
has_filters %w{open finished}, only: :index
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ module BudgetHeadingsHelper
|
|||||||
budget.headings.map {|heading| [heading.name, heading.id]}
|
budget.headings.map {|heading| [heading.name, heading.id]}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def multiple_budgets_heading_select_options(headings)
|
||||||
|
headings.map { |heading| ["#{heading.budget.name} - #{heading.group.name} - #{heading.name}", heading.id] }
|
||||||
|
end
|
||||||
|
|
||||||
def budget_scoped_heading_select_options(budget)
|
def budget_scoped_heading_select_options(budget)
|
||||||
budget.headings.includes(:group).order("group_id ASC, budget_headings.name ASC").map {|heading| [heading.group.name + ': ' + heading.name, heading.id]}
|
budget.headings.includes(:group).order("group_id ASC, budget_headings.name ASC").map {|heading| [heading.group.name + ': ' + heading.name, heading.id]}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class Budget < ActiveRecord::Base
|
|||||||
scope :open, -> { where.not(phase: "finished") }
|
scope :open, -> { where.not(phase: "finished") }
|
||||||
scope :finished, -> { where(phase: "finished") }
|
scope :finished, -> { where(phase: "finished") }
|
||||||
scope :valuating, -> { where(valuating: true) }
|
scope :valuating, -> { where(valuating: true) }
|
||||||
|
scope :accepting, -> { where(phase: "accepting") }
|
||||||
|
|
||||||
def on_hold?
|
def on_hold?
|
||||||
phase == "on_hold"
|
phase == "on_hold"
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
<% provide :title do %><%= @investment.title %><% end %>
|
<% provide :title do %><%= @investment.title %><% end %>
|
||||||
|
|
||||||
<section class="budget-investment-show">
|
<section class="budget-investment-show">
|
||||||
|
|
||||||
|
<ul class="breadcrumbs">
|
||||||
|
<li><%= link_to @investment.budget.name, budget_path(@investment.budget) %></a></li>
|
||||||
|
<li><%= @investment.group.name %></a></li>
|
||||||
|
<li><%= @investment.heading.name %></a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
<div id="<%= dom_id(@investment) %>" class="row">
|
<div id="<%= dom_id(@investment) %>" class="row">
|
||||||
<div class="small-12 medium-9 column">
|
<div class="small-12 medium-9 column">
|
||||||
<%= link_to :back, class: "back" do %>
|
<%= link_to :back, class: "back" do %>
|
||||||
@@ -44,19 +51,19 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% if (@budget.selecting? && !@investment.unfeasible?) ||
|
<% if (@investment.budget.selecting? && !@investment.unfeasible?) ||
|
||||||
(@budget.balloting? && @investment.feasible? ||
|
(@investment.budget.balloting? && @investment.feasible? ||
|
||||||
(@budget.on_hold?)) %>
|
(@investment.budget.on_hold?)) %>
|
||||||
<aside class="small-12 medium-3 column">
|
<aside class="small-12 medium-3 column">
|
||||||
<div class="sidebar-divider"></div>
|
<div class="sidebar-divider"></div>
|
||||||
<h3><%= t("votes.supports") %></h3>
|
<h3><%= t("votes.supports") %></h3>
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
|
|
||||||
<% if @budget.selecting? || @budget.on_hold? %>
|
<% if @investment.budget.selecting? || @investment.budget.on_hold? %>
|
||||||
<div id="<%= dom_id(@investment) %>_votes">
|
<div id="<%= dom_id(@investment) %>_votes">
|
||||||
<%= render 'votes',
|
<%= render 'votes',
|
||||||
{ investment: @investment,
|
{ investment: @investment,
|
||||||
vote_url: vote_budget_investment_path(@budget, @investment, value: 'yes') }
|
vote_url: vote_budget_investment_path(@investment.budget, @investment, value: 'yes') }
|
||||||
%>
|
%>
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
@@ -71,7 +78,7 @@
|
|||||||
<div class="social-share-full">
|
<div class="social-share-full">
|
||||||
<%= social_share_button_tag("#{@investment.title} #{setting['twitter_hashtag']}") %>
|
<%= social_share_button_tag("#{@investment.title} #{setting['twitter_hashtag']}") %>
|
||||||
<% if browser.device.mobile? %>
|
<% if browser.device.mobile? %>
|
||||||
<a href="whatsapp://send?text=<%= @investment.title %> <%= budget_investment_url(budget_id: budget.id, id: @investment.id) %>" data-action="share/whatsapp/share">
|
<a href="whatsapp://send?text=<%= @investment.title %> <%= budget_investment_url(budget_id: @investment.budget.id, id: @investment.id) %>" data-action="share/whatsapp/share">
|
||||||
<span class="icon-whatsapp whatsapp"></span>
|
<span class="icon-whatsapp whatsapp"></span>
|
||||||
</a>
|
</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -6,7 +6,49 @@
|
|||||||
|
|
||||||
<div class="small-12 medium-9 column end">
|
<div class="small-12 medium-9 column end">
|
||||||
<h1 class=""><%= t("management.budget_investments.create") %></h1>
|
<h1 class=""><%= t("management.budget_investments.create") %></h1>
|
||||||
<%= render "budgets/investments/form", form_url: management_budget_investments_url %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
<%= form_for(@investment, url: management_budget_investments_path, method: :post) do |f| %>
|
||||||
|
<%= render 'shared/errors', resource: @investment %>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="small-12 column">
|
||||||
|
<%= f.label :title, t("budget.investments.form.title") %>
|
||||||
|
<%= f.text_field :title, maxlength: SpendingProposal.title_max_length, placeholder: t("budget.investments.form.title"), label: false %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= f.invisible_captcha :subtitle %>
|
||||||
|
|
||||||
|
<div class="ckeditor small-12 column">
|
||||||
|
<%= f.label :description, t("budget.investments.form.description") %>
|
||||||
|
<%= f.cktext_area :description, maxlength: SpendingProposal.description_max_length, ckeditor: { language: I18n.locale }, label: false %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="small-12 column">
|
||||||
|
<%= f.label :external_url, t("budget.investments.form.external_url") %>
|
||||||
|
<%= f.text_field :external_url, placeholder: t("budget.investments.form.external_url"), label: false %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="small-12 column">
|
||||||
|
<%= f.label :heading_id, t("budget.investments.form.heading") %>
|
||||||
|
<%= f.select :heading_id, multiple_budgets_heading_select_options(@headings), {include_blank: t("budget.headings.none"), label: false} %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="small-12 column">
|
||||||
|
<%= f.label :terms_of_service do %>
|
||||||
|
<%= f.check_box :terms_of_service, title: t('form.accept_terms_title'), label: false %>
|
||||||
|
<span class="checkbox">
|
||||||
|
<%= t("form.accept_terms",
|
||||||
|
policy: link_to(t("form.policy"), "/privacy", target: "blank"),
|
||||||
|
conditions: link_to(t("form.conditions"), "/conditions", target: "blank")).html_safe %>
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="actions small-12 column">
|
||||||
|
<%= f.submit(class: "button", value: t("budget.investments.form.submit_buttons.#{action_name}")) %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,21 +4,16 @@ feature 'Budget Investments' do
|
|||||||
|
|
||||||
background do
|
background do
|
||||||
login_as_manager
|
login_as_manager
|
||||||
@budget = create(:budget)
|
budget = create(:budget, phase: 'accepting', name: "2016")
|
||||||
end
|
group = create(:budget_group, budget: budget, name: 'Whole city')
|
||||||
|
@heading = create(:budget_heading, group: group, name: "Health")
|
||||||
context "Select a budget" do
|
|
||||||
budget2 = create(:budget)
|
|
||||||
budget3 = create(:budget)
|
|
||||||
|
|
||||||
click_link "Create budget investment"
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Create" do
|
context "Create" do
|
||||||
|
|
||||||
scenario 'Creating budget investments on behalf of someone' do
|
scenario 'Creating budget investments on behalf of someone, selecting a budget' do
|
||||||
user = create(:user, :level_two)
|
user = create(:user, :level_two)
|
||||||
|
|
||||||
login_managed_user(user)
|
login_managed_user(user)
|
||||||
|
|
||||||
click_link "Create budget investment"
|
click_link "Create budget investment"
|
||||||
@@ -30,6 +25,7 @@ feature 'Budget Investments' do
|
|||||||
expect(page).to have_content "#{user.document_number}"
|
expect(page).to have_content "#{user.document_number}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
select "2016 - Whole city - Health", from: 'budget_investment_heading_id'
|
||||||
fill_in 'budget_investment_title', with: 'Build a park in my neighborhood'
|
fill_in 'budget_investment_title', with: 'Build a park in my neighborhood'
|
||||||
fill_in 'budget_investment_description', with: 'There is no parks here...'
|
fill_in 'budget_investment_description', with: 'There is no parks here...'
|
||||||
fill_in 'budget_investment_external_url', with: 'http://moarparks.com'
|
fill_in 'budget_investment_external_url', with: 'http://moarparks.com'
|
||||||
@@ -37,11 +33,13 @@ feature 'Budget Investments' do
|
|||||||
|
|
||||||
click_button 'Create'
|
click_button 'Create'
|
||||||
|
|
||||||
expect(page).to have_content 'budget investment created successfully.'
|
expect(page).to have_content 'Investment created successfully.'
|
||||||
|
|
||||||
|
expect(page).to have_content '2016'
|
||||||
|
expect(page).to have_content 'Whole city'
|
||||||
|
expect(page).to have_content 'Health'
|
||||||
expect(page).to have_content 'Build a park in my neighborhood'
|
expect(page).to have_content 'Build a park in my neighborhood'
|
||||||
expect(page).to have_content 'There is no parks here...'
|
expect(page).to have_content 'There is no parks here...'
|
||||||
expect(page).to have_content 'All city'
|
|
||||||
expect(page).to have_content 'http://moarparks.com'
|
expect(page).to have_content 'http://moarparks.com'
|
||||||
expect(page).to have_content user.name
|
expect(page).to have_content user.name
|
||||||
expect(page).to have_content I18n.l(Budget::Investment.last.created_at.to_date)
|
expect(page).to have_content I18n.l(Budget::Investment.last.created_at.to_date)
|
||||||
|
|||||||
Reference in New Issue
Block a user