From 9324b02ce14c2e1813b3e2d5ad249eabb674c632 Mon Sep 17 00:00:00 2001 From: Eduardo Martinez Echevarria Date: Sat, 1 Jul 2017 12:39:16 +0200 Subject: [PATCH 01/15] Avoid set_process on legislation/processes controller member actions --- app/controllers/legislation/processes_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index 002b5ea65..588ffdf9e 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -83,7 +83,12 @@ class Legislation::ProcessesController < Legislation::BaseController private + def member_method? + params[:id].present? + end + def set_process + return if member_method? @process = ::Legislation::Process.find(params[:process_id]) end end From c8b36719aa50d98c5b863fbcb9b7b16a378ebe50 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 3 Jul 2017 13:59:59 +0200 Subject: [PATCH 02/15] Add missinng translation for admin budget investments winners filter label --- config/locales/admin.en.yml | 1 + config/locales/admin.es.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 9cc37b359..72eca7a5d 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -120,6 +120,7 @@ en: valuation_finished: Valuation finished valuation_finished_feasible: Val. fin. Feasible selected: Selected + winners: Winners all: All title: Investment projects assigned_admin: Assigned administrator diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index cb852328e..eb71ceba2 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -120,6 +120,7 @@ es: valuation_finished: Evaluación finalizada valuation_finished_feasible: Viables selected: Seleccionadas + winners: Ganadoras all: Todas title: Propuestas de inversión assigned_admin: Administrador asignado From e8c6c6ad8c1e76834fbe9e1de7b165ae6398591e Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 3 Jul 2017 14:03:01 +0200 Subject: [PATCH 03/15] Add incompatible boolean column to Budget Investments table and factory --- ...3120055_add_incompatible_to_budget_investments.rb | 5 +++++ db/schema.rb | 12 +++++++----- spec/factories.rb | 6 ++++++ 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20170703120055_add_incompatible_to_budget_investments.rb diff --git a/db/migrate/20170703120055_add_incompatible_to_budget_investments.rb b/db/migrate/20170703120055_add_incompatible_to_budget_investments.rb new file mode 100644 index 000000000..2fffc0802 --- /dev/null +++ b/db/migrate/20170703120055_add_incompatible_to_budget_investments.rb @@ -0,0 +1,5 @@ +class AddIncompatibleToBudgetInvestments < ActiveRecord::Migration + def change + add_column :budget_investments, :incompatible, :bool, default: false, index: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 042bec7dd..48fc9accb 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: 20170626081337) do +ActiveRecord::Schema.define(version: 20170703120055) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -95,8 +95,9 @@ ActiveRecord::Schema.define(version: 20170626081337) do create_table "budget_ballots", force: :cascade do |t| t.integer "user_id" t.integer "budget_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "ballot_lines_count", default: 0 end create_table "budget_groups", force: :cascade do |t| @@ -108,8 +109,8 @@ ActiveRecord::Schema.define(version: 20170626081337) do create_table "budget_headings", force: :cascade do |t| t.integer "group_id" - t.string "name", limit: 50 - t.integer "price", limit: 8 + t.string "name", limit: 50 + t.integer "price", limit: 8 t.integer "population" end @@ -157,6 +158,7 @@ ActiveRecord::Schema.define(version: 20170626081337) do t.integer "ballot_lines_count", default: 0 t.integer "previous_heading_id" t.boolean "winner", default: false + t.boolean "incompatible", default: false end add_index "budget_investments", ["administrator_id"], name: "index_budget_investments_on_administrator_id", using: :btree diff --git a/spec/factories.rb b/spec/factories.rb index c0cbd1cc1..aafc4d82a 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -266,6 +266,7 @@ FactoryGirl.define do unfeasibility_explanation '' external_url 'http://external_documention.org' terms_of_service '1' + incompatible false trait :with_confidence_score do before(:save) { |i| i.calculate_confidence_score } @@ -300,6 +301,11 @@ FactoryGirl.define do winner true end + trait :incompatible do + selected + incompatible true + end + trait :unselected do selected false feasibility "feasible" From 21864f3fb54ce221feea73a6dc25bddda07d46f6 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 3 Jul 2017 15:43:37 +0200 Subject: [PATCH 04/15] Increase Budget Result spec to check incompatible investments can't be winners Why: * A incompatible investment can't be chosen as a winner * When a winner investment is marked as incompatible, winnersmust be recalculated and it can't be a winner How: * Increasing existing scenarios to include a incompatible investment * Adding a new scenario where a winner investment gets flagged as incompatible --- spec/models/budget/result_spec.rb | 53 +++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/spec/models/budget/result_spec.rb b/spec/models/budget/result_spec.rb index f96428221..85eb14f3e 100644 --- a/spec/models/budget/result_spec.rb +++ b/spec/models/budget/result_spec.rb @@ -7,29 +7,48 @@ describe Budget::Result do let(:group) { create(:budget_group, budget: budget) } let(:heading) { create(:budget_heading, group: group, price: 1000) } - it "calculates a budget's winner investments" do - investment1 = create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 900) - investment2 = create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 800) - investment3 = create(:budget_investment, :selected, heading: heading, price: 500, ballot_lines_count: 700) - investment4 = create(:budget_investment, :selected, heading: heading, price: 100, ballot_lines_count: 600) + context "When there is no winners" do + it "calculates the correct winner set" do + investment1 = create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 900, winner: false) + investment2 = create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 800, winner: false) + investment3 = create(:budget_investment, :incompatible, heading: heading, price: 500, ballot_lines_count: 700, winner: false) + investment4 = create(:budget_investment, :selected, heading: heading, price: 500, ballot_lines_count: 600, winner: false) + investment5 = create(:budget_investment, :selected, heading: heading, price: 100, ballot_lines_count: 500, winner: false) - result = Budget::Result.new(budget, heading) - result.calculate_winners + Budget::Result.new(budget, heading).calculate_winners - expect(result.winners).to eq([investment1, investment2, investment3]) + expect(heading.investments.winners.pluck(:id)).to match_array([investment1.id, investment2.id, investment4.id]) + end end - it "resets winners before recalculating" do - investment1 = create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 900, winner: true) - investment2 = create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 800, winner: true) - investment3 = create(:budget_investment, :selected, heading: heading, price: 500, ballot_lines_count: 700, winner: true) - investment4 = create(:budget_investment, :selected, heading: heading, price: 100, ballot_lines_count: 600, winner: true) + context "When there are winners" do + it "removes winners and recalculates" do + investment1 = create(:budget_investment, :winner, heading: heading, price: 200, ballot_lines_count: 900) + investment2 = create(:budget_investment, :winner, heading: heading, price: 300, ballot_lines_count: 800) + investment3 = create(:budget_investment, :incompatible, heading: heading, price: 500, ballot_lines_count: 700, winner: true) + investment4 = create(:budget_investment, :winner, heading: heading, price: 500, ballot_lines_count: 600) + investment5 = create(:budget_investment, :winner, heading: heading, price: 100, ballot_lines_count: 500) - result = Budget::Result.new(budget, heading) - result.calculate_winners + Budget::Result.new(budget, heading).calculate_winners - expect(result.winners).to eq([investment1, investment2, investment3]) + expect(heading.investments.winners.pluck(:id)).to match_array([investment1.id, investment2.id, investment4.id]) + end + end + + context "When a winner is flagged as incompatible" do + it "recalculates winners leaving it out" do + investment1 = create(:budget_investment, :winner, heading: heading, price: 200, ballot_lines_count: 900) + investment2 = create(:budget_investment, :winner, heading: heading, price: 300, ballot_lines_count: 800) + investment3 = create(:budget_investment, :winner, heading: heading, price: 500, ballot_lines_count: 700) + investment4 = create(:budget_investment, :winner, heading: heading, price: 500, ballot_lines_count: 600) + investment5 = create(:budget_investment, :winner, heading: heading, price: 100, ballot_lines_count: 500) + + investment3.incompatible = true + investment3.save + + expect(heading.investments.winners.pluck(:id)).to match_array([investment1.id, investment2.id, investment4.id]) + end end end -end \ No newline at end of file +end From 9c157e25bbe1c77ebee765ae19a45b5c791d4ef8 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 3 Jul 2017 16:07:45 +0200 Subject: [PATCH 05/15] Increase Admin Budget Investment edit to cover new incompatible checkbox edit Why: * Admins can now mark/unmark a investment as incompatible How: * With a new checkbox in the edit form and a section at the investment details view to show the current status --- spec/features/admin/budget_investments_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index 727cc3d6c..375a09770 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -311,7 +311,7 @@ feature 'Admin budget investments' do context "Edit" do - scenario "Change title, description or heading" do + scenario "Change title, incompatible, description or heading" do budget_investment = create(:budget_investment) create(:budget_heading, group: budget_investment.group, name: "Barbate") @@ -321,12 +321,14 @@ feature 'Admin budget investments' do fill_in 'budget_investment_title', with: 'Potatoes' fill_in 'budget_investment_description', with: 'Carrots' select "#{budget_investment.group.name}: Barbate", from: 'budget_investment[heading_id]' + check "budget_investment_incompatible" click_button 'Update' expect(page).to have_content 'Potatoes' expect(page).to have_content 'Carrots' expect(page).to have_content 'Barbate' + expect(page).to have_content 'Incompatible' end scenario "Add administrator" do From ed016d7afd988f25a4426efeddd0872a27727f3f Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 3 Jul 2017 16:56:15 +0200 Subject: [PATCH 06/15] Add compatible scope to Budget Investment and use it on the winners scope Why: * Only compatible investments can be winners How: * Using the new column incompatible to filter compatible investments --- app/models/budget/investment.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 0d9c738b9..6bcd28b72 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -50,7 +50,8 @@ class Budget scope :undecided, -> { where(feasibility: "undecided") } scope :with_supports, -> { where('cached_votes_up > 0') } scope :selected, -> { feasible.where(selected: true) } - scope :winners, -> { selected.where(winner: true) } + scope :compatible, -> { where(incompatible: false) } + scope :winners, -> { selected.compatible.where(winner: true) } scope :unselected, -> { not_unfeasible.where(selected: false) } scope :last_week, -> { where("created_at >= ?", 7.days.ago)} From 640e0e1c2ab01b6f6c5683594b50f3531e0bb679 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 3 Jul 2017 18:13:35 +0200 Subject: [PATCH 07/15] Use compatible filter when calculating budget heading winners --- app/models/budget/result.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/budget/result.rb b/app/models/budget/result.rb index f835bce0c..aa6c4c7ac 100644 --- a/app/models/budget/result.rb +++ b/app/models/budget/result.rb @@ -10,7 +10,7 @@ class Budget def calculate_winners reset_winners - investments.each do |investment| + investments.compatible.each do |investment| @current_investment = investment set_winner if inside_budget? end From 99052485fb720f461465c1e229f9461b7c1b25e7 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 3 Jul 2017 18:15:44 +0200 Subject: [PATCH 08/15] Recalculate heading winner investments when a winner is flagged as incompatible --- app/models/budget/investment.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 6bcd28b72..68bf21953 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -64,6 +64,7 @@ class Budget scope :for_render, -> { includes(:heading) } before_save :calculate_confidence_score + after_save :recalculate_heading_winners if :incompatible_changed? before_validation :set_responsible_name before_validation :set_denormalized_ids @@ -201,6 +202,10 @@ class Budget self.confidence_score = ScoreCalculator.confidence_score(total_votes, total_votes) end + def recalculate_heading_winners + Budget::Result.new(budget, heading).calculate_winners if incompatible_changed? && winner? && incompatible? + end + def set_responsible_name self.responsible_name = author.try(:document_number) if author.try(:document_number).present? end From afc77f68fb45d5ba4e80773392363d8582c1e2fc Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 3 Jul 2017 18:21:28 +0200 Subject: [PATCH 09/15] Add incompatible checkbox on admin investment edit form --- .../admin/budget_investments_controller.rb | 2 +- app/views/admin/budget_investments/edit.html.erb | 15 +++++++++++++-- config/locales/admin.en.yml | 2 ++ config/locales/admin.es.yml | 2 ++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb index 743faa166..8a7f33c3c 100644 --- a/app/controllers/admin/budget_investments_controller.rb +++ b/app/controllers/admin/budget_investments_controller.rb @@ -51,7 +51,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController def budget_investment_params params.require(:budget_investment) - .permit(:title, :description, :external_url, :heading_id, :administrator_id, :valuation_tag_list, valuator_ids: []) + .permit(:title, :description, :external_url, :heading_id, :administrator_id, :valuation_tag_list, :incompatible, valuator_ids: []) end def load_budget diff --git a/app/views/admin/budget_investments/edit.html.erb b/app/views/admin/budget_investments/edit.html.erb index 17dd88665..0e9b6afc9 100644 --- a/app/views/admin/budget_investments/edit.html.erb +++ b/app/views/admin/budget_investments/edit.html.erb @@ -61,9 +61,20 @@ -

+

<%= t("admin.budget_investments.edit.compatibility") %>

+ +
+
+ <%= f.label :incompatible do %> + <%= f.check_box :incompatible, title: t('admin.budget_investments.edit.compatibility'), label: false %> + <%= t("admin.budget_investments.edit.mark_as_incompatible") %> + <% end %> +
+
+ +
<%= f.submit(class: "button", value: t("admin.budget_investments.edit.submit_button")) %> -

+
<% end %>
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 72eca7a5d..24c3a9802 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -161,6 +161,8 @@ en: new_milestone: Create new milestone edit: classification: Clasification + compatibility: Compatibility + mark_as_incompatible: Mark this investement project as incompatible assigned_valuators: Valuators select_heading: Select heading submit_button: Update diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index eb71ceba2..fbc56fa04 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -161,6 +161,8 @@ es: new_milestone: Crear nuevo hito edit: classification: Clasificación + compatibility: Compatibilidad + mark_as_incompatible: Marcar esta propuesta de inversión como incompatible assigned_valuators: Evaluadores select_heading: Seleccionar partida submit_button: Actualizar From 646b3657ee43506fe93a3ab314c84cf8e5b665f9 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 3 Jul 2017 18:21:49 +0200 Subject: [PATCH 10/15] Add investment status on admin budget investment detail show page --- app/views/admin/budget_investments/show.html.erb | 5 +++++ config/locales/admin.en.yml | 4 ++++ config/locales/admin.es.yml | 4 ++++ config/routes.rb | 1 - 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/views/admin/budget_investments/show.html.erb b/app/views/admin/budget_investments/show.html.erb index f220c0955..95fc6c76a 100644 --- a/app/views/admin/budget_investments/show.html.erb +++ b/app/views/admin/budget_investments/show.html.erb @@ -56,3 +56,8 @@

<%= link_to t("admin.budget_investments.show.new_milestone"), new_admin_budget_budget_investment_budget_investment_milestone_path(@budget, @investment) %>

+ +

<%= t("admin.budget_investments.show.compatibility.title") %>

+

+ <%= t("admin.budget_investments.show.compatibility.#{@investment.incompatible?}") %> +

diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 24c3a9802..6f72defa5 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -159,6 +159,10 @@ en: undefined: Undefined milestone: Milestone new_milestone: Create new milestone + compatibility: + title: Compatibility + "true": Incompatible + "false": Compatible edit: classification: Clasification compatibility: Compatibility diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index fbc56fa04..773520629 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -159,6 +159,10 @@ es: undefined: Sin definir milestone: Seguimiento new_milestone: Crear nuevo hito + compatibility: + title: Compatibilidad + "true": Incompatible + "false": Compatible edit: classification: Clasificación compatibility: Compatibilidad diff --git a/config/routes.rb b/config/routes.rb index dbf3e4709..bdf1e22f3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -210,7 +210,6 @@ Rails.application.routes.draw do end end - resources :signature_sheets, only: [:index, :new, :create, :show] resources :banners, only: [:index, :new, :create, :edit, :update, :destroy] do From 688ec05ea25066664829fb7b8afd01bc6683e1bf Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 3 Jul 2017 23:59:15 +0200 Subject: [PATCH 11/15] Replace winner column for incompatible on admin investment list filter by selected --- .../admin/budget_investments/_investments.html.erb | 12 ++++++++---- config/locales/admin.en.yml | 2 +- config/locales/admin.es.yml | 2 +- config/locales/admin.fr.yml | 2 +- config/locales/admin.nl.yml | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/views/admin/budget_investments/_investments.html.erb index 0c56e579c..fca3560a4 100644 --- a/app/views/admin/budget_investments/_investments.html.erb +++ b/app/views/admin/budget_investments/_investments.html.erb @@ -12,7 +12,9 @@ <%= t("admin.budget_investments.index.table_feasibility") %> <%= t("admin.budget_investments.index.table_valuation_finished") %> <%= t("admin.budget_investments.index.table_selection") %> - <%= t("admin.budget_investments.index.table_winner") %> + <% if params[:filter] == 'selected' %> + <%= t("admin.budget_investments.index.table_incompatible") %> + <% end %> @@ -75,9 +77,11 @@ <% end %> <% end %> - - <%= investment.winner? ? t('shared.yes'): t('shared.no') %> - + <% if params[:filter] == 'selected' %> + + <%= investment.incompatible? ? t('shared.yes'): t('shared.no') %> + + <% end %> <% end %> diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 6f72defa5..437638d84 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -141,7 +141,7 @@ en: table_feasibility: "Feasibility" table_valuation_finished: "Val. Fin." table_selection: "Selection" - table_winner: "Winner" + table_incompatible: "Incompatible" show: assigned_admin: Assigned administrator assigned_valuators: Assigned valuators diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 773520629..39c6878fe 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -141,7 +141,7 @@ es: table_feasibility: "Viabilidad" table_valuation_finished: "Ev. Fin." table_selection: "Selección" - table_winner: "Ganadora" + table_incompatible: "Incompatible" show: assigned_admin: Administrador asignado assigned_valuators: Evaluadores asignados diff --git a/config/locales/admin.fr.yml b/config/locales/admin.fr.yml index 2c3b84786..76bd7655d 100644 --- a/config/locales/admin.fr.yml +++ b/config/locales/admin.fr.yml @@ -140,7 +140,7 @@ fr: table_feasibility: "Faisabilité" table_valuation_finished: "Ev. Ter." table_selection: "Sélection" - table_winner: "Winner" + table_incompatible: "Incompatible" show: assigned_admin: Administrateur assigné assigned_valuators: Évaluateur assigné diff --git a/config/locales/admin.nl.yml b/config/locales/admin.nl.yml index 4e35e5ace..e18087e60 100755 --- a/config/locales/admin.nl.yml +++ b/config/locales/admin.nl.yml @@ -140,7 +140,7 @@ nl: table_feasibility: "Feasibility" table_valuation_finished: "Val. Fin." table_selection: "Selection" - table_winner: "Winner" + table_incompatible: "Incompatible" show: assigned_admin: Assigned administrator assigned_valuators: Assigned valuators From 339597483e914bb0b4f47ce4d0504a4f36c6ceaf Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 4 Jul 2017 01:03:14 +0200 Subject: [PATCH 12/15] Add incompatible scope to Budget Investment model --- app/models/budget/investment.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 68bf21953..845d695bb 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -51,6 +51,7 @@ class Budget scope :with_supports, -> { where('cached_votes_up > 0') } scope :selected, -> { feasible.where(selected: true) } scope :compatible, -> { where(incompatible: false) } + scope :incompatible, -> { where(incompatible: true) } scope :winners, -> { selected.compatible.where(winner: true) } scope :unselected, -> { not_unfeasible.where(selected: false) } scope :last_week, -> { where("created_at >= ?", 7.days.ago)} From e87073301d83cd766c5311b6c7116b6f37e491a1 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 4 Jul 2017 01:03:58 +0200 Subject: [PATCH 13/15] Fix form js coffe data toggle-link helper function for toogle buttons --- app/assets/javascripts/forms.js.coffee | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/forms.js.coffee b/app/assets/javascripts/forms.js.coffee index fab812400..edf4c525f 100644 --- a/app/assets/javascripts/forms.js.coffee +++ b/app/assets/javascripts/forms.js.coffee @@ -15,6 +15,11 @@ App.Forms = toggleLink: -> $('.js-toggle-link').unbind('click').on('click', -> $($(this).data('toggle-selector')).toggle("down") + if $(this).data('toggle-text') isnt undefined + toggle_txt = $(this).text() + $(this).text( $(this).data('toggle-text') ) + $(this).data('toggle-text', toggle_txt) + false ) @@ -22,4 +27,4 @@ App.Forms = App.Forms.disableEnter() App.Forms.submitOnChange() App.Forms.toggleLink() - false \ No newline at end of file + false From 10c299d19f9bdbe1855156b6102421f0dc91d08d Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 4 Jul 2017 01:04:47 +0200 Subject: [PATCH 14/15] Add to public Budget Results page winners, discarded and incompatible listing --- app/controllers/budgets/results_controller.rb | 5 +- .../budgets/results/_results_table.html.erb | 49 ++++++++----------- app/views/budgets/results/show.html.erb | 15 +++++- config/locales/budgets.en.yml | 1 + config/locales/budgets.es.yml | 2 + 5 files changed, 40 insertions(+), 32 deletions(-) diff --git a/app/controllers/budgets/results_controller.rb b/app/controllers/budgets/results_controller.rb index d92232f67..8da1e9ef7 100644 --- a/app/controllers/budgets/results_controller.rb +++ b/app/controllers/budgets/results_controller.rb @@ -5,7 +5,8 @@ module Budgets def show authorize! :read_results, @budget - @result = load_result + @investments = load_result.investments + @heading = heading end private @@ -19,4 +20,4 @@ module Budgets end end -end \ No newline at end of file +end diff --git a/app/views/budgets/results/_results_table.html.erb b/app/views/budgets/results/_results_table.html.erb index 9c40a1d22..993060562 100644 --- a/app/views/budgets/results/_results_table.html.erb +++ b/app/views/budgets/results/_results_table.html.erb @@ -1,14 +1,10 @@ -
+
+

- <%= heading.name %> + <%= title %>

- <%= link_to t("budgets.results.show_all_link"), "#", - class: "js-toggle-link button hollow margin-bottom float-right", - data: {'toggle-selector' => '.js-discarded', - 'toggle-text' => t("budgets.results.hide_discarded_link")} %> - - +
- + <% if results_type == :compatible %> + + <% end %> - <% amount_available = heading.price %> - <% @result.investments.each do |investment| %> - <% if investment.winner? %> - - <% else %> - - <% end %> + <% amount_available = heading_price %> + <% investments.each do |investment| %> + - + <% if results_type == :compatible %> + + <% end %> <% end %> diff --git a/app/views/budgets/results/show.html.erb b/app/views/budgets/results/show.html.erb index d9253b785..2343e652c 100644 --- a/app/views/budgets/results/show.html.erb +++ b/app/views/budgets/results/show.html.erb @@ -1,6 +1,6 @@ <% provide :title, t("budgets.results.page_title", budget: @budget.name) %> <% content_for :canonical do %> - <%= render "shared/canonical", href: budget_results_url(@budget, heading_id: @result.heading) %> + <%= render "shared/canonical", href: budget_results_url(@budget, heading_id: @heading) %> <% end %>
@@ -34,5 +34,16 @@
- <%= render 'results_table', heading: @result.heading %> + <%= link_to t("budgets.results.hide_discarded_link"), "#", class: "js-toggle-link button hollow margin-bottom", data: {'toggle-selector' => '.js-discarded', 'toggle-text' => t("budgets.results.show_all_link")} %> + + + <%= render 'results_table', results_type: :compatible, + title: @heading.name, + heading_price: @heading.price, + investments: @investments.compatible %> + + <%= render 'results_table', results_type: :incompatible, + title: t("budgets.results.incompatibles"), + heading_price: @heading.price, + investments: @investments.incompatible %> diff --git a/config/locales/budgets.en.yml b/config/locales/budgets.en.yml index 75a56c919..33ef8bb80 100644 --- a/config/locales/budgets.en.yml +++ b/config/locales/budgets.en.yml @@ -136,3 +136,4 @@ en: amount_available: Available budget accepted: "Accepted spending proposal: " discarded: "Discarded spending proposal: " + incompatibles: Incompatibles diff --git a/config/locales/budgets.es.yml b/config/locales/budgets.es.yml index 4c35d8902..029c0277a 100644 --- a/config/locales/budgets.es.yml +++ b/config/locales/budgets.es.yml @@ -136,3 +136,5 @@ es: amount_available: Presupuesto disponible accepted: "Propuesta de inversión aceptada: " discarded: "Propuesta de inversión descartada: " + incompatibles: Incompatibles + From 10b17eae8f56580471f887a276fbf3807fac563c Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 4 Jul 2017 01:52:46 +0200 Subject: [PATCH 15/15] Update user budget's result feature spec to include incompatible ones --- spec/features/budgets/results_spec.rb | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/spec/features/budgets/results_spec.rb b/spec/features/budgets/results_spec.rb index d2a32f992..cd9cb0912 100644 --- a/spec/features/budgets/results_spec.rb +++ b/spec/features/budgets/results_spec.rb @@ -8,8 +8,8 @@ feature 'Results' do let!(:investment1) { create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 900) } let!(:investment2) { create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 800) } - let!(:investment3) { create(:budget_investment, :selected, heading: heading, price: 500, ballot_lines_count: 700) } - let!(:investment4) { create(:budget_investment, :selected, heading: heading, price: 100, ballot_lines_count: 600) } + let!(:investment3) { create(:budget_investment, :incompatible, heading: heading, price: 500, ballot_lines_count: 700) } + let!(:investment4) { create(:budget_investment, :selected, heading: heading, price: 600, ballot_lines_count: 600) } let!(:results) { Budget::Result.new(budget, heading).calculate_winners } @@ -17,31 +17,32 @@ feature 'Results' do visit budget_path(budget) click_link "See results" - within("#budget-investments-results") do + within("#budget-investments-compatible") do expect(page).to have_content investment1.title expect(page).to have_content investment2.title - expect(page).to have_content investment3.title - expect(page).to_not have_content investment4.title + expect(page).to have_content investment4.title expect(investment1.title).to appear_before(investment2.title) - expect(investment2.title).to appear_before(investment3.title) + expect(investment2.title).to appear_before(investment4.title) + end + + within("#budget-investments-incompatible") do + expect(page).to have_content investment3.title end end scenario "Displays non winner investments", :js do visit budget_path(budget) click_link "See results" - click_link "Show all" + click_link "Hide discarded" - within("#budget-investments-results") do + within("#budget-investments-compatible") do expect(page).to have_content investment1.title expect(page).to have_content investment2.title - expect(page).to have_content investment3.title - expect(page).to have_content investment4.title + expect(page).not_to have_content investment3.title + expect(page).not_to have_content investment4.title expect(investment1.title).to appear_before(investment2.title) - expect(investment2.title).to appear_before(investment3.title) - expect(investment3.title).to appear_before(investment4.title) end end
@@ -20,23 +16,19 @@ <%= t("budgets.results.price") %> - <%= format_price(heading.price) %>
- <%= t("budgets.results.amount_available") %> -
+ <%= format_price(heading_price) %>
+ <%= t("budgets.results.amount_available") %> +
<% if investment.winner? %> @@ -51,8 +43,7 @@ <% end %> - <%= link_to investment.title, - budget_investment_path(@budget, investment) %> + <%= link_to investment.title, budget_investment_path(@budget, investment) %> <%= investment.ballot_lines_count %> @@ -60,11 +51,13 @@ <%= format_price investment.price %> - <%= format_price amount_available - investment.price %> - <% amount_available -= investment.price if investment.winner? %> - + <%= format_price amount_available - investment.price %> + <% amount_available -= investment.price if investment.winner? %> +