From 69bca2d99eb5fed160dcd277ba90c1a8f43466d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20B=C3=B6hm?= Date: Thu, 1 Aug 2024 15:45:09 +0200 Subject: [PATCH] Some layout and model changes --- app/controllers/jobs_controller.rb | 4 +-- app/models/job.rb | 24 ++++++++++----- app/views/jobs/_form.html.erb | 49 ++++++++---------------------- app/views/jobs/_job_tr.html.erb | 10 +++--- app/views/jobs/index.html.erb | 4 +-- app/views/jobs/new.html.erb | 6 ++-- 6 files changed, 40 insertions(+), 57 deletions(-) diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb index 729a07c..e13e36a 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.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 } diff --git a/app/models/job.rb b/app/models/job.rb index a8cff3a..af0e992 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -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 diff --git a/app/views/jobs/_form.html.erb b/app/views/jobs/_form.html.erb index e55b324..e559637 100644 --- a/app/views/jobs/_form.html.erb +++ b/app/views/jobs/_form.html.erb @@ -1,12 +1,8 @@ <%= form_with(model: job, class: "contents") do |form| %> <% if job.errors.any? %> -
+

<%= pluralize(job.errors.count, "error") %> prohibited this job from being saved:

-
    <% job.errors.each do |error| %>
  • <%= error.full_message %>
  • @@ -14,63 +10,42 @@
<% end %> -
<%= 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" %>
-
<%= 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" %>
-
<%= form.label :intern %> <%= form.check_box :intern, class: "block mt-2 h-5 w-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" %>
-
<%= 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" %>
-
<%= 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" %>
-
<%= 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" %>
-
<%= 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" %> +
+
+ <%= form.label :accept_privacy %> <%= form.check_box :accept_privacy, class: "block mt-2 h-5 w-5" %>
-
- <%= 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" %>
<% end %> diff --git a/app/views/jobs/_job_tr.html.erb b/app/views/jobs/_job_tr.html.erb index 7d61309..8365a2d 100644 --- a/app/views/jobs/_job_tr.html.erb +++ b/app/views/jobs/_job_tr.html.erb @@ -2,10 +2,10 @@ <%= 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 %> + <%= 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 %> @@ -16,7 +16,7 @@ <%= job.status %> <% when :paid %> <%= job.status %> - <% when :cancelled %> + <% when :canceled %> <%= job.status %> <% end %> diff --git a/app/views/jobs/index.html.erb b/app/views/jobs/index.html.erb index 19dfa26..f491b1d 100644 --- a/app/views/jobs/index.html.erb +++ b/app/views/jobs/index.html.erb @@ -4,8 +4,8 @@ <% end %> <% content_for :title, "Current Print Jobs" %>
-

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

- <%= 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" %> +

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

+ <%= 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" %>
diff --git a/app/views/jobs/new.html.erb b/app/views/jobs/new.html.erb index aa0c983..3a62e06 100644 --- a/app/views/jobs/new.html.erb +++ b/app/views/jobs/new.html.erb @@ -1,7 +1,5 @@
-

New job

- +

Plottauftrag erteillen

<%= 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" %>