diff --git a/app/helpers/budget_executions_helper.rb b/app/helpers/budget_executions_helper.rb
new file mode 100644
index 000000000..fd8376987
--- /dev/null
+++ b/app/helpers/budget_executions_helper.rb
@@ -0,0 +1,9 @@
+module BudgetExecutionsHelper
+
+ def filters_select_counts(status)
+ @budget.investments.winners.with_milestones.select { |i| i.milestones
+ .published.with_status.order_by_publication_date
+ .last.status_id == status rescue false }.count
+ end
+
+end
diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb
index e531612a8..486e65052 100644
--- a/app/models/budget/investment.rb
+++ b/app/models/budget/investment.rb
@@ -84,6 +84,7 @@ class Budget
scope :last_week, -> { where("created_at >= ?", 7.days.ago)}
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
scope :sort_by_created_at, -> { reorder(created_at: :desc) }
+ scope :with_milestones, -> { joins(:milestones).distinct }
scope :by_budget, ->(budget) { where(budget: budget) }
scope :by_group, ->(group_id) { where(group_id: group_id) }
diff --git a/app/views/budgets/executions/show.html.erb b/app/views/budgets/executions/show.html.erb
index 941e0d2d2..c6844c955 100644
--- a/app/views/budgets/executions/show.html.erb
+++ b/app/views/budgets/executions/show.html.erb
@@ -57,9 +57,12 @@
<%= label_tag t("budgets.executions.filters.label") %>
<%= select_tag :status,
- options_from_collection_for_select(@statuses, :id, :name, params[:status]),
+ options_from_collection_for_select(@statuses,
+ :id, lambda { |s| "#{s.name} (#{filters_select_counts(s.id)})" },
+ params[:status]),
class: "js-submit-on-change",
- prompt: t("budgets.executions.filters.all") %>
+ prompt: t("budgets.executions.filters.all",
+ count: @budget.investments.winners.with_milestones.count) %>
<% end %>
diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml
index 658ac429d..e20c9f09f 100644
--- a/config/locales/en/budgets.yml
+++ b/config/locales/en/budgets.yml
@@ -182,7 +182,7 @@ en:
no_winner_investments: "No winner investments in this state"
filters:
label: "Project's current state"
- all: "All"
+ all: "All (%{count})"
phases:
errors:
dates_range_invalid: "Start date can't be equal or later than End date"
diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml
index 60a02a6eb..35ad74fe1 100644
--- a/config/locales/es/budgets.yml
+++ b/config/locales/es/budgets.yml
@@ -182,7 +182,7 @@ es:
no_winner_investments: "No hay proyectos de gasto ganadores en este estado"
filters:
label: "Estado actual del proyecto"
- all: "Todos"
+ all: "Todos (%{count})"
phases:
errors:
dates_range_invalid: "La fecha de comienzo no puede ser igual o superior a la de finalización"
diff --git a/spec/features/budgets/executions_spec.rb b/spec/features/budgets/executions_spec.rb
index 16eaa7a74..5449c8c4b 100644
--- a/spec/features/budgets/executions_spec.rb
+++ b/spec/features/budgets/executions_spec.rb
@@ -55,7 +55,7 @@ feature 'Executions' do
expect(page).not_to have_content('No winner investments in this state')
- select 'Executed', from: 'status'
+ select 'Executed (0)', from: 'status'
expect(page).to have_content('No winner investments in this state')
end
@@ -125,6 +125,25 @@ feature 'Executions' do
let!(:status1) { create(:budget_investment_status, name: I18n.t('seeds.budgets.statuses.studying_project')) }
let!(:status2) { create(:budget_investment_status, name: I18n.t('seeds.budgets.statuses.bidding')) }
+ scenario 'Filters select with counter are shown' do
+ create(:budget_investment_milestone, investment: investment1,
+ publication_date: Date.yesterday,
+ status: status1)
+
+ create(:budget_investment_milestone, investment: investment2,
+ publication_date: Date.yesterday,
+ status: status2)
+
+ visit budget_path(budget)
+
+ click_link 'See results'
+ click_link 'Milestones'
+
+ expect(page).to have_content("All (2)")
+ expect(page).to have_content("#{status1.name} (1)")
+ expect(page).to have_content("#{status2.name} (1)")
+ end
+
scenario 'by milestone status', :js do
create(:budget_investment_milestone, investment: investment1, status: status1)
create(:budget_investment_milestone, investment: investment2, status: status2)
@@ -138,17 +157,17 @@ feature 'Executions' do
expect(page).to have_content(investment1.title)
expect(page).to have_content(investment2.title)
- select 'Studying the project', from: 'status'
+ select 'Studying the project (1)', from: 'status'
expect(page).to have_content(investment1.title)
expect(page).not_to have_content(investment2.title)
- select 'Bidding', from: 'status'
+ select 'Bidding (1)', from: 'status'
expect(page).to have_content(investment2.title)
expect(page).not_to have_content(investment1.title)
- select 'Executing the project', from: 'status'
+ select 'Executing the project (0)', from: 'status'
expect(page).not_to have_content(investment1.title)
expect(page).not_to have_content(investment2.title)
@@ -167,10 +186,10 @@ feature 'Executions' do
click_link 'See results'
click_link 'Milestones'
- select 'Studying the project', from: 'status'
+ select 'Studying the project (0)', from: 'status'
expect(page).not_to have_content(investment1.title)
- select 'Bidding', from: 'status'
+ select 'Bidding (1)', from: 'status'
expect(page).to have_content(investment1.title)
end
@@ -187,10 +206,10 @@ feature 'Executions' do
click_link 'See results'
click_link 'Milestones'
- select 'Studying the project', from: 'status'
+ select 'Studying the project (1)', from: 'status'
expect(page).to have_content(investment1.title)
- select 'Bidding', from: 'status'
+ select 'Bidding (0)', from: 'status'
expect(page).not_to have_content(investment1.title)
end
end