Many Changes: Rename privacy_policy, fixed seed.rb, fixed status in migration file, created new job for operator
This commit is contained in:
@@ -83,6 +83,6 @@ class JobsController < ApplicationController
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def job_params
|
||||
params.require(:job).permit(:costumer_id, :costumer_firstname, :costumer_lastname, :privacy_policy_accepted, :pdf)
|
||||
params.require(:job).permit(:costumer_id, :costumer_firstname, :costumer_lastname, :privacy_policy, :pdf)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,6 +20,7 @@ class Operator::JobsController < ApplicationController
|
||||
# POST /jobs or /jobs.json
|
||||
def create
|
||||
@job = Job.new(job_params)
|
||||
@job.created_by_operator = true
|
||||
|
||||
respond_to do |format|
|
||||
if @job.save
|
||||
@@ -43,7 +44,6 @@ class Operator::JobsController < ApplicationController
|
||||
format.html { redirect_to operator_jobs_url, notice: "Job was successfully updated." }
|
||||
else
|
||||
flash[:alert] = "Job was not updated."
|
||||
format.turbo_stream
|
||||
format.html { render :edit, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
@@ -110,7 +110,7 @@ class Operator::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, :status, :privacy_policy_accepted, :intern, :cost_center, :number_of_plans_a0, :number_of_plans_a1, :number_of_plans_a2, :number_of_plans_a3, :costum_qm_plan)
|
||||
params.require(:job).permit(:pdf, :operator_id, :costumer_id, :operator_firstname, :operator_lastname, :costumer_firstname, :costumer_lastname, :status, :privacy_policy, :intern, :cost_center, :number_of_plans_a0, :number_of_plans_a1, :number_of_plans_a2, :number_of_plans_a3, :costum_qm_plan)
|
||||
end
|
||||
|
||||
# FIXME: Move broadcast to model though i don't think view logic belongs in the model
|
||||
|
||||
@@ -33,4 +33,8 @@ module ApplicationHelper
|
||||
def is_admin_or_operator?
|
||||
current_user.admin? || current_user.operator?
|
||||
end
|
||||
|
||||
def edit_form?
|
||||
action_name != "new" && action_name != "create"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,11 +4,10 @@ class Job < ApplicationRecord
|
||||
|
||||
has_one_attached :pdf, dependent: :purge
|
||||
|
||||
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_presence_of :costumer_firstname, :costumer_lastname, :pdf
|
||||
validates :privacy_policy, acceptance: true, unless: :created_by_operator?
|
||||
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
|
||||
|
||||
before_save :update_printed_at, if: :will_save_change_to_status?
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<%= form.file_field :pdf, accept: "application/pdf", class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
<div>
|
||||
<%= form.check_box :privacy_policy_accepted, class: "mt-2 h-5 w-5" %> <%= form.label :privacy_policy_accepted, "Datenschutzerklärung akzeptiert", class: "p-2" %>
|
||||
<%= form.check_box :privacy_policy, class: "mt-2 h-5 w-5" %> <%= form.label :privacy_policy, "Datenschutzerklärung akzeptiert", class: "p-2" %>
|
||||
</div>
|
||||
<div class="inline">
|
||||
<%= 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" %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= form_with(model: job, url: operator_job_path(job), method: "patch", class: "contents") do |form| %>
|
||||
<%= form_with(model: [:operator, job], class: "contents") do |form| %>
|
||||
<% if job.errors.any? %>
|
||||
<div id="error_explanation" class="px-3 py-2 mt-3 font-medium text-red-500 border-l rounded-lg shadow-lg bg-red-50 border-red" >
|
||||
<h2><%= pluralize(job.errors.count, "error") %>
|
||||
@@ -26,6 +26,7 @@
|
||||
<%= form.label :cost_center %>
|
||||
<%= 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>
|
||||
<% if edit_form? %>
|
||||
<div class="my-5">
|
||||
<%= form.label :number_of_plans_a0 %>
|
||||
<%= 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" %>
|
||||
@@ -46,14 +47,13 @@
|
||||
<%= form.label :costum_qm_plan %>
|
||||
<%= form.number_field :costum_qm_plan, in: 0..20.0, step: 0.01 ,class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
<!-- <div>
|
||||
<% else %>
|
||||
<div>
|
||||
<%= form.label :pdf, "Plan auswählen (PDF-Format)" %>
|
||||
<%= form.file_field :pdf, accept: "application/pdf", class: "block shadow-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div> -->
|
||||
<div>
|
||||
<%= form.check_box :privacy_policy_accepted, class: "mt-2 h-5 w-5" %> <%= form.label :privacy_policy_accepted, "Datenschutzerklärung akzeptiert", class: "p-2" %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="inline">
|
||||
<%= 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" %>
|
||||
<%= form.submit edit_form? && "Speichern" || "Druckauftrag anlegen", 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 %>
|
||||
|
||||
@@ -15,8 +15,13 @@
|
||||
<%= icon(status_icon(:printing), class: "icon") %>
|
||||
Printing
|
||||
</h1>
|
||||
<div class="flex gap-2">
|
||||
<div id="start_manual_job_btn">
|
||||
<%= link_to icon("printer", class: "icon icon-nohover size-6 mr-2", title: "Nächsten Druckauftrag starten") + "Druckauftrag erstellen" , new_operator_job_path, class: "btn block bg-green-400 text-black" %>
|
||||
</div>
|
||||
<%= render partial: 'start_next_job_btn', locals: { jobs: @openjobs } %>
|
||||
</div>
|
||||
</div>
|
||||
<%# render partial: "job_card", collection: @printingjobs, as: :job %>
|
||||
<div class="min-w-full overflow-auto shadow-lg">
|
||||
<table class="w-full py-8 bg-white table-auto">
|
||||
|
||||
5
app/views/operator/jobs/new.html.erb
Normal file
5
app/views/operator/jobs/new.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<div class="mx-auto md:w-2/3 w-full">
|
||||
<h1 class="font-bold text-4xl">Druckauftrag erstellen</h1>
|
||||
<%= render "form", job: @job %>
|
||||
<%= link_to "Zurück zur Übersicht", operator_jobs_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
||||
</div>
|
||||
@@ -14,7 +14,7 @@ class CreateJobs < ActiveRecord::Migration[7.1]
|
||||
t.datetime :paid_at
|
||||
t.boolean :intern, default: false
|
||||
t.string :cost_center
|
||||
t.string :status, default: 0, index: true
|
||||
t.string :status, default: "open", index: true
|
||||
t.integer :number_of_plans_a0, default: 0
|
||||
t.integer :number_of_plans_a1, default: 0
|
||||
t.integer :number_of_plans_a2, default: 0
|
||||
@@ -22,7 +22,8 @@ class CreateJobs < ActiveRecord::Migration[7.1]
|
||||
t.float :costum_qm_plan, default: 0
|
||||
t.float :cost, default: 0
|
||||
t.float :cost_qm, default: 0
|
||||
t.boolean :privacy_policy_accepted, default: false
|
||||
t.boolean :privacy_policy, default: false
|
||||
t.boolean :created_by_operator, default: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
5
db/schema.rb
generated
5
db/schema.rb
generated
@@ -53,7 +53,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_08_26_144016) do
|
||||
t.datetime "paid_at"
|
||||
t.boolean "intern", default: false
|
||||
t.string "cost_center"
|
||||
t.string "status", default: "0"
|
||||
t.string "status", default: "open"
|
||||
t.integer "number_of_plans_a0", default: 0
|
||||
t.integer "number_of_plans_a1", default: 0
|
||||
t.integer "number_of_plans_a2", default: 0
|
||||
@@ -61,7 +61,8 @@ ActiveRecord::Schema[7.2].define(version: 2024_08_26_144016) do
|
||||
t.float "costum_qm_plan", default: 0.0
|
||||
t.float "cost", default: 0.0
|
||||
t.float "cost_qm", default: 0.0
|
||||
t.boolean "privacy_policy_accepted", default: false
|
||||
t.boolean "privacy_policy", default: false
|
||||
t.boolean "created_by_operator", default: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["costumer_id"], name: "index_jobs_on_costumer_id"
|
||||
|
||||
@@ -36,7 +36,7 @@ end
|
||||
'DasNächsteMalGeheIchWoAndersHin.pdf' ].shuffle.each do |pdf|
|
||||
status = %i[open open open open open printing pickup paid canceled].sample
|
||||
|
||||
job = Job.new(status:, privacy_policy_accepted: true)
|
||||
job = Job.new(status:, privacy_policy: true)
|
||||
job.pdf = File.open(Rails.root.join('db/pdfs/', pdf))
|
||||
job.costumer = students[rand(0...4)]
|
||||
job.save!
|
||||
|
||||
Reference in New Issue
Block a user