From 3121dd066e1c0495a4d7956f50e05573c94c0e00 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Tue, 27 Dec 2016 18:02:35 +0100 Subject: [PATCH 1/9] adds thead and button to select on budget investement index table --- .../admin/budget_investments/index.html.erb | 22 +++++++++++++++++++ config/locales/admin.en.yml | 9 ++++++++ config/locales/admin.es.yml | 9 ++++++++ 3 files changed, 40 insertions(+) diff --git a/app/views/admin/budget_investments/index.html.erb b/app/views/admin/budget_investments/index.html.erb index 5aff40115..737bac9c8 100644 --- a/app/views/admin/budget_investments/index.html.erb +++ b/app/views/admin/budget_investments/index.html.erb @@ -41,6 +41,17 @@

<%= page_entries_info @investments %>

+ + + + + + + + + + + <% @investments.each do |investment| %> + <% end %>
<%= t("admin.budget_investments.index.table_id") %><%= t("admin.budget_investments.index.table_title") %><%= t("admin.budget_investments.index.table_admin") %><%= t("admin.budget_investments.index.table_valuator") %><%= t("admin.budget_investments.index.table_geozone") %><%= t("admin.budget_investments.index.table_status") %><%= t("admin.budget_investments.index.table_actions") %>
@@ -69,6 +80,17 @@ <%= t("admin.budget_investments.index.feasibility.#{investment.feasibility}", price: investment.price) %> + <% if investment.feasible? %> + <%= link_to "#", class: "button small hollow expanded" do %> + <%= t("admin.budget_investments.index.select") %> + <% end %> + <% else %> + <%= link_to "#", class: "button small hollow warning expanded" do %> + <%= t("admin.budget_investments.index.deselect") %> + <% end %> + <% end %> +
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index c70eda84d..75f446851 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -114,6 +114,15 @@ en: feasible: "Feasible (%{price})" not_feasible: "Not feasible" undefined: "Undefined" + deselect: "Deselect" + select: "Select" + table_id: "ID" + table_title: "Title" + table_admin: "Administrator" + table_valuator: "Valuator" + table_geozone: "Scope of operation" + table_status: "Status" + table_actions: "Actions" show: assigned_admin: Assigned administrator assigned_valuators: Assigned valuators diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 579029f18..bffb2f336 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -114,6 +114,15 @@ es: feasible: "Viable (%{price})" not_feasible: "Inviable" undefined: "Sin definir" + deselect: "Deseleccionar" + select: "Seleccionar" + table_id: "ID" + table_title: "Título" + table_admin: "Administrador" + table_valuator: "Evaluador" + table_geozone: "Ámbito de actuación" + table_status: "Estado" + table_actions: "Acciones" show: assigned_admin: Administrador asignado assigned_valuators: Evaluadores asignados From d8cc888d60803774f25ad0d5a01b77b5d0f669b5 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 28 Dec 2016 12:17:08 +0100 Subject: [PATCH 2/9] changes table headings and selected button css --- app/views/admin/budget_investments/index.html.erb | 8 ++++---- config/locales/admin.en.yml | 6 +++--- config/locales/admin.es.yml | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/views/admin/budget_investments/index.html.erb b/app/views/admin/budget_investments/index.html.erb index 737bac9c8..deb3722b3 100644 --- a/app/views/admin/budget_investments/index.html.erb +++ b/app/views/admin/budget_investments/index.html.erb @@ -48,8 +48,8 @@ <%= t("admin.budget_investments.index.table_admin") %> <%= t("admin.budget_investments.index.table_valuator") %> <%= t("admin.budget_investments.index.table_geozone") %> - <%= t("admin.budget_investments.index.table_status") %> - <%= t("admin.budget_investments.index.table_actions") %> + <%= t("admin.budget_investments.index.table_feasibility") %> + <%= t("admin.budget_investments.index.table_selection") %> <% @investments.each do |investment| %> @@ -86,8 +86,8 @@ <%= t("admin.budget_investments.index.select") %> <% end %> <% else %> - <%= link_to "#", class: "button small hollow warning expanded" do %> - <%= t("admin.budget_investments.index.deselect") %> + <%= link_to "#", class: "button small expanded" do %> + <%= t("admin.budget_investments.index.selected") %> <% end %> <% end %> diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 75f446851..2be4eea7f 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -114,15 +114,15 @@ en: feasible: "Feasible (%{price})" not_feasible: "Not feasible" undefined: "Undefined" - deselect: "Deselect" + selected: "Selected" select: "Select" table_id: "ID" table_title: "Title" table_admin: "Administrator" table_valuator: "Valuator" table_geozone: "Scope of operation" - table_status: "Status" - table_actions: "Actions" + table_feasibility: "Feasibility" + table_selection: "Selection" show: assigned_admin: Assigned administrator assigned_valuators: Assigned valuators diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index bffb2f336..c342e687c 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -114,15 +114,15 @@ es: feasible: "Viable (%{price})" not_feasible: "Inviable" undefined: "Sin definir" - deselect: "Deseleccionar" + selected: "Seleccionada" select: "Seleccionar" table_id: "ID" table_title: "Título" table_admin: "Administrador" table_valuator: "Evaluador" table_geozone: "Ámbito de actuación" - table_status: "Estado" - table_actions: "Acciones" + table_feasibility: "Viabilidad" + table_selection: "Selección" show: assigned_admin: Administrador asignado assigned_valuators: Evaluadores asignados From 3dcd7b444ae94f10de5903b1be98378c6991eaa5 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 28 Dec 2016 17:29:49 +0100 Subject: [PATCH 3/9] adds valuation_finished_feasible scope --- app/models/budget/investment.rb | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 14109ba93..3487e8a66 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -34,17 +34,18 @@ class Budget scope :sort_by_price, -> { reorder(price: :desc, confidence_score: :desc, id: :desc) } scope :sort_by_random, -> { reorder("RANDOM()") } - scope :valuation_open, -> { where(valuation_finished: false) } - scope :without_admin, -> { valuation_open.where(administrator_id: nil) } - scope :managed, -> { valuation_open.where(valuator_assignments_count: 0).where("administrator_id IS NOT ?", nil) } - scope :valuating, -> { valuation_open.where("valuator_assignments_count > 0 AND valuation_finished = ?", false) } - scope :valuation_finished, -> { where(valuation_finished: true) } - scope :feasible, -> { where(feasibility: "feasible") } - scope :unfeasible, -> { where(feasibility: "unfeasible") } - scope :not_unfeasible, -> { where.not(feasibility: "unfeasible") } - scope :undecided, -> { where(feasibility: "undecided") } - scope :with_supports, -> { where('cached_votes_up > 0') } - scope :selected, -> { where(selected: true) } + scope :valuation_open, -> { where(valuation_finished: false) } + scope :without_admin, -> { valuation_open.where(administrator_id: nil) } + scope :managed, -> { valuation_open.where(valuator_assignments_count: 0).where("administrator_id IS NOT ?", nil) } + scope :valuating, -> { valuation_open.where("valuator_assignments_count > 0 AND valuation_finished = ?", false) } + scope :valuation_finished, -> { where(valuation_finished: true) } + scope :valuation_finished_feasible, -> { where(valuation_finished: true, feasibility: "feasible") } + scope :feasible, -> { where(feasibility: "feasible") } + scope :unfeasible, -> { where(feasibility: "unfeasible") } + scope :not_unfeasible, -> { where.not(feasibility: "unfeasible") } + scope :undecided, -> { where(feasibility: "undecided") } + scope :with_supports, -> { where('cached_votes_up > 0') } + scope :selected, -> { where(selected: true) } scope :by_group, -> (group_id) { where(group_id: group_id) } scope :by_heading, -> (heading_id) { where(heading_id: heading_id) } From 010aeaa9ac7a16b52e9f244e1715416c18fafa12 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 28 Dec 2016 17:42:15 +0100 Subject: [PATCH 4/9] i18n --- app/controllers/admin/budget_investments_controller.rb | 4 ++++ config/locales/admin.en.yml | 5 ++++- config/locales/admin.es.yml | 7 +++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb index b9fa19ca9..e3440339c 100644 --- a/app/controllers/admin/budget_investments_controller.rb +++ b/app/controllers/admin/budget_investments_controller.rb @@ -2,6 +2,10 @@ class Admin::BudgetInvestmentsController < Admin::BaseController include FeatureFlags feature_flag :budgets + has_filters(%w{valuation_open without_admin managed valuating valuation_finished + valuation_finished_feasible selected all}, + only: [:index, :toggle_selection]) + before_action :load_budget before_action :load_investment, only: [:show, :edit, :update] before_action :load_ballot, only: [:show, :index] diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 2be4eea7f..4328989a1 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -105,6 +105,8 @@ en: managed: Managed valuating: Under valuation valuation_finished: Valuation finished + valuation_finished_feasible: Val. fin. Feasible + selected: Selected all: All title: Investment projects assigned_admin: Assigned administrator @@ -112,7 +114,7 @@ en: no_valuators_assigned: No valuators assigned feasibility: feasible: "Feasible (%{price})" - not_feasible: "Not feasible" + unfeasible: "Unfeasible" undefined: "Undefined" selected: "Selected" select: "Select" @@ -122,6 +124,7 @@ en: table_valuator: "Valuator" table_geozone: "Scope of operation" table_feasibility: "Feasibility" + table_valuation_finished: "Val. Fin." table_selection: "Selection" show: assigned_admin: Assigned administrator diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index c342e687c..7e749636c 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -105,6 +105,8 @@ es: managed: Gestionando valuating: En evaluación valuation_finished: Evaluación finalizada + valuation_finished_feasible: Ev. Fin. Viable + selected: Seleccionadas all: Todas title: Propuestas de inversión assigned_admin: Administrador asignado @@ -112,8 +114,8 @@ es: no_valuators_assigned: Sin evaluador feasibility: feasible: "Viable (%{price})" - not_feasible: "Inviable" - undefined: "Sin definir" + unfeasible: "Inviable" + undecided: "Sin decidir" selected: "Seleccionada" select: "Seleccionar" table_id: "ID" @@ -122,6 +124,7 @@ es: table_valuator: "Evaluador" table_geozone: "Ámbito de actuación" table_feasibility: "Viabilidad" + table_valuation_finished: "Ev. Fin." table_selection: "Selección" show: assigned_admin: Administrador asignado From f7c505392a2b8160d634bd08a8e36b6f1c85a4e4 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 28 Dec 2016 17:42:47 +0100 Subject: [PATCH 5/9] Adds new route and matching ability for administrators --- app/models/abilities/administrator.rb | 2 +- config/routes.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 037289226..8d7694b32 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -45,7 +45,7 @@ module Abilities can [:index, :read, :new, :create, :update, :destroy], Budget can [:read, :create, :update, :destroy], Budget::Group can [:read, :create, :update, :destroy], Budget::Heading - can [:hide, :update], Budget::Investment + can [:hide, :update, :toggle_selection], Budget::Investment can :valuate, Budget::Investment, budget: { valuating: true } can :create, Budget::ValuatorAssignment diff --git a/config/routes.rb b/config/routes.rb index 40ecace70..cc76297f6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -165,7 +165,9 @@ Rails.application.routes.draw do end end - resources :budget_investments, only: [:index, :show, :edit, :update] + resources :budget_investments, only: [:index, :show, :edit, :update] do + member { patch :toggle_selection } + end end resources :signature_sheets, only: [:index, :new, :create, :show] From 64ca1f18c66980af5108e091b4a50f5be29914b8 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 28 Dec 2016 17:43:21 +0100 Subject: [PATCH 6/9] Extracts code to partial. Adds remote links --- .../budget_investments/_investments.html.erb | 77 +++++++++++++++++++ .../admin/budget_investments/index.html.erb | 62 +-------------- 2 files changed, 81 insertions(+), 58 deletions(-) create mode 100644 app/views/admin/budget_investments/_investments.html.erb diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/views/admin/budget_investments/_investments.html.erb new file mode 100644 index 000000000..d001cb03b --- /dev/null +++ b/app/views/admin/budget_investments/_investments.html.erb @@ -0,0 +1,77 @@ +

<%= page_entries_info @investments %>

+ + + + + + + + + + + + + + + + <% @investments.each do |investment| %> + + + + + + + + + + + <% end %> +
<%= t("admin.budget_investments.index.table_id") %><%= t("admin.budget_investments.index.table_title") %><%= t("admin.budget_investments.index.table_admin") %><%= t("admin.budget_investments.index.table_valuator") %><%= t("admin.budget_investments.index.table_geozone") %><%= t("admin.budget_investments.index.table_feasibility") %><%= t("admin.budget_investments.index.table_valuation_finished") %><%= t("admin.budget_investments.index.table_selection") %>
+ <%= investment.id %> + + <%= link_to investment.title, admin_budget_budget_investment_path(budget_id: @budget.id, id: investment.id, params: Budget::Investment.filter_params(params)) %> + + <% if investment.administrator.present? %> + <%= investment.administrator.name %> + <% else %> + <%= t("admin.budget_investments.index.no_admin_assigned") %> + <% end %> + + <% if investment.valuators.size == 0 %> + <%= t("admin.budget_investments.index.no_valuators_assigned") %> + <% else %> + <%= investment.valuators.collect(&:description_or_name).join(', ') %> + <% end %> + + <%= investment.heading.name %> + + <%= t("admin.budget_investments.index.feasibility.#{investment.feasibility}", + price: investment.formatted_price) + %> + + <%= investment.valuation_finished? ? "✔ ": "✘" %> + + <% if investment.selected? %> + <%= link_to toggle_selection_admin_budget_budget_investment_path(@budget, + investment, + filter: params[:filter], + page: params[:page]), + method: :patch, + remote: true, + class: "button small expanded" do %> + <%= t("admin.budget_investments.index.selected") %> + <% end %> + <% elsif investment.feasible? && investment.valuation_finished? %> + <%= link_to toggle_selection_admin_budget_budget_investment_path(@budget, + investment, + filter: params[:filter], + page: params[:page]), + method: :patch, + remote: true, + class: "button small hollow expanded" do %> + <%= t("admin.budget_investments.index.select") %> + <% end %> + <% end %> +
+ +<%= paginate @investments %> diff --git a/app/views/admin/budget_investments/index.html.erb b/app/views/admin/budget_investments/index.html.erb index deb3722b3..126a933b7 100644 --- a/app/views/admin/budget_investments/index.html.erb +++ b/app/views/admin/budget_investments/index.html.erb @@ -36,63 +36,9 @@ <% end %> -<%= render 'shared/filter_subnav', i18n_namespace: "admin.budget_investments.index" %> +<%= render '/shared/filter_subnav', i18n_namespace: "admin.budget_investments.index" %> -

<%= page_entries_info @investments %>

+
+ <%= render '/admin/budget_investments/investments' %> +
- - - - - - - - - - - - - <% @investments.each do |investment| %> - - - - - - - - - - <% end %> -
<%= t("admin.budget_investments.index.table_id") %><%= t("admin.budget_investments.index.table_title") %><%= t("admin.budget_investments.index.table_admin") %><%= t("admin.budget_investments.index.table_valuator") %><%= t("admin.budget_investments.index.table_geozone") %><%= t("admin.budget_investments.index.table_feasibility") %><%= t("admin.budget_investments.index.table_selection") %>
- <%= investment.id %> - - <%= link_to investment.title, admin_budget_budget_investment_path(budget_id: @budget.id, id: investment.id, params: Budget::Investment.filter_params(params)) %> - - <% if investment.administrator.present? %> - <%= investment.administrator.name %> - <% else %> - <%= t("admin.budget_investments.index.no_admin_assigned") %> - <% end %> - - <% if investment.valuators.size == 0 %> - <%= t("admin.budget_investments.index.no_valuators_assigned") %> - <% else %> - <%= investment.valuators.collect(&:description_or_name).join(', ') %> - <% end %> - - <%= investment.heading.name %> - - <%= t("admin.budget_investments.index.feasibility.#{investment.feasibility}", price: investment.price) %> - - <% if investment.feasible? %> - <%= link_to "#", class: "button small hollow expanded" do %> - <%= t("admin.budget_investments.index.select") %> - <% end %> - <% else %> - <%= link_to "#", class: "button small expanded" do %> - <%= t("admin.budget_investments.index.selected") %> - <% end %> - <% end %> -
- -<%= paginate @investments %> \ No newline at end of file From d2356c18d0dd1d0a36a1e880e85689f511cf28b8 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 28 Dec 2016 19:11:59 +0100 Subject: [PATCH 7/9] Adds toggle_selection action --- .../admin/budget_investments_controller.rb | 19 +++- .../toggle_selection.js.erb | 1 + app/views/shared/_filter_subnav.html.erb | 2 +- .../features/admin/budget_investments_spec.rb | 94 +++++++++++++++++++ 4 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 app/views/admin/budget_investments/toggle_selection.js.erb diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb index e3440339c..c26fa0a69 100644 --- a/app/controllers/admin/budget_investments_controller.rb +++ b/app/controllers/admin/budget_investments_controller.rb @@ -7,15 +7,13 @@ class Admin::BudgetInvestmentsController < Admin::BaseController only: [:index, :toggle_selection]) before_action :load_budget - before_action :load_investment, only: [:show, :edit, :update] + before_action :load_investment, only: [:show, :edit, :update, :toggle_selection] before_action :load_ballot, only: [:show, :index] + before_action :load_investments, only: [:index, :toggle_selection] + - has_filters %w{valuation_open without_admin managed valuating valuation_finished all}, only: :index def index - @investments = Budget::Investment.scoped_filter(params, @current_filter) - .order(cached_votes_up: :desc, created_at: :desc) - .page(params[:page]) end def show @@ -39,8 +37,19 @@ class Admin::BudgetInvestmentsController < Admin::BaseController end end + def toggle_selection + @investment.toggle :selected + @investment.save + end + private + def load_investments + @investments = Budget::Investment.scoped_filter(params, @current_filter) + .order(cached_votes_up: :desc, created_at: :desc) + .page(params[:page]) + end + def budget_investment_params params.require(:budget_investment) .permit(:title, :description, :external_url, :heading_id, :administrator_id, :tag_list, valuator_ids: []) diff --git a/app/views/admin/budget_investments/toggle_selection.js.erb b/app/views/admin/budget_investments/toggle_selection.js.erb new file mode 100644 index 000000000..dc3a8d67a --- /dev/null +++ b/app/views/admin/budget_investments/toggle_selection.js.erb @@ -0,0 +1 @@ +$("#investments").html('<%= j render("admin/budget_investments/investments") %>'); diff --git a/app/views/shared/_filter_subnav.html.erb b/app/views/shared/_filter_subnav.html.erb index 51a745b09..80767f4a7 100644 --- a/app/views/shared/_filter_subnav.html.erb +++ b/app/views/shared/_filter_subnav.html.erb @@ -1,4 +1,4 @@ -