Added sort function and pagy calendar to admin/jobs index

This commit is contained in:
2024-09-23 15:17:37 +02:00
parent 084613bbf5
commit 82f91c7111
5 changed files with 74 additions and 40 deletions

View File

@@ -2,7 +2,7 @@ class Admin::DashboardsController < ApplicationController
before_action :authorize!
def show
@user = User.all
@jobs = Job.currently_working_on
@jobs = Job.all
end
def authorize!

View File

@@ -5,6 +5,23 @@ class Admin::JobsController < ApplicationController
def index
@q = Job.ransack(params[:q])
@q.sorts = "id asc" if @q.sorts.empty?
@pagy, @records = pagy(@q.result(distinct: true), limit: 20)
# @pagy, @records = pagy(@q.result(distinct: true), limit: 20)
@calendar, @pagy, @records = pagy_calendar(@q, year: {}, month: {}, pagy: {})
end
def pagy_calendar_period(collection)
if collection.is_a? Ransack::Search
collection.result.minmax.map(&:created_at) if collection.result
else
collection.minmax.map(&:created_at) if collection
end
end
def pagy_calendar_filter(collection, from, to)
if collection.is_a? Ransack::Search
collection.result.where(created_at: from...to)
else
collection.where(created_at: from...to)
end
end
end

View File

@@ -17,7 +17,7 @@
<% end %>
<%= link_to admin_users_path() do %>
<div class="p-4 shadow bg-gray-50">
<h2 class="text-xl">Tutoren:</h2>
<h2 class="text-xl">Operatoren:</h2>
<p class="size-28"><%= @user.operator.size %></p>
</div>
<% end %>
@@ -29,10 +29,15 @@
<% end %>
</div>
<div class="flex space-x-2">
<h2>Aktueller Monat</h2>
<%= link_to admin_jobs_path() do %>
<%= link_to operator_jobs_path() do %>
<div class="p-4 shadow bg-gray-50">
<h2 class="text-xl">aktuelle Druckaufträge:</h2>
<p class="size-28"><%= @jobs.where(status: %i[open printing pickup]).size %></p>
</div>
<% end %>
<%= link_to admin_jobs_path() do %>
<div class="p-4 shadow bg-gray-50">
<h2 class="text-xl">Alle Druckaufträge:</h2>
<p class="size-28"><%= @jobs.size %></p>
</div>
<% end %>

View File

@@ -1,37 +1,49 @@
<%= turbo_frame_tag "admin_jobs" do %>
<% content_for :title, "Benutzerliste" %>
<h1 class="font-bold text-4xl py-4 text-hsrm-gray">Alle Druckaufträge</h1>
<div class="flex justify-between items-center">
<div class="flex items-center justify-between py-4">
<%= search_form_for @q, data: { turbo_frame: :admin_jobs, turbo_action: 'advance' }, url: admin_jobs_path do |f| %>
<%= f.search_field :costumer_firstname_or_costumer_lastname_or_pdf_blob_filename_cont, placeholder: "Suchen", oninput: 'this.form.requestSubmit();' %>
<%= f.label :status_eq, "Status:" %>
<%= f.select :status_eq, Job.statuses.keys, {include_blank: "alle"}, 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>
<%= turbo_frame_tag "admin_jobs", data: { turbo_action: 'advance'} do %>
<div>
<h1 class="font-bold text-4xl py-4 text-hsrm-gray">Alle Druckaufträge</h1>
<div class="flex justify-between items-center">
<%== pagy_nav(@pagy) %>
<%== pagy_info(@pagy, item_name: "Users") %>
</div>
<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 text-nowrap"><%= sort_link(@q, :id, "ID", ) %></th>
<th class="min-w-24 p-2 py-3 text-left"><%= sort_link(@q, :costumer_firstname, "Vorname") %></th>
<th class="min-w-24 p-2 py-3 text-left"><%= sort_link(@q, :costumer_lastname, "Nachname") %></th>
<th class="p-2 py-3 text-left"><%= sort_link(@q, :pdf_blob_filename, "PDF") %></th>
<th class="w-1 p-1 py-3 text-left text-nowrap"><%= sort_link(@q, :number_of_plans_a0, "A0") %></th>
<th class="w-1 p-1 py-3 text-left text-nowrap"><%= sort_link(@q, :number_of_plans_a1, "A1") %></th>
<th class="w-1 p-1 py-3 text-left text-nowrap"><%= sort_link(@q, :number_of_plans_a2, "A2") %></th>
<th class="w-1 p-1 py-3 text-left text-nowrap"><%= sort_link(@q, :number_of_plans_a3, "A3") %></th>
<th class="w-1 p-2 py-3 text-center text-nowrap"><%= sort_link(@q, :costum_qm_plan, "no DIN") %></th>
<th class="w-1 p-2 py-3 text-center"><%= sort_link(@q, :cost, "Kosten") %></th>
<th class="w-1 p-2 py-3 text-center text-nowrap"><%= sort_link(@q, :created_at, "Erstellt am") %></th>
<th class="w-1 p-2 py-3 text-center text-nowrap"><%= sort_link(@q, :created_at, "Bezahlt am") %></th>
<th class="w-1 p-2 py-3 text-center"><%= sort_link(@q, :status, "Status") %></th>
</tr>
</thead>
<tbody id='jobs' class="divide-y divivde-gray-300">
<%= render partial: "job_tr", collection: @records, as: :job, locals: { no_actions: true } %>
</tbody>
</table>
</div>
<div class="flex justify-between items-center">
<%== pagy_nav(@pagy) %>
<%== pagy_info(@pagy, item_name: "Users") %>
</div>
<%== pagy_nav(@calendar[:year]) %>
<%== pagy_nav(@calendar[:month]) %>
<%== pagy_nav(@pagy) %>
<%== pagy_info(@pagy, item_name: "Users") %>
</div>
<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 text-nowrap"><%= sort_link(@q, :id, "ID", ) %></th>
<th class="min-w-24 p-2 py-3 text-left"><%= sort_link(@q, :costumer_firstname, "Vorname") %></th>
<th class="min-w-24 p-2 py-3 text-left"><%= sort_link(@q, :costumer_lastname, "Nachname") %></th>
<th class="p-2 py-3 text-left"><%= sort_link(@q, :pdf_blob_filename, "PDF") %></th>
<th class="w-1 p-1 py-3 text-left text-nowrap"><%= sort_link(@q, :number_of_plans_a0, "A0") %></th>
<th class="w-1 p-1 py-3 text-left text-nowrap"><%= sort_link(@q, :number_of_plans_a1, "A1") %></th>
<th class="w-1 p-1 py-3 text-left text-nowrap"><%= sort_link(@q, :number_of_plans_a2, "A2") %></th>
<th class="w-1 p-1 py-3 text-left text-nowrap"><%= sort_link(@q, :number_of_plans_a3, "A3") %></th>
<th class="w-1 p-2 py-3 text-center text-nowrap"><%= sort_link(@q, :costum_qm_plan, "no DIN") %></th>
<th class="w-1 p-2 py-3 text-center"><%= sort_link(@q, :cost, "Kosten") %></th>
<th class="w-1 p-2 py-3 text-center text-nowrap"><%= sort_link(@q, :created_at, "Erstellt am") %></th>
<th class="w-1 p-2 py-3 text-center text-nowrap"><%= sort_link(@q, :created_at, "Bezahlt am") %></th>
<th class="w-1 p-2 py-3 text-center"><%= sort_link(@q, :status, "Status") %></th>
</tr>
</thead>
<tbody id='jobs' class="divide-y divivde-gray-300">
<%= render partial: "job_tr", collection: @records, as: :job, locals: { no_actions: true } %>
</tbody>
</table>
</div>
<div class="flex justify-between items-center">
<%== pagy_nav(@pagy) %>
<%== pagy_info(@pagy, item_name: "Users") %>
</div>
<% end %>

View File

@@ -41,7 +41,7 @@
# Calendar extra: Add pagination filtering by calendar time unit (year, quarter, month, week, day)
# See https://ddnexus.github.io/pagy/docs/extras/calendar
# require 'pagy/extras/calendar'
require "pagy/extras/calendar"
# Default for each calendar unit class in IRB:
# >> Pagy::Calendar::Year::DEFAULT
# >> Pagy::Calendar::Quarter::DEFAULT