diff --git a/app/controllers/budgets/ballot/lines_controller.rb b/app/controllers/budgets/ballot/lines_controller.rb index 5483f40a3..c64efbd84 100644 --- a/app/controllers/budgets/ballot/lines_controller.rb +++ b/app/controllers/budgets/ballot/lines_controller.rb @@ -20,11 +20,11 @@ module Budgets #@ballot.set_geozone(@geozone) #@current_user.update(representative_id: nil) if request.get? - redirect_to @spending_proposal, notice: t('spending_proposals.notice.voted') + redirect_to @investment, notice: t('budget_investments.notice.voted') end else if request.get? - redirect_to @spending_proposal, notice: t('spending_proposals.notice.could_not_vote') + redirect_to @investment, notice: t('budget_investments.notice.could_not_vote') else render :new end @@ -74,4 +74,4 @@ module Budgets end end -end \ No newline at end of file +end diff --git a/app/controllers/management/budget_investments_controller.rb b/app/controllers/management/budget_investments_controller.rb deleted file mode 100644 index 64dd30492..000000000 --- a/app/controllers/management/budget_investments_controller.rb +++ /dev/null @@ -1,79 +0,0 @@ -class Management::BudgetInvestmentsController < Management::BaseController - - before_action :only_verified_users, except: :print - before_action :set_budget_investment, only: [:vote, :show] - before_action :load_budget - - 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) - end - - def new - @investment = Budget::Investment.new - end - - def create - @budget_investment = Budget::Investment.new(budget_investment_params) - @budget_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)) - else - render :new - end - end - - def show - set_budget_investment_votes(@budget_investment) - end - - def vote - @budget_investment.register_vote(managed_user, 'yes') - set_budget_investment_votes(@budget_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) - end - - private - - def set_budget_investment - @budget_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) - end - - def only_verified_users - check_verified_user t("management.budget_investments.alert.unverified_user") - end - - # 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) : {} - end - - def set_geozone_name - if params[:geozone] == 'all' - @geozone_name = t('geozones.none') - else - @geozone_name = Geozone.find(params[:geozone]).name - end - end - - def apply_filters_and_search(target) - target = params[:unfeasible].present? ? target.unfeasible : target.not_unfeasible - if params[:geozone].present? - target = target.by_geozone(params[:geozone]) - set_geozone_name - end - target = target.search(params[:search]) if params[:search].present? - target - end - -end diff --git a/app/controllers/management/budgets/investments_controller.rb b/app/controllers/management/budgets/investments_controller.rb new file mode 100644 index 000000000..e8c10ab50 --- /dev/null +++ b/app/controllers/management/budgets/investments_controller.rb @@ -0,0 +1,66 @@ +class Management::Budgets::InvestmentsController < Management::BaseController + + load_resource :budget + load_resource :investment, through: :budget, class: 'Budget::Investment' + + before_action :only_verified_users, except: :print + + def index + @investments = apply_filters_and_search(@investments).page(params[:page]) + set_investment_votes(@investments) + end + + def new + end + + def create + @investment.terms_of_service = "1" + @investment.author = managed_user + + if @investment.save + notice= t('flash.actions.create.notice', resource_name: Budget::Investment.model_name.human, count: 1) + redirect_to management_budget_investment_path(@budget, @investment), notice: notice + else + render :new + end + end + + def show + set_investment_votes(@investment) + end + + def vote + @investment.register_selection(managed_user) + set_investment_votes(@investment) + end + + def print + @investments = apply_filters_and_search(@investments).order(cached_votes_up: :desc).for_render.limit(15) + set_investment_votes(@investments) + end + + private + + def set_investment_votes(investments) + @investment_votes = managed_user ? managed_user.budget_investment_votes(investments) : {} + end + + def investment_params + params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id) + end + + def only_verified_users + check_verified_user t("management.budget_investments.alert.unverified_user") + end + + def apply_filters_and_search(investments) + investments = params[:unfeasible].present? ? investments.unfeasible : investments.not_unfeasible + if params[:heading_id].present? + investments = investments.by_heading(params[:heading_id]) + @heading = Budget::Heading.find(params[:heading_id]) + end + investments = investments.search(params[:search]) if params[:search].present? + investments + end + +end diff --git a/app/controllers/management/budgets_controller.rb b/app/controllers/management/budgets_controller.rb index d4d5b8592..c5cfdee76 100644 --- a/app/controllers/management/budgets_controller.rb +++ b/app/controllers/management/budgets_controller.rb @@ -1,16 +1,26 @@ class Management::BudgetsController < Management::BaseController include FeatureFlags + include HasFilters feature_flag :budgets - has_filters %w{open finished}, only: :index + before_action :only_verified_users, except: :print_investments - load_and_authorize_resource - - def index - @budgets = @budgets.send(@current_filter).order(created_at: :desc).page(params[:page]) + def create_investments + @budgets = Budget.accepting.order(created_at: :desc).page(params[:page]) end - def show - @budget = Budget.includes(groups: :headings).find(params[:id]) + def support_investments + @budgets = Budget.selecting.order(created_at: :desc).page(params[:page]) end + + def print_investments + @budgets = Budget.current.order(created_at: :desc).page(params[:page]) + end + + private + + def only_verified_users + check_verified_user t("management.budget_investments.alert.unverified_user") + end + end diff --git a/app/helpers/budget_headings_helper.rb b/app/helpers/budget_headings_helper.rb index b9944be9b..3fa1eac89 100644 --- a/app/helpers/budget_headings_helper.rb +++ b/app/helpers/budget_headings_helper.rb @@ -1,11 +1,9 @@ module BudgetHeadingsHelper def budget_heading_select_options(budget) - budget.headings.map {|heading| [heading.name, heading.id]} + budget.headings.order_by_group_name.map do |heading| + [heading.name_scoped_by_group, heading.id] + end 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 \ No newline at end of file +end diff --git a/app/helpers/budget_helper.rb b/app/helpers/budget_helper.rb deleted file mode 100644 index af239f074..000000000 --- a/app/helpers/budget_helper.rb +++ /dev/null @@ -1,36 +0,0 @@ -module BudgetHelper - def format_price(budget, number) - number_to_currency(number, - precision: 0, - locale: I18n.default_locale, - unit: budget.currency_symbol) - end - - def heading_name(heading) - heading.present? ? heading.name : t("budget.headings.none") - end - - def namespaced_budget_investment_path(investment, options={}) - @namespaced_budget_investment_path ||= namespace - options[:budget_id] ||= investment.budget.id - case @namespace_budget_investment_path - when "management" - management_budget_investment_path(investment, options) - else - budget_investment_path(investment, options) - end - end - - def display_budget_countdown?(budget) - budget.balloting? - end - - def css_for_ballot_heading(heading) - return '' unless current_ballot.present? - current_ballot.has_lines_in_heading?(heading) ? 'active' : '' - end - - def current_ballot - Budget::Ballot.where(user: current_user, budget: @budget).first - end -end diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index d281ef182..6c1471c90 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -8,4 +8,38 @@ module BudgetsHelper Budget::CURRENCY_SYMBOLS.map { |cs| [ cs, cs ] } end -end \ No newline at end of file + def heading_name(heading) + heading.present? ? heading.name : t("budget.headings.none") + end + + def namespaced_budget_investment_path(investment, options={}) + case namespace + when "management::budgets" + management_budget_investment_path(investment.budget, investment, options) + else + budget_investment_path(investment.budget, investment, options.merge(budget_id: investment.budget_id)) + 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 + + def css_for_ballot_heading(heading) + return '' unless current_ballot.present? + current_ballot.has_lines_in_heading?(heading) ? 'active' : '' + end + + def current_ballot + Budget::Ballot.where(user: current_user, budget: @budget).first + end +end diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index cf8af477b..98080aa4c 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -14,7 +14,7 @@ module Abilities can [:search, :read], Annotation can [:read], Budget can [:read], Budget::Group - can [:read], Budget::Investment + can [:read, :print], Budget::Investment can :new, DirectMessage end end diff --git a/app/models/budget.rb b/app/models/budget.rb index e716c0181..28b37a896 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -14,8 +14,13 @@ class Budget < ActiveRecord::Base has_many :groups, dependent: :destroy has_many :headings, through: :groups - scope :open, -> { where.not(phase: "finished") } + 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? @@ -41,5 +46,20 @@ class Budget < ActiveRecord::Base def heading_price(heading) heading_ids.include?(heading.id) ? heading.price : -1 end + + def translated_phase + I18n.t "budget.phase.#{phase}" + end + + def formatted_amount(amount) + ActionController::Base.helpers.number_to_currency(amount, + precision: 0, + locale: I18n.default_locale, + unit: currency_symbol) + end + + def formatted_heading_price(heading) + formatted_ammount(heading_price(heading)) + end end diff --git a/app/models/budget/heading.rb b/app/models/budget/heading.rb index c658c5d28..52da63c4f 100644 --- a/app/models/budget/heading.rb +++ b/app/models/budget/heading.rb @@ -9,6 +9,8 @@ class Budget validates :name, presence: true validates :price, presence: true + scope :order_by_group_name, -> { includes(:group).order('budget_groups.name', 'budget_headings.name') } + def budget group.budget end @@ -17,5 +19,9 @@ class Budget group.budget = resource end + def name_scoped_by_group + "#{group.name}: #{name}" + end + end end diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 619602b2a..aa86888fc 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -55,6 +55,7 @@ class Budget before_save :calculate_confidence_score before_validation :set_responsible_name + before_validation :set_denormalized_ids def self.filter_params(params) params.select{|x,_| %w{heading_id group_id administrator_id tag_name valuator_id}.include? x.to_s } @@ -155,7 +156,7 @@ class Budget def permission_problem(user) return :not_logged_in unless user return :organization if user.organization? - return :not_verified unless user.can?(:vote, SpendingProposal) + return :not_verified unless user.can?(:vote, Budget::Investment) return nil end @@ -188,5 +189,27 @@ class Budget self.responsible_name = author.try(:document_number) if author.try(:document_number).present? end + def should_show_aside? + (budget.selecting? && !unfeasible?) || (budget.balloting? && feasible?) || budget.on_hold? + end + + def should_show_votes? + budget.selecting? || budget.on_hold? + end + + def should_show_ballots? + budget.balloting? + end + + def formatted_price + budget.formatted_amount(price) + end + + private + + def set_denormalized_ids + self.group_id ||= self.heading.group_id + self.budget_id ||= self.heading.group.budget_id + end end end diff --git a/app/views/admin/budget_investments/edit.html.erb b/app/views/admin/budget_investments/edit.html.erb index db57c423b..e98483772 100644 --- a/app/views/admin/budget_investments/edit.html.erb +++ b/app/views/admin/budget_investments/edit.html.erb @@ -23,7 +23,7 @@
- <%= f.select :heading_id, budget_scoped_heading_select_options(@budget), include_blank: t("admin.budget_investments.edit.select_heading") %> + <%= f.select :heading_id, budget_heading_select_options(@budget), include_blank: t("admin.budget_investments.edit.select_heading") %>
@@ -66,4 +66,4 @@ <% end %>
-<%# render 'valuation/budget_investments/written_by_valuators' %> \ No newline at end of file +<%# render 'valuation/budget_investments/written_by_valuators' %> diff --git a/app/views/admin/shared/_budget_investment_search.html.erb b/app/views/admin/shared/_budget_investment_search.html.erb index 92bd8e24a..410044c10 100644 --- a/app/views/admin/shared/_budget_investment_search.html.erb +++ b/app/views/admin/shared/_budget_investment_search.html.erb @@ -1,10 +1,25 @@ <%= form_for(Budget::Investment.new, url: url, as: :budget_investment, method: :get) do |f| %>
- <%= text_field_tag :search, "", placeholder: t("admin.shared.budget_investment_search.placeholder") %> + <%= text_field_tag :search, "" %>
+
+ <%= select_tag :heading_id, + options_for_select(budget_heading_select_options(@budget), + params[:heading_id]), + include_blank: true + %> +
+
+
+
+ <%= check_box_tag :unfeasible, "1", params[:unfeasible].present? %> +
+
+ +
- <%= f.submit t("admin.shared.budget_investment_search.button"), class: "button" %> + <%= f.submit t("shared.search"), class: "button" %>
<% end %> diff --git a/app/views/budgets/ballot/_add.html.erb b/app/views/budgets/ballot/_add.html.erb deleted file mode 100644 index 27c22ae2f..000000000 --- a/app/views/budgets/ballot/_add.html.erb +++ /dev/null @@ -1,16 +0,0 @@ -
-

- <%= format_price(@budget, investment.price) %> -

- - <% if @budget.balloting? %> - <%= link_to budget_ballot_lines_url(investment_id: investment.id, - investments_ids: @ballot.investment_ids), - class: "button button-support small expanded", - title: t('budget.investments.investment.support_title'), - method: "post", - remote: true do %> - <%= t("budget.investments.investment.add") %> - <% end %> - <% end %> -
diff --git a/app/views/budgets/ballot/_ballot.html.erb b/app/views/budgets/ballot/_ballot.html.erb index a6529306b..99fdcd5cd 100644 --- a/app/views/budgets/ballot/_ballot.html.erb +++ b/app/views/budgets/ballot/_ballot.html.erb @@ -28,7 +28,7 @@

<%= t("budgets.ballots.show.amount_spent") %> - <%= format_price(@budget, @ballot.amount_spent(@ballot.heading_for_group(group).id)) %> + <%= @budget.formatted_amount(@ballot.amount_spent(@ballot.heading_for_group(group).id))) %>

<% else %> @@ -47,9 +47,9 @@

<%= t("budgets.ballots.show.remaining", - amount_city: format_price(@budget, @ballot.amount_available(@ballot.heading_for_group(group)))).html_safe %> + amount_city: @budget.formatted_amount(@ballot.amount_available(@ballot.heading_for_group(group))))).html_safe %>

<% end %> - \ No newline at end of file + diff --git a/app/views/budgets/ballot/_investment.html.erb b/app/views/budgets/ballot/_investment.html.erb index db30e4167..7f2bafcb8 100644 --- a/app/views/budgets/ballot/_investment.html.erb +++ b/app/views/budgets/ballot/_investment.html.erb @@ -1,6 +1,6 @@
  • <%= link_to investment.title, budget_investment_path(@budget, investment) %> - <%= format_price(@budget, investment.price) %> + <%= investment.formatted_price %> <% if @budget.balloting? %> <%= link_to budget_ballot_line_path(@budget, id: investment.id), diff --git a/app/views/budgets/ballot/_investment_for_sidebar.html.erb b/app/views/budgets/ballot/_investment_for_sidebar.html.erb index d9b3d9e69..c172e6146 100644 --- a/app/views/budgets/ballot/_investment_for_sidebar.html.erb +++ b/app/views/budgets/ballot/_investment_for_sidebar.html.erb @@ -1,6 +1,6 @@
  • <%= investment.title %> - <%= format_price(@budget, investment.price) %> + <%= investment.formatted_price %> <% if @budget.balloting? %> <%= link_to budget_ballot_line_url(id: investment.id, diff --git a/app/views/budgets/ballot/_progress_bar.html.erb b/app/views/budgets/ballot/_progress_bar.html.erb index 58214bbb3..7c3190ba6 100644 --- a/app/views/budgets/ballot/_progress_bar.html.erb +++ b/app/views/budgets/ballot/_progress_bar.html.erb @@ -1,5 +1,5 @@ - <%= format_price(@budget, @budget.heading_price(@heading)) %> + <%= @budget.formatted_heading_price(@heading) %>
    ">

    - <%= format_price(@budget, @ballot.amount_spent(@heading.id)) %> + <%= @budget.format_amount(@ballot.amount_spent(@heading.id)) %> - <%= t("spending_proposals.index.available") %> - <%= format_price(@budget, @ballot.amount_available(@heading)) %> + <%= t("budget.progress_bar.available") %> + <%= @budget.format_amount(@ballot.amount_available(@heading)) %>

    diff --git a/app/views/budgets/ballot/_remove.html.erb b/app/views/budgets/ballot/_remove.html.erb deleted file mode 100644 index e789b0ae6..000000000 --- a/app/views/budgets/ballot/_remove.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -
    - "> - - -

    - <%= format_price(@budget, investment.price) %> -

    - - <% if @budget.balloting? %> - <%= link_to t('budgets.ballots.show.remove'), - budget_ballot_line_path(id: investment.id, - investments_ids: investment_ids), - class: "delete small expanded", - method: :delete, - remote: true %> - <% end %> -
    diff --git a/app/views/budgets/groups/show.html.erb b/app/views/budgets/groups/show.html.erb index 49d18967a..e77311e07 100644 --- a/app/views/budgets/groups/show.html.erb +++ b/app/views/budgets/groups/show.html.erb @@ -1,4 +1,4 @@ -
    +
    <%= link_to budget_path(@budget), class: "back" do %> @@ -26,4 +26,4 @@
    <%= image_tag "map.jpg" %>
    -
    \ No newline at end of file +
    diff --git a/app/views/budgets/index.html.erb b/app/views/budgets/index.html.erb index 6f34d03d1..63d0287ab 100644 --- a/app/views/budgets/index.html.erb +++ b/app/views/budgets/index.html.erb @@ -20,7 +20,7 @@ <%= link_to budget.name, budget %> - <%= budget.phase %> + <%= budget.translated_phase %> <% end %> diff --git a/app/views/budgets/investments/_ballot.html.erb b/app/views/budgets/investments/_ballot.html.erb index b4aa8af97..32a788756 100644 --- a/app/views/budgets/investments/_ballot.html.erb +++ b/app/views/budgets/investments/_ballot.html.erb @@ -1,16 +1,46 @@ -<% reason = investment.reason_for_not_being_ballotable_by(current_user, @ballot) %> +<% reason = investment.reason_for_not_being_ballotable_by(current_user, investment_ballot) %>
    - <% if @ballot.has_investment?(investment) %> - <%= render 'budgets/ballot/remove', - investment: investment, - investment_ids: @investments %> + <% if investment_ballot.has_investment?(investment) %> + +
    + "> + +

    + <%= investment.formatted_price %> +

    + <% if investment.should_show_ballots? %> + <%= link_to t('budgets.ballots.show.remove'), + budget_ballot_line_path(id: investment.id, + budget_id: investment.budget_id, + investments_ids: investment_ids), + class: "delete small expanded", + method: :delete, + remote: true %> + <% end %> +
    + <% else %> - <%= render 'budgets/ballot/add', - investment: investment, - investment_ids: @investments %> + +
    +

    + <%= investment.formatted_price %> +

    + <% if investment.should_show_ballots? %> + <%= link_to t("budget.investments.investment.add"), + budget_ballot_lines_url(investment_id: investment.id, + budget_id: investment.budget_id, + investments_ids: investment_ids), + class: "button button-support small expanded", + title: t('budget.investments.investment.support_title'), + method: :post, + remote: true %> + <% end %> +
    + <% end %> - <% if reason.present? && !@ballot.has_investment?(investment) %> + <% if reason.present? && !investment_ballot.has_investment?(investment) %> diff --git a/app/views/budgets/investments/_investment.html.erb b/app/views/budgets/investments/_investment.html.erb index 773f11929..330c3b690 100644 --- a/app/views/budgets/investments/_investment.html.erb +++ b/app/views/budgets/investments/_investment.html.erb @@ -44,20 +44,28 @@ <% unless investment.unfeasible? %> - <% if @budget.selecting? || @budget.on_hold? %> + <% if investment.should_show_votes? %>
    - <%= render 'votes', - { investment: investment, - vote_url: vote_budget_investment_path(@budget, investment, value: 'yes') } %> + <%= render partial: '/budgets/investments/votes', locals: { + investment: investment, + investment_votes: investment_votes, + vote_url: namespaced_budget_investment_vote_path(investment, value: 'yes') + } %>
    - <% elsif @budget.balloting? %> + <% elsif investment.should_show_ballots? %> +
    - <%= render 'ballot', investment: investment %> + <%= render partial: '/budgets/investments/ballot', locals: { + investment: investment, + investment_ids: investment_ids, + investment_ballot: investment_ballots[investment.budget] + } %>
    + <% end %> <% end %> diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb new file mode 100644 index 000000000..d5d371290 --- /dev/null +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -0,0 +1,89 @@ +
    + + + +
    +
    + <%= link_to :back, class: "back" do %> + + <%= t("shared.back") %> + <% end %> + +

    <%= investment.title %>

    + +
    + <%= render '/shared/author_info', resource: investment %> + +  •  + <%= l investment.created_at.to_date %> +  •  + <%= heading_name(investment.heading) %> +
    + +
    +

    + <%= t("budget.investments.show.code") %> + <%= investment.id %> +

    + + <%= safe_html_with_links investment.description.html_safe %> + + <% if investment.external_url.present? %> + + <% end %> + + <% if investment.unfeasible? && investment.unfeasibility_explanation.present? %> +

    <%= t('budget.investments.show.unfeasibility_explanation') %>

    +

    <%= investment.unfeasibility_explanation %>

    + <% end %> + + <% if investment.feasible? && investment.price_explanation.present? %> +

    <%= t('budget.investments.show.price_explanation') %>

    +

    <%= investment.price_explanation %>

    + <% end %> +
    + + <% if investment.should_show_aside? %> + + <% end %> + +
    +
    + + diff --git a/app/views/budgets/investments/_sidebar.html.erb b/app/views/budgets/investments/_sidebar.html.erb index d9981d6c7..baeb72bd6 100644 --- a/app/views/budgets/investments/_sidebar.html.erb +++ b/app/views/budgets/investments/_sidebar.html.erb @@ -13,7 +13,7 @@ <%= t("budget.investments.index.sidebar.voted_html", count: @ballot.investments.by_heading(@heading.id).count, - amount_spent: format_price(@budget, @ballot.amount_spent(@heading))) %> + amount_spent: @budget.format_amount(@ballot.amount_spent(@heading))) %>

    <% else %> diff --git a/app/views/budgets/investments/_votes.html.erb b/app/views/budgets/investments/_votes.html.erb index d243535d1..81acd9749 100644 --- a/app/views/budgets/investments/_votes.html.erb +++ b/app/views/budgets/investments/_votes.html.erb @@ -1,6 +1,6 @@ <% reason = investment.reason_for_not_being_selectable_by(current_user) %> <% voting_allowed = true unless reason.presence == :not_voting_allowed %> -<% user_voted_for = voted_for?(@budget_investment_votes, investment) %> +<% user_voted_for = voted_for?(investment_votes, investment) %>
    @@ -8,12 +8,12 @@ <%= t("budget.investments.investment.supports", count: investment.total_votes) %> -
    +
    <% if user_voted_for %>
    <%= t("budget.investments.investment.already_supported") %>
    - <% elsif @budget.selecting? %> + <% elsif investment.should_show_votes? %> <%= link_to vote_url, class: "button button-support small expanded", @@ -40,7 +40,7 @@ <% if user_voted_for && setting['twitter_handle'] %> <% end %>
    diff --git a/app/views/budgets/investments/show.html.erb b/app/views/budgets/investments/show.html.erb index 2488262f8..735be8964 100644 --- a/app/views/budgets/investments/show.html.erb +++ b/app/views/budgets/investments/show.html.erb @@ -1,87 +1,5 @@ -<% provide :title do %><%= @investment.title %><% end %> +<% provide :title do %><%= investment.title %><% end %> -
    -
    -
    - <%= link_to :back, class: "back" do %> - - <%= t("shared.back") %> - <% end %> +<%= render partial: '/budgets/investments/investment_show', locals: { investment: @investment, investment_votes: @investment_votes } %> -

    <%= @investment.title %>

    - -
    - <%= render '/shared/author_info', resource: @investment %> - -  •  - <%= l @investment.created_at.to_date %> -  •  - <%= heading_name(@investment.heading) %> -
    - -
    -

    - <%= t("budget.investments.show.code") %> - <%= @investment.id %> -

    - - <%= safe_html_with_links @investment.description.html_safe %> - - <% if @investment.external_url.present? %> - - <% end %> - - <% if @investment.unfeasible? && @investment.unfeasibility_explanation.present? %> -

    <%= t('budget.investments.show.unfeasibility_explanation') %>

    -

    <%= @investment.unfeasibility_explanation %>

    - <% end %> - - <% if @investment.feasible? && @investment.price_explanation.present? %> -

    <%= t('budget.investments.show.price_explanation') %>

    -

    <%= @investment.price_explanation %>

    - <% end %> -
    - - <% if (@budget.selecting? && !@investment.unfeasible?) || - (@budget.balloting? && @investment.feasible? || - (@budget.on_hold?)) %> - - <% end %> - -
    -
    - -<% unless namespace == 'management' %> - <%= render "budgets/investments/comments" %> -<% end %> +<%= render partial: '/comments/comment_tree', locals: { comment_tree: @comment_tree, comment_flags: @comment_flags } %> diff --git a/app/views/budgets/investments/vote.js.erb b/app/views/budgets/investments/vote.js.erb index b02cfefee..848b432e0 100644 --- a/app/views/budgets/investments/vote.js.erb +++ b/app/views/budgets/investments/vote.js.erb @@ -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")) %>'); \ No newline at end of file +$("#<%= 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')) %>'); diff --git a/app/views/budgets/show.html.erb b/app/views/budgets/show.html.erb index a874a28a8..66207ac7c 100644 --- a/app/views/budgets/show.html.erb +++ b/app/views/budgets/show.html.erb @@ -6,8 +6,11 @@ <%= t('shared.back') %> <% end %> -

    <%= @budget.name %>

    +

    <%= @budget.name %> + <%= t("budgets.phases.#{@budget.phase}") %> +

    <%= @budget.description %>

    +
    @@ -36,4 +39,4 @@
    -
    \ No newline at end of file + diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index bf8bfb50d..98a0154cc 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,4 +1,5 @@ -<% cache [locale_and_user_status(comment), comment, commentable_cache_key(comment.commentable), comment.author, (@comment_flags[comment.id] if @comment_flags)] do %> +<% comment_flags ||= @comment_flags %> +<% cache [locale_and_user_status(comment), comment, commentable_cache_key(comment.commentable), comment.author, (comment_flags[comment.id] if comment_flags)] do %>
    diff --git a/app/views/comments/_comment_tree.html.erb b/app/views/comments/_comment_tree.html.erb new file mode 100644 index 000000000..0581809fb --- /dev/null +++ b/app/views/comments/_comment_tree.html.erb @@ -0,0 +1,34 @@ +<% commentable = comment_tree.commentable %> +<% current_order = comment_tree.order %> + +<% cache [locale_and_user_status, current_order, commentable_cache_key(commentable), comment_tree.comments, comment_tree.comment_authors, commentable.comments_count, comment_flags] do %> +
    +
    +
    +

    + <%= t("debates.show.comments_title") %> + (<%= commentable.comments_count %>) +

    + + <%= render 'shared/wide_order_selector', i18n_namespace: "comments" %> + + <% if user_signed_in? %> + <%= render 'comments/form', {commentable: commentable, parent_id: nil, toggeable: false} %> + <% else %> +
    + +
    + <%= t("debates.show.login_to_comment", + signin: link_to(t("votes.signin"), new_user_session_path), + signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %> +
    + <% end %> + + <% comment_tree.root_comments.each do |comment| %> + <%= render 'comments/comment', {comment: comment, comment_flags: comment_flags} %> + <% end %> + <%= paginate comment_tree.root_comments %> +
    +
    +
    +<% end %> diff --git a/app/views/budgets/investments/_comments.html.erb b/app/views/comments/_commentable_tree.html.erb similarity index 100% rename from app/views/budgets/investments/_comments.html.erb rename to app/views/comments/_commentable_tree.html.erb diff --git a/app/views/management/_menu.html.erb b/app/views/management/_menu.html.erb index 1a24bba29..050e5eb7f 100644 --- a/app/views/management/_menu.html.erb +++ b/app/views/management/_menu.html.erb @@ -16,64 +16,67 @@ <% end %>
  • -
  • > +
  • > <%= link_to new_management_proposal_path do %> <%= t("management.menu.create_proposal") %> <% end %>
  • -
  • > +
  • > <%= link_to management_proposals_path do %> <%= t("management.menu.support_proposals") %> <% end %>
  • -
  • > +
  • > <%= link_to new_management_spending_proposal_path do %> <%= t("management.menu.create_spending_proposal") %> <% end %>
  • -
  • > +
  • > <%= link_to management_spending_proposals_path do %> <%= t("management.menu.support_spending_proposals") %> <% end %>
  • -
  • > - <%= link_to new_management_budget_investment_path do %> +
  • > + <%= link_to create_investments_management_budgets_path do %> <%= t("management.menu.create_budget_investment") %> <% end %>
  • -
  • > - <%= link_to management_budget_investments_path do %> +
  • > + <%= link_to support_investments_management_budgets_path do %> <%= t("management.menu.support_budget_investments") %> <% end %>
  • -
  • > +
  • > <%= link_to print_management_proposals_path do %> <%= t("management.menu.print_proposals") %> <% end %>
  • -
  • > +
  • > <%= link_to print_management_spending_proposals_path do %> <%= t("management.menu.print_spending_proposals") %> <% end %>
  • -
  • > - <%= link_to print_management_budget_investments_path do %> +
  • > + <%= link_to print_investments_management_budgets_path do %> <%= t("management.menu.print_budget_investments") %> <% end %> diff --git a/app/views/management/budget_investments/_budget_investment.html.erb b/app/views/management/budget_investments/_budget_investment.html.erb deleted file mode 100644 index 345e8b377..000000000 --- a/app/views/management/budget_investments/_budget_investment.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render partial: 'budgets/investments/investment', locals: {investment: budget_investment} %> diff --git a/app/views/management/budget_investments/_votes.html.erb b/app/views/management/budget_investments/_votes.html.erb deleted file mode 100644 index 579c5d6c3..000000000 --- a/app/views/management/budget_investments/_votes.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -<%= render 'budgets/investments/votes', - { investment: budget_investment, vote_url: vote_management_budget_investment_path(budget_investment.budget, budget_investment, value: 'yes') } %> diff --git a/app/views/management/budget_investments/index.html.erb b/app/views/management/budget_investments/index.html.erb deleted file mode 100644 index 1f52524ef..000000000 --- a/app/views/management/budget_investments/index.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -
    - - <%= render 'admin/shared/budget_investment_search', url: management_budget_investments_path %> - - -
    -
    - - -
    - <%= content_tag(:h2, t("management.budget_investments.filters.unfeasible")) if params[:unfeasible].present? %> - <%= content_tag(:h2, t("management.budget_investments.filters.by_geozone", geozone: @geozone_name)) if @geozone_name.present? %> - <% if params[:search].present? %> -

    - <%= page_entries_info @budget_investments %> - <%= t("management.budget_investments.search_results", count: @budget_investments.size, search_term: params[:search]) %> -

    - <% end %> -
    - - <%= render @budget_investments %> - <%= paginate @budget_investments %> -
    -
    -
    diff --git a/app/views/management/budget_investments/new.html.erb b/app/views/management/budget_investments/new.html.erb deleted file mode 100644 index 59e4d30e9..000000000 --- a/app/views/management/budget_investments/new.html.erb +++ /dev/null @@ -1,12 +0,0 @@ -
    - -
    - <%= render '/shared/print' %> -
    - -
    -

    <%= t("management.budget_investments.create") %>

    - <%= render "budgets/investments/form", form_url: management_budget_investments_url %> -
    - -
    diff --git a/app/views/management/budget_investments/print.html.erb b/app/views/management/budget_investments/print.html.erb deleted file mode 100644 index 785202e1c..000000000 --- a/app/views/management/budget_investments/print.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -
    -
    -
    - -
    - <%= form_tag print_management_budget_investments_path, method: :get, enforce_utf8: false do %> -
    - <%= select_tag :geozone, - options_for_select(geozone_select_options.unshift([t("geozones.none"), "all"]), params[:geozone]), - { label: false, - class: "js-submit-on-change" } %> -
    - <% end %> - - - <%= t('management.budget_investments.print.print_button') %> - -
    - -
    - <%= content_tag(:h2, t("management.budget_investments.filters.unfeasible"), class: "inline-block") if params[:unfeasible].present? %> - <%= content_tag(:h2, t("management.budget_investments.filters.by_geozone", geozone: @geozone_name), class: "inline-block") if @geozone_name.present? %> - <%= content_tag(:h2, t("management.budget_investments.search_results", count: @budget_investments.size, search_term: params[:search]), class: "inline-block") if params[:search].present? %> -
    - - <%= render @budget_investments %> - -
    -

    <%= t("management.print.budget_investments_info") %>
    - <%= t("management.print.budget_investments_note") %>

    -
    -
    -
    -
    diff --git a/app/views/management/budget_investments/show.html.erb b/app/views/management/budget_investments/show.html.erb deleted file mode 100644 index 9b558b845..000000000 --- a/app/views/management/budget_investments/show.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= render '/shared/print' %> - -<%= render template: 'budgets/investments/show' %> diff --git a/app/views/management/budget_investments/vote.js.erb b/app/views/management/budget_investments/vote.js.erb deleted file mode 100644 index 74705cf2b..000000000 --- a/app/views/management/budget_investments/vote.js.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render template: 'budgets/investments/vote' %> diff --git a/app/views/management/budgets/create_investments.html.erb b/app/views/management/budgets/create_investments.html.erb new file mode 100644 index 000000000..fdd7073e8 --- /dev/null +++ b/app/views/management/budgets/create_investments.html.erb @@ -0,0 +1,12 @@ + +<% @budgets.each do |budget| %> + + + + + +<% end %> +
    <%= budget.name %><%= budget.translated_phase %> + <%= link_to t("management.budgets.create_new_investment"), + new_management_budget_investment_path(budget) %> +
    diff --git a/app/views/management/budgets/investments/index.html.erb b/app/views/management/budgets/investments/index.html.erb new file mode 100644 index 000000000..ad48c0578 --- /dev/null +++ b/app/views/management/budgets/investments/index.html.erb @@ -0,0 +1,32 @@ +
    + + <%= render 'admin/shared/budget_investment_search', url: management_budget_investments_path(@budget) %> + + +
    +
    + +
    + <%= content_tag(:h2, t("management.budget_investments.filters.unfeasible")) if params[:unfeasible].present? %> + <%= content_tag(:h2, t("management.budget_investments.filters.heading", heading: @heading.name)) if @heading.present? %> + <% if params[:search].present? %> +

    + <%= page_entries_info @investments %> + <%= t("management.budget_investments.search_results", count: @investments.size, search_term: params[:search]) %> +

    + <% end %> +
    + + <% @investments.each do |investment| %> + <%= render partial: '/budgets/investments/investment', locals: { + investment: investment, + investment_ids: @investment_ids, + investment_votes: @investment_votes, + investment_ballots: @investment_ballots + } %> + <% end %> + + <%= paginate @investments %> +
    +
    +
    diff --git a/app/views/management/budgets/investments/new.html.erb b/app/views/management/budgets/investments/new.html.erb new file mode 100644 index 000000000..bf8b83f90 --- /dev/null +++ b/app/views/management/budgets/investments/new.html.erb @@ -0,0 +1,56 @@ +
    + +
    + <%= render '/shared/print' %> +
    + +
    +

    <%= t("management.budget_investments.create") %>

    + + <%= form_for(@investment, url: management_budget_investments_path(@budget), method: :post) do |f| %> + <%= render 'shared/errors', resource: @investment %> + +
    +
    + <%= f.label :heading_id, t("budget.investments.form.heading") %> + <%= f.select :heading_id, budget_heading_select_options(@budget), {include_blank: t("budget.headings.none"), label: false} %> +
    + +
    + <%= 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 %> +
    + + <%= f.invisible_captcha :subtitle %> + +
    + <%= f.label :description, t("budget.investments.form.description") %> + <%= f.cktext_area :description, maxlength: SpendingProposal.description_max_length, ckeditor: { language: I18n.locale }, label: false %> +
    + +
    + <%= f.label :external_url, t("budget.investments.form.external_url") %> + <%= f.text_field :external_url, placeholder: t("budget.investments.form.external_url"), label: false %> +
    + + + +
    + <%= f.label :terms_of_service do %> + <%= f.check_box :terms_of_service, title: t('form.accept_terms_title'), label: false %> + + <%= t("form.accept_terms", + policy: link_to(t("form.policy"), "/privacy", target: "blank"), + conditions: link_to(t("form.conditions"), "/conditions", target: "blank")).html_safe %> + + <% end %> +
    + +
    + <%= f.submit(class: "button", value: t("budget.investments.form.submit_buttons.#{action_name}")) %> +
    +
    + <% end %> + +
    +
    diff --git a/app/views/management/budgets/investments/print.html.erb b/app/views/management/budgets/investments/print.html.erb new file mode 100644 index 000000000..d2390879b --- /dev/null +++ b/app/views/management/budgets/investments/print.html.erb @@ -0,0 +1,40 @@ +
    + + <%= render 'admin/shared/budget_investment_search', url: print_management_budget_investments_path(@budget) %> + + +
    +
    + + + +
    + <% if params[:unfeasible].present? %> +

    <%= t("management.budget_investments.filters.unfeasible") %>

    + <% end %> + <% if @heading.present? %> +

    <%= t("management.budget_investments.filters.heading", heading_name: @heading.name) %>

    + <% end %> +

    <%= t("management.budget_investments.search_results", count: @investments.count, search_term: params[:search]) %>

    +
    + + <% @investments.each do |investment| %> + <%= render partial: '/budgets/investments/investment', locals: { + investment: investment, + investment_ids: @investment_ids, + investment_votes: @investment_votes, + investment_ballots: @investment_ballots + } %> + <% end %> + +
    +

    <%= t("management.print.budget_investments_info") %>
    + <%= t("management.print.budget_investments_note") %>

    +
    +
    +
    +
    diff --git a/app/views/management/budgets/investments/show.html.erb b/app/views/management/budgets/investments/show.html.erb new file mode 100644 index 000000000..15c13cd93 --- /dev/null +++ b/app/views/management/budgets/investments/show.html.erb @@ -0,0 +1,8 @@ +<% provide :title do %><%= @investment.title %><% end %> + +<%= render '/shared/print' %> + +<%= render partial: '/budgets/investments/investment_show', locals: { + investment: @investment, + investment_votes: @investment_votes +} %> diff --git a/app/views/management/budgets/investments/vote.js.erb b/app/views/management/budgets/investments/vote.js.erb new file mode 100644 index 000000000..56248ba68 --- /dev/null +++ b/app/views/management/budgets/investments/vote.js.erb @@ -0,0 +1,4 @@ +$("#<%= 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')) %>'); diff --git a/app/views/management/budgets/print_investments.html.erb b/app/views/management/budgets/print_investments.html.erb new file mode 100644 index 000000000..bc115ea3d --- /dev/null +++ b/app/views/management/budgets/print_investments.html.erb @@ -0,0 +1,12 @@ + +<% @budgets.each do |budget| %> + + + + + +<% end %> +
    <%= budget.name %><%= budget.translated_phase %> + <%= link_to t("management.budgets.print_investments"), + print_management_budget_investments_path(budget) %> +
    diff --git a/app/views/management/budgets/support_investments.html.erb b/app/views/management/budgets/support_investments.html.erb new file mode 100644 index 000000000..fcd820cef --- /dev/null +++ b/app/views/management/budgets/support_investments.html.erb @@ -0,0 +1,12 @@ + +<% @budgets.each do |budget| %> + + + + + +<% end %> +
    <%= budget.name %><%= budget.translated_phase %> + <%= link_to t("management.budgets.support_investments"), + management_budget_investments_path(budget) %> +
    diff --git a/app/views/users/_budget_investments.html.erb b/app/views/users/_budget_investments.html.erb index 4532ede47..b5773cbdf 100644 --- a/app/views/users/_budget_investments.html.erb +++ b/app/views/users/_budget_investments.html.erb @@ -1,4 +1,4 @@ - +
    <% @budget_investments.each do |budget_investment| %>
    diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index 8961ee584..b5549210f 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -102,4 +102,4 @@ en: proposal_notification: attributes: minimum_interval: - invalid: "You have to wait a minium of %{interval} days between notifications" \ No newline at end of file + invalid: "You have to wait a minium of %{interval} days between notifications" diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 8511dbfc4..c9bd21c18 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -283,9 +283,6 @@ en: proposal_search: button: Search placeholder: Search proposals by title, code, description or question - budget_investment_search: - button: Search - placeholder: Search investments by title or description spending_proposal_search: button: Search placeholder: Search spending proposals by title or description diff --git a/config/locales/en.yml b/config/locales/en.yml index 5379484be..6972ef4ed 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -33,6 +33,19 @@ en: application: close: Close menu: Menu + budgets: + progress_bar: + available: Available + phases: + accepting: Accepting investment projects + on_hold: On Hold + selecting: Selecting investment projects + balloting: Voting investment projects + finished: Finished + budget_investments: + notice: + could_not_vote: Could not vote + voted: Vote stored successfully comments: comment: admin: Administrator @@ -428,6 +441,7 @@ en: flag: Flag as inappropriate print: print_button: Print this info + search: Search show: Show suggest: debate: diff --git a/config/locales/es.yml b/config/locales/es.yml index a1edcfc77..4bafd0c70 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -33,6 +33,19 @@ es: application: close: Cerrar menu: Menú + budgets: + progress_bar: + available: Disponible + phases: + accepting: Aceptación de proyectos + on_hold: En espera + selecting: Selección de proyectos + balloting: Votación de proyectos + finished: Terminado + budget_investments: + notice: + could_not_vote: No se pudo votar + voted: Voto emitido con éxito comments: comment: admin: Administrador @@ -428,6 +441,7 @@ es: flag: Denunciar como inapropiado print: print_button: Imprimir esta información + search: Buscar show: Mostrar suggest: debate: diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index 8daa53235..636e42349 100644 --- a/config/locales/management.en.yml +++ b/config/locales/management.en.yml @@ -51,8 +51,8 @@ en: print_spending_proposals: Print spending proposals support_spending_proposals: Support spending proposals create_budget_investment: Create budget investment - print_budget_investment: Print budget investment - support_budget_investment: Support budget investment + print_budget_investments: Print Budget Investments + support_budget_investments: Support Budget Investments users: Users edit_user_accounts: Edit user account user_invites: User's invites @@ -65,6 +65,8 @@ en: proposals_info: Create yor proposal on http://url.consul proposals_note: The proposals more supported will be voted. If are accepted by a majority, the city Council shall be carried out. proposals_title: 'Proposals:' + spending_proposals_info: Participate at http://url.consul + spending_proposals_note: Participatory budget will be assigned to the most voted budget investment. budget_investments_info: Participate at http://url.consul budget_investments_note: Participatory budget will be assigned to the most voted budget investment. print_info: Print this info @@ -74,13 +76,17 @@ en: create_proposal: Create proposal print: print_button: Print + budgets: + create_new_investment: Create New Investment + print_investments: Print Budget Investments + support_investments: Support Budget Investments budget_investments: alert: unverified_user: User is not verified create: Create budget investment filters: + heading: Concepto unfeasible: Unfeasible investment - by_geozone: "Investment with scope: %{geozone}" print: print_button: Print search_results: diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index fe3d08697..f4ada5c9e 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -50,6 +50,9 @@ es: create_spending_proposal: Crear propuesta de inversión print_spending_proposals: Imprimir propts. de inversión support_spending_proposals: Apoyar propts. de inversión + create_budget_investment: Crear proyectos de inversión + print_budget_investments: Imprimir proyectos de inversión + support_budget_investments: Apoyar proyectos de inversión users: Usuarios edit_user_accounts: Editar cuenta de usuario user_invites: Invitaciones para usuarios @@ -64,6 +67,8 @@ es: proposals_title: 'Propuestas:' spending_proposals_info: Participa en http://url.consul spending_proposals_note: Los presupuestos participativos se invertirán en las propuestas de inversión más apoyadas. + budget_investments_info: Participa en http://url.consul + budget_investments_note: Los presupuestos participativos se invertirán en las propuestas de inversión más apoyadas. print_info: Imprimir esta información proposals: alert: @@ -71,6 +76,22 @@ es: create_proposal: Crear propuesta print: print_button: Imprimir + budgets: + create_new_investment: Crear nuevo proyecto + print_investments: Imprimir proyectos + support_investments: Apoyar proyectos + budget_investments: + alert: + unverified_user: Usuario no verificado + create: Crear nuevo proyecto + filters: + heading: Concepto + unfeasible: Proyectos no factibles + print: + print_button: Imprimir + search_results: + one: " contiene el término '%{search_term}'" + other: " contienen el término '%{search_term}'" spending_proposals: alert: unverified_user: Este usuario no está verificado @@ -106,4 +127,4 @@ es: title: Invitaciones para usuarios create: success_html: Se han enviado %{count} invitaciones. - title: Invitaciones para usuarios \ No newline at end of file + title: Invitaciones para usuarios diff --git a/config/routes.rb b/config/routes.rb index 90decfb7e..77f7d167e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -286,9 +286,16 @@ Rails.application.routes.draw do get :print, on: :collection end - resources :budget_investments, only: [:index, :new, :create, :show] do - post :vote, on: :member - get :print, on: :collection + resources :budgets, only: :index do + collection do + get :create_investments + get :support_investments + get :print_investments + end + resources :investments, only: [:index, :new, :create, :show], controller: 'budgets/investments' do + post :vote, on: :member + get :print, on: :collection + end end end diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 6ca056a33..9563e4e83 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -51,6 +51,9 @@ admin.create_administrator moderator = create_user('mod@consul.dev', 'mod') moderator.create_moderator +manager = create_user('manager@consul.dev', 'manager') +manager.create_manager + valuator = create_user('valuator@consul.dev', 'valuator') valuator.create_valuator diff --git a/spec/features/management/budget_investments_spec.rb b/spec/features/management/budget_investments_spec.rb index 75cc7b4eb..9f5d11c79 100644 --- a/spec/features/management/budget_investments_spec.rb +++ b/spec/features/management/budget_investments_spec.rb @@ -4,32 +4,32 @@ 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: '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' 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" + within "#budget_#{@budget.id}" do + click_link "Create New Investment" + end within(".account-info") do expect(page).to have_content "Identified as" - expect(page).to have_content "#{user.username}" - expect(page).to have_content "#{user.email}" - expect(page).to have_content "#{user.document_number}" + expect(page).to have_content user.username + expect(page).to have_content user.email + expect(page).to have_content user.document_number end + select "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,16 +37,16 @@ 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) - - expect(current_path).to eq(management_budget_investment_path(Budget::Investment.last)) + expect(page).to have_content I18n.l(@budget.created_at.to_date) end scenario "Should not allow unverified users to create budget investments" do @@ -60,124 +60,138 @@ feature 'Budget Investments' do end context "Searching" do + scenario "by title" do - budget_investment1 = create(:budget_investment, title: "Show me what you got") - budget_investment2 = create(:budget_investment, title: "Get Schwifty") + budget_investment1 = create(:budget_investment, budget: @budget, title: "Show me what you got") + budget_investment2 = create(:budget_investment, budget: @budget, title: "Get Schwifty") user = create(:user, :level_two) 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 + click_link "Support Budget Investments" + end fill_in "search", with: "what you got" click_button "Search" - expect(current_path).to eq(management_budget_investments_path) - - within("#investment-projects") do - expect(page).to have_css('.investment-project', count: 1) + within("#budget-investments") do + expect(page).to have_css('.budget-investment', count: 1) expect(page).to have_content(budget_investment1.title) expect(page).to_not have_content(budget_investment2.title) - expect(page).to have_css("a[href='#{management_budget_investment_path(budget_investment1)}']", text: budget_investment1.title) - expect(page).to have_css("a[href='#{management_budget_investment_path(budget_investment1)}']", text: budget_investment1.description) + expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment1)}']", text: budget_investment1.title) + expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment1)}']", text: budget_investment1.description) end end - scenario "by district" do - budget_investment1 = create(:budget_investment, title: "Hey ho", geozone_id: create(:geozone, name: "District 9").id) - budget_investment2 = create(:budget_investment, title: "Let's go", geozone_id: create(:geozone, name: "Area 52").id) + scenario "by heading" do + budget_investment1 = create(:budget_investment, budget: @budget, title: "Hey ho", heading: create(:budget_heading, name: "District 9")) + budget_investment2 = create(:budget_investment, budget: @budget, title: "Let's go", heading: create(:budget_heading, name: "Area 52")) user = create(:user, :level_two) 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 + click_link "Support Budget Investments" + end fill_in "search", with: "Area 52" click_button "Search" - expect(current_path).to eq(management_budget_investments_path) - - within("#investment-projects") do - expect(page).to have_css('.investment-project', count: 1) + within("#budget-investments") do + expect(page).to have_css('.budget-investment', count: 1) expect(page).to_not have_content(budget_investment1.title) expect(page).to have_content(budget_investment2.title) - expect(page).to have_css("a[href='#{management_budget_investment_path(budget_investment2)}']", text: budget_investment2.title) - expect(page).to have_css("a[href='#{management_budget_investment_path(budget_investment2)}']", text: budget_investment2.description) + expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment2)}']", text: budget_investment2.title) + expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment2)}']", text: budget_investment2.description) end end end scenario "Listing" do - budget_investment1 = create(:budget_investment, title: "Show me what you got") - budget_investment2 = create(:budget_investment, title: "Get Schwifty") + budget_investment1 = create(:budget_investment, budget: @budget, title: "Show me what you got") + budget_investment2 = create(:budget_investment, budget: @budget, title: "Get Schwifty") user = create(:user, :level_two) login_managed_user(user) - click_link "Support budget investments" - - expect(current_path).to eq(management_budget_investments_path) + click_link "Support Budget Investments" + expect(page).to have_content(@budget.name) + within "#budget_#{@budget.id}" do + click_link "Support Budget Investments" + end within(".account-info") do expect(page).to have_content "Identified as" - expect(page).to have_content "#{user.username}" - expect(page).to have_content "#{user.email}" - expect(page).to have_content "#{user.document_number}" + expect(page).to have_content user.username + expect(page).to have_content user.email + expect(page).to have_content user.document_number end - within("#investment-projects") do - expect(page).to have_css('.investment-project', count: 2) - expect(page).to have_css("a[href='#{management_budget_investment_path(budget_investment1)}']", text: budget_investment1.title) - expect(page).to have_css("a[href='#{management_budget_investment_path(budget_investment1)}']", text: budget_investment1.description) - expect(page).to have_css("a[href='#{management_budget_investment_path(budget_investment2)}']", text: budget_investment2.title) - expect(page).to have_css("a[href='#{management_budget_investment_path(budget_investment2)}']", text: budget_investment2.description) + within("#budget-investments") do + expect(page).to have_css('.budget-investment', count: 2) + expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment1)}']", text: budget_investment1.title) + expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment1)}']", text: budget_investment1.description) + expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment2)}']", text: budget_investment2.title) + expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment2)}']", text: budget_investment2.description) end end - context "Voting" do + context "Supporting" do - scenario 'Voting budget investments on behalf of someone in index view', :js do - budget_investment = create(:budget_investment) + scenario 'Supporting budget investments on behalf of someone in index view', :js do + budget_investment = create(:budget_investment, budget: @budget) user = create(:user, :level_two) 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 + click_link "Support Budget Investments" + end + expect(page).to have_content(budget_investment.title) - within("#investment-projects") do - find('.in-favor a').click + within("#budget-investments") do + find('.js-in-favor a').click expect(page).to have_content "1 support" expect(page).to have_content "You have already supported this. Share it!" end - expect(current_path).to eq(management_budget_investments_path) end - scenario 'Voting budget investments on behalf of someone in show view', :js do - budget_investment = create(:budget_investment) + scenario 'Supporting budget investments on behalf of someone in show view', :js do + budget_investment = create(:budget_investment, budget: @budget) user = create(:user, :level_two) 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 + click_link "Support Budget Investments" + end - within("#investment-projects") do + within("#budget-investments") do click_link budget_investment.title end - find('.in-favor a').click + find('.js-in-favor a').click expect(page).to have_content "1 support" expect(page).to have_content "You have already supported this. Share it!" - expect(current_path).to eq(management_budget_investment_path(budget_investment)) end scenario "Should not allow unverified users to vote proposals" do - budget_investment = create(:budget_investment) + budget_investment = create(:budget_investment, budget: @budget) user = create(:user) login_managed_user(user) - click_link "Support budget investments" + click_link "Support Budget Investments" expect(page).to have_content "User is not verified" end @@ -186,41 +200,45 @@ feature 'Budget Investments' do context "Printing" do scenario 'Printing budget investments' do - 16.times { create(:budget_investment, 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 + click_link "Print Budget Investments" + end - expect(page).to have_css('.investment-project', count: 15) + expect(page).to have_css('.budget-investment', count: 15) expect(page).to have_css("a[href='javascript:window.print();']", text: 'Print') end - scenario "Filtering budget investments by geozone to be printed", :js do - district_9 = create(:geozone, name: "District Nine") - create(:budget_investment, title: 'Change district 9', geozone: district_9, cached_votes_up: 10) - create(:budget_investment, title: 'Destroy district 9', geozone: district_9, cached_votes_up: 100) - create(:budget_investment, title: 'Nuke district 9', geozone: district_9, cached_votes_up: 1) - create(:budget_investment, title: 'Add new districts to the city', geozone_id: nil) + scenario "Filtering budget investments by heading to be printed", :js do + 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') user = create(:user, :level_two) login_managed_user(user) - click_link "Print budget investments" - - expect(page).to have_content "Budget investments with scope: All city" - - within '#investment-projects' do - expect(page).to have_content('Add new districts to the city') - expect(page).to_not have_content('Change district 9') - expect(page).to_not have_content('Destroy district 9') - expect(page).to_not have_content('Nuke district 9') + click_link "Print Budget Investments" + expect(page).to have_content(@budget.name) + within "#budget_#{@budget.id}" do + click_link "Print Budget Investments" end - select 'District Nine', from: 'geozone' + within '#budget-investments' do + expect(page).to have_content('Add new districts to the city') + expect(page).to have_content('Change district 9') + expect(page).to have_content('Destroy district 9') + expect(page).to have_content('Nuke district 9') + end - expect(page).to have_content "Investment projects with scope: District Nine" - expect(current_url).to include("geozone=#{district_9.id}") + select 'Whole city: District Nine', from: 'heading_id' + click_button("Search") - within '#investment-projects' do + within '#budget-investments' do expect(page).to_not have_content('Add new districts to the city') expect('Destroy district 9').to appear_before('Change district 9') expect('Change district 9').to appear_before('Nuke district 9')