Added pdf file upload

This commit is contained in:
2024-08-01 23:15:05 +02:00
parent 69bca2d99e
commit f7a60a90d8
10 changed files with 199 additions and 31 deletions

View File

@@ -67,6 +67,6 @@ class JobsController < ApplicationController
params.require(:job).permit(:operator_id, :costumer_id, :operator_firstname, :operator_lastname,
:costumer_firstname, :costumer_lastname, :paid, :printed_at, :intern,
:cost_center, :number_of_plans_a0, :number_of_plans_a1,
:number_of_plans_a2, :number_of_plans_a3, :costum_qm_plan)
:number_of_plans_a2, :number_of_plans_a3, :costum_qm_plan, :privacy_policy_accepted, :pdf)
end
end

View File

@@ -2,6 +2,10 @@ class Job < ApplicationRecord
belongs_to :operator, class_name: 'User', optional: true
belongs_to :costumer, class_name: 'User', optional: true
has_one_attached :pdf
validates_presence_of :costumer_firstname, :costumer_lastname, :privacy_policy_accepted, :pdf
# NOTE: Multiple status if paing before brinting?
enum status: {
open: 0,
@@ -32,4 +36,16 @@ class Job < ApplicationRecord
def fullname
[costumer_firstname, ' ', costumer_lastname].join
end
# TODO: Implement validation
def acceptable_pdf
return unless pdf.attached?
errors.add(:main_image, 'is too big') unless main_image.blob.byte_size <= 100.megabyte
acceptable_types = ['application/pdf']
return if acceptable_types.include?(main_image.content_type)
errors.add(:main_image, 'must be a PDF')
end
end

View File

@@ -18,32 +18,36 @@
<%= form.label :costumer_lastname %>
<%= form.text_field :costumer_lastname, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div class="my-5">
<%= form.label :intern %>
<%= form.check_box :intern, class: "block mt-2 h-5 w-5" %>
</div>
<div class="my-5">
<%= form.label :cost_center %>
<%= form.text_field :cost_center, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div class="my-5">
<%= form.label :number_of_plans_a0 %>
<%= form.number_field :number_of_plans_a0, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div class="my-5">
<%= form.label :number_of_plans_a1 %>
<%= form.number_field :number_of_plans_a1, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div class="my-5">
<%= form.label :number_of_plans_a2 %>
<%= form.number_field :number_of_plans_a2, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div class="my-5">
<%= form.label :number_of_plans_a3 %>
<%= form.number_field :number_of_plans_a3, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %>
<!-- <div class="my-5"> -->
<!-- <%= form.label :intern %> -->
<!-- <%= form.check_box :intern, class: "block mt-2 h-5 w-5" %> -->
<!-- </div> -->
<!-- <div class="my-5"> -->
<!-- <%= form.label :cost_center %> -->
<!-- <%= form.text_field :cost_center, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %> -->
<!-- </div> -->
<!-- <div class="my-5"> -->
<!-- <%= form.label :number_of_plans_a0 %> -->
<!-- <%= form.number_field :number_of_plans_a0, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %> -->
<!-- </div> -->
<!-- <div class="my-5"> -->
<!-- <%= form.label :number_of_plans_a1 %> -->
<!-- <%= form.number_field :number_of_plans_a1, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %> -->
<!-- </div> -->
<!-- <div class="my-5"> -->
<!-- <%= form.label :number_of_plans_a2 %> -->
<!-- <%= form.number_field :number_of_plans_a2, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %> -->
<!-- </div> -->
<!-- <div class="my-5"> -->
<!-- <%= form.label :number_of_plans_a3 %> -->
<!-- <%= form.number_field :number_of_plans_a3, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %> -->
<!-- </div> -->
<div>
<%= form.label :pdf, "Plan auswählen (PDF-Format)" %>
<%= form.file_field :pdf, accept: "application/pdf", class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div>
<%= form.label :accept_privacy %> <%= form.check_box :accept_privacy, class: "block mt-2 h-5 w-5" %>
<%= form.check_box :privacy_policy_accepted, class: "mt-2 h-5 w-5" %> <%= form.label :privacy_policy_accepted, "Datenschutzerklärung akzeptiert", class: "p-2" %>
</div>
<div class="inline">
<%= form.submit "Plottauftrag abschicken", class: "py-2 px-3 bg-hsrm-red hover:bg-hsrm-red-light shadow-lg text-white inline-block font-medium cursor-pointer" %>

View File

@@ -1,7 +1,11 @@
<tr id="<%= dom_id job %>" class="<%= cycle('bg-gray-50','bg-gray-200') %> ">
<td class="p-3 text-sm text-hsrm-gray"> <%= job.id %> </td>
<td class="p-3 text-sm text-hsrm-gray"> <%= job.fullname %> </td>
<td class="p-3 text-sm text-hsrm-gray"> <%= job.pdf %> </td>
<td class="p-3 text-sm text-hsrm-gray">
<% if job.pdf.attached? %>
<%= job.pdf.filename %><span class="p-1.5 bg-gray-300 font-medium rounded-lg shadow-lg ml-2"><%=number_to_human_size job.pdf.blob.byte_size%></span>
<% end %>
</td>
<td class="p-3 text-sm text-center text-hsrm-gray"><span class="p-1.5 bg-gray-300 font-medium rounded-lg"> <%= job.number_of_plans_a0 %></span> </td>
<td class="p-3 text-sm text-center text-hsrm-gray"><span class="p-1.5 bg-gray-300 font-medium rounded-lg"><%= job.number_of_plans_a1 %></span> </td>
<td class="p-3 text-sm text-center text-hsrm-gray"><span class="p-1.5 bg-gray-300 font-medium rounded-lg"><%= job.number_of_plans_a2 %> </span></td>