Added sort function in admin/jobs index
This commit is contained in:
@@ -3,7 +3,8 @@ class Admin::JobsController < ApplicationController
|
|||||||
|
|
||||||
before_action :authorize!
|
before_action :authorize!
|
||||||
def index
|
def index
|
||||||
@jobs = Job.all
|
@q = Job.ransack(params[:q])
|
||||||
@pagy, @records = pagy(@jobs, limit: 20)
|
@q.sorts = "id asc" if @q.sorts.empty?
|
||||||
|
@pagy, @records = pagy(@q.result(distinct: true), limit: 20)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -122,6 +122,14 @@ class Job < ApplicationRecord
|
|||||||
end
|
end
|
||||||
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
|
private
|
||||||
|
|
||||||
def printed_pages_changes?
|
def printed_pages_changes?
|
||||||
|
|||||||
@@ -6,22 +6,21 @@
|
|||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td class="p-2 py-3 text-center">
|
<td class="p-2 py-3">
|
||||||
<% if job.pdf.attached? && job.pdf.previewable? %>
|
<%= link_to job.costumer_firstname, admin_user_path(job.costumer), target: "_top" %>
|
||||||
<%= link_to job.pdf, target: "_blank", target: "_top" do %>
|
|
||||||
<span class="badge badge-hover">
|
|
||||||
<%= icon("eye", class:"icon") %>
|
|
||||||
</span>
|
|
||||||
<% end %>
|
|
||||||
<% end %>
|
|
||||||
</td>
|
</td>
|
||||||
<td class="p-2 py-3">
|
<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>
|
||||||
<td class="p-2 py-3">
|
<td class="p-2 py-3">
|
||||||
<% if job.pdf.attached? %>
|
<% if job.pdf.attached? %>
|
||||||
<%#= link_to job.pdf.filename, rails_blob_path(job.pdf, disposition: "attachment") %>
|
<%#= 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" %>
|
<%= 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 %>
|
<%= link_to job.pdf, download:true, target: "_top" do %>
|
||||||
<span class="badge badge-hover">
|
<span class="badge badge-hover">
|
||||||
<%= icon("document-arrow-down", class: "text-hsrm-gray size-6 inline", title: "Download") %>
|
<%= icon("document-arrow-down", class: "text-hsrm-gray size-6 inline", title: "Download") %>
|
||||||
@@ -32,20 +31,20 @@
|
|||||||
</td>
|
</td>
|
||||||
<% Job::AVAILABLE_PAGE_FORMATS.each do |din| %>
|
<% Job::AVAILABLE_PAGE_FORMATS.each do |din| %>
|
||||||
<td class="p-1 py-3">
|
<td class="p-1 py-3">
|
||||||
<span class="badge">
|
|
||||||
<%= job.public_send("number_of_plans_#{din}") if job.respond_to? "number_of_plans_#{din}" %>
|
<%= job.public_send("number_of_plans_#{din}") if job.respond_to? "number_of_plans_#{din}" %>
|
||||||
</span>
|
|
||||||
</td>
|
</td>
|
||||||
<% end %>
|
<% end %>
|
||||||
<td class="p-2 py-3 text-right">
|
<td class="p-2 py-3 text-right">
|
||||||
<span class="badge">
|
|
||||||
<%= number_with_delimiter job.costum_qm_plan.round(2) %> m²
|
<%= number_with_delimiter job.costum_qm_plan.round(2) %> m²
|
||||||
</span>
|
|
||||||
</td>
|
</td>
|
||||||
<td class="w-24 p-2 py-3 text-right">
|
<td class="w-24 p-2 py-3 text-right">
|
||||||
<span class="badge">
|
|
||||||
<%= number_to_currency job.cost, locale: :de %>
|
<%= number_to_currency job.cost, locale: :de %>
|
||||||
</span>
|
</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>
|
||||||
<td class="p-2 py-3">
|
<td class="p-2 py-3">
|
||||||
<span class="badge badge-status text-status-<%= job.status.to_sym %> bg-status-<%= job.status %>-light">
|
<span class="badge badge-status text-status-<%= job.status.to_sym %> bg-status-<%= job.status %>-light">
|
||||||
|
|||||||
@@ -1,22 +1,27 @@
|
|||||||
<%= turbo_frame_tag "admin_jobs" do %>
|
<%= turbo_frame_tag "admin_jobs" do %>
|
||||||
<div>
|
<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">
|
||||||
<%== pagy_nav(@pagy) %>
|
<%== pagy_nav(@pagy) %>
|
||||||
|
<%== pagy_info(@pagy, item_name: "Users") %>
|
||||||
|
</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"> ID </th>
|
<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"> Vorschau </th>
|
<th class="min-w-24 p-2 py-3 text-left"><%= sort_link(@q, :costumer_firstname, "Vorname") %></th>
|
||||||
<th class="w-1 p-2 py-3 text-left"> Auftraggeber </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"> 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"> 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"> 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"> 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"> 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"> 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"> 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"> Status </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>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id='jobs' class="divide-y divivde-gray-300">
|
<tbody id='jobs' class="divide-y divivde-gray-300">
|
||||||
@@ -24,6 +29,9 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex justify-between items-center">
|
||||||
<%== pagy_nav(@pagy) %>
|
<%== pagy_nav(@pagy) %>
|
||||||
|
<%== pagy_info(@pagy, item_name: "Users") %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
5
config/initializers/active_storage.rb
Normal file
5
config/initializers/active_storage.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
ActiveSupport.on_load(:active_storage_blob) do
|
||||||
|
def self.ransackable_attributes(auth_object = nil)
|
||||||
|
%w[filename]
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user