Added ransack search function to admin/users index

This commit is contained in:
2024-09-18 14:59:07 +02:00
parent 4bff15cd4e
commit ff1c1017cf
11 changed files with 77 additions and 21 deletions

View File

@@ -7,17 +7,26 @@
<% end %>
</td>
<td class="p-2 py-3">
<%= user.name %>
<%= highlight(user.firstname, [ params.dig(:q, :firstname_or_lastname_or_email_cont).to_s, params.dig(:q, :firstname_cont).to_s ]) %>
<%#= user.firstname %>
</td>
<td class="p-2 py-3">
<%= highlight user.lastname, [params.dig(:q, :firstname_or_lastname_or_email_cont).to_s, params.dig(:q, :lastname_cont).to_s] %>
</td>
<td class="p-2 py-3">
<%= icon bool_icon(user.verified), class: "icon #{user.verified ? "text-green-600" : "text-red-600"}", title: "E-Mail-Adresse verifiziert" %>
<%= user.email %>
<%= highlight user.email, [params.dig(:q, :firstname_or_lastname_or_email_cont).to_s, params.dig(:q, :email_start).to_s] %>
</td>
<td class="p-2 py-3">
<span class="badge block w-28 bg-role-<%= user.role %>-light">
<%= user.jobs_as_costumer.size %>
</span>
</td>
<td class="p-2 py-3">
<span class="badge block w-28 bg-role-<%= user.role %>-light">
<%= l user.created_at.localtime.to_date %>
</span>
</td>
<td class="p-2 py-3">
<span class="badge block w-28 bg-role-<%= user.role %>-light">
<%= user.role %>

View File

@@ -1,19 +1,43 @@
<%= turbo_frame_tag "admin_users" do %>
<div class="w-full">
<% content_for :title, "Current Print Jobs" %>
<div class="flex items-center justify-between py-4">
<h1 class="text-4xl font-bold text-hsrm-gray">Benutzerliste</h1>
<%= link_to "Filter", "#", class: "px-3 py-2 bg-hsrm-red drop-shadow-lg transition-colors hover:bg-hsrm-red-light text-white block font-medium" %>
<div class="w-full">
<% content_for :title, "Current Print Jobs" %>
<h1 class="text-4xl font-bold text-hsrm-gray">Benutzerliste</h1>
<div class="flex items-center justify-between py-4">
<div>
<%= search_form_for @q, data: { turbo_frame: :admin_users, turbo_action: 'advance' }, url: admin_users_path do |f| %>
<%#= f.label :firstname_cont, "Vorname:" %>
<%#= f.search_field :firstname_cont, oninput: 'this.form.requestSubmit();' %>
<%#= f.label :lastname_cont, "Nachname:" %>
<%#= f.search_field :lastname_cont, oninput: 'this.form.requestSubmit();' %>
<%#= f.label :email_start, "E-Mail:" %>
<%#= f.search_field :email_start, oninput: 'this.form.requestSubmit();' %>
<%#= f.label :name_or_email_cont, "Name oder E-Mail:" %>
<%= f.search_field :firstname_or_lastname_or_email_cont, oninput: 'this.form.requestSubmit();' %>
<%= f.label :created_at_gteq, "Erstellt von:" %>
<%= f.date_field :created_at_gteq, onchange: 'this.form.requestSubmit();' %>
<%= f.label :created_at_lteq, "bis:" %>
<%= f.date_field :created_at_lteq, onchange: 'this.form.requestSubmit();' %>
<%= f.label :verified_eq, "E-Mail validiert:" %>
<%= f.select :verified_eq, [true,false], {include_blank: true}, onchange: 'this.form.requestSubmit();' %>
<%= f.label :role_eq, "Rolle:" %>
<%= f.select :role_eq, User::AVAILABLE_ROLES, {include_blank: true}, onchange: 'this.form.requestSubmit();' %>
<%#= f. %>
<%= f.submit "Filter anwenden", class: "py-2 px-3 bg-hsrm-red hover:bg-hsrm-red-light shadow-lg text-white inline-block font-medium cursor-pointer" %>
<% end %>
</div>
<div class="min-w-full overflow-auto shadow-lg">
</div>
<%= turbo_frame_tag "admin_users", data: { turbo_action: 'advance'} do %>
<%== pagy_nav(@pagy) %>
<div class="min-w-full overflow-auto shadow-lg pt-2">
<table class="w-full py-8 table-auto">
<thead class="font-semibold tracking-wide bg-gray-200 border-b-2 border-gray-300 text text-hsrm-gray">
<tr>
<th class="w-1 p-2 py-3 text-center">ID</th>
<th class="w-1 p-2 py-3 text-left">Name</th>
<th class="p-2 py-3 text-center">E-Mail-Adresse</th>
<th class="w-1 p-2 py-3 text-center"># Jobs</th>
<th class="w-1 p-2 py-3 text-center">Rolle</th>
<th class="w-1 p-2 py-3 text-center"><%= sort_link(@q, :id, "ID", ) %></th>
<th class="min-w-24 p-2 py-3 text-left"><%= sort_link(@q, :firstname, "Vorname") %></th>
<th class="min-w-24 p-2 py-3 text-left"><%= sort_link(@q, :lastname, "Nachname") %></th>
<th class="p-2 py-3 text-left"><%= sort_link(@q, :email, "E-Mail-Adresse") %></th>
<th class="w-1 p-2 py-3 text-center"><%= sort_link(@q, :jobs_as_costumer_count, "# Jobs") %></th>
<th class="w-1 p-2 py-3 text-center text-nowrap"><%= sort_link(@q, :created_at, "Registriert am") %></th>
<th class="w-1 p-2 py-3 text-center"><%= sort_link(@q, :role, "Rolle") %></th>
<th class="w-1 p-2 py-3 text-center">Rolle ändern zu</th>
</tr>
</thead>