/ip_addresses: add paginator to group_by=(user|ip_addr) pages.
This commit is contained in:
@@ -3,12 +3,14 @@ class IpAddressesController < ApplicationController
|
|||||||
before_action :moderator_only
|
before_action :moderator_only
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@ip_addresses = IpAddress.visible(CurrentUser.user).paginated_search(params)
|
||||||
|
|
||||||
if search_params[:group_by] == "ip_addr"
|
if search_params[:group_by] == "ip_addr"
|
||||||
@ip_addresses = IpAddress.search(search_params).group_by_ip_addr(search_params[:ipv4_masklen], search_params[:ipv6_masklen]).paginate(params[:page], limit: params[:limit] || 1000)
|
@ip_addresses = @ip_addresses.group_by_ip_addr(search_params[:ipv4_masklen], search_params[:ipv6_masklen])
|
||||||
elsif search_params[:group_by] == "user"
|
elsif search_params[:group_by] == "user"
|
||||||
@ip_addresses = IpAddress.includes(:user).search(search_params).group_by_user.paginate(params[:page], limit: params[:limit] || 1000)
|
@ip_addresses = @ip_addresses.group_by_user.includes(:user)
|
||||||
else
|
else
|
||||||
@ip_addresses = IpAddress.includes(:user, :model).paginated_search(params)
|
@ip_addresses = @ip_addresses.includes(:user, :model)
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_with(@ip_addresses)
|
respond_with(@ip_addresses)
|
||||||
|
|||||||
@@ -7,9 +7,12 @@ class IpAddress < ApplicationRecord
|
|||||||
%w[Post User Comment Dmail ArtistVersion ArtistCommentaryVersion NoteVersion WikiPageVersion]
|
%w[Post User Comment Dmail ArtistVersion ArtistCommentaryVersion NoteVersion WikiPageVersion]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.visible(user)
|
||||||
|
CurrentUser.is_admin? ? all : where.not(model_type: "Dmail")
|
||||||
|
end
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = super
|
q = super
|
||||||
q = q.where.not(model_type: "Dmail") unless CurrentUser.is_admin?
|
|
||||||
q = q.search_attributes(params, :user, :model_type, :model_id, :ip_addr)
|
q = q.search_attributes(params, :user, :model_type, :model_id, :ip_addr)
|
||||||
q.order(created_at: :desc)
|
q.order(created_at: :desc)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,5 +20,3 @@
|
|||||||
<%= link_to "IP info", "https://ipinfo.io/#{ip.ip_addr}" %>
|
<%= link_to "IP info", "https://ipinfo.io/#{ip.ip_addr}" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= numbered_paginator(@ip_addresses) %>
|
|
||||||
|
|||||||
@@ -21,5 +21,7 @@
|
|||||||
<% elsif @ip_addresses.present? %>
|
<% elsif @ip_addresses.present? %>
|
||||||
<%= render "index" %>
|
<%= render "index" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<%= numbered_paginator(@ip_addresses) %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user