Added sort function and pagy calendar to admin/jobs index
This commit is contained in:
@@ -2,7 +2,7 @@ class Admin::DashboardsController < ApplicationController
|
|||||||
before_action :authorize!
|
before_action :authorize!
|
||||||
def show
|
def show
|
||||||
@user = User.all
|
@user = User.all
|
||||||
@jobs = Job.currently_working_on
|
@jobs = Job.all
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorize!
|
def authorize!
|
||||||
|
|||||||
@@ -5,6 +5,23 @@ class Admin::JobsController < ApplicationController
|
|||||||
def index
|
def index
|
||||||
@q = Job.ransack(params[:q])
|
@q = Job.ransack(params[:q])
|
||||||
@q.sorts = "id asc" if @q.sorts.empty?
|
@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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<%= link_to admin_users_path() do %>
|
<%= link_to admin_users_path() do %>
|
||||||
<div class="p-4 shadow bg-gray-50">
|
<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>
|
<p class="size-28"><%= @user.operator.size %></p>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -29,10 +29,15 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<h2>Aktueller Monat</h2>
|
<%= link_to operator_jobs_path() do %>
|
||||||
<%= link_to admin_jobs_path() do %>
|
|
||||||
<div class="p-4 shadow bg-gray-50">
|
<div class="p-4 shadow bg-gray-50">
|
||||||
<h2 class="text-xl">aktuelle Druckaufträge:</h2>
|
<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>
|
<p class="size-28"><%= @jobs.size %></p>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -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>
|
<div>
|
||||||
<h1 class="font-bold text-4xl py-4 text-hsrm-gray">Alle Druckaufträge</h1>
|
<%== pagy_nav(@calendar[:year]) %>
|
||||||
<div class="flex justify-between items-center">
|
<%== pagy_nav(@calendar[:month]) %>
|
||||||
<%== pagy_nav(@pagy) %>
|
<%== pagy_nav(@pagy) %>
|
||||||
<%== pagy_info(@pagy, item_name: "Users") %>
|
<%== pagy_info(@pagy, item_name: "Users") %>
|
||||||
</div>
|
</div>
|
||||||
<div class="min-w-full overflow-auto shadow-lg pt-2">
|
<div class="min-w-full overflow-auto shadow-lg pt-2">
|
||||||
<table class="w-full py-8 table-auto">
|
<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">
|
<thead class="font-semibold tracking-wide bg-gray-200 border-b-2 border-gray-300 text text-hsrm-gray">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-1 p-2 py-3 text-center text-nowrap"><%= sort_link(@q, :id, "ID", ) %></th>
|
<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_firstname, "Vorname") %></th>
|
||||||
<th class="min-w-24 p-2 py-3 text-left"><%= sort_link(@q, :costumer_lastname, "Nachname") %></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="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_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_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_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-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 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"><%= 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, "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 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>
|
<th class="w-1 p-2 py-3 text-center"><%= sort_link(@q, :status, "Status") %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id='jobs' class="divide-y divivde-gray-300">
|
<tbody id='jobs' class="divide-y divivde-gray-300">
|
||||||
<%= render partial: "job_tr", collection: @records, as: :job, locals: { no_actions: true } %>
|
<%= render partial: "job_tr", collection: @records, as: :job, locals: { no_actions: true } %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
<%== pagy_nav(@pagy) %>
|
<%== pagy_nav(@pagy) %>
|
||||||
<%== pagy_info(@pagy, item_name: "Users") %>
|
<%== pagy_info(@pagy, item_name: "Users") %>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
# Calendar extra: Add pagination filtering by calendar time unit (year, quarter, month, week, day)
|
# Calendar extra: Add pagination filtering by calendar time unit (year, quarter, month, week, day)
|
||||||
# See https://ddnexus.github.io/pagy/docs/extras/calendar
|
# 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:
|
# Default for each calendar unit class in IRB:
|
||||||
# >> Pagy::Calendar::Year::DEFAULT
|
# >> Pagy::Calendar::Year::DEFAULT
|
||||||
# >> Pagy::Calendar::Quarter::DEFAULT
|
# >> Pagy::Calendar::Quarter::DEFAULT
|
||||||
|
|||||||
Reference in New Issue
Block a user