@@ -29,58 +30,14 @@
-
- <%= form_for [:admin, @budget, group, Budget::Heading.new], remote: true do |f| %>
-
- <%= f.text_field :name,
- label: false,
- maxlength: 50,
- placeholder: t("admin.budgets.form.heading") %>
-
-
-
-
- <%= f.text_field :price,
- label: false,
- maxlength: 8,
- placeholder: t("admin.budgets.form.amount") %>
-
-
-
-
-
- <%= f.number_field :population,
- label: false,
- maxlength: 8,
- min: 1,
- placeholder: t("admin.budgets.form.population"),
- data: {toggle_focus: "population-info"} %>
-
-
-
- <%= t("admin.budgets.form.population_info") %>
-
-
-
-
- <%= f.submit t("admin.budgets.form.save_heading"), class: "button success" %>
- <% end %>
+ |
+ <%= render "admin/budgets/heading_form", group: group, budget: @budget, heading: Budget::Heading.new %>
|
<% headings.each do |heading| %>
-
- |
- <%= heading.name %>
- |
-
- <%= heading.price %>
- |
-
- <%= heading.population %>
- |
-
+ <%= render "admin/budgets/heading", group: group, budget: @budget, heading: heading %>
<% end %>
diff --git a/app/views/admin/budgets/_heading.html.erb b/app/views/admin/budgets/_heading.html.erb
new file mode 100644
index 000000000..bc9d59c5f
--- /dev/null
+++ b/app/views/admin/budgets/_heading.html.erb
@@ -0,0 +1,27 @@
+
+ |
+ <%= heading.name %>
+ |
+
+ <%= heading.price %>
+ |
+
+ <%= heading.population %>
+ |
+
+ <%= link_to t("admin.actions.edit"),
+ edit_admin_budget_budget_group_budget_heading_path(budget_id: group.budget.id, budget_group_id: group.id, id: heading.id),
+ class: "button hollow",
+ remote: true %>
+ <%= link_to t("admin.budget_investments.index.title"),
+ admin_budget_budget_investments_path(budget_id: group.budget.id, heading_id: heading.id),
+ class: "button hollow" %>
+ <% if heading.can_be_deleted? %>
+ <%= link_to t('admin.administrators.administrator.delete'),
+ #admin_budget_budget_group_budget_headings_path(group.budget.id, group.id),
+ [:admin, group.budget, group, heading],
+ method: :delete,
+ class: "button hollow alert" %>
+ <% end %>
+ |
+
diff --git a/app/views/admin/budgets/_heading_form.html.erb b/app/views/admin/budgets/_heading_form.html.erb
new file mode 100644
index 000000000..56590bf1b
--- /dev/null
+++ b/app/views/admin/budgets/_heading_form.html.erb
@@ -0,0 +1,35 @@
+<%= form_for [:admin, budget, group, heading], remote: true do |f| %>
+ <%= render 'shared/errors', resource: heading %>
+
+
+
+ <%= f.text_field :price,
+ label: false,
+ maxlength: 8,
+ placeholder: t("admin.budgets.form.amount") %>
+
+
+
+
+
+ <%= f.text_field :population,
+ label: false,
+ maxlength: 8,
+ placeholder: t("admin.budgets.form.population"),
+ data: {toggle_focus: "population-info"} %>
+
+
+
+ <%= t("admin.budgets.form.population_info") %>
+
+
+
+
+ <%= f.submit t("admin.budgets.form.save_heading"), class: "button success" %>
+<% end %>
diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml
index df5a59c90..39d0e022a 100644
--- a/config/locales/en/activerecord.yml
+++ b/config/locales/en/activerecord.yml
@@ -125,6 +125,10 @@ en:
title: "Title"
description: "Description"
publication_date: "Publication date"
+ budget/heading:
+ name: "Heading name"
+ price: "Price"
+ population: "Population"
comment:
body: "Comment"
user: "User"
diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml
index d73f853f3..e62766a2a 100644
--- a/config/locales/en/general.yml
+++ b/config/locales/en/general.yml
@@ -177,6 +177,7 @@ en:
proposal_notification: "Notification"
spending_proposal: Spending proposal
budget/investment: Investment
+ budget/heading: Budget Heading
poll/shift: Shift
poll/question/answer: Answer
user: Account
diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml
index 60492dc32..18296b7bf 100644
--- a/config/locales/es/activerecord.yml
+++ b/config/locales/es/activerecord.yml
@@ -116,6 +116,10 @@ es:
organization_name: "Si estás proponiendo en nombre de una organización o colectivo, escribe su nombre"
image: "Imagen descriptiva de la propuesta de inversión"
image_title: "Título de la imagen"
+ budget/heading:
+ name: "Nombre de la partida"
+ price: "Cantidad"
+ population: "Población"
budget/investment/milestone:
title: "Título"
description: "Descripción"
diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml
index 284d20487..adc6aed49 100644
--- a/config/locales/es/general.yml
+++ b/config/locales/es/general.yml
@@ -177,6 +177,7 @@ es:
proposal_notification: "la notificación"
spending_proposal: la propuesta de gasto
budget/investment: la propuesta de inversión
+ budget/heading: la partida presupuestaria
poll/shift: el turno
poll/question/answer: la respuesta
user: la cuenta
diff --git a/spec/features/admin/budgets_spec.rb b/spec/features/admin/budgets_spec.rb
index 0507b45f2..239865317 100644
--- a/spec/features/admin/budgets_spec.rb
+++ b/spec/features/admin/budgets_spec.rb
@@ -244,5 +244,43 @@ feature 'Admin budgets' do
end
end
+ scenario 'Update heading', :js do
+ budget = create(:budget, name: 'Yearly participatory budget')
+ group = create(:budget_group, budget: budget, name: 'Districts improvments')
+ heading = create(:budget_heading, group: group, name: "District 1")
+ heading = create(:budget_heading, group: group, name: "District 3")
+
+ visit admin_budget_path(budget)
+
+ within("#heading-#{heading.id}") do
+ click_link 'Edit'
+
+ fill_in 'budget_heading_name', with: 'District 2'
+ fill_in 'budget_heading_price', with: '10000'
+ fill_in 'budget_heading_population', with: '6000'
+ click_button 'Save heading'
+ end
+
+ expect(page).to have_content 'District 2'
+ expect(page).to have_content '10000'
+ expect(page).to have_content '6000'
+ end
+
+ scenario 'Delete heading', :js do
+ budget = create(:budget, name: 'Yearly participatory budget')
+ group = create(:budget_group, budget: budget, name: 'Districts improvments')
+ heading = create(:budget_heading, group: group, name: "District 1")
+
+ visit admin_budget_path(budget)
+
+ expect(page).to have_content 'District 1'
+
+ within("#heading-#{heading.id}") do
+ click_link 'Delete'
+ end
+
+ expect(page).to_not have_content 'District 1'
+ end
+
end
end
diff --git a/spec/models/budget/heading_spec.rb b/spec/models/budget/heading_spec.rb
index 70787550f..655a77b4f 100644
--- a/spec/models/budget/heading_spec.rb
+++ b/spec/models/budget/heading_spec.rb
@@ -44,4 +44,16 @@ describe Budget::Heading do
end
end
+ describe "heading" do
+ it "can be deleted if no budget's investments associated" do
+ heading1 = create(:budget_heading, group: group, name: 'name')
+ heading2 = create(:budget_heading, group: group, name: 'name 2')
+
+ create(:budget_investment, heading: heading1)
+
+ expect(heading1.can_be_deleted?).to eq false
+ expect(heading2.can_be_deleted?).to eq true
+ end
+ end
+
end