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>

View File

@@ -1,6 +1,6 @@
require_relative "boot"
require_relative 'boot'
require "rails/all"
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
@@ -14,7 +14,7 @@ module Plottservice
# Please, add to the `ignore` list any other `lib` subdirectories that do
# not contain `.rb` files, or that should not be reloaded or eager loaded.
# Common ones are `templates`, `generators`, or `middleware`, for example.
config.autoload_lib(ignore: %w(assets tasks))
config.autoload_lib(ignore: %w[assets tasks])
# Configuration for the application, engines, and railties goes here.
#
@@ -23,5 +23,7 @@ module Plottservice
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
# config.i18n.default_locale = :de
end
end

40
config/locales/de.yml Normal file
View File

@@ -0,0 +1,40 @@
# Files in the config/locales directory are used for internationalization and
# are automatically loaded by Rails. If you want to use locales other than
# English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t "hello"
#
# In views, this is aliased to just `t`:
#
# <%= t("hello") %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# To learn more about the API, please read the Rails Internationalization guide
# at https://guides.rubyonrails.org/i18n.html.
#
# Be aware that YAML interprets the following case-insensitive strings as
# booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings
# must be quoted to be interpreted as strings. For example:
#
# en:
# "yes": yup
# enabled: "ON"
de:
activerecord:
attributes:
job:
pdf: "PDF Dokument"
errors:
models:
job:
attributes:
pdf:
blank: "is erforderlich"

View File

@@ -28,4 +28,13 @@
# enabled: "ON"
en:
hello: "Hello world"
activerecord:
attributes:
job:
pdf: "PDF Document"
errors:
models:
job:
attributes:
pdf:
blank: "is required"

View File

@@ -0,0 +1,57 @@
# This migration comes from active_storage (originally 20170806125915)
class CreateActiveStorageTables < ActiveRecord::Migration[7.0]
def change
# Use Active Record's configured type for primary and foreign keys
primary_key_type, foreign_key_type = primary_and_foreign_key_types
create_table :active_storage_blobs, id: primary_key_type do |t|
t.string :key, null: false
t.string :filename, null: false
t.string :content_type
t.text :metadata
t.string :service_name, null: false
t.bigint :byte_size, null: false
t.string :checksum
if connection.supports_datetime_with_precision?
t.datetime :created_at, precision: 6, null: false
else
t.datetime :created_at, null: false
end
t.index [ :key ], unique: true
end
create_table :active_storage_attachments, id: primary_key_type do |t|
t.string :name, null: false
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
t.references :blob, null: false, type: foreign_key_type
if connection.supports_datetime_with_precision?
t.datetime :created_at, precision: 6, null: false
else
t.datetime :created_at, null: false
end
t.index [ :record_type, :record_id, :name, :blob_id ], name: :index_active_storage_attachments_uniqueness, unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
create_table :active_storage_variant_records, id: primary_key_type do |t|
t.belongs_to :blob, null: false, index: false, type: foreign_key_type
t.string :variation_digest, null: false
t.index [ :blob_id, :variation_digest ], name: :index_active_storage_variant_records_uniqueness, unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end
private
def primary_and_foreign_key_types
config = Rails.configuration.generators
setting = config.options[config.orm][:primary_key_type]
primary_key_type = setting || :primary_key
foreign_key_type = setting || :bigint
[primary_key_type, foreign_key_type]
end
end

View File

@@ -0,0 +1,5 @@
class AddPrivacyPolicyAcceptedToJob < ActiveRecord::Migration[7.1]
def change
add_column :jobs, :privacy_policy_accepted, :boolean, default: false
end
end

33
db/schema.rb generated
View File

@@ -10,7 +10,35 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_07_30_214152) do
ActiveRecord::Schema[7.1].define(version: 2024_08_01_205025) do
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
t.bigint "record_id", null: false
t.bigint "blob_id", null: false
t.datetime "created_at", null: false
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end
create_table "active_storage_blobs", force: :cascade do |t|
t.string "key", null: false
t.string "filename", null: false
t.string "content_type"
t.text "metadata"
t.string "service_name", null: false
t.bigint "byte_size", null: false
t.string "checksum"
t.datetime "created_at", null: false
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end
create_table "active_storage_variant_records", force: :cascade do |t|
t.bigint "blob_id", null: false
t.string "variation_digest", null: false
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
end
create_table "jobs", force: :cascade do |t|
t.integer "operator_id"
t.integer "costumer_id"
@@ -33,6 +61,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_07_30_214152) do
t.string "pdf"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "privacy_policy_accepted", default: false
t.index ["costumer_id"], name: "index_jobs_on_costumer_id"
t.index ["operator_id"], name: "index_jobs_on_operator_id"
t.index ["status"], name: "index_jobs_on_status"
@@ -45,6 +74,8 @@ ActiveRecord::Schema[7.1].define(version: 2024_07_30_214152) do
t.datetime "updated_at", null: false
end
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "jobs", "users", column: "costumer_id"
add_foreign_key "jobs", "users", column: "operator_id"
end