Merge pull request #201 from AyuntamientoMadrid/pagination
Adds Pagination
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
class Admin::CommentsController < Admin::BaseController
|
||||
|
||||
def index
|
||||
@comments = Comment.only_hidden
|
||||
@comments = Comment.only_hidden.page(params[:page])
|
||||
end
|
||||
|
||||
def restore
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Admin::DebatesController < Admin::BaseController
|
||||
|
||||
def index
|
||||
@debates = Debate.only_hidden
|
||||
@debates = Debate.only_hidden.page(params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
|
||||
@@ -6,17 +6,17 @@ class Admin::OrganizationsController < Admin::BaseController
|
||||
|
||||
def index
|
||||
@organizations = @organizations.send(@filter)
|
||||
@organizations = @organizations.includes(:user).order(:name, 'users.email')
|
||||
@organizations = @organizations.includes(:user).order(:name, 'users.email').page(params[:page])
|
||||
end
|
||||
|
||||
def verify
|
||||
@organization.verify
|
||||
redirect_to action: :index, filter: @filter
|
||||
redirect_to request.query_parameters.merge(action: :index)
|
||||
end
|
||||
|
||||
def reject
|
||||
@organization.reject
|
||||
redirect_to action: :index, filter: @filter
|
||||
redirect_to request.query_parameters.merge(action: :index)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -4,7 +4,7 @@ class Admin::TagsController < Admin::BaseController
|
||||
respond_to :html, :js
|
||||
|
||||
def index
|
||||
@tags = ActsAsTaggableOn::Tag.order(featured: :desc)
|
||||
@tags = ActsAsTaggableOn::Tag.order(featured: :desc).page(params[:page])
|
||||
@tag = ActsAsTaggableOn::Tag.new
|
||||
end
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@ class DebatesController < ApplicationController
|
||||
respond_to :html, :js
|
||||
|
||||
def index
|
||||
@debates = Debate.includes(:tags).search(params)
|
||||
@debates = Debate.includes(:tags).search(params).page(params[:page])
|
||||
set_debate_votes(@debates)
|
||||
end
|
||||
|
||||
def show
|
||||
set_debate_votes(@debate)
|
||||
@comments = @debate.root_comments.with_hidden.recent
|
||||
@comments = @debate.root_comments.with_hidden.recent.page(params[:page])
|
||||
end
|
||||
|
||||
def new
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'numeric'
|
||||
class Debate < ActiveRecord::Base
|
||||
include ActsAsParanoidAliases
|
||||
default_scope { order('created_at DESC') }
|
||||
default_scope { order(created_at: :desc) }
|
||||
|
||||
apply_simple_captcha
|
||||
TITLE_LENGTH = Debate.columns.find { |c| c.name == 'title' }.limit
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<h2><%= t("admin.comments.index.title") %></h2>
|
||||
|
||||
<h3><%= page_entries_info @comments %></h3>
|
||||
|
||||
<ul class="admin-list">
|
||||
<% @comments.each do |comment| %>
|
||||
<li id="<%= dom_id(comment) %>">
|
||||
@@ -16,3 +18,5 @@
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= paginate @comments %>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<h2><%= t("admin.debates.index.title") %></h2>
|
||||
|
||||
<h3><%= page_entries_info @debates %></h3>
|
||||
|
||||
<ul class="admin-list">
|
||||
<% @debates.each do |debate| %>
|
||||
<li id="<%= dom_id(debate) %>">
|
||||
@@ -11,3 +13,5 @@
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= paginate @debates %>
|
||||
@@ -1,48 +1,48 @@
|
||||
<div class="left">
|
||||
<h2><%= t('admin.organizations.index.title') %></h2>
|
||||
|
||||
<h1><%= t('admin.organizations.index.title') %></h1>
|
||||
<p>
|
||||
<%= t('admin.organizations.index.filter') %>:
|
||||
|
||||
<p>
|
||||
<%= t('admin.organizations.index.filter') %>:
|
||||
|
||||
<% @valid_filters.each do |filter| %>
|
||||
<% if @filter == filter %>
|
||||
<%= t("admin.organizations.index.filters.#{filter}") %>
|
||||
<% else %>
|
||||
<%= link_to t("admin.organizations.index.filters.#{filter}"),
|
||||
admin_organizations_path(filter: filter) %>
|
||||
<% end %>
|
||||
<% @valid_filters.each do |filter| %>
|
||||
<% if @filter == filter %>
|
||||
<%= t("admin.organizations.index.filters.#{filter}") %>
|
||||
<% else %>
|
||||
<%= link_to t("admin.organizations.index.filters.#{filter}"),
|
||||
admin_organizations_path(filter: filter) %>
|
||||
<% end %>
|
||||
</p>
|
||||
|
||||
<table>
|
||||
<% @organizations.each do |organization| %>
|
||||
<tr>
|
||||
<td><%= organization.name %></td>
|
||||
<td><%= organization.email %></td>
|
||||
<td><%= organization.phone_number %></td>
|
||||
<% if organization.verified? %>
|
||||
<td><%= t('admin.organizations.index.verified') %></td>
|
||||
<% end %>
|
||||
<% if can? :verify, organization %>
|
||||
<td><%= link_to t('admin.organizations.index.verify'),
|
||||
verify_admin_organization_path(organization, filter: @filter),
|
||||
method: :put
|
||||
%>
|
||||
</td>
|
||||
<% end %>
|
||||
<% if organization.rejected? %>
|
||||
<td><%= t('admin.organizations.index.rejected') %></td>
|
||||
<% end %>
|
||||
<% if can? :reject, organization %>
|
||||
<td><%= link_to t('admin.organizations.index.reject'),
|
||||
reject_admin_organization_path(organization, filter: @filter),
|
||||
method: :put
|
||||
%>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
<h3><%= page_entries_info @organizations %></h3>
|
||||
|
||||
<table>
|
||||
<% @organizations.each do |organization| %>
|
||||
<tr>
|
||||
<td><%= organization.name %></td>
|
||||
<td><%= organization.email %></td>
|
||||
<td><%= organization.phone_number %></td>
|
||||
<% if organization.verified? %>
|
||||
<td><%= t('admin.organizations.index.verified') %></td>
|
||||
<% end %>
|
||||
<% if can? :verify, organization %>
|
||||
<td><%= link_to t('admin.organizations.index.verify'),
|
||||
verify_admin_organization_path(organization, request.query_parameters),
|
||||
method: :put
|
||||
%>
|
||||
</td>
|
||||
<% end %>
|
||||
<% if organization.rejected? %>
|
||||
<td><%= t('admin.organizations.index.rejected') %></td>
|
||||
<% end %>
|
||||
<% if can? :reject, organization %>
|
||||
<td><%= link_to t('admin.organizations.index.reject'),
|
||||
reject_admin_organization_path(organization, request.query_parameters),
|
||||
method: :put
|
||||
%>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<%= paginate @organizations %>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
<% end %>
|
||||
|
||||
<h3><%= t("admin.tags.index.title") %></h3>
|
||||
<h3><%= t("admin.tags.index.title") %>: <%= page_entries_info @tags %></h3>
|
||||
|
||||
<ul class="admin-list">
|
||||
<% @tags.each do |tag| %>
|
||||
@@ -44,3 +44,5 @@
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= paginate @tags %>
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<%= t("shared.organization") %>
|
||||
</span>
|
||||
<% end %>
|
||||
<% if comment.user == @debate.author %>
|
||||
<% if comment.user_id == @debate.author_id %>
|
||||
•
|
||||
<span class="label round is-author">
|
||||
<%= t("debates.comment.author") %>
|
||||
@@ -41,7 +41,7 @@
|
||||
|
||||
<% if comment.user.official? %>
|
||||
<p class="comment-user level-<%= comment.user.official_level %>"><%= comment.body %></p>
|
||||
<% elsif comment.user == @debate.author %>
|
||||
<% elsif comment.user_id == @debate.author_id %>
|
||||
<p class="comment-user is-author"><%= comment.body %></p>
|
||||
<% else %>
|
||||
<p class="comment-user"><%= comment.body %></p>
|
||||
|
||||
@@ -75,6 +75,7 @@
|
||||
<div class="row">
|
||||
<div id="debates" class="debates-list small-12 medium-9 column">
|
||||
<%= render @debates %>
|
||||
<%= paginate @debates %>
|
||||
</div>
|
||||
<div class="small-12 medium-3 column">
|
||||
<aside class="sidebar" role="complementary">
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
<% end %>
|
||||
|
||||
<%= render @comments %>
|
||||
<%= paginate @comments %>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Moderations::Organizations' do
|
||||
feature 'Admin::Organizations' do
|
||||
|
||||
|
||||
background do
|
||||
@@ -111,4 +111,18 @@ feature 'Moderations::Organizations' do
|
||||
expect(page).to_not have_content('Verified Organization')
|
||||
end
|
||||
|
||||
scenario "Verifying organization links remember the pagination setting and the filter" do
|
||||
30.times { create(:organization) }
|
||||
|
||||
visit admin_organizations_path(filter: 'pending', page: 2)
|
||||
|
||||
click_on('Verify', match: :first)
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
query_params = Rack::Utils.parse_nested_query(uri.query).symbolize_keys
|
||||
|
||||
expect(query_params[:filter]).to eq('pending')
|
||||
expect(query_params[:page]).to eq('2')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -19,6 +19,24 @@ feature 'Comments' do
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Paginated comments' do
|
||||
debate = create(:debate)
|
||||
per_page = Kaminari.config.default_per_page
|
||||
(per_page + 2).times { create(:comment, commentable: debate)}
|
||||
|
||||
visit debate_path(debate)
|
||||
|
||||
expect(page).to have_css('.comment', count: per_page)
|
||||
within("nav.pagination") do
|
||||
expect(page).to have_content("1")
|
||||
expect(page).to have_content("2")
|
||||
expect(page).to_not have_content("3")
|
||||
click_link "Next"
|
||||
end
|
||||
|
||||
expect(page).to have_css('.comment', count: 2)
|
||||
end
|
||||
|
||||
feature 'Not logged user' do
|
||||
scenario 'can not see comments forms' do
|
||||
debate = create(:debate)
|
||||
|
||||
@@ -16,6 +16,24 @@ feature 'Debates' do
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Paginated Index' do
|
||||
per_page = Kaminari.config.default_per_page
|
||||
(per_page + 2).times { create(:debate) }
|
||||
|
||||
visit debates_path
|
||||
|
||||
expect(page).to have_selector('#debates .debate', count: per_page)
|
||||
|
||||
within("nav.pagination") do
|
||||
expect(page).to have_content("1")
|
||||
expect(page).to have_content("2")
|
||||
expect(page).to_not have_content("3")
|
||||
click_link "Next"
|
||||
end
|
||||
|
||||
expect(page).to have_selector('#debates .debate', count: 2)
|
||||
end
|
||||
|
||||
scenario 'Show' do
|
||||
debate = create(:debate)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user