Add type to budget index table
Co-Authored-By: decabeza <alberto@decabeza.es>
This commit is contained in:
committed by
Javi Martín
parent
51bca66533
commit
17b4fb58c9
@@ -14,6 +14,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th><%= t("admin.budgets.index.table_name") %></th>
|
<th><%= t("admin.budgets.index.table_name") %></th>
|
||||||
<th><%= t("admin.budgets.index.table_phase") %></th>
|
<th><%= t("admin.budgets.index.table_phase") %></th>
|
||||||
|
<th><%= t("admin.budgets.index.table_budget_type") %></th>
|
||||||
<th><%= t("admin.budgets.index.table_duration") %></th>
|
<th><%= t("admin.budgets.index.table_duration") %></th>
|
||||||
<th><%= t("admin.actions.actions") %></th>
|
<th><%= t("admin.actions.actions") %></th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -29,6 +30,7 @@
|
|||||||
<%= budget.current_phase.name %>
|
<%= budget.current_phase.name %>
|
||||||
<small><%= phase_progress_text(budget) %></small>
|
<small><%= phase_progress_text(budget) %></small>
|
||||||
</td>
|
</td>
|
||||||
|
<td><%= type(budget) %></td>
|
||||||
<td>
|
<td>
|
||||||
<%= dates(budget) %>
|
<%= dates(budget) %>
|
||||||
<%= duration(budget) %>
|
<%= duration(budget) %>
|
||||||
|
|||||||
@@ -26,6 +26,16 @@ class Admin::Budgets::IndexComponent < ApplicationComponent
|
|||||||
budget.phases.enabled.order(:id).pluck(:kind).index(budget.phase) || -1
|
budget.phases.enabled.order(:id).pluck(:kind).index(budget.phase) || -1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def type(budget)
|
||||||
|
if budget.single_heading?
|
||||||
|
t("admin.budgets.index.type_single")
|
||||||
|
elsif budget.headings.blank?
|
||||||
|
t("admin.budgets.index.type_pending")
|
||||||
|
else
|
||||||
|
t("admin.budgets.index.type_multiple")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def dates(budget)
|
def dates(budget)
|
||||||
Admin::Budgets::DurationComponent.new(budget).dates
|
Admin::Budgets::DurationComponent.new(budget).dates
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -162,6 +162,10 @@ class Budget < ApplicationRecord
|
|||||||
current_phase&.balloting_or_later?
|
current_phase&.balloting_or_later?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def single_heading?
|
||||||
|
groups.one? && headings.one?
|
||||||
|
end
|
||||||
|
|
||||||
def heading_price(heading)
|
def heading_price(heading)
|
||||||
heading_ids.include?(heading.id) ? heading.price : -1
|
heading_ids.include?(heading.id) ? heading.price : -1
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -79,12 +79,16 @@ en:
|
|||||||
open: Open
|
open: Open
|
||||||
finished: Finished
|
finished: Finished
|
||||||
budget_investments: Manage projects
|
budget_investments: Manage projects
|
||||||
|
table_budget_type: "Type"
|
||||||
table_completed: Completed
|
table_completed: Completed
|
||||||
table_draft: "Draft"
|
table_draft: "Draft"
|
||||||
table_duration: "Duration"
|
table_duration: "Duration"
|
||||||
table_name: Name
|
table_name: Name
|
||||||
table_phase: Phase
|
table_phase: Phase
|
||||||
table_phase_progress: "(%{current_phase_number}/%{total_phases})"
|
table_phase_progress: "(%{current_phase_number}/%{total_phases})"
|
||||||
|
type_multiple: "Multiple headings"
|
||||||
|
type_pending: "Pending: No headings yet"
|
||||||
|
type_single: "Single heading"
|
||||||
edit_groups: Edit headings groups
|
edit_groups: Edit headings groups
|
||||||
edit_budget: Edit budget
|
edit_budget: Edit budget
|
||||||
admin_ballots: Admin ballots
|
admin_ballots: Admin ballots
|
||||||
|
|||||||
@@ -79,12 +79,16 @@ es:
|
|||||||
open: Abiertos
|
open: Abiertos
|
||||||
finished: Terminados
|
finished: Terminados
|
||||||
budget_investments: Gestionar proyectos de gasto
|
budget_investments: Gestionar proyectos de gasto
|
||||||
|
table_budget_type: "Tipo"
|
||||||
table_completed: Completado
|
table_completed: Completado
|
||||||
table_draft: "Borrador"
|
table_draft: "Borrador"
|
||||||
table_duration: "Duración"
|
table_duration: "Duración"
|
||||||
table_name: Nombre
|
table_name: Nombre
|
||||||
table_phase: Fase
|
table_phase: Fase
|
||||||
table_phase_progress: "(%{current_phase_number}/%{total_phases})"
|
table_phase_progress: "(%{current_phase_number}/%{total_phases})"
|
||||||
|
type_multiple: "Múltiples partidas"
|
||||||
|
type_pending: "Pendiente: Aún no hay partidas"
|
||||||
|
type_single: "Partida única"
|
||||||
edit_groups: Editar grupos de partidas
|
edit_groups: Editar grupos de partidas
|
||||||
edit_budget: Editar presupuesto
|
edit_budget: Editar presupuesto
|
||||||
admin_ballots: Gestionar urnas
|
admin_ballots: Gestionar urnas
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ describe Admin::Budgets::IndexComponent, type: :component do
|
|||||||
allow_any_instance_of(Admin::BudgetsController).to receive(:current_filter).and_return("all")
|
allow_any_instance_of(Admin::BudgetsController).to receive(:current_filter).and_return("all")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#phase_progress_text" do
|
||||||
it "displays current phase zero for budgets with no current phase" do
|
it "displays current phase zero for budgets with no current phase" do
|
||||||
budget = create(:budget, :accepting, name: "Not enabled phase")
|
budget = create(:budget, :accepting, name: "Not enabled phase")
|
||||||
budget.phases.accepting.update!(enabled: false)
|
budget.phases.accepting.update!(enabled: false)
|
||||||
@@ -24,4 +25,36 @@ describe Admin::Budgets::IndexComponent, type: :component do
|
|||||||
|
|
||||||
expect(page.find("tr", text: "Without phases")).to have_content "0/0"
|
expect(page.find("tr", text: "Without phases")).to have_content "0/0"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#type" do
|
||||||
|
let(:budget) { create(:budget, name: "With type") }
|
||||||
|
|
||||||
|
it "displays 'single heading' for budgets with one heading" do
|
||||||
|
create(:budget_heading, budget: budget)
|
||||||
|
|
||||||
|
render_inline Admin::Budgets::IndexComponent.new(Budget.page(1))
|
||||||
|
|
||||||
|
expect(page.find("thead")).to have_content "Type"
|
||||||
|
expect(page.find("tr", text: "With type")).to have_content "Single heading"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "displays 'multiple headings' for budgets with multiple headings" do
|
||||||
|
2.times { create(:budget_heading, budget: budget) }
|
||||||
|
|
||||||
|
render_inline Admin::Budgets::IndexComponent.new(Budget.page(1))
|
||||||
|
|
||||||
|
expect(page.find("thead")).to have_content "Type"
|
||||||
|
expect(page.find("tr", text: "With type")).to have_content "Multiple headings"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "displays 'pending: no headings yet' for budgets without headings" do
|
||||||
|
create(:budget, name: "Without headings")
|
||||||
|
|
||||||
|
render_inline Admin::Budgets::IndexComponent.new(Budget.page(1))
|
||||||
|
|
||||||
|
expect(page.find("thead")).to have_content "Type"
|
||||||
|
expect(page.find("tr", text: "Without headings")).to have_content "Pending: No headings yet"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -447,4 +447,43 @@ describe Budget do
|
|||||||
expect(Valuator.count).to be 1
|
expect(Valuator.count).to be 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#single_heading?" do
|
||||||
|
it "returns false for budgets with no groups nor headings" do
|
||||||
|
expect(create(:budget).single_heading?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false for budgets with one group and no headings" do
|
||||||
|
create(:budget_group, budget: budget)
|
||||||
|
|
||||||
|
expect(budget.single_heading?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false for budgets with multiple groups and one heading" do
|
||||||
|
2.times { create(:budget_group, budget: budget) }
|
||||||
|
create(:budget_heading, group: budget.groups.last)
|
||||||
|
|
||||||
|
expect(budget.single_heading?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false for budgets with one group and multiple headings" do
|
||||||
|
group = create(:budget_group, budget: budget)
|
||||||
|
2.times { create(:budget_heading, group: group) }
|
||||||
|
|
||||||
|
expect(budget.single_heading?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false for budgets with one group and multiple headings" do
|
||||||
|
2.times { create(:budget_group, budget: budget) }
|
||||||
|
2.times { create(:budget_heading, group: budget.groups.sample) }
|
||||||
|
|
||||||
|
expect(budget.single_heading?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns true for budgets with one group and one heading" do
|
||||||
|
create(:budget_heading, group: create(:budget_group, budget: budget))
|
||||||
|
|
||||||
|
expect(budget.single_heading?).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -30,8 +30,10 @@ describe "Admin budgets", :admin do
|
|||||||
budget = create(:budget, :accepting)
|
budget = create(:budget, :accepting)
|
||||||
visit admin_budgets_path
|
visit admin_budgets_path
|
||||||
|
|
||||||
expect(page).to have_content budget.name
|
within "tr", text: budget.name do
|
||||||
expect(page).to have_content "Accepting projects"
|
expect(page).to have_content "Accepting projects"
|
||||||
|
expect(page).to have_content "Pending: No headings yet"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Filters by phase" do
|
scenario "Filters by phase" do
|
||||||
|
|||||||
Reference in New Issue
Block a user