Many Changes: Rename privacy_policy, fixed seed.rb, fixed status in migration file, created new job for operator

This commit is contained in:
2024-09-09 14:35:07 +02:00
parent cf8cc196a3
commit c195cd3b22
11 changed files with 59 additions and 44 deletions

View File

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

View File

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

View File

@@ -29,8 +29,12 @@ module ApplicationHelper
def profile_tab?
controller_name=="profiles"
end
def is_admin_or_operator?
current_user.admin? || current_user.operator?
end
def edit_form?
action_name != "new" && action_name != "create"
end
end

View File

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

View File

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

View File

@@ -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,34 +26,34 @@
<%= 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>
<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" %>
</div>
<div class="my-5">
<%= form.label :number_of_plans_a1 %>
<%= 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-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-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div class="my-5">
<%= 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>
<%= 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>
<% 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" %>
</div>
<div class="my-5">
<%= form.label :number_of_plans_a1 %>
<%= 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-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-lg rounded-md border border-hsrm-gray outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div class="my-5">
<%= 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>
<% 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>
<% 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 %>

View File

@@ -15,7 +15,12 @@
<%= icon(status_icon(:printing), class: "icon") %>
Printing
</h1>
<%= render partial: 'start_next_job_btn', locals: { jobs: @openjobs } %>
<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">

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