Some layout and model changes
This commit is contained in:
@@ -3,7 +3,7 @@ class JobsController < ApplicationController
|
||||
|
||||
# GET /jobs or /jobs.json
|
||||
def index
|
||||
@jobs = Job.current_jobs
|
||||
@jobs = Job.current_jobs_of_today
|
||||
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 jobs_url(Job.current_jobs), notice: 'Job was successfully created.' }
|
||||
format.html { redirect_to jobs_url(Job.current_jobs_of_today), notice: 'Job was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @job }
|
||||
else
|
||||
format.html { render :new, status: :unprocessable_entity }
|
||||
|
||||
@@ -2,21 +2,31 @@ 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
|
||||
# NOTE: Multiple status if paing before brinting?
|
||||
enum status: {
|
||||
open: 0,
|
||||
printing: 1,
|
||||
ready_for_pickup: 2,
|
||||
paid: 3,
|
||||
cancelled: 4
|
||||
canceled: 4
|
||||
}
|
||||
|
||||
# BUG: shows the hole day of the utc timezone
|
||||
scope :today, -> { where('DATE(created_at) = ?', Time.now.utc.to_date) }
|
||||
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
|
||||
scope :in_status_order, -> { in_order_of(:status, %w[open printing ready_for_pickup paid canceled]) }
|
||||
|
||||
def self.current_jobs
|
||||
today.order(created_at: :desc, status: :asc)
|
||||
# today.order(created_at: :desc, status: :asc)
|
||||
# TODO: add logic (all with status: open, printing, ready_for_pickup. with status paid and canceled only from today)
|
||||
scope :done_on_day, ->(date) { where('created_at >= ? AND created_at <= ?', date.beginning_of_day, date.end_of_day) }
|
||||
|
||||
def self.current_jobs_of_today
|
||||
# NOTE: use Time.now instead of Date.today to take the timezone into account
|
||||
of_the_day(Time.now).in_status_order
|
||||
end
|
||||
|
||||
def self.current_jobs_of_(date)
|
||||
# NOTE: use Time.now instead of Date.today to take the timezone into account
|
||||
of_the_day(date).in_status_order
|
||||
end
|
||||
|
||||
def fullname
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
<%= form_with(model: job, class: "contents") do |form| %>
|
||||
<% if job.errors.any? %>
|
||||
<div
|
||||
id="error_explanation"
|
||||
class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3"
|
||||
>
|
||||
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3" >
|
||||
<h2><%= pluralize(job.errors.count, "error") %>
|
||||
prohibited this job from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% job.errors.each do |error| %>
|
||||
<li><%= error.full_message %></li>
|
||||
@@ -14,63 +10,42 @@
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :costumer_firstname %>
|
||||
<%= form.text_field :costumer_firstname,
|
||||
class:
|
||||
"block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
<%= form.text_field :costumer_firstname, class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :costumer_lastname %>
|
||||
<%= form.text_field :costumer_lastname,
|
||||
class:
|
||||
"block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
<%= 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" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :intern %>
|
||||
<%= form.check_box :intern, class: "block mt-2 h-5 w-5" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :cost_center %>
|
||||
<%= form.text_field :cost_center,
|
||||
class:
|
||||
"block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
<%= 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" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :number_of_plans_a0 %>
|
||||
<%= form.number_field :number_of_plans_a0,
|
||||
class:
|
||||
"block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
<%= 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" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :number_of_plans_a1 %>
|
||||
<%= form.number_field :number_of_plans_a1,
|
||||
class:
|
||||
"block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
<%= 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" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :number_of_plans_a2 %>
|
||||
<%= form.number_field :number_of_plans_a2,
|
||||
class:
|
||||
"block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
<%= 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" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :number_of_plans_a3 %>
|
||||
<%= form.number_field :number_of_plans_a3,
|
||||
class:
|
||||
"block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
<%= 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" %>
|
||||
</div>
|
||||
<div>
|
||||
<%= form.label :accept_privacy %> <%= form.check_box :accept_privacy, class: "block mt-2 h-5 w-5" %>
|
||||
</div>
|
||||
|
||||
<div class="inline">
|
||||
<%= form.submit class:
|
||||
"rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
|
||||
<%= 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" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
<td class="p-3 text-sm text-hsrm-gray"> <%= job.id %> </td>
|
||||
<td class="p-3 text-sm text-hsrm-gray"> <%= job.fullname %> </td>
|
||||
<td class="p-3 text-sm text-hsrm-gray"> <%= job.pdf %> </td>
|
||||
<td class="p-3 text-sm text-center text-hsrm-gray"><span class="p-1.5 font-bg-gray-gray-900 bg-gray-300 font-medium rounded-lg"> <%= job.number_of_plans_a0 %></span> </td>
|
||||
<td class="p-3 text-sm text-center text-hsrm-gray"><span class="p-1.5 font-bg-gray-gray-900 bg-gray-300 font-medium rounded-lg"><%= job.number_of_plans_a1 %></span> </td>
|
||||
<td class="p-3 text-sm text-center text-hsrm-gray"><span class="p-1.5 font-bg-gray-gray-900 bg-gray-300 font-medium rounded-lg"><%= job.number_of_plans_a2 %> </span></td>
|
||||
<td class="p-3 text-sm text-center text-hsrm-gray"><span class="p-1.5 font-bg-gray-gray-900 bg-gray-300 font-medium rounded-lg"><%= job.number_of_plans_a3 %></span> </td>
|
||||
<td class="p-3 text-sm text-center text-hsrm-gray"><span class="p-1.5 bg-gray-300 font-medium rounded-lg"> <%= job.number_of_plans_a0 %></span> </td>
|
||||
<td class="p-3 text-sm text-center text-hsrm-gray"><span class="p-1.5 bg-gray-300 font-medium rounded-lg"><%= job.number_of_plans_a1 %></span> </td>
|
||||
<td class="p-3 text-sm text-center text-hsrm-gray"><span class="p-1.5 bg-gray-300 font-medium rounded-lg"><%= job.number_of_plans_a2 %> </span></td>
|
||||
<td class="p-3 text-sm text-center text-hsrm-gray"><span class="p-1.5 bg-gray-300 font-medium rounded-lg"><%= job.number_of_plans_a3 %></span> </td>
|
||||
<td class="p-3 text-sm text-center text-hsrm-gray">
|
||||
<% case job.status.to_sym %>
|
||||
<% when :open %>
|
||||
@@ -16,7 +16,7 @@
|
||||
<span class="p-1.5 text-xs font-medium upercase tracking-wider text-lime-900 bg-lime-300 rounded-lg"> <%= job.status %> </span>
|
||||
<% when :paid %>
|
||||
<span class="p-1.5 text-xs font-medium upercase tracking-wider text-green-900 bg-green-300 rounded-lg"> <%= job.status %> </span>
|
||||
<% when :cancelled %>
|
||||
<% when :canceled %>
|
||||
<span class="p-1.5 text-xs font-medium upercase tracking-wider text-red-900 bg-red-300 rounded-lg"> <%= job.status %> </span>
|
||||
<% end %>
|
||||
</td>
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
<% end %>
|
||||
<% content_for :title, "Current Print Jobs" %>
|
||||
<div class="flex justify-between items-center py-4">
|
||||
<h1 class="font-bold text-hsrm-gray text-4xl">Plottaufträge am <%= Date.today.strftime("%d.%m.%Y") %></h1>
|
||||
<%= link_to "Plottauftrag aufgeben", new_job_path, class: "px-3 py-2 bg-hsrm-red drop-shadow-lg transition-colors duration-100 hover:bg-hsrm-red-light text-white block font-medium" %>
|
||||
<h1 class="font-bold text-hsrm-gray text-4xl">Aktuelle Plottaufträge <span class="font-semibold text-sm"><%= Date.today.strftime("%d.%m.%Y") %></span></h1>
|
||||
<%= link_to "Plottauftrag aufgeben", new_job_path, class: "px-3 py-2 bg-hsrm-red drop-shadow-lg transition-colors hover:bg-hsrm-red-light text-white block font-medium" %>
|
||||
</div>
|
||||
<div id="jobs" class="min-w-full drop-shadow-lg">
|
||||
<table class="w-full py-8 table-auto">
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<div class="mx-auto md:w-2/3 w-full">
|
||||
<h1 class="font-bold text-4xl">New job</h1>
|
||||
|
||||
<h1 class="font-bold text-4xl">Plottauftrag erteillen</h1>
|
||||
<%= render "form", job: @job %>
|
||||
|
||||
<%= link_to "Back to jobs", jobs_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
||||
<%= link_to "Zurück zur Übersicht", jobs_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user