ip bans: add search form.
* Add IP ban search form to /ip_bans page. * Make some attributes searchable that weren't previously searchable.
This commit is contained in:
@@ -25,14 +25,18 @@ class IpBan < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :reason, :creator)
|
q = search_attributes(params, :id, :created_at, :updated_at, :ip_addr, :reason, :is_deleted, :category, :hit_count, :last_hit_at, :creator)
|
||||||
q = q.text_attribute_matches(:reason, params[:reason_matches])
|
q = q.text_attribute_matches(:reason, params[:reason_matches])
|
||||||
|
|
||||||
if params[:ip_addr].present?
|
case params[:order]
|
||||||
q = q.where("ip_addr = ?", params[:ip_addr])
|
when /\A(created_at|updated_at|last_hit_at)(?:_(asc|desc))?\z/i
|
||||||
|
dir = $2 || :desc
|
||||||
|
q = q.order($1 => dir).order(id: :desc)
|
||||||
|
else
|
||||||
|
q = q.apply_default_order(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
q.apply_default_order(params)
|
q
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_mod_action
|
def create_mod_action
|
||||||
|
|||||||
@@ -2,6 +2,16 @@
|
|||||||
<div id="a-index">
|
<div id="a-index">
|
||||||
<h1>IP Bans</h1>
|
<h1>IP Bans</h1>
|
||||||
|
|
||||||
|
<%= search_form_for(ip_bans_path) do |f| %>
|
||||||
|
<%= f.input :ip_addr, label: "IP Addr", hint: "Use /24 for subnet", input_html: { value: params[:search][:ip_addr] } %>
|
||||||
|
<%= f.input :reason, input_html: { value: params[:search][:reason] } %>
|
||||||
|
<%= f.input :creator_name, label: "Creator", input_html: { value: params[:search][:creator_name], "data-autocomplete": "user" } %>
|
||||||
|
<%= f.input :category, collection: IpBan.categories, include_blank: true, selected: params[:search][:category] %>
|
||||||
|
<%= f.input :is_deleted, label: "Deleted?", collection: ["Yes", "No"], include_blank: true, input_html: { value: params[:search][:is_deleted] } %>
|
||||||
|
<%= f.input :order, collection: [%w[Newest created_at], %w[Oldest created_at_asc], %w[Last\ Seen last_hit_at]], include_blank: true, selected: params[:search][:order] %>
|
||||||
|
<%= f.submit "Search" %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<%= table_for @ip_bans, class: "striped autofit", width: "100%" do |t| %>
|
<%= table_for @ip_bans, class: "striped autofit", width: "100%" do |t| %>
|
||||||
<% t.column "IP Address" do |ip_ban| %>
|
<% t.column "IP Address" do |ip_ban| %>
|
||||||
<%= link_to_ip ip_ban.subnetted_ip %>
|
<%= link_to_ip ip_ban.subnetted_ip %>
|
||||||
|
|||||||
Reference in New Issue
Block a user