]> git.openstreetmap.org Git - rails.git/commitdiff
Add search form to the top of the user list view
authorTom Hughes <tom@compton.nu>
Sat, 15 Feb 2025 14:21:35 +0000 (14:21 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 15 Feb 2025 14:37:28 +0000 (14:37 +0000)
app/controllers/users/lists_controller.rb
app/views/users/lists/_page.html.erb
app/views/users/lists/show.html.erb
config/locales/en.yml

index a5cd7203d715b4bd1629f5c942152d2de0ec84eb..d0bb648889c21325d1cf645952d00ac00a9cb84b 100644 (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
index d06516e06999009428ccc7d437898a8781fc8a9f..2c06f02375230e55d17d930f3ca7bf617cc1a16d 100644 (file)
@@ -1,48 +1,52 @@
 <turbo-frame id="pagination" target="_top" data-turbo="false">
-  <%= form_tag @params, :method => :put do %>
-    <div class="row">
-      <div class="col">
-        <%= render "shared/pagination",
-                   :translation_scope => "shared.pagination.users",
-                   :newer_id => @newer_users_id,
-                   :older_id => @older_users_id %>
-      </div>
-      <div class="col col-auto">
-        <%= t ".found_users", :count => @users_count %>
-      </div>
-    <div>
+  <% unless @users.empty? %>
+    <%= form_tag @params, :method => :put do %>
+      <div class="row">
+        <div class="col">
+          <%= render "shared/pagination",
+                     :translation_scope => "shared.pagination.users",
+                     :newer_id => @newer_users_id,
+                     :older_id => @older_users_id %>
+        </div>
+        <div class="col col-auto">
+          <%= t ".found_users", :count => @users_count %>
+        </div>
+      <div>
 
-    <%= 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] %>
-    <table id="user_list" class="table table-borderless table-striped">
-      <thead>
-        <tr>
-          <td colspan="2">
-          </td>
-          <td>
-            <%= check_box_tag "user_all", "1", false %>
-          </td>
-        </tr>
-      </thead>
-      <%= render :partial => "user", :collection => @users %>
-    </table>
+      <%= 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] %>
+      <table id="user_list" class="table table-borderless table-striped">
+        <thead>
+          <tr>
+            <td colspan="2">
+            </td>
+            <td>
+              <%= check_box_tag "user_all", "1", false %>
+            </td>
+          </tr>
+        </thead>
+        <%= render :partial => "user", :collection => @users %>
+      </table>
 
-    <div class="row">
-      <div class="col">
-        <%= render "shared/pagination",
-                   :translation_scope => "shared.pagination.users",
-                   :newer_id => @newer_users_id,
-                   :older_id => @older_users_id %>
-      </div>
-      <div class="col col-auto">
-        <%= t ".found_users", :count => @users_count %>
-      </div>
-    <div>
+      <div class="row">
+        <div class="col">
+          <%= render "shared/pagination",
+                     :translation_scope => "shared.pagination.users",
+                     :newer_id => @newer_users_id,
+                     :older_id => @older_users_id %>
+        </div>
+        <div class="col col-auto">
+          <%= t ".found_users", :count => @users_count %>
+        </div>
+      <div>
 
-    <div>
-      <%= submit_tag t(".confirm"), :name => "confirm", :class => "btn btn-primary" %>
-      <%= submit_tag t(".hide"), :name => "hide", :class => "btn btn-primary" %>
-    </div>
-  <% end %>
+      <div>
+        <%= submit_tag t(".confirm"), :name => "confirm", :class => "btn btn-primary" %>
+        <%= submit_tag t(".hide"), :name => "hide", :class => "btn btn-primary" %>
+      </div>
+    <% end %>
+  <% else -%>
+    <p><%= t ".empty" %></p>
+  <% end -%>
 </turbo-frame>
index abf0092cebb5c8c695c7369406719b85e64e05c8..dd037c7af6c3a13dee647bf9ba3e077ca658be7e 100644 (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" %>
index 5571a4232228b90528646e785331395183fcc286..03458b00d566626d6e0c25b894de1fbeabbce70c 100644 (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}"