Add Milestone tag select filter on executions public page
This commit is contained in:
@@ -12,15 +12,15 @@ module Budgets
|
||||
|
||||
private
|
||||
def investments_by_heading
|
||||
base = @budget.investments.winners
|
||||
base = base.joins(milestones: :translations).includes(:milestones)
|
||||
base = base.tagged_with(params[:milestone_tag]) if params[:milestone_tag].present?
|
||||
|
||||
if params[:status].present?
|
||||
@budget.investments.winners
|
||||
.with_milestone_status_id(params[:status])
|
||||
.uniq
|
||||
.group_by(&:heading)
|
||||
base = base.with_milestone_status_id(params[:status])
|
||||
base.uniq.group_by(&:heading)
|
||||
else
|
||||
@budget.investments.winners
|
||||
.joins(milestones: :translations)
|
||||
.distinct.group_by(&:heading)
|
||||
base.distinct.group_by(&:heading)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -4,6 +4,12 @@ module BudgetExecutionsHelper
|
||||
@budget.investments.winners.with_milestone_status_id(status).count
|
||||
end
|
||||
|
||||
def options_for_milestone_tags
|
||||
@budget.milestone_tags.map do |tag|
|
||||
["#{tag} (#{@budget.investments.winners.tagged_with(tag).count})", tag]
|
||||
end
|
||||
end
|
||||
|
||||
def first_milestone_with_image(investment)
|
||||
investment.milestones.order_by_publication_date
|
||||
.select{ |milestone| milestone.image.present? }.last
|
||||
|
||||
@@ -195,6 +195,10 @@ class Budget < ApplicationRecord
|
||||
investments.winners.any?
|
||||
end
|
||||
|
||||
def milestone_tags
|
||||
investments.winners.map(&:milestone_tag_list).flatten.uniq.sort
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sanitize_descriptions
|
||||
|
||||
@@ -106,10 +106,9 @@
|
||||
</div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.label :milestone_tag_list, t("admin.budget_investments.edit.milestone_tags") %>
|
||||
<%= f.text_field :milestone_tag_list,
|
||||
value: @investment.milestone_tag_list.sort.join(", "),
|
||||
label: false %>
|
||||
label: t("admin.budget_investments.edit.milestone_tags") %>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
|
||||
<% if milestoneable.milestone_tag_list.any? %>
|
||||
<div>
|
||||
<b><%= t("admin.milestones.index.milestone_tags") %>:</b> <%= milestoneable.milestone_tag_list.sort.join(", ") %>
|
||||
<strong>
|
||||
<%= t("admin.milestones.index.milestone_tags") %>:
|
||||
</strong> <%= milestoneable.milestone_tag_list.sort.join(", ") %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
@@ -44,13 +44,24 @@
|
||||
<div class="small-12 medium-9 large-10 column">
|
||||
<%= form_tag(budget_executions_path(@budget), method: :get) do %>
|
||||
<div class="small-12 medium-3 column">
|
||||
<%= label_tag :status, t("budgets.executions.filters.label") %>
|
||||
<%= label_tag :milestone_tag, t("budgets.executions.filters.milestone_tag.label") %>
|
||||
<%= select_tag :milestone_tag,
|
||||
options_for_select(
|
||||
options_for_milestone_tags,
|
||||
params[:milestone_tag]
|
||||
),
|
||||
class: "js-submit-on-change",
|
||||
prompt: t("budgets.executions.filters.milestone_tag.all",
|
||||
count: @budget.investments.winners.with_milestones.count) %>
|
||||
</div>
|
||||
<div class="small-12 medium-3 column">
|
||||
<%= label_tag :status, t("budgets.executions.filters.status.label") %>
|
||||
<%= select_tag :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.status.all",
|
||||
count: @budget.investments.winners.with_milestones.count) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -168,6 +168,7 @@ ar:
|
||||
heading_selection_title: "جسب المنطقة"
|
||||
no_winner_investments: "لا يوجد استثمارات فائزة"
|
||||
filters:
|
||||
status:
|
||||
label: "حالة المشروع الحالية"
|
||||
all: "الكل (%{count})"
|
||||
phases:
|
||||
|
||||
@@ -182,6 +182,7 @@ de:
|
||||
heading_selection_title: "Nach Bezirk"
|
||||
no_winner_investments: "Keine erfolgreichen Ausgabenvorschläge in diesem Status"
|
||||
filters:
|
||||
status:
|
||||
label: "Aktueller Stand des Projekts"
|
||||
all: "Alle (%{count})"
|
||||
phases:
|
||||
|
||||
@@ -298,6 +298,7 @@ en:
|
||||
documents: "Documents"
|
||||
milestone: Milestone
|
||||
new_milestone: Create new milestone
|
||||
milestone_tags: Milestone Tags
|
||||
form:
|
||||
admin_statuses: Manage statuses
|
||||
no_statuses_defined: There are no defined statuses yet
|
||||
|
||||
@@ -184,8 +184,12 @@ en:
|
||||
heading_selection_title: "By district"
|
||||
no_winner_investments: "No winner investments in this state"
|
||||
filters:
|
||||
status:
|
||||
label: "Project's current state"
|
||||
all: "All (%{count})"
|
||||
milestone_tag:
|
||||
label: "Milestone tag"
|
||||
all: "All (%{count})"
|
||||
phases:
|
||||
errors:
|
||||
dates_range_invalid: "Start date can't be equal or later than End date"
|
||||
|
||||
@@ -3,7 +3,6 @@ en:
|
||||
index:
|
||||
no_milestones: Don't have defined milestones
|
||||
progress: Progress
|
||||
milestone_tags: Milestone Tags
|
||||
show:
|
||||
publication_date: "Published %{publication_date}"
|
||||
status_changed: Status changed to
|
||||
|
||||
@@ -298,6 +298,7 @@ es:
|
||||
documents: "Documentos"
|
||||
milestone: Seguimiento
|
||||
new_milestone: Crear nuevo hito
|
||||
milestone_tags: Etiquetas de Seguimiento
|
||||
form:
|
||||
admin_statuses: Gestionar estados
|
||||
no_statuses_defined: No hay estados definidos
|
||||
|
||||
@@ -184,8 +184,12 @@ es:
|
||||
heading_selection_title: "Ámbito de actuación"
|
||||
no_winner_investments: "No hay proyectos de gasto ganadores en este estado"
|
||||
filters:
|
||||
status:
|
||||
label: "Estado actual del proyecto"
|
||||
all: "Todos (%{count})"
|
||||
milestone_tag:
|
||||
label: "Etiquetas de Seguimiento"
|
||||
all: "Todos (%{count})"
|
||||
phases:
|
||||
errors:
|
||||
dates_range_invalid: "La fecha de comienzo no puede ser igual o superior a la de finalización"
|
||||
|
||||
@@ -3,7 +3,6 @@ es:
|
||||
index:
|
||||
no_milestones: No hay hitos definidos
|
||||
progress: Progreso
|
||||
milestone_tags: Etiquetas de Seguimiento
|
||||
show:
|
||||
publication_date: "Publicado el %{publication_date}"
|
||||
status_changed: El proyecto ha cambiado al estado
|
||||
|
||||
@@ -50,4 +50,5 @@ fi:
|
||||
link: "Tavoitteet"
|
||||
page_title: "%{budget} - Tavoitteet"
|
||||
filters:
|
||||
status:
|
||||
all: "Kaikki (%{count})"
|
||||
|
||||
@@ -182,6 +182,7 @@ gl:
|
||||
heading_selection_title: "Por ámbito de actuación"
|
||||
no_winner_investments: "Non hai investimentos gañadores neste estado"
|
||||
filters:
|
||||
status:
|
||||
label: "Estado actual do proxecto"
|
||||
all: "Todo (%{count})"
|
||||
phases:
|
||||
|
||||
@@ -176,6 +176,7 @@ it:
|
||||
link: "Traguardi"
|
||||
heading_selection_title: "Per circoscrizione"
|
||||
filters:
|
||||
status:
|
||||
all: "Tutto (%{count})"
|
||||
phases:
|
||||
errors:
|
||||
|
||||
@@ -184,6 +184,7 @@ nl:
|
||||
heading_selection_title: "Per wijk"
|
||||
no_winner_investments: "Geen geaccepteerde investeringen in deze status"
|
||||
filters:
|
||||
status:
|
||||
label: "Status van het project"
|
||||
all: "Alle (%{count})"
|
||||
phases:
|
||||
|
||||
@@ -181,6 +181,7 @@ so:
|
||||
heading_selection_title: "Degmo ahaan"
|
||||
no_winner_investments: "Mana jiraan maalgalin ku guuleysta gobolkan"
|
||||
filters:
|
||||
status:
|
||||
label: "Mashruca hada gobolka kasocda"
|
||||
all: "Dhaman%{count}"
|
||||
phases:
|
||||
|
||||
@@ -181,6 +181,7 @@ sq:
|
||||
heading_selection_title: "Nga rrethi"
|
||||
no_winner_investments: "Asnjë investim fitues në këtë gjendje"
|
||||
filters:
|
||||
status:
|
||||
label: "Gjendja aktuale e projektit"
|
||||
all: "Të gjitha (%{count})"
|
||||
phases:
|
||||
|
||||
@@ -182,6 +182,7 @@ val:
|
||||
heading_selection_title: "Àmbit d'actuació"
|
||||
no_winner_investments: "No hi ha propostes en aquest estat"
|
||||
filters:
|
||||
status:
|
||||
label: "Estat actual del projecte"
|
||||
all: "Tots (%{count})"
|
||||
phases:
|
||||
|
||||
@@ -176,6 +176,7 @@ zh-CN:
|
||||
heading_selection_title: "按区域"
|
||||
no_winner_investments: "这个州里没有胜出的投资"
|
||||
filters:
|
||||
status:
|
||||
label: "项目的当前状态"
|
||||
all: "所有(%{count})"
|
||||
phases:
|
||||
|
||||
@@ -66,6 +66,7 @@ FactoryBot.define do
|
||||
|
||||
trait :published do
|
||||
published_at { Time.current }
|
||||
end
|
||||
|
||||
trait :with_milestone_tags do
|
||||
after(:create) { |proposal| proposal.milestone_tags << create(:tag, :milestone) }
|
||||
|
||||
@@ -1335,6 +1335,7 @@ describe "Admin budget investments" do
|
||||
budget_investment = create(:budget_investment)
|
||||
|
||||
visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
|
||||
|
||||
expect(page).not_to have_content("Milestone Tags:")
|
||||
|
||||
click_link "Edit classification"
|
||||
|
||||
@@ -235,6 +235,52 @@ describe "Executions" do
|
||||
select "Bidding (0)", from: "status"
|
||||
expect(page).not_to have_content(investment1.title)
|
||||
end
|
||||
|
||||
scenario "by milestone tag, only display tags for winner investments", :js do
|
||||
create(:milestone, milestoneable: investment1, status: status1)
|
||||
create(:milestone, milestoneable: investment2, status: status2)
|
||||
create(:milestone, milestoneable: investment3, status: status2)
|
||||
investment1.milestone_tag_list.add("tag1", "tag2")
|
||||
investment1.save
|
||||
investment2.milestone_tag_list.add("tag2")
|
||||
investment2.save
|
||||
investment3.milestone_tag_list.add("tag2")
|
||||
investment3.save
|
||||
|
||||
visit budget_path(budget)
|
||||
|
||||
click_link "See results"
|
||||
click_link "Milestones"
|
||||
|
||||
expect(page).to have_content(investment1.title)
|
||||
expect(page).to have_content(investment2.title)
|
||||
|
||||
select "tag2 (2)", from: "milestone_tag"
|
||||
|
||||
expect(page).to have_content(investment1.title)
|
||||
expect(page).to have_content(investment2.title)
|
||||
|
||||
select "Studying the project (1)", from: "status"
|
||||
|
||||
expect(page).to have_content(investment1.title)
|
||||
expect(page).not_to have_content(investment2.title)
|
||||
|
||||
select "Bidding (1)", from: "status"
|
||||
|
||||
expect(page).not_to have_content(investment1.title)
|
||||
expect(page).to have_content(investment2.title)
|
||||
|
||||
select "tag1 (1)", from: "milestone_tag"
|
||||
|
||||
expect(page).not_to have_content(investment1.title)
|
||||
expect(page).not_to have_content(investment2.title)
|
||||
|
||||
select "All (2)", from: "milestone_tag"
|
||||
|
||||
expect(page).not_to have_content(investment1.title)
|
||||
expect(page).to have_content(investment2.title)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "Heading Order" do
|
||||
|
||||
@@ -1274,17 +1274,22 @@ describe Budget::Investment do
|
||||
describe "milestone_tags" do
|
||||
context "without milestone_tags" do
|
||||
let(:investment) {create(:budget_investment)}
|
||||
|
||||
it "do not have milestone_tags" do
|
||||
expect(investment.milestone_tag_list).to eq([])
|
||||
expect(investment.milestone_tags).to eq([])
|
||||
end
|
||||
|
||||
it "add a new milestone_tag" do
|
||||
investment.milestone_tag_list = "tag1,tag2"
|
||||
|
||||
expect(investment.milestone_tag_list).to eq(["tag1", "tag2"])
|
||||
end
|
||||
end
|
||||
|
||||
context "with milestone_tags" do
|
||||
let(:investment) {create(:budget_investment, :with_milestone_tags)}
|
||||
|
||||
it "has milestone_tags" do
|
||||
expect(investment.milestone_tag_list.count).to eq(1)
|
||||
end
|
||||
|
||||
@@ -306,4 +306,46 @@ describe Budget do
|
||||
expect(budget.formatted_amount(1000.00)).to eq ("€1,000")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#milestone_tags" do
|
||||
let(:investment1) { build(:budget_investment, :winner) }
|
||||
let(:investment2) { build(:budget_investment, :winner) }
|
||||
let(:investment3) { build(:budget_investment) }
|
||||
|
||||
it "returns an empty array if not investments milestone_tags" do
|
||||
budget.investments << investment1
|
||||
|
||||
expect(budget.milestone_tags).to eq([])
|
||||
end
|
||||
|
||||
it "returns array of investments milestone_tags" do
|
||||
investment1.milestone_tag_list = "tag1"
|
||||
investment1.save
|
||||
budget.investments << investment1
|
||||
|
||||
expect(budget.milestone_tags).to eq(["tag1"])
|
||||
end
|
||||
|
||||
it "returns uniq list of investments milestone_tags" do
|
||||
investment1.milestone_tag_list = "tag1"
|
||||
investment1.save
|
||||
investment2.milestone_tag_list = "tag1"
|
||||
investment2.save
|
||||
budget.investments << investment1
|
||||
budget.investments << investment2
|
||||
|
||||
expect(budget.milestone_tags).to eq(["tag1"])
|
||||
end
|
||||
|
||||
it "returns tags only for winner investments" do
|
||||
investment1.milestone_tag_list = "tag1"
|
||||
investment1.save
|
||||
investment3.milestone_tag_list = "tag2"
|
||||
investment3.save
|
||||
budget.investments << investment1
|
||||
budget.investments << investment3
|
||||
|
||||
expect(budget.milestone_tags).to eq(["tag1"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -197,21 +197,28 @@ describe Legislation::Process do
|
||||
describe "milestone_tags" do
|
||||
context "without milestone_tags" do
|
||||
let(:process) {create(:legislation_process)}
|
||||
|
||||
it "do not have milestone_tags" do
|
||||
expect(process.milestone_tag_list).to eq([])
|
||||
expect(process.milestone_tags).to eq([])
|
||||
end
|
||||
|
||||
it "add a new milestone_tag" do
|
||||
process.milestone_tag_list = "tag1,tag2"
|
||||
|
||||
expect(process.milestone_tag_list).to eq(["tag1", "tag2"])
|
||||
end
|
||||
end
|
||||
|
||||
context "with milestone_tags" do
|
||||
|
||||
let(:process) {create(:legislation_process, :with_milestone_tags)}
|
||||
|
||||
it "has milestone_tags" do
|
||||
expect(process.milestone_tag_list.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user