Added job attributes, fixed seeds.rb
Added some attributes like status_changed_at. Refactored migration files. Changes to the migration file makes it necessary to reimport the database: db:drop, db:create, db:migrate, db:seed
This commit is contained in:
@@ -3,7 +3,7 @@ class JobsController < ApplicationController
|
|||||||
|
|
||||||
# GET /jobs or /jobs.json
|
# GET /jobs or /jobs.json
|
||||||
def index
|
def index
|
||||||
@jobs = Job.current_jobs_of_today
|
@jobs = Job.currently_working_on
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /jobs/1 or /jobs/1.json
|
# GET /jobs/1 or /jobs/1.json
|
||||||
@@ -23,7 +23,7 @@ class JobsController < ApplicationController
|
|||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @job.save
|
if @job.save
|
||||||
format.html { redirect_to jobs_url(Job.current_jobs_of_today), notice: 'Job was successfully created.' }
|
format.html { redirect_to jobs_url(Job.currently_working_on), notice: 'Job was successfully created.' }
|
||||||
format.json { render :show, status: :created, location: @job }
|
format.json { render :show, status: :created, location: @job }
|
||||||
else
|
else
|
||||||
format.html { render :new, status: :unprocessable_entity }
|
format.html { render :new, status: :unprocessable_entity }
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ class Job < ApplicationRecord
|
|||||||
has_one_attached :pdf
|
has_one_attached :pdf
|
||||||
|
|
||||||
validates_presence_of :costumer_firstname, :costumer_lastname, :privacy_policy_accepted, :pdf
|
validates_presence_of :costumer_firstname, :costumer_lastname, :privacy_policy_accepted, :pdf
|
||||||
|
validate :acceptable_pdf
|
||||||
|
|
||||||
|
before_save :update_printed_at, if: :will_save_change_to_status?
|
||||||
|
before_save :update_paid_at, if: :will_save_change_to_status?
|
||||||
|
before_save :update_status_changed_at, if: :will_save_change_to_status?
|
||||||
|
|
||||||
# NOTE: Multiple status if paing before brinting?
|
# NOTE: Multiple status if paing before brinting?
|
||||||
enum status: {
|
enum status: {
|
||||||
@@ -15,37 +20,55 @@ class Job < ApplicationRecord
|
|||||||
canceled: 4
|
canceled: 4
|
||||||
}
|
}
|
||||||
|
|
||||||
scope :of_the_day, ->(date) { where('created_at >= ? AND created_at <= ?', date.beginning_of_day, date.end_of_day) }
|
|
||||||
scope :of_today, -> { of_the_day(Time.now) }
|
|
||||||
# NOTE: only named status are returned because of WHERE/IN clause for the enum values
|
# NOTE: only named status are returned because of WHERE/IN clause for the enum values
|
||||||
scope :in_status_order, -> { in_order_of(:status, %w[open printing ready_for_pickup paid canceled]) }
|
scope :in_status_order, -> { in_order_of(:status, %w[open printing ready_for_pickup paid canceled]) }
|
||||||
|
|
||||||
# TODO: add logic (all with status: open, printing, ready_for_pickup. with status paid and canceled only from today)
|
scope :created_today, -> { created_on_day(Time.now) }
|
||||||
scope :done_on_day, ->(date) { where('created_at >= ? AND created_at <= ?', date.beginning_of_day, date.end_of_day) }
|
scope :created_on_day, lambda { |date|
|
||||||
|
where('created_at >= ? AND created_at <= ?', date.beginning_of_day, date.end_of_day)
|
||||||
def self.current_jobs_of_today
|
}
|
||||||
|
scope :upgraded_today, -> { upgraded_on_day(Time.now) }
|
||||||
|
scope :upgraded_on_day, lambda { |date|
|
||||||
|
where('upgraded_at >= ? AND upgraded_at <= ?', date.beginning_of_day, date.end_of_day)
|
||||||
|
}
|
||||||
|
# Returns all jobs with status: open print ready_for_pickup and jobs from today with status: paid canceled
|
||||||
|
# paid: only printed_at today
|
||||||
|
# canceled: only updated_at today
|
||||||
|
def self.currently_working_on
|
||||||
# NOTE: use Time.now instead of Date.today to take the timezone into account
|
# NOTE: use Time.now instead of Date.today to take the timezone into account
|
||||||
of_the_day(Time.now).in_status_order
|
where(status: %i[open printing ready_for_pickup])
|
||||||
end
|
.or(Job.where(status: %i[paid canceled])
|
||||||
|
.where('status_changed_at >= ?', Time.now.beginning_of_day))
|
||||||
def self.current_jobs_of_(date)
|
# .in_status_order
|
||||||
# NOTE: use Time.now instead of Date.today to take the timezone into account
|
.order(created_at: :asc)
|
||||||
of_the_day(date).in_status_order
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def fullname
|
def fullname
|
||||||
[costumer_firstname, ' ', costumer_lastname].join
|
[costumer_firstname, ' ', costumer_lastname].join
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Implement validation
|
|
||||||
def acceptable_pdf
|
def acceptable_pdf
|
||||||
return unless pdf.attached?
|
return unless pdf.attached?
|
||||||
|
|
||||||
errors.add(:main_image, 'is too big') unless main_image.blob.byte_size <= 100.megabyte
|
errors.add(:pdf, 'is too big') unless pdf.blob.byte_size <= 100.megabyte
|
||||||
|
|
||||||
acceptable_types = ['application/pdf']
|
acceptable_types = ['application/pdf']
|
||||||
return if acceptable_types.include?(main_image.content_type)
|
return if acceptable_types.include?(pdf.content_type)
|
||||||
|
|
||||||
errors.add(:main_image, 'must be a PDF')
|
errors.add(:pdf, 'must be a PDF')
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def update_printed_at
|
||||||
|
self.printed_at = Time.now if ready_for_pickup? || (paid? && printed_at.nil?)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_paid_at
|
||||||
|
self.paid_at = Time.now if paid?
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_status_changed_at
|
||||||
|
self.status_changed_at = Time.now
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ class CreateJobs < ActiveRecord::Migration[7.1]
|
|||||||
t.boolean :printed, default: false
|
t.boolean :printed, default: false
|
||||||
t.boolean :paid, default: false
|
t.boolean :paid, default: false
|
||||||
t.datetime :printed_at
|
t.datetime :printed_at
|
||||||
|
t.datetime :status_changed_at
|
||||||
t.datetime :paid_at
|
t.datetime :paid_at
|
||||||
t.boolean :intern, default: false
|
t.boolean :intern, default: false
|
||||||
t.string :cost_center
|
t.string :cost_center
|
||||||
@@ -19,7 +20,7 @@ class CreateJobs < ActiveRecord::Migration[7.1]
|
|||||||
t.integer :number_of_plans_a2, default: 0
|
t.integer :number_of_plans_a2, default: 0
|
||||||
t.integer :number_of_plans_a3, default: 0
|
t.integer :number_of_plans_a3, default: 0
|
||||||
t.float :costum_qm_plan, default: 0
|
t.float :costum_qm_plan, default: 0
|
||||||
t.string :pdf
|
t.boolean :privacy_policy_accepted, default: false
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
class AddPrivacyPolicyAcceptedToJob < ActiveRecord::Migration[7.1]
|
|
||||||
def change
|
|
||||||
add_column :jobs, :privacy_policy_accepted, :boolean, default: false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
BIN
db/pdfs/DasNächsteMalGeheIchWoAndersHin.pdf
Normal file
BIN
db/pdfs/DasNächsteMalGeheIchWoAndersHin.pdf
Normal file
Binary file not shown.
BIN
db/pdfs/DenPlanBezahleIchNicht.pdf
Normal file
BIN
db/pdfs/DenPlanBezahleIchNicht.pdf
Normal file
Binary file not shown.
BIN
db/pdfs/DerPlanDerImmerProblemeMacht.pdf
Normal file
BIN
db/pdfs/DerPlanDerImmerProblemeMacht.pdf
Normal file
Binary file not shown.
BIN
db/pdfs/DieFarbenGefallenMirNicht.pdf
Normal file
BIN
db/pdfs/DieFarbenGefallenMirNicht.pdf
Normal file
Binary file not shown.
BIN
db/pdfs/GanzWichtig.pdf
Normal file
BIN
db/pdfs/GanzWichtig.pdf
Normal file
Binary file not shown.
BIN
db/pdfs/IchBinIn5MinDran.pdf
Normal file
BIN
db/pdfs/IchBinIn5MinDran.pdf
Normal file
Binary file not shown.
BIN
db/pdfs/IchWarAlsErstesDran.pdf
Normal file
BIN
db/pdfs/IchWarAlsErstesDran.pdf
Normal file
Binary file not shown.
BIN
db/pdfs/MachHinIchHabsEilig.pdf
Normal file
BIN
db/pdfs/MachHinIchHabsEilig.pdf
Normal file
Binary file not shown.
BIN
db/pdfs/WarumDauertDasSoLange.pdf
Normal file
BIN
db/pdfs/WarumDauertDasSoLange.pdf
Normal file
Binary file not shown.
BIN
db/pdfs/WarumIstDerPlotterDefekt.pdf
Normal file
BIN
db/pdfs/WarumIstDerPlotterDefekt.pdf
Normal file
Binary file not shown.
6
db/schema.rb
generated
6
db/schema.rb
generated
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.1].define(version: 2024_08_01_205025) do
|
ActiveRecord::Schema[7.1].define(version: 2024_08_01_153403) do
|
||||||
create_table "active_storage_attachments", force: :cascade do |t|
|
create_table "active_storage_attachments", force: :cascade do |t|
|
||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
t.string "record_type", null: false
|
t.string "record_type", null: false
|
||||||
@@ -49,6 +49,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_08_01_205025) do
|
|||||||
t.boolean "printed", default: false
|
t.boolean "printed", default: false
|
||||||
t.boolean "paid", default: false
|
t.boolean "paid", default: false
|
||||||
t.datetime "printed_at"
|
t.datetime "printed_at"
|
||||||
|
t.datetime "status_changed_at"
|
||||||
t.datetime "paid_at"
|
t.datetime "paid_at"
|
||||||
t.boolean "intern", default: false
|
t.boolean "intern", default: false
|
||||||
t.string "cost_center"
|
t.string "cost_center"
|
||||||
@@ -58,10 +59,9 @@ ActiveRecord::Schema[7.1].define(version: 2024_08_01_205025) do
|
|||||||
t.integer "number_of_plans_a2", default: 0
|
t.integer "number_of_plans_a2", default: 0
|
||||||
t.integer "number_of_plans_a3", default: 0
|
t.integer "number_of_plans_a3", default: 0
|
||||||
t.float "costum_qm_plan", default: 0.0
|
t.float "costum_qm_plan", default: 0.0
|
||||||
t.string "pdf"
|
t.boolean "privacy_policy_accepted", default: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_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 ["costumer_id"], name: "index_jobs_on_costumer_id"
|
||||||
t.index ["operator_id"], name: "index_jobs_on_operator_id"
|
t.index ["operator_id"], name: "index_jobs_on_operator_id"
|
||||||
t.index ["status"], name: "index_jobs_on_status"
|
t.index ["status"], name: "index_jobs_on_status"
|
||||||
|
|||||||
11
db/seeds.rb
11
db/seeds.rb
@@ -15,7 +15,7 @@ Faker::Config.locale = :de
|
|||||||
end
|
end
|
||||||
['GanzWichtig.pdf', 'IchBinIn5MinDran.pdf', 'DerPlanDerImmerProblemeMacht.pdf',
|
['GanzWichtig.pdf', 'IchBinIn5MinDran.pdf', 'DerPlanDerImmerProblemeMacht.pdf',
|
||||||
'DieFarbenGefallenMirNicht.pdf', 'MachHinIchHabsEilig.pdf', 'WarumDauertDasSoLange.pdf',
|
'DieFarbenGefallenMirNicht.pdf', 'MachHinIchHabsEilig.pdf', 'WarumDauertDasSoLange.pdf',
|
||||||
'DenPlanBezahleIchNicht.pdf', 'IchWarAlsErstesDran.pdf', 'WarumIstDerPlotterDefekt.pdf', 'DasNächsteMalGeheIchWoAndersHin'].shuffle.each do |pdf|
|
'DenPlanBezahleIchNicht.pdf', 'IchWarAlsErstesDran.pdf', 'WarumIstDerPlotterDefekt.pdf', 'DasNächsteMalGeheIchWoAndersHin.pdf'].shuffle.each do |pdf|
|
||||||
a0 = rand(0...7)
|
a0 = rand(0...7)
|
||||||
a1 = rand(0...7)
|
a1 = rand(0...7)
|
||||||
a2 = rand(0...7)
|
a2 = rand(0...7)
|
||||||
@@ -23,9 +23,12 @@ end
|
|||||||
a0.zero? || a1 = 0 && a2 = 0 && a3 = 0
|
a0.zero? || a1 = 0 && a2 = 0 && a3 = 0
|
||||||
a1.zero? || a2 = 0 && a3 = 0
|
a1.zero? || a2 = 0 && a3 = 0
|
||||||
a2.zero? || a3 = 0
|
a2.zero? || a3 = 0
|
||||||
status = %i[open printing ready_for_pickup paid cancelled].sample
|
status = %i[open printing ready_for_pickup paid canceled].sample
|
||||||
|
|
||||||
Job.new(costumer_firstname: Faker::Name.unique.first_name, costumer_lastname: Faker::Name.unique.last_name,
|
job = Job.new(costumer_firstname: Faker::Name.unique.first_name, costumer_lastname: Faker::Name.unique.last_name,
|
||||||
number_of_plans_a0: a0, number_of_plans_a1: a1, number_of_plans_a2: a2, number_of_plans_a3: a3,
|
number_of_plans_a0: a0, number_of_plans_a1: a1, number_of_plans_a2: a2, number_of_plans_a3: a3,
|
||||||
pdf:, status:).save
|
status:, privacy_policy_accepted: true)
|
||||||
|
job.pdf = File.open(Rails.root.join('db/pdfs/', pdf))
|
||||||
|
job.save!
|
||||||
|
sleep 1
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user