From 979880f910fc7a7b58a41d9c86035f561644eeda Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 28 Nov 2016 19:08:09 +0100 Subject: [PATCH 01/42] adds i18n for budget phases --- app/views/budgets/index.html.erb | 2 +- app/views/budgets/show.html.erb | 7 +++++-- config/locales/en.yml | 7 +++++++ config/locales/es.yml | 7 +++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/views/budgets/index.html.erb b/app/views/budgets/index.html.erb index 6f34d03d1..440248293 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 %> + <%= t("budgets.phases.#{budget.phase}") %> <% end %> 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/config/locales/en.yml b/config/locales/en.yml index 5379484be..544c54964 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -33,6 +33,13 @@ en: application: close: Close menu: Menu + budgets: + phases: + accepting: Accepting investment projects + on_hold: On Hold + selecting: Selecting investment projects + balloting: Voting investment projects + finished: Finished comments: comment: admin: Administrator diff --git a/config/locales/es.yml b/config/locales/es.yml index a1edcfc77..7848777ad 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -33,6 +33,13 @@ es: application: close: Cerrar menu: Menú + budgets: + phases: + accepting: Aceptación de proyectos + on_hold: En espera + selecting: Selección de proyectos + balloting: Votación de proyectos + finished: Terminado comments: comment: admin: Administrador From 424d0201c42f192c349fd114c11451e103b8456b Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 1 Dec 2016 14:14:05 +0100 Subject: [PATCH 02/42] Adds denormalized ids to budget investment --- app/models/budget/investment.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 619602b2a..ad9876df5 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 } @@ -188,5 +189,11 @@ class Budget self.responsible_name = author.try(:document_number) if author.try(:document_number).present? end + private + + def set_denormalized_ids + self.group_id ||= self.heading.group_id + self.budget_id ||= self.heading.group.budget_id + end end end From 00cfb95913d4efd4628903dc35401f447220b1da Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 1 Dec 2016 16:31:05 +0100 Subject: [PATCH 03/42] Starts fixing management budget investments --- .../budget_investments_controller.rb | 37 +++++++++------ .../management/budgets_controller.rb | 1 + app/helpers/budget_headings_helper.rb | 6 ++- app/models/budget.rb | 1 + app/views/budgets/investments/show.html.erb | 19 +++++--- .../budget_investments/new.html.erb | 46 ++++++++++++++++++- config/locales/activerecord.en.yml | 2 +- .../management/budget_investments_spec.rb | 22 ++++----- 8 files changed, 97 insertions(+), 37 deletions(-) diff --git a/app/controllers/management/budget_investments_controller.rb b/app/controllers/management/budget_investments_controller.rb index 64dd30492..dec517171 100644 --- a/app/controllers/management/budget_investments_controller.rb +++ b/app/controllers/management/budget_investments_controller.rb @@ -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 diff --git a/app/controllers/management/budgets_controller.rb b/app/controllers/management/budgets_controller.rb index d4d5b8592..ed127df68 100644 --- a/app/controllers/management/budgets_controller.rb +++ b/app/controllers/management/budgets_controller.rb @@ -1,5 +1,6 @@ class Management::BudgetsController < Management::BaseController include FeatureFlags + include HasFilters feature_flag :budgets has_filters %w{open finished}, only: :index diff --git a/app/helpers/budget_headings_helper.rb b/app/helpers/budget_headings_helper.rb index b9944be9b..9bb511394 100644 --- a/app/helpers/budget_headings_helper.rb +++ b/app/helpers/budget_headings_helper.rb @@ -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 \ No newline at end of file +end diff --git a/app/models/budget.rb b/app/models/budget.rb index e716c0181..9c4f9e7e1 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -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" diff --git a/app/views/budgets/investments/show.html.erb b/app/views/budgets/investments/show.html.erb index 2488262f8..f27daf0f7 100644 --- a/app/views/budgets/investments/show.html.erb +++ b/app/views/budgets/investments/show.html.erb @@ -1,6 +1,13 @@ <% provide :title do %><%= @investment.title %><% end %>
+ + +
<%= link_to :back, class: "back" do %> @@ -44,19 +51,19 @@ <% end %>
- <% 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?)) %>
+ + diff --git a/app/views/budgets/investments/show.html.erb b/app/views/budgets/investments/show.html.erb deleted file mode 100644 index f27daf0f7..000000000 --- a/app/views/budgets/investments/show.html.erb +++ /dev/null @@ -1,94 +0,0 @@ -<% provide :title do %><%= @investment.title %><% end %> - -
- - - -
-
- <%= 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.budget.selecting? && !@investment.unfeasible?) || - (@investment.budget.balloting? && @investment.feasible? || - (@investment.budget.on_hold?)) %> - - <% end %> - -
-
- -<% unless namespace == 'management' %> - <%= render "budgets/investments/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/budget_investments/new.html.erb b/app/views/management/budgets/investments/new.html.erb similarity index 95% rename from app/views/management/budget_investments/new.html.erb rename to app/views/management/budgets/investments/new.html.erb index f51fe3ffb..d761f81a3 100644 --- a/app/views/management/budget_investments/new.html.erb +++ b/app/views/management/budgets/investments/new.html.erb @@ -7,7 +7,7 @@

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

- <%= form_for(@investment, url: management_budget_investments_path, method: :post) do |f| %> + <%= form_for(@investment, url: management_budgets_investments_path, method: :post) do |f| %> <%= render 'shared/errors', resource: @investment %>
diff --git a/app/views/management/budget_investments/print.html.erb b/app/views/management/budgets/investments/print.html.erb similarity index 88% rename from app/views/management/budget_investments/print.html.erb rename to app/views/management/budgets/investments/print.html.erb index 785202e1c..a80f7d673 100644 --- a/app/views/management/budget_investments/print.html.erb +++ b/app/views/management/budgets/investments/print.html.erb @@ -1,9 +1,9 @@
-
+
- <%= form_tag print_management_budget_investments_path, method: :get, enforce_utf8: false do %> + <%= form_tag print_management_budgets_investments_path, method: :get, enforce_utf8: false do %>
<%= select_tag :geozone, options_for_select(geozone_select_options.unshift([t("geozones.none"), "all"]), params[:geozone]), diff --git a/app/views/management/budget_investments/vote.js.erb b/app/views/management/budgets/investments/vote.js.erb similarity index 100% rename from app/views/management/budget_investments/vote.js.erb rename to app/views/management/budgets/investments/vote.js.erb From 84eb6fcfc170e03c8393b48392e0e61aa8b502d2 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Dec 2016 19:20:33 +0100 Subject: [PATCH 08/42] Adds _comment_tree view --- app/views/comments/_comment.html.erb | 3 +- app/views/comments/_comment_tree.html.erb | 34 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 app/views/comments/_comment_tree.html.erb 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 %> From bd8d3aaf0498900c3b4449d54859e8f155a47715 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Dec 2016 19:21:28 +0100 Subject: [PATCH 09/42] Removes old views --- .../_budget_investment.html.erb | 1 - .../budget_investments/_votes.html.erb | 2 -- .../budget_investments/index.html.erb | 25 ------------------- .../budget_investments/show.html.erb | 3 --- 4 files changed, 31 deletions(-) delete mode 100644 app/views/management/budget_investments/_budget_investment.html.erb delete mode 100644 app/views/management/budget_investments/_votes.html.erb delete mode 100644 app/views/management/budget_investments/index.html.erb delete mode 100644 app/views/management/budget_investments/show.html.erb 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/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' %> From 2ec4f5336775b6b13f4aa215daf8593af27aa456 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Dec 2016 19:21:46 +0100 Subject: [PATCH 10/42] investment-project -> budget-investment --- app/views/budgets/groups/show.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 +
From e280645511fb55b37f73d4a7f3f7261ebe21231a Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Dec 2016 19:22:11 +0100 Subject: [PATCH 11/42] transforms _votes to use parameters instead of @ variables --- app/views/budgets/investments/_votes.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/budgets/investments/_votes.html.erb b/app/views/budgets/investments/_votes.html.erb index d243535d1..7045ff63b 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) %>
@@ -13,7 +13,7 @@
<%= t("budget.investments.investment.already_supported") %>
- <% elsif @budget.selecting? %> + <% elsif investment.budget.selecting? %> <%= link_to vote_url, class: "button button-support small expanded", @@ -40,7 +40,7 @@ <% if user_voted_for && setting['twitter_handle'] %> <% end %>
From 4372238df898bc82f165231d0388d757a1745f2b Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Dec 2016 19:22:42 +0100 Subject: [PATCH 12/42] investment-projects -> budget-investments --- app/views/users/_budget_investments.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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| %> <% end %> From 8ef479bf3193fbba482c6a91923b4ec3ab37fee3 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 6 Dec 2016 18:01:37 +0100 Subject: [PATCH 30/42] Changes routes to use budgets resource instead of namespace --- app/helpers/budget_helper.rb | 2 +- app/views/management/budgets/investments/index.html.erb | 2 +- app/views/management/budgets/investments/new.html.erb | 2 +- app/views/management/budgets/investments/print.html.erb | 2 +- config/routes.rb | 9 +++++++-- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/helpers/budget_helper.rb b/app/helpers/budget_helper.rb index 65e7ea683..881087acf 100644 --- a/app/helpers/budget_helper.rb +++ b/app/helpers/budget_helper.rb @@ -7,7 +7,7 @@ module BudgetHelper def namespaced_budget_investment_path(investment, options={}) case namespace when "management::budgets" - management_budgets_investment_path(investment, options) + management_budget_investment_path(investment, options) else budget_investment_path(investment, options.merge(budget_id: investment.budget_id)) end diff --git a/app/views/management/budgets/investments/index.html.erb b/app/views/management/budgets/investments/index.html.erb index 08ae3390d..9a597c6a7 100644 --- a/app/views/management/budgets/investments/index.html.erb +++ b/app/views/management/budgets/investments/index.html.erb @@ -1,6 +1,6 @@
- <%= render 'admin/shared/budget_investment_search', url: management_budgets_investments_path %> + <%= render 'admin/shared/budget_investment_search', url: management_budget_investments_path %>
diff --git a/app/views/management/budgets/investments/new.html.erb b/app/views/management/budgets/investments/new.html.erb index d761f81a3..1aa8431de 100644 --- a/app/views/management/budgets/investments/new.html.erb +++ b/app/views/management/budgets/investments/new.html.erb @@ -7,7 +7,7 @@

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

- <%= form_for(@investment, url: management_budgets_investments_path, method: :post) do |f| %> + <%= form_for(@investment, url: management_budget_investments_path(@budget), method: :post) do |f| %> <%= render 'shared/errors', resource: @investment %>
diff --git a/app/views/management/budgets/investments/print.html.erb b/app/views/management/budgets/investments/print.html.erb index a80f7d673..9c78f93cd 100644 --- a/app/views/management/budgets/investments/print.html.erb +++ b/app/views/management/budgets/investments/print.html.erb @@ -3,7 +3,7 @@
- <%= form_tag print_management_budgets_investments_path, method: :get, enforce_utf8: false do %> + <%= 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]), diff --git a/config/routes.rb b/config/routes.rb index 6a90ddd2a..77f7d167e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -286,8 +286,13 @@ Rails.application.routes.draw do get :print, on: :collection end - namespace :budgets do - resources :investments, only: [:index, :new, :create, :show] do + 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 From 05643929646b11ffa6b3394df745668040b43dd4 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 6 Dec 2016 18:02:25 +0100 Subject: [PATCH 31/42] Introduces management budgets --- .../management/budgets_controller.rb | 17 +++++++++-------- .../budgets/create_investments.html.erb | 12 ++++++++++++ .../budgets/print_investments.html.erb | 12 ++++++++++++ .../budgets/support_investments.html.erb | 12 ++++++++++++ config/locales/management.en.yml | 4 ++++ 5 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 app/views/management/budgets/create_investments.html.erb create mode 100644 app/views/management/budgets/print_investments.html.erb create mode 100644 app/views/management/budgets/support_investments.html.erb diff --git a/app/controllers/management/budgets_controller.rb b/app/controllers/management/budgets_controller.rb index ed127df68..c4b16b7dc 100644 --- a/app/controllers/management/budgets_controller.rb +++ b/app/controllers/management/budgets_controller.rb @@ -3,15 +3,16 @@ class Management::BudgetsController < Management::BaseController include HasFilters feature_flag :budgets - has_filters %w{open finished}, only: :index - - 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.accepting.order(created_at: :desc).page(params[:page]) end + + def print_investments + @budgets = Budget.current.order(created_at: :desc).page(params[:page]) + end + end 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..518b2a854 --- /dev/null +++ b/app/views/management/budgets/create_investments.html.erb @@ -0,0 +1,12 @@ +
From c1f62dd31728b6a588d3fbb2e50455e09bcf3337 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Dec 2016 19:23:46 +0100 Subject: [PATCH 13/42] Reimplements several bi views --- app/views/budgets/investments/show.html.erb | 5 ++++ .../budgets/investments/index.html.erb | 27 +++++++++++++++++++ .../budgets/investments/show.html.erb | 5 ++++ 3 files changed, 37 insertions(+) create mode 100644 app/views/budgets/investments/show.html.erb create mode 100644 app/views/management/budgets/investments/index.html.erb create mode 100644 app/views/management/budgets/investments/show.html.erb diff --git a/app/views/budgets/investments/show.html.erb b/app/views/budgets/investments/show.html.erb new file mode 100644 index 000000000..02ddde33c --- /dev/null +++ b/app/views/budgets/investments/show.html.erb @@ -0,0 +1,5 @@ +<% provide :title do %><%= investment.title %><% end %> + +<%= render partial: '/budgets/investments/investment', locals: { investment: @investment, investment_votes: @investment_votes } %> + +<%= render partial: '/comments/comment_tree', locals: { comment_tree: @comment_tree, comment_flags: @comment_flags } %> 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..8430f24ab --- /dev/null +++ b/app/views/management/budgets/investments/index.html.erb @@ -0,0 +1,27 @@ +
+ + <%= render 'admin/shared/budget_investment_search', url: management_budgets_investments_path %> + + +
+
+ +
+ <%= content_tag(:h2, t("management.investments.filters.unfeasible")) if params[:unfeasible].present? %> + <%= content_tag(:h2, t("management.investments.filters.by_geozone", geozone: @geozone_name)) if @geozone_name.present? %> + <% if params[:search].present? %> +

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

+ <% end %> +
+ + <% @investments.each do |investment| %> + <%= render partial: '/budgets/investments/investment', locals: { investment: investment, investment_votes: @investment_votes } %> + <% end %> + + <%= paginate @investments %> +
+
+
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..4ec9d9375 --- /dev/null +++ b/app/views/management/budgets/investments/show.html.erb @@ -0,0 +1,5 @@ +<% provide :title do %><%= investment.title %><% end %> + +<%= render '/shared/print' %> + +<%= render partial: '/budgets/investments/investment', locals: { investment: @investment, investment_votes: @investment_votes } %> From 3508c6d59c293b7ff21c7ce8c631ff53134d6625 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Dec 2016 19:24:01 +0100 Subject: [PATCH 14/42] Implements decorator methods in investment --- app/models/budget/investment.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index ad9876df5..d521ffadb 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -189,6 +189,16 @@ class Budget self.responsible_name = author.try(:document_number) if author.try(:document_number).present? end + def should_show_aside? + (budget.selecting? && !investment.unfeasible?) || + (budget.balloting? && investment.feasible?) || + budget.on_hold? + end + + def should_show_votes? + budget.selecting? || budget.on_hold? + end + private def set_denormalized_ids From 6aab9f5253b9715edf05952aa7528926103357e3 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Dec 2016 19:32:56 +0100 Subject: [PATCH 15/42] renames _investment to _investment_show --- .../{_investment.html.erb => _investment_show.html.erb} | 0 app/views/budgets/investments/show.html.erb | 2 +- app/views/management/budgets/investments/show.html.erb | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename app/views/budgets/investments/{_investment.html.erb => _investment_show.html.erb} (100%) diff --git a/app/views/budgets/investments/_investment.html.erb b/app/views/budgets/investments/_investment_show.html.erb similarity index 100% rename from app/views/budgets/investments/_investment.html.erb rename to app/views/budgets/investments/_investment_show.html.erb diff --git a/app/views/budgets/investments/show.html.erb b/app/views/budgets/investments/show.html.erb index 02ddde33c..735be8964 100644 --- a/app/views/budgets/investments/show.html.erb +++ b/app/views/budgets/investments/show.html.erb @@ -1,5 +1,5 @@ <% provide :title do %><%= investment.title %><% end %> -<%= render partial: '/budgets/investments/investment', locals: { investment: @investment, investment_votes: @investment_votes } %> +<%= render partial: '/budgets/investments/investment_show', locals: { investment: @investment, investment_votes: @investment_votes } %> <%= render partial: '/comments/comment_tree', locals: { comment_tree: @comment_tree, comment_flags: @comment_flags } %> diff --git a/app/views/management/budgets/investments/show.html.erb b/app/views/management/budgets/investments/show.html.erb index 4ec9d9375..42779f900 100644 --- a/app/views/management/budgets/investments/show.html.erb +++ b/app/views/management/budgets/investments/show.html.erb @@ -2,4 +2,4 @@ <%= render '/shared/print' %> -<%= render partial: '/budgets/investments/investment', locals: { investment: @investment, investment_votes: @investment_votes } %> +<%= render partial: '/budgets/investments/investment_show', locals: { investment: @investment, investment_votes: @investment_votes } %> From f677d90f73a7c75eb2b372cfad3499adc7254b2f Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Dec 2016 20:10:07 +0100 Subject: [PATCH 16/42] Implements bi.should_show_ballots? --- app/models/budget/investment.rb | 4 ++++ app/views/budgets/investments/_investment_show.html.erb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index d521ffadb..5f986cc82 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -199,6 +199,10 @@ class Budget budget.selecting? || budget.on_hold? end + def should_show_ballots? + budget.balloting? + end + private def set_denormalized_ids diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index bc451ff3b..aa62b6262 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -64,7 +64,7 @@ vote_url: vote_budget_investment_path(investment.budget, investment, value: 'yes') } %> - <% else %> + <% elseif investment.sould_show_ballots? %>
<%= render 'ballot', investment: investment %>
From 98549d8e61c6d8f146615390bb92f458e632dc9b Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Dec 2016 20:10:22 +0100 Subject: [PATCH 17/42] Restores investment/_investment view --- .../budgets/investments/_investment.html.erb | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 app/views/budgets/investments/_investment.html.erb diff --git a/app/views/budgets/investments/_investment.html.erb b/app/views/budgets/investments/_investment.html.erb new file mode 100644 index 000000000..e21b6dc00 --- /dev/null +++ b/app/views/budgets/investments/_investment.html.erb @@ -0,0 +1,70 @@ +
+
+
+ +
+
+ + <% cache [locale_and_user_status(investment), 'index', investment, investment.author] do %> + <%= t("budget.investments.investment.title") %> + +

<%= link_to investment.title, namespaced_budget_investment_path(investment) %>

+

+ + <%= l investment.created_at.to_date %> + + <% if investment.author.hidden? || investment.author.erased? %> +  •  + + <%= t("budget.investments.show.author_deleted") %> + + <% else %> +  •  + + <%= investment.author.name %> + + <% if investment.author.official? %> +  •  + + <%= investment.author.official_position %> + + <% end %> + <% end %> + +  •  + <%= heading_name(investment.heading) %> +

+
+

<%= link_to investment.description, namespaced_budget_investment_path(investment) %>

+
+
+ <% end %> +
+
+ + <% unless investment.unfeasible? %> + + <% if investment.should_show_votes? %> + +
+ <%= render partial: '/budgets/investments/votes', locals: { + investment: investment, + investment_votes: investment_votes, + vote_url: vote_budget_investment_path(investment.budget, investment, value: 'yes') + } %> +
+ + <% elsif investment.should_show_ballots? %> + +
+ <%= render 'ballot', investment: investment %> +
+ + <% end %> + + <% end %> +
+
+
From dee409cfc84c9dd4d27b1db84d19202a93f8ebaa Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 2 Dec 2016 20:10:42 +0100 Subject: [PATCH 18/42] Fixes budget_helper issues --- app/helpers/budget_helper.rb | 8 ++- .../management/budget_investments_spec.rb | 52 +++++++++---------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/app/helpers/budget_helper.rb b/app/helpers/budget_helper.rb index c35808389..b78cc19f7 100644 --- a/app/helpers/budget_helper.rb +++ b/app/helpers/budget_helper.rb @@ -11,13 +11,11 @@ module BudgetHelper 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" + case namespace + when "management::budgets" management_budgets_investment_path(investment, options) else - budget_investment_path(investment, options) + budget_investment_path(investment, options.merge(budget_id: investment.budget_id)) end end diff --git a/spec/features/management/budget_investments_spec.rb b/spec/features/management/budget_investments_spec.rb index cb681db9a..d1eaa2723 100644 --- a/spec/features/management/budget_investments_spec.rb +++ b/spec/features/management/budget_investments_spec.rb @@ -44,7 +44,7 @@ feature 'Budget Investments' do 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(current_path).to eq(management_budgets_investment_path(Budget::Investment.last)) end scenario "Should not allow unverified users to create budget investments" do @@ -65,19 +65,19 @@ feature 'Budget Investments' do user = create(:user, :level_two) login_managed_user(user) - click_link "Support budget investments" + click_link "Support Budget Investments" fill_in "search", with: "what you got" click_button "Search" - expect(current_path).to eq(management_budget_investments_path) + expect(current_path).to eq(management_budgets_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_budgets_investment_path(budget_investment1)}']", text: budget_investment1.title) + expect(page).to have_css("a[href='#{management_budgets_investment_path(budget_investment1)}']", text: budget_investment1.description) end end @@ -93,14 +93,14 @@ feature 'Budget Investments' do fill_in "search", with: "Area 52" click_button "Search" - expect(current_path).to eq(management_budget_investments_path) + expect(current_path).to eq(management_budgets_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_budgets_investment_path(budget_investment2)}']", text: budget_investment2.title) + expect(page).to have_css("a[href='#{management_budgets_investment_path(budget_investment2)}']", text: budget_investment2.description) end end end @@ -114,7 +114,7 @@ feature 'Budget Investments' do click_link "Support budget investments" - expect(current_path).to eq(management_budget_investments_path) + expect(current_path).to eq(management_budgets_investments_path) within(".account-info") do expect(page).to have_content "Identified as" @@ -123,12 +123,12 @@ feature 'Budget Investments' do 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_budgets_investment_path(budget_investment1)}']", text: budget_investment1.title) + expect(page).to have_css("a[href='#{management_budgets_investment_path(budget_investment1)}']", text: budget_investment1.description) + expect(page).to have_css("a[href='#{management_budgets_investment_path(budget_investment2)}']", text: budget_investment2.title) + expect(page).to have_css("a[href='#{management_budgets_investment_path(budget_investment2)}']", text: budget_investment2.description) end end @@ -142,13 +142,13 @@ feature 'Budget Investments' do click_link "Support budget investments" - within("#investment-projects") do + within("#budget-investments") do find('.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) + expect(current_path).to eq(management_budgets_investments_path) end scenario 'Voting budget investments on behalf of someone in show view', :js do @@ -159,14 +159,14 @@ feature 'Budget Investments' do click_link "Support budget investments" - within("#investment-projects") do + within("#budget-investments") do click_link budget_investment.title end find('.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)) + expect(current_path).to eq(management_budgets_investment_path(budget_investment)) end scenario "Should not allow unverified users to vote proposals" do @@ -188,7 +188,7 @@ feature 'Budget Investments' do click_link "Print budget investments" - 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 @@ -206,7 +206,7 @@ feature 'Budget Investments' do expect(page).to have_content "Budget investments with scope: All city" - within '#investment-projects' do + within '#budget-investments' 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') @@ -218,7 +218,7 @@ feature 'Budget Investments' do expect(page).to have_content "Investment projects with scope: District Nine" expect(current_url).to include("geozone=#{district_9.id}") - 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') From c64c88da43756a1633190759997bb9c252f25b4e Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 5 Dec 2016 11:13:57 +0100 Subject: [PATCH 19/42] Fixes typo --- app/views/budgets/investments/_investment_show.html.erb | 1 - app/views/management/budgets/investments/show.html.erb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index aa62b6262..3af814d7c 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -1,4 +1,3 @@ -
- <%= t("budgets.phases.#{budget.phase}") %> + <%= budget.translated_phase %>
+<% @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/print_investments.html.erb b/app/views/management/budgets/print_investments.html.erb new file mode 100644 index 000000000..87969f9be --- /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..fec714f56 --- /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.vote_investments"), + management_budget_investments_path(budget) %> +
diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index 8daa53235..373aabf73 100644 --- a/config/locales/management.en.yml +++ b/config/locales/management.en.yml @@ -74,6 +74,10 @@ 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 From 34071a0f9f4c63df66b26bdd06644fed2b5bfabf Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 6 Dec 2016 18:03:03 +0100 Subject: [PATCH 32/42] Unifies budget_headings_helper --- app/helpers/budget_headings_helper.rb | 12 +++--------- app/views/admin/budget_investments/edit.html.erb | 4 ++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/app/helpers/budget_headings_helper.rb b/app/helpers/budget_headings_helper.rb index 9bb511394..e8d45ace1 100644 --- a/app/helpers/budget_headings_helper.rb +++ b/app/helpers/budget_headings_helper.rb @@ -1,15 +1,9 @@ module BudgetHeadingsHelper def budget_heading_select_options(budget) - 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]} + budget.headings.includes(:group).order('budget_groups.name', 'budget_headings.name').map do |heading| + ["#{heading.group.name}: #{heading.name}", heading.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' %> From e793a0d8e171be1b263fc35f0a44de4e109ceecf Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 6 Dec 2016 18:05:58 +0100 Subject: [PATCH 33/42] Adapts management::budget_investments to new budgets --- .../budgets/investments_controller.rb | 55 +++++-------------- .../budgets/investments/new.html.erb | 10 ++-- .../management/budget_investments_spec.rb | 43 +++++++-------- 3 files changed, 42 insertions(+), 66 deletions(-) diff --git a/app/controllers/management/budgets/investments_controller.rb b/app/controllers/management/budgets/investments_controller.rb index c613655f3..0f268e3c8 100644 --- a/app/controllers/management/budgets/investments_controller.rb +++ b/app/controllers/management/budgets/investments_controller.rb @@ -1,63 +1,49 @@ class Management::Budgets::InvestmentsController < Management::BaseController + load_and_authorize_resource :budget + load_and_authorize_resource :investment, through: :budget, class: 'Budget::Investment' + before_action :only_verified_users, except: :print - before_action :set_budget_investment, only: [:vote, :show] - before_action :load_accepting_headings, only: [:new, :create] def index - @investments = apply_filters_and_search(Budget::Investment).order(cached_votes_up: :desc).page(params[:page]).for_render + @investments = apply_filters_and_search(@investments).order(cached_votes_up: :desc).page(params[:page]).for_render @investment_ids = @investments.pluck(:id) - set_investment_ballots(@investments) - set_budget_investment_votes(@investments) end def new - @investment = Budget::Investment.new end def create - @investment = Budget::Investment.new(budget_investment_params) @investment.terms_of_service = "1" @investment.author = managed_user if @investment.save - redirect_to management_budgets_investment_path(@investment), notice: t('flash.actions.create.notice', resource_name: Budget::Investment.model_name.human, count: 1) + 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_ballots(@investment) - set_budget_investment_votes(@investment) end def vote @investment.register_vote(managed_user, 'yes') - set_investment_ballots(@investment) - set_budget_investment_votes(@investment) end def print params[:geozone] ||= 'all' - @investments = apply_filters_and_search(Budget::Investment).order(cached_votes_up: :desc).for_render.limit(15) - set_budget_investment_votes(@investments) + @investments = apply_filters_and_search(@investments).order(cached_votes_up: :desc).for_render.limit(15) end private - def set_investment_ballots(investments) - @investment_ballots = {} - Budget.where(id: Array.wrap(investments).map(&:budget_id).uniq).each do |budget| - @investment_ballots[budget] = Budget::Ballot.where(user: current_user, budget: budget).first_or_create - end + def load_budget + @budget = Budget.find(params[:budget_id]) end - def set_budget_investment - @investment = Budget::Investment.find(params[:id]) - end - - def budget_investment_params + def investment_params params.require(:budget_investment).permit(:title, :description, :external_url, :geozone_id, :heading_id) end @@ -65,11 +51,6 @@ class Management::Budgets::InvestmentsController < Management::BaseController 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) - @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') @@ -78,20 +59,14 @@ class Management::Budgets::InvestmentsController < Management::BaseController end end - def apply_filters_and_search(target) - target = params[:unfeasible].present? ? target.unfeasible : target.not_unfeasible + def apply_filters_and_search(investments) + investments = params[:unfeasible].present? ? investments.unfeasible : investments.not_unfeasible if params[:geozone].present? - target = target.by_geozone(params[:geozone]) + investments = investments.by_geozone(params[:geozone]) set_geozone_name end - target = target.search(params[:search]) if params[:search].present? - 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) + investments = investments.search(params[:search]) if params[:search].present? + investments end end diff --git a/app/views/management/budgets/investments/new.html.erb b/app/views/management/budgets/investments/new.html.erb index 1aa8431de..bf8b83f90 100644 --- a/app/views/management/budgets/investments/new.html.erb +++ b/app/views/management/budgets/investments/new.html.erb @@ -11,6 +11,11 @@ <%= 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 %> @@ -28,10 +33,7 @@ <%= f.text_field :external_url, placeholder: t("budget.investments.form.external_url"), label: false %>
-
- <%= 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} %> -
+
<%= f.label :terms_of_service do %> diff --git a/spec/features/management/budget_investments_spec.rb b/spec/features/management/budget_investments_spec.rb index f0f29ae40..6217f7250 100644 --- a/spec/features/management/budget_investments_spec.rb +++ b/spec/features/management/budget_investments_spec.rb @@ -4,8 +4,8 @@ feature 'Budget Investments' do background do login_as_manager - budget = create(:budget, phase: 'accepting', name: "2016") - group = create(:budget_group, budget: budget, name: 'Whole city') + @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 @@ -17,15 +17,16 @@ feature 'Budget Investments' do login_managed_user(user) click_link "Create budget investment" + click_link "Create New Investment" 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 "2016 - Whole city - Health", from: 'budget_investment_heading_id' + 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' @@ -42,9 +43,7 @@ feature 'Budget Investments' do expect(page).to have_content 'There is no parks here...' 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_budgets_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 @@ -70,14 +69,14 @@ feature 'Budget Investments' do fill_in "search", with: "what you got" click_button "Search" - expect(current_path).to eq(management_budgets_investments_path) + expect(current_path).to eq(management_budget_investments_path) 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_budgets_investment_path(budget_investment1)}']", text: budget_investment1.title) - expect(page).to have_css("a[href='#{management_budgets_investment_path(budget_investment1)}']", text: budget_investment1.description) + 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) end end @@ -93,14 +92,14 @@ feature 'Budget Investments' do fill_in "search", with: "Area 52" click_button "Search" - expect(current_path).to eq(management_budgets_investments_path) + expect(current_path).to eq(management_budget_investments_path) 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_budgets_investment_path(budget_investment2)}']", text: budget_investment2.title) - expect(page).to have_css("a[href='#{management_budgets_investment_path(budget_investment2)}']", text: budget_investment2.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) end end end @@ -114,7 +113,7 @@ feature 'Budget Investments' do click_link "Support Budget Investments" - expect(current_path).to eq(management_budgets_investments_path) + expect(current_path).to eq(management_budget_investments_path) within(".account-info") do expect(page).to have_content "Identified as" @@ -125,10 +124,10 @@ feature 'Budget Investments' do within("#budget-investments") do expect(page).to have_css('.budget-investment', count: 2) - expect(page).to have_css("a[href='#{management_budgets_investment_path(budget_investment1)}']", text: budget_investment1.title) - expect(page).to have_css("a[href='#{management_budgets_investment_path(budget_investment1)}']", text: budget_investment1.description) - expect(page).to have_css("a[href='#{management_budgets_investment_path(budget_investment2)}']", text: budget_investment2.title) - expect(page).to have_css("a[href='#{management_budgets_investment_path(budget_investment2)}']", text: budget_investment2.description) + 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) end end @@ -148,7 +147,7 @@ feature 'Budget Investments' do 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_budgets_investments_path) + expect(current_path).to eq(management_budget_investments_path) end scenario 'Voting budget investments on behalf of someone in show view', :js do @@ -166,7 +165,7 @@ feature '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!" - expect(current_path).to eq(management_budgets_investment_path(budget_investment)) + expect(current_path).to eq(management_budget_investment_path(budget_investment)) end scenario "Should not allow unverified users to vote proposals" do From e6cbc4acf6aeea3bca3bfdb0374d69a01ad54527 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 6 Dec 2016 18:13:29 +0100 Subject: [PATCH 34/42] Fixes spec --- app/controllers/management/budgets_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/controllers/management/budgets_controller.rb b/app/controllers/management/budgets_controller.rb index c4b16b7dc..0643cbf94 100644 --- a/app/controllers/management/budgets_controller.rb +++ b/app/controllers/management/budgets_controller.rb @@ -3,6 +3,8 @@ class Management::BudgetsController < Management::BaseController include HasFilters feature_flag :budgets + before_action :only_verified_users, except: :print_investments + def create_investments @budgets = Budget.accepting.order(created_at: :desc).page(params[:page]) end @@ -15,4 +17,10 @@ class Management::BudgetsController < Management::BaseController @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 From ad2d35bafadaad8e19a1609129a74f847578967e Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 6 Dec 2016 20:08:37 +0100 Subject: [PATCH 35/42] merge budget helpers in a single file --- app/helpers/budget_helper.rb | 28 ---------------------------- app/helpers/budgets_helper.rb | 27 ++++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 29 deletions(-) delete mode 100644 app/helpers/budget_helper.rb diff --git a/app/helpers/budget_helper.rb b/app/helpers/budget_helper.rb deleted file mode 100644 index 881087acf..000000000 --- a/app/helpers/budget_helper.rb +++ /dev/null @@ -1,28 +0,0 @@ -module BudgetHelper - - 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, options) - else - budget_investment_path(investment, options.merge(budget_id: investment.budget_id)) - 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..65f38d257 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -8,4 +8,29 @@ 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 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 From 7afa12fa4ec5bf618a08eddb3d14485d35732b29 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 6 Dec 2016 20:09:04 +0100 Subject: [PATCH 36/42] Adds dom_ids to views --- app/views/management/budgets/create_investments.html.erb | 2 +- app/views/management/budgets/print_investments.html.erb | 2 +- app/views/management/budgets/support_investments.html.erb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/management/budgets/create_investments.html.erb b/app/views/management/budgets/create_investments.html.erb index 518b2a854..fdd7073e8 100644 --- a/app/views/management/budgets/create_investments.html.erb +++ b/app/views/management/budgets/create_investments.html.erb @@ -1,6 +1,6 @@ <% @budgets.each do |budget| %> - +
<%= budget.name %> <%= budget.translated_phase %> diff --git a/app/views/management/budgets/print_investments.html.erb b/app/views/management/budgets/print_investments.html.erb index 87969f9be..bc115ea3d 100644 --- a/app/views/management/budgets/print_investments.html.erb +++ b/app/views/management/budgets/print_investments.html.erb @@ -1,6 +1,6 @@ <% @budgets.each do |budget| %> - +
<%= budget.name %> <%= budget.translated_phase %> diff --git a/app/views/management/budgets/support_investments.html.erb b/app/views/management/budgets/support_investments.html.erb index fec714f56..fcd820cef 100644 --- a/app/views/management/budgets/support_investments.html.erb +++ b/app/views/management/budgets/support_investments.html.erb @@ -1,10 +1,10 @@ <% @budgets.each do |budget| %> - + From 2760e751e72f92511a801d1c58e1fc8278d67779 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 6 Dec 2016 20:09:17 +0100 Subject: [PATCH 37/42] fixes several specs --- .../budgets/investments/index.html.erb | 2 +- .../management/budget_investments_spec.rb | 91 +++++++++++-------- 2 files changed, 55 insertions(+), 38 deletions(-) diff --git a/app/views/management/budgets/investments/index.html.erb b/app/views/management/budgets/investments/index.html.erb index 9a597c6a7..7e0d1cc7a 100644 --- a/app/views/management/budgets/investments/index.html.erb +++ b/app/views/management/budgets/investments/index.html.erb @@ -1,6 +1,6 @@
- <%= render 'admin/shared/budget_investment_search', url: management_budget_investments_path %> + <%= render 'admin/shared/budget_investment_search', url: management_budget_investments_path(@budget) %>
diff --git a/spec/features/management/budget_investments_spec.rb b/spec/features/management/budget_investments_spec.rb index 6217f7250..eed41216a 100644 --- a/spec/features/management/budget_investments_spec.rb +++ b/spec/features/management/budget_investments_spec.rb @@ -17,7 +17,9 @@ feature 'Budget Investments' do login_managed_user(user) click_link "Create budget investment" - click_link "Create New Investment" + within "#budget_#{@budget.id}" do + click_link "Create New Investment" + end within(".account-info") do expect(page).to have_content "Identified as" @@ -58,88 +60,96 @@ feature 'Budget Investments' do 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" + 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("#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 heading" do - budget_investment1 = create(:budget_investment, title: "Hey ho", heading: create(:budget_heading, name: "District 9")) - budget_investment2 = create(:budget_investment, title: "Let's go", heading: create(:budget_heading, name: "Area 52")) + 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" + 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("#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) + 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("#budget-investments") do expect(page).to have_css('.budget-investment', 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) + 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" + within "#budget_#{@budget.id}" do + click_link "Support Budget Investments" + end + + save_and_open_page within("#budget-investments") do find('.js-in-favor a').click @@ -147,16 +157,18 @@ feature 'Budget Investments' do 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" + within "#budget_#{@budget.id}" do + click_link "Support Budget Investments" + end within("#budget-investments") do click_link budget_investment.title @@ -165,11 +177,10 @@ feature '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!" - 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) @@ -183,9 +194,12 @@ 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, geozone_id: nil) } click_link "Print budget investments" + within "#budget_#{@budget.id}" do + click_link "Support Budget Investments" + end expect(page).to have_css('.budget-investment', count: 15) expect(page).to have_css("a[href='javascript:window.print();']", text: 'Print') @@ -193,15 +207,18 @@ feature 'Budget Investments' do 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) + create(:budget_investment, budget: @budget, title: 'Change district 9', geozone: district_9, cached_votes_up: 10) + create(:budget_investment, budget: @budget, title: 'Destroy district 9', geozone: district_9, cached_votes_up: 100) + create(:budget_investment, budget: @budget, title: 'Nuke district 9', geozone: district_9, cached_votes_up: 1) + create(:budget_investment, budget: @budget, title: 'Add new districts to the city', geozone_id: nil) user = create(:user, :level_two) login_managed_user(user) click_link "Print budget investments" + within "#budget_#{@budget.id}" do + click_link "Support Budget Investments" + end expect(page).to have_content "Budget investments with scope: All city" From b3be1633af07f854d60a4c5add7ad9015553da41 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 7 Dec 2016 16:35:27 +0100 Subject: [PATCH 38/42] Fixes all management bi issues except filtering by geozone --- .../budgets/investments_controller.rb | 12 ++++++-- .../management/budgets_controller.rb | 2 +- app/helpers/budgets_helper.rb | 9 ++++++ app/models/budget.rb | 9 ++++-- app/models/budget/investment.rb | 4 +-- .../budgets/investments/_investment.html.erb | 2 +- .../investments/_investment_show.html.erb | 2 +- app/views/budgets/investments/vote.js.erb | 5 +++- .../budgets/investments/show.html.erb | 5 +++- .../budgets/investments/vote.js.erb | 5 +++- .../management/budget_investments_spec.rb | 30 ++++++++++++------- 11 files changed, 59 insertions(+), 26 deletions(-) diff --git a/app/controllers/management/budgets/investments_controller.rb b/app/controllers/management/budgets/investments_controller.rb index 0f268e3c8..bfa56df8b 100644 --- a/app/controllers/management/budgets/investments_controller.rb +++ b/app/controllers/management/budgets/investments_controller.rb @@ -6,8 +6,8 @@ class Management::Budgets::InvestmentsController < Management::BaseController before_action :only_verified_users, except: :print def index - @investments = apply_filters_and_search(@investments).order(cached_votes_up: :desc).page(params[:page]).for_render - @investment_ids = @investments.pluck(:id) + @investments = apply_filters_and_search(@investments).page(params[:page]) + set_investment_votes(@investments) end def new @@ -26,10 +26,12 @@ class Management::Budgets::InvestmentsController < Management::BaseController end def show + set_investment_votes(@investment) end def vote - @investment.register_vote(managed_user, 'yes') + @investment.register_selection(managed_user) + set_investment_votes(@investment) end def print @@ -39,6 +41,10 @@ class Management::Budgets::InvestmentsController < Management::BaseController private + def set_investment_votes(investments) + @investment_votes = managed_user ? managed_user.budget_investment_votes(investments) : {} + end + def load_budget @budget = Budget.find(params[:budget_id]) end diff --git a/app/controllers/management/budgets_controller.rb b/app/controllers/management/budgets_controller.rb index 0643cbf94..c5cfdee76 100644 --- a/app/controllers/management/budgets_controller.rb +++ b/app/controllers/management/budgets_controller.rb @@ -10,7 +10,7 @@ class Management::BudgetsController < Management::BaseController end def support_investments - @budgets = Budget.accepting.order(created_at: :desc).page(params[:page]) + @budgets = Budget.selecting.order(created_at: :desc).page(params[:page]) end def print_investments diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index 65f38d257..6c1471c90 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -21,6 +21,15 @@ module BudgetsHelper end end + def namespaced_budget_investment_vote_path(investment, options={}) + case namespace + when "management::budgets" + vote_management_budget_investment_path(investment.budget, investment, options) + else + vote_budget_investment_path(investment.budget, investment, options) + end + end + def display_budget_countdown?(budget) budget.balloting? end diff --git a/app/models/budget.rb b/app/models/budget.rb index 755f824da..28b37a896 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -14,11 +14,14 @@ class Budget < ActiveRecord::Base has_many :groups, dependent: :destroy has_many :headings, through: :groups - scope :current, -> { where.not(phase: "finished") } - scope :finished, -> { where(phase: "finished") } - scope :valuating, -> { where(valuating: true) } + scope :on_hold, -> { where(phase: "on_hold") } scope :accepting, -> { where(phase: "accepting") } + scope :selecting, -> { where(phase: "selecting") } scope :balloting, -> { where(phase: "balloting") } + scope :finished, -> { where(phase: "finished") } + + scope :current, -> { where.not(phase: "finished") } + scope :valuating, -> { where(valuating: true) } def on_hold? phase == "on_hold" diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 4a82240cb..aa86888fc 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -190,9 +190,7 @@ class Budget end def should_show_aside? - (budget.selecting? && !investment.unfeasible?) || - (budget.balloting? && investment.feasible?) || - budget.on_hold? + (budget.selecting? && !unfeasible?) || (budget.balloting? && feasible?) || budget.on_hold? end def should_show_votes? diff --git a/app/views/budgets/investments/_investment.html.erb b/app/views/budgets/investments/_investment.html.erb index e0ea250e4..330c3b690 100644 --- a/app/views/budgets/investments/_investment.html.erb +++ b/app/views/budgets/investments/_investment.html.erb @@ -51,7 +51,7 @@ <%= render partial: '/budgets/investments/votes', locals: { investment: investment, investment_votes: investment_votes, - vote_url: vote_budget_investment_path(investment.budget, investment, value: 'yes') + vote_url: namespaced_budget_investment_vote_path(investment, value: 'yes') } %>
diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index 3af814d7c..d5d371290 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -63,7 +63,7 @@ vote_url: vote_budget_investment_path(investment.budget, investment, value: 'yes') } %> - <% elseif investment.sould_show_ballots? %> + <% elsif investment.should_show_ballots? %>
<%= render 'ballot', investment: investment %>
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/management/budgets/investments/show.html.erb b/app/views/management/budgets/investments/show.html.erb index 0948da1d5..15c13cd93 100644 --- a/app/views/management/budgets/investments/show.html.erb +++ b/app/views/management/budgets/investments/show.html.erb @@ -2,4 +2,7 @@ <%= render '/shared/print' %> -<%= render partial: '/budgets/investments/investment_show', locals: { investment: @investment, investment_votes: @investment_votes } %> +<%= render partial: '/budgets/investments/investment_show', locals: { + investment: @investment, + investment_votes: @investment_votes +} %> diff --git a/app/views/management/budgets/investments/vote.js.erb b/app/views/management/budgets/investments/vote.js.erb index 74705cf2b..56248ba68 100644 --- a/app/views/management/budgets/investments/vote.js.erb +++ b/app/views/management/budgets/investments/vote.js.erb @@ -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')) %>'); diff --git a/spec/features/management/budget_investments_spec.rb b/spec/features/management/budget_investments_spec.rb index eed41216a..216af5d20 100644 --- a/spec/features/management/budget_investments_spec.rb +++ b/spec/features/management/budget_investments_spec.rb @@ -4,12 +4,13 @@ feature 'Budget Investments' do background do login_as_manager - @budget = create(:budget, phase: 'accepting', name: "2016") - group = create(:budget_group, budget: @budget, name: 'Whole city') - @heading = create(:budget_heading, group: group, name: "Health") + @budget = create(:budget, phase: 'selecting', name: "2016") + @group = create(:budget_group, budget: @budget, name: 'Whole city') + @heading = create(:budget_heading, group: @group, name: "Health") end context "Create" do + before { @budget.update(phase: 'accepting') } scenario 'Creating budget investments on behalf of someone, selecting a budget' do user = create(:user, :level_two) @@ -59,6 +60,7 @@ feature 'Budget Investments' do end context "Searching" do + scenario "by title" do budget_investment1 = create(:budget_investment, budget: @budget, title: "Show me what you got") budget_investment2 = create(:budget_investment, budget: @budget, title: "Get Schwifty") @@ -67,6 +69,7 @@ feature 'Budget Investments' do login_managed_user(user) click_link "Support Budget Investments" + expect(page).to have_content(@budget.name) within "#budget_#{@budget.id}" do click_link "Support Budget Investments" end @@ -91,6 +94,7 @@ feature 'Budget Investments' do login_managed_user(user) click_link "Support Budget Investments" + expect(page).to have_content(@budget.name) within "#budget_#{@budget.id}" do click_link "Support Budget Investments" end @@ -116,6 +120,7 @@ feature 'Budget Investments' do login_managed_user(user) click_link "Support Budget Investments" + expect(page).to have_content(@budget.name) within "#budget_#{@budget.id}" do click_link "Support Budget Investments" end @@ -145,11 +150,11 @@ feature 'Budget Investments' do login_managed_user(user) click_link "Support Budget Investments" + expect(page).to have_content(@budget.name) within "#budget_#{@budget.id}" do click_link "Support Budget Investments" end - - save_and_open_page + expect(page).to have_content(budget_investment.title) within("#budget-investments") do find('.js-in-favor a').click @@ -166,6 +171,7 @@ feature 'Budget Investments' do login_managed_user(user) click_link "Support Budget Investments" + expect(page).to have_content(@budget.name) within "#budget_#{@budget.id}" do click_link "Support Budget Investments" end @@ -194,9 +200,10 @@ feature 'Budget Investments' do context "Printing" do scenario 'Printing budget investments' do - 16.times { create(:budget_investment, budget: @budget, geozone_id: nil) } + 16.times { create(:budget_investment, budget: @budget) } click_link "Print budget investments" + expect(page).to have_content(@budget.name) within "#budget_#{@budget.id}" do click_link "Support Budget Investments" end @@ -206,16 +213,17 @@ feature 'Budget Investments' do end scenario "Filtering budget investments by geozone to be printed", :js do - district_9 = create(:geozone, name: "District Nine") - create(:budget_investment, budget: @budget, title: 'Change district 9', geozone: district_9, cached_votes_up: 10) - create(:budget_investment, budget: @budget, title: 'Destroy district 9', geozone: district_9, cached_votes_up: 100) - create(:budget_investment, budget: @budget, title: 'Nuke district 9', geozone: district_9, cached_votes_up: 1) - create(:budget_investment, budget: @budget, title: 'Add new districts to the city', geozone_id: nil) + district_9 = create(:budget_heading, group: @group, name: "District Nine") + create(:budget_investment, budget: @budget, title: 'Change district 9', heading: district_9, cached_votes_up: 10) + create(:budget_investment, budget: @budget, title: 'Destroy district 9', heading: district_9, cached_votes_up: 100) + create(:budget_investment, budget: @budget, title: 'Nuke district 9', heading: district_9, cached_votes_up: 1) + create(:budget_investment, budget: @budget, title: 'Add new districts to the city', heading: @heading) user = create(:user, :level_two) login_managed_user(user) click_link "Print budget investments" + expect(page).to have_content(@budget.name) within "#budget_#{@budget.id}" do click_link "Support Budget Investments" end From a962b2dfa74646b7cd601407f014d197686c7b06 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 7 Dec 2016 17:46:33 +0100 Subject: [PATCH 39/42] i18n shared.search --- app/views/admin/shared/_budget_investment_search.html.erb | 2 +- config/locales/en.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/admin/shared/_budget_investment_search.html.erb b/app/views/admin/shared/_budget_investment_search.html.erb index 92bd8e24a..7ca19b50f 100644 --- a/app/views/admin/shared/_budget_investment_search.html.erb +++ b/app/views/admin/shared/_budget_investment_search.html.erb @@ -4,7 +4,7 @@ <%= text_field_tag :search, "", placeholder: t("admin.shared.budget_investment_search.placeholder") %>
- <%= f.submit t("admin.shared.budget_investment_search.button"), class: "button" %> + <%= f.submit t("shared.search"), class: "button" %>
<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 544c54964..9887eb625 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -435,6 +435,7 @@ en: flag: Flag as inappropriate print: print_button: Print this info + search: Search show: Show suggest: debate: From 1e3a44b3803f14d4a5efbe975c15513d2132f0ea Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 7 Dec 2016 17:46:46 +0100 Subject: [PATCH 40/42] everyone can print budget investments --- app/models/abilities/everyone.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 748fd8becf2662887454fd6556030460938b8c8a Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 7 Dec 2016 19:16:37 +0100 Subject: [PATCH 41/42] Makes all tests pass in bi management --- .../budgets/investments_controller.rb | 26 ++++---------- app/helpers/budget_headings_helper.rb | 4 +-- app/models/budget/heading.rb | 6 ++++ .../shared/_budget_investment_search.html.erb | 17 +++++++++- .../budgets/investments/print.html.erb | 34 +++++++++++-------- config/locales/es.yml | 1 + .../management/budget_investments_spec.rb | 26 ++++++-------- 7 files changed, 63 insertions(+), 51 deletions(-) diff --git a/app/controllers/management/budgets/investments_controller.rb b/app/controllers/management/budgets/investments_controller.rb index bfa56df8b..e8c10ab50 100644 --- a/app/controllers/management/budgets/investments_controller.rb +++ b/app/controllers/management/budgets/investments_controller.rb @@ -1,7 +1,7 @@ class Management::Budgets::InvestmentsController < Management::BaseController - load_and_authorize_resource :budget - load_and_authorize_resource :investment, through: :budget, class: 'Budget::Investment' + load_resource :budget + load_resource :investment, through: :budget, class: 'Budget::Investment' before_action :only_verified_users, except: :print @@ -35,8 +35,8 @@ class Management::Budgets::InvestmentsController < Management::BaseController end def print - params[:geozone] ||= 'all' @investments = apply_filters_and_search(@investments).order(cached_votes_up: :desc).for_render.limit(15) + set_investment_votes(@investments) end private @@ -45,31 +45,19 @@ class Management::Budgets::InvestmentsController < Management::BaseController @investment_votes = managed_user ? managed_user.budget_investment_votes(investments) : {} end - def load_budget - @budget = Budget.find(params[:budget_id]) - end - def investment_params - params.require(:budget_investment).permit(:title, :description, :external_url, :geozone_id, :heading_id) + 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 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(investments) investments = params[:unfeasible].present? ? investments.unfeasible : investments.not_unfeasible - if params[:geozone].present? - investments = investments.by_geozone(params[:geozone]) - set_geozone_name + 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 diff --git a/app/helpers/budget_headings_helper.rb b/app/helpers/budget_headings_helper.rb index e8d45ace1..3fa1eac89 100644 --- a/app/helpers/budget_headings_helper.rb +++ b/app/helpers/budget_headings_helper.rb @@ -1,8 +1,8 @@ module BudgetHeadingsHelper def budget_heading_select_options(budget) - budget.headings.includes(:group).order('budget_groups.name', 'budget_headings.name').map do |heading| - ["#{heading.group.name}: #{heading.name}", heading.id] + budget.headings.order_by_group_name.map do |heading| + [heading.name_scoped_by_group, heading.id] 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/views/admin/shared/_budget_investment_search.html.erb b/app/views/admin/shared/_budget_investment_search.html.erb index 7ca19b50f..410044c10 100644 --- a/app/views/admin/shared/_budget_investment_search.html.erb +++ b/app/views/admin/shared/_budget_investment_search.html.erb @@ -1,8 +1,23 @@ <%= 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("shared.search"), class: "button" %>
diff --git a/app/views/management/budgets/investments/print.html.erb b/app/views/management/budgets/investments/print.html.erb index 9c78f93cd..d2390879b 100644 --- a/app/views/management/budgets/investments/print.html.erb +++ b/app/views/management/budgets/investments/print.html.erb @@ -1,29 +1,35 @@
-
+ + <%= render 'admin/shared/budget_investment_search', url: print_management_budget_investments_path(@budget) %> + + +
- <%= 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? %> + <% 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]) %>

- <%= render @budget_investments %> + <% @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") %>
diff --git a/config/locales/es.yml b/config/locales/es.yml index 7848777ad..9dbd241d9 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -435,6 +435,7 @@ es: flag: Denunciar como inapropiado print: print_button: Imprimir esta información + search: Buscar show: Mostrar suggest: debate: diff --git a/spec/features/management/budget_investments_spec.rb b/spec/features/management/budget_investments_spec.rb index 216af5d20..9f5d11c79 100644 --- a/spec/features/management/budget_investments_spec.rb +++ b/spec/features/management/budget_investments_spec.rb @@ -202,45 +202,41 @@ feature 'Budget Investments' do scenario 'Printing budget investments' do 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 "Support Budget Investments" + click_link "Print Budget Investments" end 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 + 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', heading: @heading) + 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" + click_link "Print Budget Investments" expect(page).to have_content(@budget.name) within "#budget_#{@budget.id}" do - click_link "Support Budget Investments" + click_link "Print Budget Investments" end - expect(page).to have_content "Budget investments with scope: All city" - within '#budget-investments' 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') + 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 - select 'District Nine', from: 'geozone' - - 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 '#budget-investments' do expect(page).to_not have_content('Add new districts to the city') From 869f7b39d6b4b2ac8dc22108b385e0632788ce89 Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 8 Dec 2016 11:49:13 +0100 Subject: [PATCH 42/42] fixes i18n --- .../budgets/ballot/lines_controller.rb | 6 ++--- .../budgets/ballot/_progress_bar.html.erb | 2 +- .../budgets/investments/index.html.erb | 6 ++--- config/locales/admin.en.yml | 3 --- config/locales/en.yml | 6 +++++ config/locales/es.yml | 6 +++++ config/locales/management.en.yml | 8 ++++--- config/locales/management.es.yml | 23 ++++++++++++++++++- 8 files changed, 46 insertions(+), 14 deletions(-) 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/views/budgets/ballot/_progress_bar.html.erb b/app/views/budgets/ballot/_progress_bar.html.erb index a01d8395e..7c3190ba6 100644 --- a/app/views/budgets/ballot/_progress_bar.html.erb +++ b/app/views/budgets/ballot/_progress_bar.html.erb @@ -20,7 +20,7 @@

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

diff --git a/app/views/management/budgets/investments/index.html.erb b/app/views/management/budgets/investments/index.html.erb index 7e0d1cc7a..ad48c0578 100644 --- a/app/views/management/budgets/investments/index.html.erb +++ b/app/views/management/budgets/investments/index.html.erb @@ -7,12 +7,12 @@
- <%= content_tag(:h2, t("management.investments.filters.unfeasible")) if params[:unfeasible].present? %> - <%= content_tag(:h2, t("management.investments.filters.by_geozone", geozone: @geozone_name)) if @geozone_name.present? %> + <%= 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.investments.search_results", count: @investments.size, search_term: params[:search]) %> + <%= t("management.budget_investments.search_results", count: @investments.size, search_term: params[:search]) %>

<% end %>
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 9887eb625..6972ef4ed 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -34,12 +34,18 @@ en: 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 diff --git a/config/locales/es.yml b/config/locales/es.yml index 9dbd241d9..4bafd0c70 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -34,12 +34,18 @@ es: 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 diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index 373aabf73..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 @@ -83,8 +85,8 @@ en: 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
<%= budget.name %> <%= budget.translated_phase %> - <%= link_to t("management.budgets.vote_investments"), + <%= link_to t("management.budgets.support_investments"), management_budget_investments_path(budget) %>