From: Tom Hughes Date: Sat, 15 Feb 2025 14:21:35 +0000 (+0000) Subject: Add search form to the top of the user list view X-Git-Tag: live~164^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/4ea868ace783da734ada2e9d7f8bc2453a142829 Add search form to the top of the user list view --- diff --git a/app/controllers/users/lists_controller.rb b/app/controllers/users/lists_controller.rb index a5cd7203d..d0bb64888 100644 --- a/app/controllers/users/lists_controller.rb +++ b/app/controllers/users/lists_controller.rb @@ -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 diff --git a/app/views/users/lists/_page.html.erb b/app/views/users/lists/_page.html.erb index d06516e06..2c06f0237 100644 --- a/app/views/users/lists/_page.html.erb +++ b/app/views/users/lists/_page.html.erb @@ -1,48 +1,52 @@ - <%= form_tag @params, :method => :put do %> -
-
- <%= render "shared/pagination", - :translation_scope => "shared.pagination.users", - :newer_id => @newer_users_id, - :older_id => @older_users_id %> -
-
- <%= t ".found_users", :count => @users_count %> -
-
+ <% unless @users.empty? %> + <%= form_tag @params, :method => :put do %> +
+
+ <%= render "shared/pagination", + :translation_scope => "shared.pagination.users", + :newer_id => @newer_users_id, + :older_id => @older_users_id %> +
+
+ <%= t ".found_users", :count => @users_count %> +
+
- <%= hidden_field_tag :status, params[:status] if params[:status] %> - <%= hidden_field_tag :ip, params[:ip] if params[:ip] %> - <%= hidden_field_tag :page, params[:page] if params[:page] %> - - - - - - - - <%= render :partial => "user", :collection => @users %> -
- - <%= check_box_tag "user_all", "1", false %> -
+ <%= hidden_field_tag :status, params[:status] if params[:status] %> + <%= hidden_field_tag :ip, params[:ip] if params[:ip] %> + <%= hidden_field_tag :page, params[:page] if params[:page] %> + + + + + + + + <%= render :partial => "user", :collection => @users %> +
+ + <%= check_box_tag "user_all", "1", false %> +
-
-
- <%= render "shared/pagination", - :translation_scope => "shared.pagination.users", - :newer_id => @newer_users_id, - :older_id => @older_users_id %> -
-
- <%= t ".found_users", :count => @users_count %> -
-
+
+
+ <%= render "shared/pagination", + :translation_scope => "shared.pagination.users", + :newer_id => @newer_users_id, + :older_id => @older_users_id %> +
+
+ <%= t ".found_users", :count => @users_count %> +
+
-
- <%= submit_tag t(".confirm"), :name => "confirm", :class => "btn btn-primary" %> - <%= submit_tag t(".hide"), :name => "hide", :class => "btn btn-primary" %> -
- <% end %> +
+ <%= submit_tag t(".confirm"), :name => "confirm", :class => "btn btn-primary" %> + <%= submit_tag t(".hide"), :name => "hide", :class => "btn btn-primary" %> +
+ <% end %> + <% else -%> +

<%= t ".empty" %>

+ <% end -%> diff --git a/app/views/users/lists/show.html.erb b/app/views/users/lists/show.html.erb index abf0092ce..dd037c7af 100644 --- a/app/views/users/lists/show.html.erb +++ b/app/views/users/lists/show.html.erb @@ -8,8 +8,26 @@

<%= t(".heading") %>

<% end %> -<% unless @users.empty? %> - <%= render :partial => "page" %> -<% else %> -

<%= t ".empty" %>

-<% end %> +<%= form_tag(users_list_path, :method => :get, :data => { "turbo" => true, "turbo-frame" => "pagination", "turbo-action" => "advance" }) do %> +
+
+ <%= 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" %> +
+
+ <%= text_field_tag :ip, + params[:ip], + :placeholder => t(".ip_address"), + :autocomplete => "on", + :class => "form-control" %> +
+
+ <%= submit_tag t(".search"), :name => nil, :class => "btn btn-primary" %> +
+
+<% end -%> + +<%= render :partial => "page" %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 5571a4232..03458b00d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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}"