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
This commit is contained in:
2024-08-01 00:27:55 +02:00
parent 40ea1910c7
commit e3d5d97c6c
9 changed files with 137 additions and 34 deletions

View File

@@ -3,7 +3,7 @@ class JobsController < ApplicationController
# GET /jobs or /jobs.json # GET /jobs or /jobs.json
def index def index
@jobs = Job.all @jobs = Job.current_jobs
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 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 } format.json { render :show, status: :created, location: @job }
else else
format.html { render :new, status: :unprocessable_entity } format.html { render :new, status: :unprocessable_entity }
@@ -65,6 +65,8 @@ class JobsController < ApplicationController
# Only allow a list of trusted parameters through. # Only allow a list of trusted parameters through.
def job_params def job_params
params.require(:job).permit(:operator_id, :costumer_id, :operator_firstname, :operator_lastname, 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
end end

View File

@@ -1,4 +1,25 @@
class Job < ApplicationRecord class Job < ApplicationRecord
belongs_to :operator, class_name: 'User', optional: true belongs_to :operator, class_name: 'User', optional: true
belongs_to :costumer, 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 end

View File

@@ -0,0 +1,23 @@
<tr id="<%= dom_id job %>" class="<%= cycle('bg-gray-50','bg-gray-200') %> ">
<td class="p-3 text-sm text-gray-900"> <%= job.id %> </td>
<td class="p-3 text-sm text-gray-900"> <%= job.fullname %> </td>
<td class="p-3 text-sm text-gray-900"> <%= job.pdf %> </td>
<td class="p-3 text-sm text-gray-900"> <%= job.number_of_plans_a0 %> </td>
<td class="p-3 text-sm text-gray-900"> <%= job.number_of_plans_a1 %> </td>
<td class="p-3 text-sm text-gray-900"> <%= job.number_of_plans_a2 %> </td>
<td class="p-3 text-sm text-gray-900"> <%= job.number_of_plans_a3 %> </td>
<td class="p-3 text-sm text-gray-900">
<% case job.status.to_sym %>
<% when :open %>
<span class="p-1.5 text-xs font-medium upercase tracking-wieder text-gray-900 bg-gray-300 rounded-lg"> <%= job.status %> </span>
<% when :printing %>
<span class="p-1.5 text-xs font-medium upercase tracking-wieder text-yellow-900 bg-yellow-300 rounded-lg"> <%= job.status %> </span>
<% when :ready_for_pickup %>
<span class="p-1.5 text-xs font-medium upercase tracking-wieder text-orange-900 bg-orange-300 rounded-lg"> <%= job.status %> </span>
<% when :paid %>
<span class="p-1.5 text-xs font-medium upercase tracking-wieder text-green-900 bg-green-300 rounded-lg"> <%= job.status %> </span>
<% when :cancelled %>
<span class="p-1.5 text-xs font-medium upercase tracking-wieder text-red-900 bg-red-300 rounded-lg"> <%= job.status %> </span>
<% end %>
</td>
</tr>

View File

@@ -3,19 +3,31 @@
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p> <p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
<% end %> <% end %>
<% content_for :title, "Jobs" %> <% content_for :title, "Current Print Jobs" %>
<div class="flex justify-between items-center"> <div class="flex justify-between items-center py-4">
<h1 class="font-bold text-4xl">Jobs</h1> <h1 class="font-bold text-4xl">Plottaufträge am <%= Date.today.strftime("%d.%m.%Y") %></h1>
<%= link_to "New job", new_job_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %> <%= 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" %>
</div> </div>
<div id="jobs" class="min-w-full"> <div id="jobs" class="min-w-full drop-shadow-lg">
<% @jobs.each do |job| %> <table class="w-full">
<%= render job %> <thead class="bg-gray-200 border-b-2 border-gray-400">
<p> <tr>
<%= link_to "Show this job", job, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> <th class="p-3 text-sm font-semibold tracking-wide text-left"> ID </th>
</p> <th class="p-3 text-sm font-semibold tracking-wide text-left"> Name </th>
<% end %> <th class="p-3 text-sm font-semibold tracking-wide text-left"> PDF </th>
<th class="p-3 text-sm font-semibold tracking-wide text-left"> A0 </th>
<th class="p-3 text-sm font-semibold tracking-wide text-left"> A1 </th>
<th class="p-3 text-sm font-semibold tracking-wide text-left"> A2 </th>
<th class="p-3 text-sm font-semibold tracking-wide text-left"> A3 </th>
<th class="p-3 text-sm font-semibold tracking-wide text-left"> Status </th>
</tr>
</thead>
<tbody>
<%= 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" %>
</tbody>
</table>
</div> </div>
</div> </div>

View File

@@ -10,16 +10,28 @@
<%= javascript_importmap_tags %> <%= javascript_importmap_tags %>
</head> </head>
<body> <body>
<header class="container mx-auto px-4 py-6 flex items-center justify-between"> <header class="container mx-auto px-4 py-6 flex items-center justify-between border-b-2">
<a href="/" class="font-bold text-black text-xl">Plottservice</a> <a href="/" class="font-bold text-black text-4xl">Plottservice Fachbereich AB</a>
<nav> <nav>
<ul class="flex items-color justify-center font-semibold">
<li class="relative">
<button class="px-4 py-2 hover:text-hsrm-red cursor-default">
Products
</button>
</li>
<li class="relative">
<button class="px-4 py-2 hover:text-hsrm-red cursor-default">
Products
</button>
</li>
</ul>
</nav> </nav>
<nav> <nav>
<ul> <ul>
<li> <li>
<a href="#" class="rounded-full px-3 py-2 font-semibold bg-white bg-opacity-10 flex items-center group"> <a href="#" class="px-3 py-2 font-semibold bg-hsrm-red hover:bg-hsrm-red-light drop-shadow-lg transition-colors duration-100 bg-opacity-100 flex items-center group text-white">
<span class="mr-2">Sign in</span> <span class="mr-2">Anmelden</span>
<svg class="stroke-current" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true" style="stroke: rgb(194, 62, 110);"> <svg class="stroke-current" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true" style="stroke: rgb(255, 255, 255);">
<g fill-rule="evenodd"> <g fill-rule="evenodd">
<path class="opacity-0 group-hover:opacity-100 transition ease-in-out duration-200" d="M0 5h7"></path> <path class="opacity-0 group-hover:opacity-100 transition ease-in-out duration-200" d="M0 5h7"></path>
<path class="HoverArrow__tipPath" d="M1 1l4 4-4 4"></path> <path class="HoverArrow__tipPath" d="M1 1l4 4-4 4"></path>
@@ -30,10 +42,11 @@
</ul> </ul>
</nav> </nav>
</header> </header>
<main class="container mx-auto mt-28 px-5 flex"> <main class="container mx-auto mt-8 px-5 flex">
<%= yield %> <%= yield %>
</main> </main>
<footer> <footer>
<p></p>
</footer> </footer>
</body> </body>
</html> </html>

View File

@@ -13,6 +13,13 @@ module.exports = {
sans: ["Inter var", ...defaultTheme.fontFamily.sans], sans: ["Inter var", ...defaultTheme.fontFamily.sans],
}, },
}, },
extend: {
colors: {
"hsrm-red": "#c20008",
"hsrm-red-dark": "#af0007",
"hsrm-red-light": "#e20009",
},
},
}, },
plugins: [ plugins: [
require("@tailwindcss/forms"), require("@tailwindcss/forms"),

View File

@@ -7,15 +7,19 @@ class CreateJobs < ActiveRecord::Migration[7.1]
t.string :operator_lastname t.string :operator_lastname
t.string :costumer_firstname t.string :costumer_firstname
t.string :costumer_lastname t.string :costumer_lastname
t.boolean :paid t.boolean :printed, default: false
t.boolean :paid, default: false
t.datetime :printed_at t.datetime :printed_at
t.boolean :intern t.datetime :paid_at
t.boolean :intern, default: false
t.string :cost_center t.string :cost_center
t.integer :number_of_plans_a0 t.integer :status, default: 0, index: true
t.integer :number_of_plans_a1 t.integer :number_of_plans_a0, default: 0
t.integer :number_of_plans_a2 t.integer :number_of_plans_a1, default: 0
t.integer :number_of_plans_a3 t.integer :number_of_plans_a2, default: 0
t.float :costum_qm_plan t.integer :number_of_plans_a3, default: 0
t.float :costum_qm_plan, default: 0
t.string :pdf
t.timestamps t.timestamps
end end

19
db/schema.rb generated
View File

@@ -18,19 +18,24 @@ ActiveRecord::Schema[7.1].define(version: 2024_07_30_214152) do
t.string "operator_lastname" t.string "operator_lastname"
t.string "costumer_firstname" t.string "costumer_firstname"
t.string "costumer_lastname" t.string "costumer_lastname"
t.boolean "paid" t.boolean "printed", default: false
t.boolean "paid", default: false
t.datetime "printed_at" t.datetime "printed_at"
t.boolean "intern" t.datetime "paid_at"
t.boolean "intern", default: false
t.string "cost_center" t.string "cost_center"
t.integer "number_of_plans_a0" t.integer "status", default: 0
t.integer "number_of_plans_a1" t.integer "number_of_plans_a0", default: 0
t.integer "number_of_plans_a2" t.integer "number_of_plans_a1", default: 0
t.integer "number_of_plans_a3" t.integer "number_of_plans_a2", default: 0
t.float "costum_qm_plan" 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 "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: 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"
end end
create_table "users", force: :cascade do |t| create_table "users", force: :cascade do |t|

View File

@@ -13,3 +13,19 @@ Faker::Config.locale = :de
10.times do 10.times do
User.new(firstname: Faker::Name.unique.first_name, lastname: Faker::Name.unique.last_name).save User.new(firstname: Faker::Name.unique.first_name, lastname: Faker::Name.unique.last_name).save
end 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