diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb index e13e36a..e88475b 100644 --- a/app/controllers/jobs_controller.rb +++ b/app/controllers/jobs_controller.rb @@ -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 diff --git a/app/models/job.rb b/app/models/job.rb index af0e992..ae06782 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -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 diff --git a/app/views/jobs/_form.html.erb b/app/views/jobs/_form.html.erb index e559637..87ce68d 100644 --- a/app/views/jobs/_form.html.erb +++ b/app/views/jobs/_form.html.erb @@ -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" %> -
- <%= form.label :intern %> - <%= form.check_box :intern, class: "block mt-2 h-5 w-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" %> -
-
- <%= 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" %> -
-
- <%= 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" %> -
-
- <%= 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" %> -
-
- <%= 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" %> + + + + + + + + + + + + + + + + + + + + + + + + +
+ <%= 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" %>
- <%= 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" %>
<%= 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" %> diff --git a/app/views/jobs/_job_tr.html.erb b/app/views/jobs/_job_tr.html.erb index 8365a2d..76ef75c 100644 --- a/app/views/jobs/_job_tr.html.erb +++ b/app/views/jobs/_job_tr.html.erb @@ -1,7 +1,11 @@ <%= job.id %> <%= job.fullname %> - <%= job.pdf %> + + <% if job.pdf.attached? %> + <%= job.pdf.filename %><%=number_to_human_size job.pdf.blob.byte_size%> + <% end %> + <%= job.number_of_plans_a0 %> <%= job.number_of_plans_a1 %> <%= job.number_of_plans_a2 %> diff --git a/config/application.rb b/config/application.rb index 868b972..645bbf6 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 diff --git a/config/locales/de.yml b/config/locales/de.yml new file mode 100644 index 0000000..75c67a5 --- /dev/null +++ b/config/locales/de.yml @@ -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" diff --git a/config/locales/en.yml b/config/locales/en.yml index 6c349ae..b8cfc7d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -28,4 +28,13 @@ # enabled: "ON" en: - hello: "Hello world" + activerecord: + attributes: + job: + pdf: "PDF Document" + errors: + models: + job: + attributes: + pdf: + blank: "is required" diff --git a/db/migrate/20240801153403_create_active_storage_tables.active_storage.rb b/db/migrate/20240801153403_create_active_storage_tables.active_storage.rb new file mode 100644 index 0000000..e4706aa --- /dev/null +++ b/db/migrate/20240801153403_create_active_storage_tables.active_storage.rb @@ -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 diff --git a/db/migrate/20240801205025_add_privacy_policy_accepted_to_job.rb b/db/migrate/20240801205025_add_privacy_policy_accepted_to_job.rb new file mode 100644 index 0000000..2e270e3 --- /dev/null +++ b/db/migrate/20240801205025_add_privacy_policy_accepted_to_job.rb @@ -0,0 +1,5 @@ +class AddPrivacyPolicyAcceptedToJob < ActiveRecord::Migration[7.1] + def change + add_column :jobs, :privacy_policy_accepted, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index d1b8856..9d862d4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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