Merge pull request #994 from consul/preserve-filters-in-spending-proposals

Preserve filters in spending proposals admin views
This commit is contained in:
Juanjo Bazán
2016-03-14 18:41:31 +01:00
7 changed files with 92 additions and 22 deletions

View File

@@ -21,7 +21,10 @@ class Admin::SpendingProposalsController < Admin::BaseController
def update
if @spending_proposal.update(spending_proposal_params)
redirect_to admin_spending_proposal_path(@spending_proposal, anchor: 'classification'), notice: t("flash.actions.update.spending_proposal")
path = admin_spending_proposal_path( @spending_proposal,
{ anchor: 'classification' }.merge(SpendingProposal.filter_params(params)))
redirect_to path, notice: t("flash.actions.update.spending_proposal")
else
render :edit
end

View File

@@ -35,6 +35,10 @@ class SpendingProposal < ActiveRecord::Base
super.try :html_safe
end
def self.filter_params(params)
params.select{|x,_| %w{geozone_id administrator_id tag_name valuator_id}.include? x.to_s }
end
def self.search(params, current_filter)
results = self
results = results.by_geozone(params[:geozone_id]) if params[:geozone_id].present?

View File

@@ -1,4 +1,4 @@
<%= link_to admin_spending_proposals_path(@spending_proposal), class: 'back' do %>
<%= link_to admin_spending_proposal_path(@spending_proposal, SpendingProposal.filter_params(params)), class: 'back' do %>
<i class="icon-angle-left"></i> <%= t("admin.spending_proposals.show.back") %>
<% end %>
@@ -6,7 +6,12 @@
<h2 id="form"><%= t("admin.spending_proposals.edit.classification") %></h2>
<%= form_for @spending_proposal, url: admin_spending_proposal_path(@spending_proposal) do |f| %>
<%= form_for @spending_proposal,
url: admin_spending_proposal_path(@spending_proposal) do |f| %>
<% SpendingProposal.filter_params(params).each do |filter_name, filter_value| %>
<%= hidden_field_tag filter_name, filter_value %>
<% end %>
<%= f.select(:administrator_id,
@admins.collect{ |a| [a.name_and_email, a.id ] },
@@ -24,15 +29,11 @@
placeholder: t("admin.spending_proposals.edit.tags_placeholder"),
class: 'js-tag-list' %>
<div class="row collapse">
<%= f.label :valuator_ids, t("admin.spending_proposals.edit.assigned_valuators") %>
<%= f.label :valuator_ids, t("admin.spending_proposals.edit.assigned_valuators") %>
<%= f.collection_check_boxes :valuator_ids, @valuators, :id, :email do |b| %>
<div class="small-12 medium-4 column end">
<%= b.label(title: b.object.name) { b.check_box + b.text } %>
</div>
<% end %>
</div>
<%= f.collection_check_boxes :valuator_ids, @valuators, :id, :email do |b| %>
<%= b.label(title: b.object.name) { b.check_box + b.text } %>
<% end %>
<p class="clear">
<%= f.submit(class: "button", value: t("admin.spending_proposals.edit.submit_button")) %>
@@ -41,4 +42,4 @@
<% end %>
<hr>
<%= render 'valuation/spending_proposals/written_by_valuators' %>
<%= render 'valuation/spending_proposals/written_by_valuators' %>

View File

@@ -37,7 +37,7 @@
<strong><%= spending_proposal.id %></strong>
</td>
<td>
<%= link_to spending_proposal.title, admin_spending_proposal_path(spending_proposal) %>
<%= link_to spending_proposal.title, admin_spending_proposal_path(spending_proposal, SpendingProposal.filter_params(params)) %>
</td>
<td class="small">
<% if spending_proposal.administrator.present? %>

View File

@@ -1,4 +1,4 @@
<%= link_to :back, class: 'back' do %>
<%= link_to admin_spending_proposals_path(SpendingProposal.filter_params(params)) do %>
<i class="icon-angle-left"></i> <%= t("admin.spending_proposals.show.back") %>
<% end %>
@@ -8,7 +8,8 @@
<p>
<%= link_to t("admin.spending_proposals.show.edit_classification"),
edit_admin_spending_proposal_path(@spending_proposal, anchor: "form") %>
edit_admin_spending_proposal_path(@spending_proposal,
{anchor: 'form'}.merge(SpendingProposal.filter_params(params))) %>
</p>
<p><strong><%= t("admin.spending_proposals.show.assigned_admin") %>:</strong>

View File

@@ -252,6 +252,8 @@ end
puts "Creating Spending Proposals"
tags = Faker::Lorem.words(10)
(1..30).each do |i|
geozone = Geozone.reorder("RANDOM()").first
author = User.reorder("RANDOM()").first
@@ -262,6 +264,7 @@ puts "Creating Spending Proposals"
description: description,
created_at: rand((Time.now - 1.week) .. Time.now),
geozone: [geozone, nil].sample,
tag_list: tags.sample(3).join(','),
terms_of_service: "1")
puts " #{spending_proposal.title}"
end
@@ -295,4 +298,4 @@ puts "Confirming hiding in debates, comments & proposals"
Comment.only_hidden.flagged.reorder("RANDOM()").limit(10).each(&:confirm_hide)
Debate.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide)
Proposal.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide)
Proposal.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide)

View File

@@ -66,11 +66,6 @@ feature 'Admin spending proposals' do
expect(page).to have_link("Realocate visitors")
expect(page).to have_link("Destroy the city")
select "District 9", from: "geozone_id"
expect(page).to have_link("Realocate visitors")
expect(page).to_not have_link("Destroy the city")
select "All city", from: "geozone_id"
expect(page).to have_link("Destroy the city")
@@ -79,6 +74,28 @@ feature 'Admin spending proposals' do
select "All zones", from: "geozone_id"
expect(page).to have_link("Realocate visitors")
expect(page).to have_link("Destroy the city")
select "District 9", from: "geozone_id"
expect(page).to_not have_link("Destroy the city")
expect(page).to have_link("Realocate visitors")
click_link("Realocate visitors")
click_link("Back")
expect(page).to_not have_link("Destroy the city")
expect(page).to have_link("Realocate visitors")
click_link("Realocate visitors")
click_on("Edit classification")
expect(page).to have_button("Update")
click_on("Back")
expect(page).to_not have_button("Update")
click_on("Back")
expect(page).to_not have_link("Destroy the city")
expect(page).to have_link("Realocate visitors")
end
scenario "Filtering by admin", :js do
@@ -94,13 +111,36 @@ feature 'Admin spending proposals' do
select "Admin 1", from: "administrator_id"
expect(page).to have_link("Realocate visitors")
expect(page).to have_content('There is 1 spending proposal')
expect(page).to_not have_link("Destroy the city")
expect(page).to have_link("Realocate visitors")
select "All administrators", from: "administrator_id"
expect(page).to have_content('There are 2 spending proposals')
expect(page).to have_link("Destroy the city")
expect(page).to have_link("Realocate visitors")
select "Admin 1", from: "administrator_id"
expect(page).to have_content('There is 1 spending proposal')
click_link("Realocate visitors")
click_link("Back")
expect(page).to have_content('There is 1 spending proposal')
expect(page).to_not have_link("Destroy the city")
expect(page).to have_link("Realocate visitors")
click_link("Realocate visitors")
click_on("Edit classification")
expect(page).to have_button("Update")
click_on("Back")
expect(page).to_not have_button("Update")
click_on("Back")
expect(page).to have_content('There is 1 spending proposal')
expect(page).to_not have_link("Destroy the city")
expect(page).to have_link("Realocate visitors")
end
scenario "Current filter is properly highlighted" do
@@ -183,10 +223,28 @@ feature 'Admin spending proposals' do
visit admin_spending_proposals_path(tag_name: 'Education')
expect(page).to_not have_content("More hospitals")
expect(page).to have_css(".spending_proposal", count: 2)
expect(page).to have_content("Educate the children")
expect(page).to have_content("More schools")
click_link("Educate the children")
click_link("Back")
expect(page).to_not have_content("More hospitals")
expect(page).to have_content("Educate the children")
expect(page).to have_content("More schools")
click_link("Educate the children")
click_on("Edit classification")
expect(page).to have_button("Update")
click_on("Back")
expect(page).to_not have_button("Update")
click_on("Back")
expect(page).to_not have_content("More hospitals")
expect(page).to have_content("Educate the children")
expect(page).to have_content("More schools")
end
end