From 6d941f8b5203d2d2d43587ee2a969c36756ef738 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 21 Jun 2017 20:08:35 +0200 Subject: [PATCH 1/7] Add population integer attribute to Budget::Heading model table --- .../20170621180611_add_population_to_budget_headings.rb | 5 +++++ db/schema.rb | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20170621180611_add_population_to_budget_headings.rb diff --git a/db/migrate/20170621180611_add_population_to_budget_headings.rb b/db/migrate/20170621180611_add_population_to_budget_headings.rb new file mode 100644 index 000000000..b17673397 --- /dev/null +++ b/db/migrate/20170621180611_add_population_to_budget_headings.rb @@ -0,0 +1,5 @@ +class AddPopulationToBudgetHeadings < ActiveRecord::Migration + def change + add_column :budget_headings, :population, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 8fae3e8dd..64b81a350 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170613203256) do +ActiveRecord::Schema.define(version: 20170621180611) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -110,6 +110,7 @@ ActiveRecord::Schema.define(version: 20170613203256) do t.integer "group_id" t.string "name", limit: 50 t.integer "price", limit: 8 + t.integer "population", default: 0 end add_index "budget_headings", ["group_id"], name: "index_budget_headings_on_group_id", using: :btree From 51f897565409fc049bfec84511ad5c181a4633b5 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 21 Jun 2017 20:21:32 +0200 Subject: [PATCH 2/7] Increase admin budget spec feature to check Budget Heading creation allows to set population value --- spec/features/admin/budgets_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/features/admin/budgets_spec.rb b/spec/features/admin/budgets_spec.rb index 760817c26..57cf1ec16 100644 --- a/spec/features/admin/budgets_spec.rb +++ b/spec/features/admin/budgets_spec.rb @@ -156,6 +156,7 @@ feature 'Admin budgets' do fill_in 'budget_heading_name', with: 'District 9 reconstruction' fill_in 'budget_heading_price', with: '6785' + fill_in 'budget_heading_population', with: '100500' click_button 'Save heading' end @@ -167,6 +168,7 @@ feature 'Admin budgets' do expect(page).to have_content 'District 9 reconstruction' expect(page).to have_content '6785' + expect(page).to have_content '100500' end end From 8cd7c685dc17f41585ae308a2440717e5bfd88ba Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 21 Jun 2017 20:22:37 +0200 Subject: [PATCH 3/7] Add population to allowed params on admin budget heading controller --- app/controllers/admin/budget_headings_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/budget_headings_controller.rb b/app/controllers/admin/budget_headings_controller.rb index 56903b744..eea93716f 100644 --- a/app/controllers/admin/budget_headings_controller.rb +++ b/app/controllers/admin/budget_headings_controller.rb @@ -12,7 +12,7 @@ class Admin::BudgetHeadingsController < Admin::BaseController private def budget_heading_params - params.require(:budget_heading).permit(:name, :price, :geozone_id) + params.require(:budget_heading).permit(:name, :price, :population) end -end \ No newline at end of file +end From d77355de0d74ef8b8a4a8377abb46583841774d1 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 21 Jun 2017 20:23:14 +0200 Subject: [PATCH 4/7] Add population field to admin Budget Heading form and headings list table --- app/views/admin/budgets/_group.html.erb | 15 ++++++++++++++- ...621180611_add_population_to_budget_headings.rb | 2 +- db/schema.rb | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/views/admin/budgets/_group.html.erb b/app/views/admin/budgets/_group.html.erb index 6193fe287..8537fa477 100644 --- a/app/views/admin/budgets/_group.html.erb +++ b/app/views/admin/budgets/_group.html.erb @@ -1,7 +1,7 @@ - @@ -21,6 +21,7 @@ + @@ -45,6 +46,15 @@ placeholder: t("admin.budgets.form.amount") %> +
+
+ + <%= f.text_field :population, + label: false, + maxlength: 8, + placeholder: t("admin.budgets.form.population") %> +
+
<%= f.submit t("admin.budgets.form.save_heading"), class: "button success" %> <% end %> @@ -60,6 +70,9 @@ + <% end %> diff --git a/db/migrate/20170621180611_add_population_to_budget_headings.rb b/db/migrate/20170621180611_add_population_to_budget_headings.rb index b17673397..fe723bc98 100644 --- a/db/migrate/20170621180611_add_population_to_budget_headings.rb +++ b/db/migrate/20170621180611_add_population_to_budget_headings.rb @@ -1,5 +1,5 @@ class AddPopulationToBudgetHeadings < ActiveRecord::Migration def change - add_column :budget_headings, :population, :integer, default: 0 + add_column :budget_headings, :population, :integer, default: nil end end diff --git a/db/schema.rb b/db/schema.rb index 64b81a350..dbdcc318d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -110,7 +110,7 @@ ActiveRecord::Schema.define(version: 20170621180611) do t.integer "group_id" t.string "name", limit: 50 t.integer "price", limit: 8 - t.integer "population", default: 0 + t.integer "population" end add_index "budget_headings", ["group_id"], name: "index_budget_headings_on_group_id", using: :btree From 9f05cda5c307a24108a2ed25dd9dc6072444a4f5 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 21 Jun 2017 20:23:34 +0200 Subject: [PATCH 5/7] Add text translations for new population field on Budget Heading for admin panel --- config/locales/admin.en.yml | 2 ++ config/locales/admin.es.yml | 2 ++ config/locales/admin.fr.yml | 2 ++ config/locales/admin.nl.yml | 2 ++ 4 files changed, 8 insertions(+) diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index bbd8dd1bd..5821fd99d 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -97,10 +97,12 @@ en: heading: Heading name add_heading: Add heading amount: Amount + population: Population save_heading: Save heading no_heading: This group has no assigned heading. table_heading: Heading table_amount: Amount + table_population: Population budget_investments: index: heading_filter_all: All headings diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index a3c6a99b9..488935f06 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -97,10 +97,12 @@ es: heading: Nombre de la partida add_heading: Añadir partida amount: Cantidad + population: Población save_heading: Guardar partida no_heading: Este grupo no tiene ninguna partida asignada. table_heading: Partida table_amount: Cantidad + table_population: Población budget_investments: index: heading_filter_all: Todas las partidas diff --git a/config/locales/admin.fr.yml b/config/locales/admin.fr.yml index 8100a95a6..4db6d1915 100644 --- a/config/locales/admin.fr.yml +++ b/config/locales/admin.fr.yml @@ -97,10 +97,12 @@ fr: heading: Nom de la rubrique add_heading: Ajouter une rubrique amount: Montant + population: Population save_heading: Sauvegarder la rubrique no_heading: Ce groupe n'a pas de rubrique assignée. table_heading: Rubrique table_amount: Montant + table_population: Population budget_investments: index: heading_filter_all: Toutes les rubriques diff --git a/config/locales/admin.nl.yml b/config/locales/admin.nl.yml index 40b21ed32..b97e0a9c2 100755 --- a/config/locales/admin.nl.yml +++ b/config/locales/admin.nl.yml @@ -98,10 +98,12 @@ nl: heading: Heading name add_heading: Add heading amount: Amount + population: Population save_heading: Save heading no_heading: This group has no assigned heading. table_heading: Heading table_amount: Amount + table_population: Population budget_investments: index: heading_filter_all: All headings From 97a7cb71d0e69e4102b8873ac32d75b8c3c81749 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 27 Jun 2017 23:25:28 +0200 Subject: [PATCH 6/7] Add population value to Budget Heading factory --- spec/factories.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/factories.rb b/spec/factories.rb index a93d911ed..7397669bd 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -254,6 +254,7 @@ FactoryGirl.define do association :group, factory: :budget_group sequence(:name) { |n| "Heading #{n}" } price 1000000 + population 1234 end factory :budget_investment, class: 'Budget::Investment' do From c96d58df757fcc61eba2358329dea200f29103d1 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 27 Jun 2017 23:28:22 +0200 Subject: [PATCH 7/7] Add population value to dev seed budget headings --- db/dev_seeds.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 99605b392..42018d41d 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -390,7 +390,8 @@ Budget::PHASES.each_with_index do |phase, i| geozones = Geozone.reorder("RANDOM()").limit([2, 5, 6, 7].sample) geozones.each do |geozone| group.headings << group.headings.create!(name: geozone.name, - price: rand(1..100) * 100000) + price: rand(1..100) * 100000, + population: rand(1..50) * 10000) end end end
+ <%= group.name %> <%= link_to t("admin.budgets.form.add_heading"), "#", class: "button float-right js-toggle-link", data: { "toggle-selector" => "#group-#{group.id}-new-heading-form" } %>
<%= t("admin.budgets.form.table_heading") %> <%= t("admin.budgets.form.table_amount") %><%= t("admin.budgets.form.table_population") %>
<%= heading.price %> + <%= heading.population %> +