Merge pull request #1311 from consul/budgets-select

adds thead and button to select on budget investement index table
This commit is contained in:
Juanjo Bazán
2016-12-29 12:31:43 +01:00
committed by GitHub
13 changed files with 245 additions and 61 deletions

View File

@@ -2,16 +2,18 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
include FeatureFlags
feature_flag :budgets
before_action :load_budget
before_action :load_investment, only: [:show, :edit, :update]
before_action :load_ballot, only: [:show, :index]
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, :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
@@ -35,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: [])

View File

@@ -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

View File

@@ -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) }

View File

@@ -0,0 +1,77 @@
<h3><%= page_entries_info @investments %></h3>
<table>
<thead>
<tr>
<th><%= t("admin.budget_investments.index.table_id") %></th>
<th><%= t("admin.budget_investments.index.table_title") %></th>
<th><%= t("admin.budget_investments.index.table_admin") %></th>
<th><%= t("admin.budget_investments.index.table_valuator") %></th>
<th><%= t("admin.budget_investments.index.table_geozone") %></th>
<th><%= t("admin.budget_investments.index.table_feasibility") %></th>
<th class="text-center"><%= t("admin.budget_investments.index.table_valuation_finished") %></th>
<th class="text-center"><%= t("admin.budget_investments.index.table_selection") %></th>
</tr>
</thead>
<% @investments.each do |investment| %>
<tr id="<%= dom_id(investment) %>" class="budget_investment">
<td class="text-right">
<strong><%= investment.id %></strong>
</td>
<td>
<%= link_to investment.title, admin_budget_budget_investment_path(budget_id: @budget.id, id: investment.id, params: Budget::Investment.filter_params(params)) %>
</td>
<td class="small">
<% if investment.administrator.present? %>
<span title="<%= t('admin.budget_investments.index.assigned_admin') %>"><%= investment.administrator.name %></span>
<% else %>
<%= t("admin.budget_investments.index.no_admin_assigned") %>
<% end %>
</td>
<td class="small">
<% if investment.valuators.size == 0 %>
<%= t("admin.budget_investments.index.no_valuators_assigned") %>
<% else %>
<%= investment.valuators.collect(&:description_or_name).join(', ') %>
<% end %>
</td>
<td class="small">
<%= investment.heading.name %>
</td>
<td class="small">
<%= t("admin.budget_investments.index.feasibility.#{investment.feasibility}",
price: investment.formatted_price)
%>
</td>
<td class="small text-center">
<%= investment.valuation_finished? ? t('shared.yes'): t('shared.no') %>
</td>
<td class="small">
<% 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 %>
</td>
</tr>
<% end %>
</table>
<%= paginate @investments %>

View File

@@ -36,41 +36,9 @@
<% end %>
</div>
<%= render 'shared/filter_subnav', i18n_namespace: "admin.budget_investments.index" %>
<%= render '/shared/filter_subnav', i18n_namespace: "admin.budget_investments.index" %>
<h3><%= page_entries_info @investments %></h3>
<div id="investments">
<%= render '/admin/budget_investments/investments' %>
</div>
<table>
<% @investments.each do |investment| %>
<tr id="<%= dom_id(investment) %>" class="budget_investment">
<td>
<strong><%= investment.id %></strong>
</td>
<td>
<%= link_to investment.title, admin_budget_budget_investment_path(budget_id: @budget.id, id: investment.id, params: Budget::Investment.filter_params(params)) %>
</td>
<td class="small">
<% if investment.administrator.present? %>
<span title="<%= t('admin.budget_investments.index.assigned_admin') %>"><%= investment.administrator.name %></span>
<% else %>
<%= t("admin.budget_investments.index.no_admin_assigned") %>
<% end %>
</td>
<td class="small">
<% if investment.valuators.size == 0 %>
<%= t("admin.budget_investments.index.no_valuators_assigned") %>
<% else %>
<%= investment.valuators.collect(&:description_or_name).join(', ') %>
<% end %>
</td>
<td class="small">
<%= investment.heading.name %>
</td>
<td class="small">
<%= t("admin.budget_investments.index.feasibility.#{investment.feasibility}", price: investment.price) %>
</td>
</tr>
<% end %>
</table>
<%= paginate @investments %>

View File

@@ -0,0 +1 @@
$("#investments").html('<%= j render("admin/budget_investments/investments") %>');

View File

@@ -1,4 +1,4 @@
<ul class="menu simple clear">
<ul class="menu simple clear" id="filter-subnav">
<li class="sr-only"><%= t("#{i18n_namespace}.filter") %>: </li>
<% @valid_filters.each do |filter| %>

View File

@@ -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,8 +114,18 @@ en:
no_valuators_assigned: No valuators assigned
feasibility:
feasible: "Feasible (%{price})"
not_feasible: "Not feasible"
undefined: "Undefined"
unfeasible: "Unfeasible"
undecided: "Undecided"
selected: "Selected"
select: "Select"
table_id: "ID"
table_title: "Title"
table_admin: "Administrator"
table_valuator: "Valuator"
table_geozone: "Scope of operation"
table_feasibility: "Feasibility"
table_valuation_finished: "Val. Fin."
table_selection: "Selection"
show:
assigned_admin: Assigned administrator
assigned_valuators: Assigned valuators

View File

@@ -105,6 +105,8 @@ es:
managed: Gestionando
valuating: En evaluación
valuation_finished: Evaluación finalizada
valuation_finished_feasible: Viables
selected: Seleccionadas
all: Todas
title: Propuestas de inversión
assigned_admin: Administrador asignado
@@ -112,8 +114,18 @@ 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"
table_title: "Título"
table_admin: "Administrador"
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
assigned_valuators: Evaluadores asignados

View File

@@ -408,6 +408,8 @@ en:
show:
back: "Go back to my activity"
shared:
"yes": "Yes"
"no": "No"
advanced_search:
author_type: 'By author category'
author_type_blank: 'Select a category'

View File

@@ -408,6 +408,8 @@ es:
show:
back: "Volver a mi actividad"
shared:
"yes": "Sí"
"no": "No"
advanced_search:
author_type: 'Por categoría de autor'
author_type_blank: 'Elige una categoría'

View File

@@ -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]

View File

@@ -397,4 +397,98 @@ feature 'Admin budget investments' do
end
context "Selecting" do
let!(:unfeasible_bi) { create(:budget_investment, :unfeasible, budget: @budget, title: "Unfeasible project") }
let!(:feasible_bi) { create(:budget_investment, :feasible, budget: @budget, title: "Feasible project") }
let!(:feasible_vf_bi) { create(:budget_investment, :feasible, :finished, budget: @budget, title: "Feasible, VF project") }
let!(:selected_bi) { create(:budget_investment, :selected, budget: @budget, title: "Selected project") }
scenario "Filtering by valuation and selection" do
visit admin_budget_budget_investments_path(@budget)
within('#filter-subnav') { click_link 'Valuation finished' }
expect(page).to_not have_content(unfeasible_bi.title)
expect(page).to_not have_content(feasible_bi.title)
expect(page).to have_content(feasible_vf_bi.title)
expect(page).to have_content(selected_bi.title)
within('#filter-subnav') { click_link 'Val. fin. Feasible' }
expect(page).to_not have_content(unfeasible_bi.title)
expect(page).to_not have_content(feasible_bi.title)
expect(page).to have_content(feasible_vf_bi.title)
expect(page).to have_content(selected_bi.title)
within('#filter-subnav') { click_link 'Selected' }
expect(page).to_not have_content(unfeasible_bi.title)
expect(page).to_not have_content(feasible_bi.title)
expect(page).to_not have_content(feasible_vf_bi.title)
expect(page).to have_content(selected_bi.title)
end
scenario "Showing the selection buttons", :js do
visit admin_budget_budget_investments_path(@budget)
within('#filter-subnav') { click_link 'All' }
within("#budget_investment_#{unfeasible_bi.id}") do
expect(page).to_not have_link('Select')
expect(page).to_not have_link('Selected')
end
within("#budget_investment_#{feasible_bi.id}") do
expect(page).to_not have_link('Select')
expect(page).to_not have_link('Selected')
end
within("#budget_investment_#{feasible_vf_bi.id}") do
expect(page).to have_link('Select')
expect(page).to_not have_link('Selected')
end
within("#budget_investment_#{selected_bi.id}") do
expect(page).to_not have_link('Select')
expect(page).to have_link('Selected')
end
end
scenario "Selecting an investment", :js do
visit admin_budget_budget_investments_path(@budget)
within('#filter-subnav') { click_link 'All' }
within("#budget_investment_#{feasible_vf_bi.id}") do
click_link('Select')
expect(page).to have_link('Selected')
end
within('#filter-subnav') { click_link 'Selected' }
within("#budget_investment_#{feasible_vf_bi.id}") do
expect(page).to_not have_link('Select')
expect(page).to have_link('Selected')
end
end
scenario "Unselecting an investment", :js do
visit admin_budget_budget_investments_path(@budget)
within('#filter-subnav') { click_link 'Selected' }
expect(page).to have_content('There is 1 investment')
within("#budget_investment_#{selected_bi.id}") do
click_link('Selected')
end
expect(page).to_not have_content(selected_bi.title)
expect(page).to have_content('investments cannot be found')
within('#filter-subnav') { click_link 'All' }
within("#budget_investment_#{selected_bi.id}") do
expect(page).to have_link('Select')
expect(page).to_not have_link('Selected')
end
end
end
end