From e3d5d97c6c2140fc31bb789ac5691df39e9d21a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20B=C3=B6hm?= Date: Thu, 1 Aug 2024 00:27:55 +0200 Subject: [PATCH] Worked on layout, added model funktions, changed database Changes to the migration file make it necessary to reimport the database: db:drop, db:create, db:migrate, db:seed --- app/controllers/jobs_controller.rb | 8 +++--- app/models/job.rb | 21 +++++++++++++++ app/views/jobs/_job_tr.html.erb | 23 ++++++++++++++++ app/views/jobs/index.html.erb | 34 ++++++++++++++++-------- app/views/layouts/application.html.erb | 25 ++++++++++++----- config/tailwind.config.js | 7 +++++ db/migrate/20240727101347_create_jobs.rb | 18 ++++++++----- db/schema.rb | 19 ++++++++----- db/seeds.rb | 16 +++++++++++ 9 files changed, 137 insertions(+), 34 deletions(-) create mode 100644 app/views/jobs/_job_tr.html.erb diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb index 2d0f07f..729a07c 100644 --- a/app/controllers/jobs_controller.rb +++ b/app/controllers/jobs_controller.rb @@ -3,7 +3,7 @@ class JobsController < ApplicationController # GET /jobs or /jobs.json def index - @jobs = Job.all + @jobs = Job.current_jobs end # GET /jobs/1 or /jobs/1.json @@ -23,7 +23,7 @@ class JobsController < ApplicationController respond_to do |format| if @job.save - format.html { redirect_to job_url(@job), notice: 'Job was successfully created.' } + format.html { redirect_to jobs_url(Job.current_jobs), notice: 'Job was successfully created.' } format.json { render :show, status: :created, location: @job } else format.html { render :new, status: :unprocessable_entity } @@ -65,6 +65,8 @@ class JobsController < ApplicationController # Only allow a list of trusted parameters through. def job_params 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) + :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) end end diff --git a/app/models/job.rb b/app/models/job.rb index e5a594e..a8cff3a 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -1,4 +1,25 @@ class Job < ApplicationRecord belongs_to :operator, class_name: 'User', optional: true belongs_to :costumer, class_name: 'User', optional: true + + # NOTE: Multiple status if paing before brinting + enum status: { + open: 0, + printing: 1, + ready_for_pickup: 2, + paid: 3, + cancelled: 4 + } + + # BUG: shows the hole day of the utc timezone + scope :today, -> { where('DATE(created_at) = ?', Time.now.utc.to_date) } + + def self.current_jobs + today.order(created_at: :desc, status: :asc) + # today.order(created_at: :desc, status: :asc) + end + + def fullname + [costumer_firstname, ' ', costumer_lastname].join + end end diff --git a/app/views/jobs/_job_tr.html.erb b/app/views/jobs/_job_tr.html.erb new file mode 100644 index 0000000..86fcffb --- /dev/null +++ b/app/views/jobs/_job_tr.html.erb @@ -0,0 +1,23 @@ + + <%= job.id %> + <%= job.fullname %> + <%= job.pdf %> + <%= job.number_of_plans_a0 %> + <%= job.number_of_plans_a1 %> + <%= job.number_of_plans_a2 %> + <%= job.number_of_plans_a3 %> + + <% case job.status.to_sym %> + <% when :open %> + <%= job.status %> + <% when :printing %> + <%= job.status %> + <% when :ready_for_pickup %> + <%= job.status %> + <% when :paid %> + <%= job.status %> + <% when :cancelled %> + <%= job.status %> + <% end %> + + diff --git a/app/views/jobs/index.html.erb b/app/views/jobs/index.html.erb index c3e70cc..2e7bc91 100644 --- a/app/views/jobs/index.html.erb +++ b/app/views/jobs/index.html.erb @@ -3,19 +3,31 @@

<%= notice %>

<% end %> - <% content_for :title, "Jobs" %> + <% content_for :title, "Current Print Jobs" %> -
-

Jobs

- <%= link_to "New job", new_job_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %> +
+

Plottaufträge am <%= Date.today.strftime("%d.%m.%Y") %>

+ <%= link_to "Plottauftrag aufgeben", new_job_path, class: "py-3 px-5 bg-hsrm-red drop-shadow-lg transition-colors duration-100 hover:bg-hsrm-red-light text-white block font-medium" %>
-
- <% @jobs.each do |job| %> - <%= render job %> -

- <%= link_to "Show this job", job, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -

- <% end %> +
+ + + + + + + + + + + + + + + <%= render partial: "job_tr", collection: @jobs, as: :job %> + <%#= link_to "Show this job", job, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> + +
ID Name PDF A0 A1 A2 A3 Status
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 189a32b..2f822d8 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,16 +10,28 @@ <%= javascript_importmap_tags %> -
- Plottservice +
+ Plottservice Fachbereich AB
-
+
<%= yield %>
diff --git a/config/tailwind.config.js b/config/tailwind.config.js index 09b0f40..f10df50 100644 --- a/config/tailwind.config.js +++ b/config/tailwind.config.js @@ -13,6 +13,13 @@ module.exports = { sans: ["Inter var", ...defaultTheme.fontFamily.sans], }, }, + extend: { + colors: { + "hsrm-red": "#c20008", + "hsrm-red-dark": "#af0007", + "hsrm-red-light": "#e20009", + }, + }, }, plugins: [ require("@tailwindcss/forms"), diff --git a/db/migrate/20240727101347_create_jobs.rb b/db/migrate/20240727101347_create_jobs.rb index 9949596..d68a33e 100644 --- a/db/migrate/20240727101347_create_jobs.rb +++ b/db/migrate/20240727101347_create_jobs.rb @@ -7,15 +7,19 @@ class CreateJobs < ActiveRecord::Migration[7.1] t.string :operator_lastname t.string :costumer_firstname t.string :costumer_lastname - t.boolean :paid + t.boolean :printed, default: false + t.boolean :paid, default: false t.datetime :printed_at - t.boolean :intern + t.datetime :paid_at + t.boolean :intern, default: false t.string :cost_center - t.integer :number_of_plans_a0 - t.integer :number_of_plans_a1 - t.integer :number_of_plans_a2 - t.integer :number_of_plans_a3 - t.float :costum_qm_plan + t.integer :status, default: 0, index: true + t.integer :number_of_plans_a0, default: 0 + t.integer :number_of_plans_a1, default: 0 + t.integer :number_of_plans_a2, default: 0 + t.integer :number_of_plans_a3, default: 0 + t.float :costum_qm_plan, default: 0 + t.string :pdf t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index 58a4e89..d1b8856 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -18,19 +18,24 @@ ActiveRecord::Schema[7.1].define(version: 2024_07_30_214152) do t.string "operator_lastname" t.string "costumer_firstname" t.string "costumer_lastname" - t.boolean "paid" + t.boolean "printed", default: false + t.boolean "paid", default: false t.datetime "printed_at" - t.boolean "intern" + t.datetime "paid_at" + t.boolean "intern", default: false t.string "cost_center" - t.integer "number_of_plans_a0" - t.integer "number_of_plans_a1" - t.integer "number_of_plans_a2" - t.integer "number_of_plans_a3" - t.float "costum_qm_plan" + t.integer "status", default: 0 + t.integer "number_of_plans_a0", default: 0 + t.integer "number_of_plans_a1", default: 0 + t.integer "number_of_plans_a2", default: 0 + t.integer "number_of_plans_a3", default: 0 + t.float "costum_qm_plan", default: 0.0 + t.string "pdf" t.datetime "created_at", null: false t.datetime "updated_at", null: 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" end create_table "users", force: :cascade do |t| diff --git a/db/seeds.rb b/db/seeds.rb index 6ae3157..0e67c8c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -13,3 +13,19 @@ Faker::Config.locale = :de 10.times do User.new(firstname: Faker::Name.unique.first_name, lastname: Faker::Name.unique.last_name).save end +['GanzWichtig.pdf', 'IchBinIn5MinDran.pdf', 'DerPlanDerImmerProblemeMacht.pdf', + 'DieFarbenGefallenMirNicht.pdf', 'MachHinIchHabsEilig.pdf', 'WarumDauertDasSoLange.pdf', + 'DenPlanBezahleIchNicht.pdf', 'IchWarAlsErstesDran.pdf', 'WarumIstDerPlotterDefekt.pdf', 'DasNächsteMalGeheIchWoAndersHin'].shuffle.each do |pdf| + a0 = rand(0...7) + a1 = rand(0...7) + a2 = rand(0...7) + a3 = rand(0...7) + a0.zero? || a1 = 0 && a2 = 0 && a3 = 0 + a1.zero? || a2 = 0 && a3 = 0 + a2.zero? || a3 = 0 + status = %i[open printing ready_for_pickup paid cancelled].sample + + 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, + pdf:, status:).save +end