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,7 +1,20 @@
|
|||||||
<%= turbo_frame_tag "admin_jobs" do %>
|
<% content_for :title, "Benutzerliste" %>
|
||||||
<div>
|
|
||||||
<h1 class="font-bold text-4xl py-4 text-hsrm-gray">Alle Druckaufträge</h1>
|
<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 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>
|
||||||
|
<%== pagy_nav(@calendar[:year]) %>
|
||||||
|
<%== pagy_nav(@calendar[:month]) %>
|
||||||
<%== pagy_nav(@pagy) %>
|
<%== pagy_nav(@pagy) %>
|
||||||
<%== pagy_info(@pagy, item_name: "Users") %>
|
<%== pagy_info(@pagy, item_name: "Users") %>
|
||||||
</div>
|
</div>
|
||||||
@@ -33,5 +46,4 @@
|
|||||||
<%== 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