Add search form to the top of the user list view

This commit is contained in:
Tom Hughes 2025-02-15 14:21:35 +00:00
parent 30fe6c5b86
commit 4ea868ace7
4 changed files with 82 additions and 51 deletions

View file

@ -16,8 +16,8 @@ module Users
@params = params.permit(:status, :ip, :before, :after)
users = User.all
users = users.where(:status => @params[:status]) if @params[:status]
users = users.where(:creation_address => @params[:ip]) if @params[:ip]
users = users.where(:status => @params[:status]) if @params[:status].present?
users = users.where(:creation_address => @params[:ip]) if @params[:ip].present?
@users_count = users.limit(501).count
@users_count = I18n.t("count.at_least_pattern", :count => 500) if @users_count > 500

View file

@ -1,4 +1,5 @@
<turbo-frame id="pagination" target="_top" data-turbo="false">
<% unless @users.empty? %>
<%= form_tag @params, :method => :put do %>
<div class="row">
<div class="col">
@ -45,4 +46,7 @@
<%= submit_tag t(".hide"), :name => "hide", :class => "btn btn-primary" %>
</div>
<% end %>
<% else -%>
<p><%= t ".empty" %></p>
<% end -%>
</turbo-frame>

View file

@ -8,8 +8,26 @@
<h1><%= t(".heading") %></h1>
<% end %>
<% unless @users.empty? %>
<%= render :partial => "page" %>
<% else %>
<p><%= t ".empty" %></p>
<% end %>
<%= form_tag(users_list_path, :method => :get, :data => { "turbo" => true, "turbo-frame" => "pagination", "turbo-action" => "advance" }) do %>
<div class="row gx-1">
<div class="mb-3 col-md-auto">
<%= select_tag :status,
options_for_select(User.aasm.states.map(&:name).map { |state| [t(".states.#{state}"), state] }, params[:status]),
:include_blank => t(".select_status"),
:data => { :behavior => "category_dropdown" },
:class => "form-select" %>
</div>
<div class="mb-3 col-md">
<%= text_field_tag :ip,
params[:ip],
:placeholder => t(".ip_address"),
:autocomplete => "on",
:class => "form-control" %>
</div>
<div class="mb-3 col-md-auto">
<%= submit_tag t(".search"), :name => nil, :class => "btn btn-primary" %>
</div>
</div>
<% end -%>
<%= render :partial => "page" %>

View file

@ -2882,13 +2882,22 @@ en:
show:
title: Users
heading: Users
empty: No matching users found
select_status: Select Status
states:
pending: Pending
active: Active
confirmed: Confirmed
suspended: Suspended
deleted: Deleted
ip_address: IP Address
search: Search
page:
found_users:
one: "%{count} user found"
other: "%{count} users found"
confirm: Confirm Selected Users
hide: Hide Selected Users
empty: No matching users found
user:
summary_html: "%{name} created from %{ip_address} on %{date}"
summary_no_ip_html: "%{name} created on %{date}"