Added sort function in admin/jobs index

This commit is contained in:
2024-09-23 10:16:16 +02:00
parent feb37a8a6b
commit 0f877456a4
5 changed files with 54 additions and 33 deletions

View File

@@ -3,7 +3,8 @@ class Admin::JobsController < ApplicationController
before_action :authorize!
def index
@jobs = Job.all
@pagy, @records = pagy(@jobs, limit: 20)
@q = Job.ransack(params[:q])
@q.sorts = "id asc" if @q.sorts.empty?
@pagy, @records = pagy(@q.result(distinct: true), limit: 20)
end
end

View File

@@ -122,6 +122,14 @@ class Job < ApplicationRecord
end
end
def self.ransackable_attributes(auth_object = nil)
[ "created_at", "id", "costumer_firstname", "costumer_lastname", "pdf.", "number_of_plans_a0", "number_of_plans_a1", "number_of_plans_a2", "number_of_plans_a3", "costum_qm_plan", "cost", "status" ]
end
def self.ransackable_associations(auth_object = nil)
[ "pdf_blob" ]
end
private
def printed_pages_changes?

View File

@@ -6,22 +6,21 @@
</span>
<% end %>
</td>
<td class="p-2 py-3 text-center">
<% if job.pdf.attached? && job.pdf.previewable? %>
<%= link_to job.pdf, target: "_blank", target: "_top" do %>
<span class="badge badge-hover">
<%= icon("eye", class:"icon") %>
</span>
<% end %>
<% end %>
<td class="p-2 py-3">
<%= link_to job.costumer_firstname, admin_user_path(job.costumer), target: "_top" %>
</td>
<td class="p-2 py-3">
<%= link_to job.costumer_fullname, admin_user_path(job.costumer), target: "_top" %>
<%= link_to job.costumer_lastname, admin_user_path(job.costumer), target: "_top" %>
</td>
<td class="p-2 py-3">
<% if job.pdf.attached? %>
<%#= link_to job.pdf.filename, rails_blob_path(job.pdf, disposition: "attachment") %>
<%= link_to truncate(job.pdf.filename.to_s, length: 45), job.pdf, download:true, target: "_top" %>
<% if job.pdf.previewable? %>
<%= link_to job.pdf, target: "_blank", target: "_top" do %>
<span class="badge badge-hover mr-1"><%= icon("eye", class:"icon text-hsrm-gray size-6 inline") %></span>
<% end %>
<% end %>
<%= link_to job.pdf, download:true, target: "_top" do %>
<span class="badge badge-hover">
<%= icon("document-arrow-down", class: "text-hsrm-gray size-6 inline", title: "Download") %>
@@ -32,20 +31,20 @@
</td>
<% Job::AVAILABLE_PAGE_FORMATS.each do |din| %>
<td class="p-1 py-3">
<span class="badge">
<%= job.public_send("number_of_plans_#{din}") if job.respond_to? "number_of_plans_#{din}" %>
</span>
<%= job.public_send("number_of_plans_#{din}") if job.respond_to? "number_of_plans_#{din}" %>
</td>
<% end %>
<td class="p-2 py-3 text-right">
<span class="badge">
<%= number_with_delimiter job.costum_qm_plan.round(2) %> m²
</span>
<%= number_with_delimiter job.costum_qm_plan.round(2) %> m²
</td>
<td class="w-24 p-2 py-3 text-right">
<span class="badge">
<%= number_to_currency job.cost, locale: :de %>
</span>
<%= number_to_currency job.cost, locale: :de %>
</td>
<td class="p-2 py-3 text-center">
<%= l job.created_at.localtime.to_date %>
</td>
<td class="p-2 py-3 text-center">
<%= l job.paid_at.localtime.to_date if job.paid_at %>
</td>
<td class="p-2 py-3">
<span class="badge badge-status text-status-<%= job.status.to_sym %> bg-status-<%= job.status %>-light">

View File

@@ -1,22 +1,27 @@
<%= turbo_frame_tag "admin_jobs" do %>
<div>
<h1 class="font-bold text-4xl py-4 text-hsrm-gray">Alle Druckaufträge</h1>
<%== pagy_nav(@pagy) %>
<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"> ID </th>
<th class="w-1 p-2 py-3 text-center"> Vorschau </th>
<th class="w-1 p-2 py-3 text-left"> Auftraggeber </th>
<th class="p-2 py-3 text-left"> PDF </th>
<th class="w-1 p-1 py-3 text-left"> A0 </th>
<th class="w-1 p-1 py-3 text-left"> A1 </th>
<th class="w-1 p-1 py-3 text-left"> A2 </th>
<th class="w-1 p-1 py-3 text-left"> A3 </th>
<th class="w-1 p-2 py-3 text-center text-nowrap"> no DIN </th>
<th class="w-1 p-2 py-3 text-center"> Kosten </th>
<th class="w-1 p-2 py-3 text-center"> Status </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_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">
@@ -24,6 +29,9 @@
</tbody>
</table>
</div>
<%== pagy_nav(@pagy) %>
<div class="flex justify-between items-center">
<%== pagy_nav(@pagy) %>
<%== pagy_info(@pagy, item_name: "Users") %>
</div>
</div>
<% end %>

View File

@@ -0,0 +1,5 @@
ActiveSupport.on_load(:active_storage_blob) do
def self.ransackable_attributes(auth_object = nil)
%w[filename]
end
end