Starts fixing management budget investments

This commit is contained in:
kikito
2016-12-01 16:31:05 +01:00
parent 424d0201c4
commit 00cfb95913
8 changed files with 97 additions and 37 deletions

View File

@@ -2,11 +2,11 @@ class Management::BudgetInvestmentsController < Management::BaseController
before_action :only_verified_users, except: :print
before_action :set_budget_investment, only: [:vote, :show]
before_action :load_budget
before_action :load_accepting_headings, only: [:new, :create]
def index
@budget_investments = apply_filters_and_search(Budget::Investment).order(cached_votes_up: :desc).page(params[:page]).for_render
set_budget_investment_votes(@budget_investments)
@investments = apply_filters_and_search(Budget::Investment).order(cached_votes_up: :desc).page(params[:page]).for_render
set_budget_investment_votes(@investments)
end
def new
@@ -14,39 +14,40 @@ class Management::BudgetInvestmentsController < Management::BaseController
end
def create
@budget_investment = Budget::Investment.new(budget_investment_params)
@budget_investment.author = managed_user
@investment = Budget::Investment.new(budget_investment_params)
@investment.terms_of_service = "1"
@investment.author = managed_user
if @budget_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))
if @investment.save
redirect_to management_budget_investment_path(@investment), notice: t('flash.actions.create.notice', resource_name: Budget::Investment.model_name.human, count: 1)
else
render :new
end
end
def show
set_budget_investment_votes(@budget_investment)
set_budget_investment_votes(@investment)
end
def vote
@budget_investment.register_vote(managed_user, 'yes')
set_budget_investment_votes(@budget_investment)
@investment.register_vote(managed_user, 'yes')
set_budget_investment_votes(@investment)
end
def print
params[:geozone] ||= 'all'
@budget_investments = apply_filters_and_search(Budget::Investment).order(cached_votes_up: :desc).for_render.limit(15)
set_budget_investment_votes(@budget_investments)
@investments = apply_filters_and_search(Budget::Investment).order(cached_votes_up: :desc).for_render.limit(15)
set_budget_investment_votes(@investments)
end
private
def set_budget_investment
@budget_investment = Budget::Investment.find(params[:id])
@investment = Budget::Investment.find(params[:id])
end
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
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.
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
def set_geozone_name
@@ -76,4 +77,10 @@ class Management::BudgetInvestmentsController < Management::BaseController
target
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

View File

@@ -1,5 +1,6 @@
class Management::BudgetsController < Management::BaseController
include FeatureFlags
include HasFilters
feature_flag :budgets
has_filters %w{open finished}, only: :index

View File

@@ -4,8 +4,12 @@ module BudgetHeadingsHelper
budget.headings.map {|heading| [heading.name, heading.id]}
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)
budget.headings.includes(:group).order("group_id ASC, budget_headings.name ASC").map {|heading| [heading.group.name + ': ' + heading.name, heading.id]}
end
end
end

View File

@@ -17,6 +17,7 @@ class Budget < ActiveRecord::Base
scope :open, -> { where.not(phase: "finished") }
scope :finished, -> { where(phase: "finished") }
scope :valuating, -> { where(valuating: true) }
scope :accepting, -> { where(phase: "accepting") }
def on_hold?
phase == "on_hold"

View File

@@ -1,6 +1,13 @@
<% provide :title do %><%= @investment.title %><% end %>
<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 class="small-12 medium-9 column">
<%= link_to :back, class: "back" do %>
@@ -44,19 +51,19 @@
<% end %>
</div>
<% if (@budget.selecting? && !@investment.unfeasible?) ||
(@budget.balloting? && @investment.feasible? ||
(@budget.on_hold?)) %>
<% if (@investment.budget.selecting? && !@investment.unfeasible?) ||
(@investment.budget.balloting? && @investment.feasible? ||
(@investment.budget.on_hold?)) %>
<aside class="small-12 medium-3 column">
<div class="sidebar-divider"></div>
<h3><%= t("votes.supports") %></h3>
<div class="text-center">
<% if @budget.selecting? || @budget.on_hold? %>
<% if @investment.budget.selecting? || @investment.budget.on_hold? %>
<div id="<%= dom_id(@investment) %>_votes">
<%= render 'votes',
{ investment: @investment,
vote_url: vote_budget_investment_path(@budget, @investment, value: 'yes') }
vote_url: vote_budget_investment_path(@investment.budget, @investment, value: 'yes') }
%>
</div>
<% else %>
@@ -71,7 +78,7 @@
<div class="social-share-full">
<%= social_share_button_tag("#{@investment.title} #{setting['twitter_hashtag']}") %>
<% 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>
</a>
<% end %>

View File

@@ -6,7 +6,49 @@
<div class="small-12 medium-9 column end">
<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>

View File

@@ -102,4 +102,4 @@ en:
proposal_notification:
attributes:
minimum_interval:
invalid: "You have to wait a minium of %{interval} days between notifications"
invalid: "You have to wait a minium of %{interval} days between notifications"

View File

@@ -4,21 +4,16 @@ feature 'Budget Investments' do
background do
login_as_manager
@budget = create(:budget)
end
context "Select a budget" do
budget2 = create(:budget)
budget3 = create(:budget)
click_link "Create budget investment"
budget = create(:budget, phase: 'accepting', name: "2016")
group = create(:budget_group, budget: budget, name: 'Whole city')
@heading = create(:budget_heading, group: group, name: "Health")
end
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)
login_managed_user(user)
click_link "Create budget investment"
@@ -30,6 +25,7 @@ feature 'Budget Investments' do
expect(page).to have_content "#{user.document_number}"
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_description', with: 'There is no parks here...'
fill_in 'budget_investment_external_url', with: 'http://moarparks.com'
@@ -37,11 +33,13 @@ feature 'Budget Investments' do
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 '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 user.name
expect(page).to have_content I18n.l(Budget::Investment.last.created_at.to_date)