Number of plans can no be incremented or decremented
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
class Operator::JobsController < ApplicationController
|
class Operator::JobsController < ApplicationController
|
||||||
before_action :set_job, only: %i[show edit update destroy cancel]
|
before_action :set_job, only: %i[show edit update destroy cancel increment_page decrement_page]
|
||||||
|
|
||||||
# GET /jobs or /jobs.json
|
# GET /jobs or /jobs.json
|
||||||
def index
|
def index
|
||||||
@@ -29,9 +29,9 @@ class Operator::JobsController < ApplicationController
|
|||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @job.save
|
if @job.save
|
||||||
flash[:notice] = "Job was successfully created."
|
flash[:notice] = "Job was successfully created."
|
||||||
Turbo::StreamsChannel.broadcast_prepend_later_to "jobs", target: :jobs, partial: "jobs/job_tr",
|
Turbo::StreamsChannel.broadcast_prepend_later_to "jobs", target: :jobs, partial: "operator/jobs/job_tr",
|
||||||
locals: { job: @job }
|
locals: { job: @job }
|
||||||
format.html { redirect_to jobs_url }
|
format.html { redirect_to operator_jobs_url }
|
||||||
else
|
else
|
||||||
format.html { render :new, status: :unprocessable_entity }
|
format.html { render :new, status: :unprocessable_entity }
|
||||||
end
|
end
|
||||||
@@ -43,7 +43,7 @@ class Operator::JobsController < ApplicationController
|
|||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @job.update(job_params)
|
if @job.update(job_params)
|
||||||
broadcast_update_job
|
broadcast_update_job
|
||||||
format.html { redirect_to jobs_url, notice: "Job was successfully updated." }
|
format.html { redirect_to operator_jobs_url, notice: "Job was successfully updated." }
|
||||||
else
|
else
|
||||||
format.html { render :edit, status: :unprocessable_entity }
|
format.html { render :edit, status: :unprocessable_entity }
|
||||||
end
|
end
|
||||||
@@ -60,7 +60,7 @@ class Operator::JobsController < ApplicationController
|
|||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
broadcast_update_job
|
broadcast_update_job
|
||||||
format.turbo_stream
|
format.turbo_stream
|
||||||
format.html { redirect_to jobs_url }
|
format.html { redirect_to operator_jobs_url }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -70,7 +70,23 @@ class Operator::JobsController < ApplicationController
|
|||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
Turbo::StreamsChannel.broadcast_remove_to "jobs", target: @job
|
Turbo::StreamsChannel.broadcast_remove_to "jobs", target: @job
|
||||||
format.html { redirect_to jobs_url, notice: "Job was successfully destroyed." }
|
format.html { redirect_to operator_jobs_url, notice: "Job was successfully destroyed." }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def increment_page
|
||||||
|
@job.increment_page(params[:din])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to operator_jobs_url, notice: "Job was successfully updated." }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def decrement_page
|
||||||
|
@job.decrement_page(params[:din])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to operator_jobs_url, notice: "Job was successfully updated." }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -87,7 +103,7 @@ class Operator::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, :opertator_firstname, :operator_lastname, :costumer_firstname, :costumer_lastname)
|
params.require(:job).permit(:operator_id, :costumer_id, :operator_firstname, :operator_lastname, :costumer_firstname, :costumer_lastname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -5,18 +5,23 @@ class Job < ApplicationRecord
|
|||||||
has_one_attached :pdf, dependent: :purge
|
has_one_attached :pdf, dependent: :purge
|
||||||
|
|
||||||
validates_presence_of :costumer_firstname, :costumer_lastname, :privacy_policy_accepted, :pdf
|
validates_presence_of :costumer_firstname, :costumer_lastname, :privacy_policy_accepted, :pdf
|
||||||
|
# validates_numericality_of {:number_of_plans_a0,:number_of_plans_a1, :number_of_plans_a2, :number_of_plans_a3}, greater_than_or_equal_to: 0
|
||||||
|
validates :number_of_plans_a0, :number_of_plans_a1, :number_of_plans_a2, :number_of_plans_a3, numericality: { greater_than_or_equal_to: 0 }
|
||||||
|
|
||||||
|
|
||||||
validate :acceptable_pdf
|
validate :acceptable_pdf
|
||||||
|
|
||||||
before_save :update_printed_at, if: :will_save_change_to_status?
|
before_save :update_printed_at, if: :will_save_change_to_status?
|
||||||
before_save :update_paid_at, if: :will_save_change_to_status?
|
before_save :update_paid_at, if: :will_save_change_to_status?
|
||||||
before_save :update_status_changed_at, if: :will_save_change_to_status?
|
before_save :update_status_changed_at, if: :will_save_change_to_status?
|
||||||
before_save :set_cost_qm
|
before_save :set_cost_qm
|
||||||
|
before_save :calc_cost, if: :printed_pages_changes?
|
||||||
|
|
||||||
# TODO: works only when job is created. Should move analyzer to activestorage :https://discuss.rubyonrails.org/t/active-storage-in-production-lessons-learned-and-in-depth-look-at-how-it-works/83289
|
# TODO: works only when job is created. Should move analyzer to activestorage :https://discuss.rubyonrails.org/t/active-storage-in-production-lessons-learned-and-in-depth-look-at-how-it-works/83289
|
||||||
after_create_commit :analyze_pdf
|
after_create_commit :analyze_pdf
|
||||||
|
|
||||||
# NOTE: Multiple status if paing before brinting?
|
# NOTE: Multiple status if paing before brinting?
|
||||||
enum status: {
|
enum :status, {
|
||||||
open: 0,
|
open: 0,
|
||||||
printing: 1,
|
printing: 1,
|
||||||
pickup: 2,
|
pickup: 2,
|
||||||
@@ -24,6 +29,8 @@ class Job < ApplicationRecord
|
|||||||
canceled: 4
|
canceled: 4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AVAILABLE_PAGE_FORMATS = [ :a0, :a1, :a2, :a3 ]
|
||||||
|
|
||||||
# NOTE: only named status are returned because of WHERE/IN clause for the enum values
|
# 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 pickup paid canceled]) }
|
scope :in_status_order, -> { in_order_of(:status, %w[open printing pickup paid canceled]) }
|
||||||
|
|
||||||
@@ -86,8 +93,24 @@ class Job < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def increment_page(din)
|
||||||
|
return false unless AVAILABLE_PAGE_FORMATS.include?(din.to_sym)
|
||||||
|
public_send("number_of_plans_#{din}=", public_send("number_of_plans_#{din}") + 1) if respond_to? "number_of_plans_#{din}="
|
||||||
|
save
|
||||||
|
end
|
||||||
|
|
||||||
|
def decrement_page(din)
|
||||||
|
return false unless AVAILABLE_PAGE_FORMATS.include?(din.to_sym)
|
||||||
|
public_send("number_of_plans_#{din}=", public_send("number_of_plans_#{din}") - 1) if respond_to? "number_of_plans_#{din}="
|
||||||
|
save
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def printed_pages_changes?
|
||||||
|
costum_qm_plan_previously_changed? || number_of_plans_a0_changed? || number_of_plans_a1_changed? || number_of_plans_a2_changed? || number_of_plans_a3_changed?
|
||||||
|
end
|
||||||
|
|
||||||
def update_printed_at
|
def update_printed_at
|
||||||
self.printed_at = Time.now if pickup? || (paid? && printed_at.nil?)
|
self.printed_at = Time.now if pickup? || (paid? && printed_at.nil?)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td class="p-3 text-sm text-hsrm-gray whitespace-nowrap w-6">
|
<td class="p-3 text-sm text-hsrm-gray whitespace-nowrap w-6">
|
||||||
<% if job.pdf.attached? %>
|
<% if job.pdf.attached? %>
|
||||||
<%= link_to_if job.printing?, image_tag(url_for(job.pdf.preview(resize_to_limit: [100, 100]))), job.pdf, download:true, class: "shadow-lg" %>
|
<%= link_to_if job.printing?, image_tag(url_for(job.pdf.preview(resize_to_limit: [100, 100]))), job.pdf, target: "_blank", class: "shadow-lg" %>
|
||||||
<!--<iframe src=<%= url_for(job.pdf) %> width="500" height="700" style="border: none;"></iframe>-->
|
<!--<iframe src=<%= url_for(job.pdf) %> width="500" height="700" style="border: none;"></iframe>-->
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
@@ -16,42 +16,31 @@
|
|||||||
<td class="p-3 text-sm text-hsrm-gray whitespace-nowrap">
|
<td class="p-3 text-sm text-hsrm-gray whitespace-nowrap">
|
||||||
<% if job.pdf.attached? %>
|
<% if job.pdf.attached? %>
|
||||||
<%#= link_to job.pdf.filename, rails_blob_path(job.pdf, disposition: "attachment") %>
|
<%#= link_to job.pdf.filename, rails_blob_path(job.pdf, disposition: "attachment") %>
|
||||||
<%= link_to job.pdf.filename, job.pdf, download:true %>
|
<%= link_to_if job.printing?, job.pdf.filename, job.pdf, download:true %>
|
||||||
<span class="p-1.5 bg-gray-300 bg-opacity-50 text-hsrm-gray font-medium rounded-lg ml-2">
|
<span class="p-1.5 bg-gray-300 bg-opacity-50 text-hsrm-gray font-medium rounded-lg ml-2">
|
||||||
<%=number_to_human_size job.pdf.blob.byte_size%>
|
<%=number_to_human_size job.pdf.blob.byte_size%>
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
|
<% Job::AVAILABLE_PAGE_FORMATS.each do |din| %>
|
||||||
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap">
|
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap">
|
||||||
<% if job.printing? %>
|
<% if job.printing? %>
|
||||||
|
<div class="flex flex-col items-center">
|
||||||
<span class="p-1 bg-gray-300 bg-opacity-50 font-medium rounded-lg inline-block">
|
<span class="p-1 bg-gray-300 bg-opacity-50 font-medium rounded-lg inline-block">
|
||||||
<%= button_to icon("chevron-up", class: "size-5 inline", title: "erhöhen"), operator_job_path(job), method: :patch, form_class: "inline" %>
|
<%= button_to icon("chevron-up", class: "size-5 inline", title: "erhöhen"), increment_page_operator_job_path(job, din:), method: :patch, form_class: "inline" %>
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
<span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg text-center">
|
<span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg text-center">
|
||||||
<%= job.number_of_plans_a0 %>
|
<%= job.public_send("number_of_plans_#{din}") if job.respond_to? "number_of_plans_#{din}" %>
|
||||||
</span>
|
</span>
|
||||||
<% if job.printing? %>
|
<% if job.printing? %>
|
||||||
<span class="p-1 bg-gray-300 bg-opacity-50 font-medium rounded-lg inline-block">
|
<span class="p-1 bg-gray-300 bg-opacity-50 font-medium rounded-lg inline-block">
|
||||||
<%= button_to icon("chevron-down", class: "size-5 inline", title: "verringern"), operator_job_path(job), method: :patch, form_class: "inline" %>
|
<%= button_to icon("chevron-down", class: "size-5 inline", title: "verringern"), decrement_page_operator_job_path(job, din:), method: :patch, form_class: "inline" %>
|
||||||
</span>
|
</span>
|
||||||
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap">
|
<% end %>
|
||||||
<span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg">
|
|
||||||
<%= job.number_of_plans_a1 %>
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap">
|
|
||||||
<span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg">
|
|
||||||
<%= job.number_of_plans_a2 %>
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap">
|
|
||||||
<span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg">
|
|
||||||
<%= job.number_of_plans_a3 %>
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td class="p-3 text-sm text-right text-hsrm-gray whitespace-nowrap">
|
<td class="p-3 text-sm text-right text-hsrm-gray whitespace-nowrap">
|
||||||
<span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg">
|
<span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg">
|
||||||
<%= job.costum_qm_plan.round(2) %> m²
|
<%= job.costum_qm_plan.round(2) %> m²
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ Rails.application.routes.draw do
|
|||||||
patch "pickup"
|
patch "pickup"
|
||||||
patch "printing"
|
patch "printing"
|
||||||
patch "paid"
|
patch "paid"
|
||||||
|
patch "increment_page"
|
||||||
|
patch "decrement_page"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user