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
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

View File

@@ -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

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

View File

@@ -10,16 +10,28 @@
<%= javascript_importmap_tags %>
</head>
<body>
<header class="container mx-auto px-4 py-6 flex items-center justify-between">
<a href="/" class="font-bold text-black text-xl">Plottservice</a>
<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-4xl">Plottservice Fachbereich AB</a>
<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>
<ul>
<li>
<a href="#" class="rounded-full px-3 py-2 font-semibold bg-white bg-opacity-10 flex items-center group">
<span class="mr-2">Sign in</span>
<svg class="stroke-current" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true" style="stroke: rgb(194, 62, 110);">
<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">Anmelden</span>
<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">
<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>
@@ -30,10 +42,11 @@
</ul>
</nav>
</header>
<main class="container mx-auto mt-28 px-5 flex">
<main class="container mx-auto mt-8 px-5 flex">
<%= yield %>
</main>
<footer>
<p></p>
</footer>
</body>
</html>