Merge pull request #384 from AyuntamientoMadrid/pending-filter-in-admin

Pending filters in admin
This commit is contained in:
Raimond Garcia
2015-09-06 22:38:17 +02:00
14 changed files with 70 additions and 32 deletions

View File

@@ -1,10 +1,10 @@
class Admin::CommentsController < Admin::BaseController class Admin::CommentsController < Admin::BaseController
has_filters %w{all with_confirmed_hide} has_filters %w{without_confirmed_hide all with_confirmed_hide}
before_action :load_comment, only: [:confirm_hide, :restore] before_action :load_comment, only: [:confirm_hide, :restore]
def index def index
@comments = Comment.only_hidden.send(@current_filter).page(params[:page]) @comments = Comment.only_hidden.send(@current_filter).order(hidden_at: :desc).page(params[:page])
end end
def confirm_hide def confirm_hide

View File

@@ -1,10 +1,10 @@
class Admin::DebatesController < Admin::BaseController class Admin::DebatesController < Admin::BaseController
has_filters %w{all with_confirmed_hide}, only: :index has_filters %w{without_confirmed_hide all with_confirmed_hide}, only: :index
before_action :load_debate, only: [:confirm_hide, :restore] before_action :load_debate, only: [:confirm_hide, :restore]
def index def index
@debates = Debate.only_hidden.send(@current_filter).page(params[:page]) @debates = Debate.only_hidden.send(@current_filter).order(hidden_at: :desc).page(params[:page])
end end
def confirm_hide def confirm_hide

View File

@@ -1,5 +1,5 @@
class Admin::UsersController < Admin::BaseController class Admin::UsersController < Admin::BaseController
has_filters %w{all with_confirmed_hide}, only: :index has_filters %w{without_confirmed_hide all with_confirmed_hide}, only: :index
before_action :load_user, only: [:confirm_hide, :restore] before_action :load_user, only: [:confirm_hide, :restore]

View File

@@ -18,11 +18,12 @@
method: :put, method: :put,
data: { confirm: t("admin.actions.confirm") }, data: { confirm: t("admin.actions.confirm") },
class: "button radius tiny success right" %> class: "button radius tiny success right" %>
<% unless comment.confirmed_hide? %>
<%= link_to t("admin.actions.confirm_hide"), <%= link_to t("admin.actions.confirm_hide"),
confirm_hide_admin_comment_path(comment, request.query_parameters), confirm_hide_admin_comment_path(comment, request.query_parameters),
method: :put, method: :put,
class: "button radius tiny warning right" %> class: "button radius tiny warning right" %>
<% end %>
</div> </div>
</div> </div>
</li> </li>

View File

@@ -15,10 +15,12 @@
data: { confirm: t("admin.actions.confirm") }, data: { confirm: t("admin.actions.confirm") },
class: "button radius tiny success right" %> class: "button radius tiny success right" %>
<% unless debate.confirmed_hide? %>
<%= link_to t("admin.actions.confirm_hide"), <%= link_to t("admin.actions.confirm_hide"),
confirm_hide_admin_debate_path(debate, request.query_parameters), confirm_hide_admin_debate_path(debate, request.query_parameters),
method: :put, method: :put,
class: "button radius tiny warning right" %> class: "button radius tiny warning right" %>
<% end %>
</li> </li>
<% end %> <% end %>
</ul> </ul>

View File

@@ -14,11 +14,12 @@
method: :put, method: :put,
data: { confirm: t("admin.actions.confirm") }, data: { confirm: t("admin.actions.confirm") },
class: "button radius tiny success right" %> class: "button radius tiny success right" %>
<% unless user.confirmed_hide? %>
<%= link_to t("admin.actions.confirm_hide"), <%= link_to t("admin.actions.confirm_hide"),
confirm_hide_admin_user_path(user, request.query_parameters), confirm_hide_admin_user_path(user, request.query_parameters),
method: :put, method: :put,
class: "button radius tiny warning right" %> class: "button radius tiny warning right" %>
<% end %>
</li> </li>
<% end %> <% end %>
</ul> </ul>

View File

@@ -10,7 +10,7 @@
<%= f.submit comment_button_text(parent_id), class: "button radius small inline-block" %> <%= f.submit comment_button_text(parent_id), class: "button radius small inline-block" %>
<% if can? :comment_as_moderator, commentable %>º <% if can? :comment_as_moderator, commentable %>
<div class="right"> <div class="right">
<%= f.check_box :as_moderator, id: "comment-as-moderator-#{css_id}", label: false %> <%= f.check_box :as_moderator, id: "comment-as-moderator-#{css_id}", label: false %>
<%= label_tag "comment-as-moderator-#{css_id}", t("comments.form.comment_as_moderator"), class: "checkbox" %> <%= label_tag "comment-as-moderator-#{css_id}", t("comments.form.comment_as_moderator"), class: "checkbox" %>

View File

@@ -59,6 +59,7 @@ en:
filters: filters:
all: All all: All
with_confirmed_hide: Confirmed with_confirmed_hide: Confirmed
without_confirmed_hide: Pending
debates: debates:
index: index:
title: Hidden debates title: Hidden debates
@@ -66,6 +67,7 @@ en:
filters: filters:
all: All all: All
with_confirmed_hide: Confirmed with_confirmed_hide: Confirmed
without_confirmed_hide: Pending
users: users:
index: index:
title: Banned users title: Banned users
@@ -73,6 +75,7 @@ en:
filters: filters:
all: All all: All
with_confirmed_hide: Confirmed with_confirmed_hide: Confirmed
without_confirmed_hide: Pending
show: show:
title: "User activity from %{user}" title: "User activity from %{user}"
back: Back back: Back

View File

@@ -59,6 +59,7 @@ es:
filters: filters:
all: Todos all: Todos
with_confirmed_hide: Confirmados with_confirmed_hide: Confirmados
without_confirmed_hide: Pendientes
debates: debates:
index: index:
title: Debates ocultos title: Debates ocultos
@@ -66,6 +67,7 @@ es:
filters: filters:
all: Todos all: Todos
with_confirmed_hide: Confirmados with_confirmed_hide: Confirmados
without_confirmed_hide: Pendientes
users: users:
index: index:
title: Usuarios bloqueados title: Usuarios bloqueados
@@ -73,6 +75,7 @@ es:
filters: filters:
all: Todos all: Todos
with_confirmed_hide: Confirmados with_confirmed_hide: Confirmados
without_confirmed_hide: Pendientes
show: show:
title: "Actividad del usuario %{user}" title: "Actividad del usuario %{user}"
back: Volver back: Volver

View File

@@ -34,6 +34,10 @@ module ActsAsParanoidAliases
where("confirmed_hide_at IS NOT NULL") where("confirmed_hide_at IS NOT NULL")
end end
def without_confirmed_hide
where("confirmed_hide_at IS NULL")
end
def with_hidden def with_hidden
with_deleted with_deleted
end end

View File

@@ -24,22 +24,31 @@ feature 'Admin comments' do
click_link 'Confirm' click_link 'Confirm'
expect(page).to_not have_content(comment.body)
click_link('Confirmed')
expect(page).to have_content(comment.body) expect(page).to have_content(comment.body)
expect(page).to have_content('Confirmed')
expect(comment.reload).to be_confirmed_hide expect(comment.reload).to be_confirmed_hide
end end
scenario "Current filter is properly highlighted" do scenario "Current filter is properly highlighted" do
visit admin_comments_path visit admin_comments_path
expect(page).to_not have_link('All') expect(page).to_not have_link('Pending')
expect(page).to have_link('All')
expect(page).to have_link('Confirmed')
visit admin_comments_path(filter: 'Pending')
expect(page).to_not have_link('Pending')
expect(page).to have_link('All')
expect(page).to have_link('Confirmed') expect(page).to have_link('Confirmed')
visit admin_comments_path(filter: 'all') visit admin_comments_path(filter: 'all')
expect(page).to have_link('Pending')
expect(page).to_not have_link('All') expect(page).to_not have_link('All')
expect(page).to have_link('Confirmed') expect(page).to have_link('Confirmed')
visit admin_comments_path(filter: 'with_confirmed_hide') visit admin_comments_path(filter: 'with_confirmed_hide')
expect(page).to have_link('Pending')
expect(page).to have_link('All') expect(page).to have_link('All')
expect(page).to_not have_link('Confirmed') expect(page).to_not have_link('Confirmed')
end end

View File

@@ -24,23 +24,32 @@ feature 'Admin debates' do
click_link 'Confirm' click_link 'Confirm'
expect(page).to_not have_content(debate.title)
click_link('Confirmed')
expect(page).to have_content(debate.title) expect(page).to have_content(debate.title)
expect(page).to have_content('Confirmed')
expect(debate.reload).to be_confirmed_hide expect(debate.reload).to be_confirmed_hide
end end
scenario "Current filter is properly highlighted" do scenario "Current filter is properly highlighted" do
visit admin_debates_path visit admin_debates_path
expect(page).to_not have_link('All') expect(page).to_not have_link('Pending')
expect(page).to have_link('All')
expect(page).to have_link('Confirmed')
visit admin_debates_path(filter: 'Pending')
expect(page).to_not have_link('Pending')
expect(page).to have_link('All')
expect(page).to have_link('Confirmed') expect(page).to have_link('Confirmed')
visit admin_debates_path(filter: 'all') visit admin_debates_path(filter: 'all')
expect(page).to have_link('Pending')
expect(page).to_not have_link('All') expect(page).to_not have_link('All')
expect(page).to have_link('Confirmed') expect(page).to have_link('Confirmed')
visit admin_debates_path(filter: 'with_confirmed_hide') visit admin_debates_path(filter: 'with_confirmed_hide')
expect(page).to have_link('All') expect(page).to have_link('All')
expect(page).to have_link('Pending')
expect(page).to_not have_link('Confirmed') expect(page).to_not have_link('Confirmed')
end end
@@ -48,6 +57,10 @@ feature 'Admin debates' do
create(:debate, :hidden, title: "Unconfirmed debate") create(:debate, :hidden, title: "Unconfirmed debate")
create(:debate, :hidden, :with_confirmed_hide, title: "Confirmed debate") create(:debate, :hidden, :with_confirmed_hide, title: "Confirmed debate")
visit admin_debates_path(filter: 'pending')
expect(page).to have_content('Unconfirmed debate')
expect(page).to_not have_content('Confirmed debate')
visit admin_debates_path(filter: 'all') visit admin_debates_path(filter: 'all')
expect(page).to have_content('Unconfirmed debate') expect(page).to have_content('Unconfirmed debate')
expect(page).to have_content('Confirmed debate') expect(page).to have_content('Confirmed debate')

View File

@@ -40,23 +40,32 @@ feature 'Admin users' do
click_link 'Confirm' click_link 'Confirm'
expect(page).to_not have_content(user.username)
click_link('Confirmed')
expect(page).to have_content(user.username) expect(page).to have_content(user.username)
expect(page).to have_content('Confirmed')
expect(user.reload).to be_confirmed_hide expect(user.reload).to be_confirmed_hide
end end
scenario "Current filter is properly highlighted" do scenario "Current filter is properly highlighted" do
visit admin_users_path visit admin_users_path
expect(page).to_not have_link('All') expect(page).to_not have_link('Pending')
expect(page).to have_link('All')
expect(page).to have_link('Confirmed')
visit admin_users_path(filter: 'Pending')
expect(page).to_not have_link('Pending')
expect(page).to have_link('All')
expect(page).to have_link('Confirmed') expect(page).to have_link('Confirmed')
visit admin_users_path(filter: 'all') visit admin_users_path(filter: 'all')
expect(page).to have_link('Pending')
expect(page).to_not have_link('All') expect(page).to_not have_link('All')
expect(page).to have_link('Confirmed') expect(page).to have_link('Confirmed')
visit admin_users_path(filter: 'with_confirmed_hide') visit admin_users_path(filter: 'with_confirmed_hide')
expect(page).to have_link('All') expect(page).to have_link('All')
expect(page).to have_link('Pending')
expect(page).to_not have_link('Confirmed') expect(page).to_not have_link('Confirmed')
end end

View File

@@ -296,20 +296,13 @@ feature 'Debates' do
end end
describe 'Limiting tags shown' do describe 'Limiting tags shown' do
tags = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa", "Huelgas"]
let(:all_tags) { tags }
let(:debate) { create :debate, tag_list: all_tags }
scenario 'Index page shows up to 5 tags per debate' do scenario 'Index page shows up to 5 tags per debate' do
debate tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa", "Huelgas"]
visible_tags = ["Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa", "Huelgas"] create :debate, tag_list: tag_list
visit debates_path visit debates_path
within('.debate .tags') do within('.debate .tags') do
visible_tags.each do |tag|
expect(page).to have_content tag
end
expect(page).to have_content '2+' expect(page).to have_content '2+'
end end
end end