From c195cd3b22a3c06ccbb024e0bfae3b2d64d6719a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20B=C3=B6hm?= Date: Mon, 9 Sep 2024 14:35:07 +0200 Subject: [PATCH] Many Changes: Rename privacy_policy, fixed seed.rb, fixed status in migration file, created new job for operator --- app/controllers/jobs_controller.rb | 2 +- app/controllers/operator/jobs_controller.rb | 4 +- app/helpers/application_helper.rb | 6 ++- app/models/job.rb | 5 +- app/views/jobs/_form.html.erb | 2 +- app/views/operator/jobs/_form.html.erb | 58 ++++++++++----------- app/views/operator/jobs/index.html.erb | 7 ++- app/views/operator/jobs/new.html.erb | 5 ++ db/migrate/20240727101347_create_jobs.rb | 7 +-- db/schema.rb | 5 +- db/seeds.rb | 2 +- 11 files changed, 59 insertions(+), 44 deletions(-) create mode 100644 app/views/operator/jobs/new.html.erb diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb index 850303e..9e6be22 100644 --- a/app/controllers/jobs_controller.rb +++ b/app/controllers/jobs_controller.rb @@ -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 diff --git a/app/controllers/operator/jobs_controller.rb b/app/controllers/operator/jobs_controller.rb index 3af8185..9073678 100644 --- a/app/controllers/operator/jobs_controller.rb +++ b/app/controllers/operator/jobs_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d37828c..99be053 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/models/job.rb b/app/models/job.rb index 1d4fa47..b55005a 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -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? diff --git a/app/views/jobs/_form.html.erb b/app/views/jobs/_form.html.erb index 4ad8d4c..3c390cb 100644 --- a/app/views/jobs/_form.html.erb +++ b/app/views/jobs/_form.html.erb @@ -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" %>
- <%= 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" %>
<%= 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" %> diff --git a/app/views/operator/jobs/_form.html.erb b/app/views/operator/jobs/_form.html.erb index 8bd42d0..94af127 100644 --- a/app/views/operator/jobs/_form.html.erb +++ b/app/views/operator/jobs/_form.html.erb @@ -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? %>

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

-
- <%= 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" %> -
-
- <%= 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" %> -
-
- <%= 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" %> -
-
- <%= 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" %> -
-
- <%= 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" %> -
- -
- <%= form.check_box :privacy_policy_accepted, class: "mt-2 h-5 w-5" %> <%= form.label :privacy_policy_accepted, "Datenschutzerklärung akzeptiert", class: "p-2" %> -
+ <% if edit_form? %> +
+ <%= 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" %> +
+
+ <%= 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" %> +
+
+ <%= 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" %> +
+
+ <%= 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" %> +
+
+ <%= 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" %> +
+ <% else %> +
+ <%= 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" %> +
+ <% end %>
- <%= 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" %>
<% end %> diff --git a/app/views/operator/jobs/index.html.erb b/app/views/operator/jobs/index.html.erb index fc44df6..38c2d84 100644 --- a/app/views/operator/jobs/index.html.erb +++ b/app/views/operator/jobs/index.html.erb @@ -15,7 +15,12 @@ <%= icon(status_icon(:printing), class: "icon") %> Printing - <%= render partial: 'start_next_job_btn', locals: { jobs: @openjobs } %> +
+
+ <%= 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" %> +
+ <%= render partial: 'start_next_job_btn', locals: { jobs: @openjobs } %> +
<%# render partial: "job_card", collection: @printingjobs, as: :job %>
diff --git a/app/views/operator/jobs/new.html.erb b/app/views/operator/jobs/new.html.erb new file mode 100644 index 0000000..1331f29 --- /dev/null +++ b/app/views/operator/jobs/new.html.erb @@ -0,0 +1,5 @@ +
+

Druckauftrag erstellen

+ <%= 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" %> +
diff --git a/db/migrate/20240727101347_create_jobs.rb b/db/migrate/20240727101347_create_jobs.rb index 90b3f0e..05ce13a 100644 --- a/db/migrate/20240727101347_create_jobs.rb +++ b/db/migrate/20240727101347_create_jobs.rb @@ -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,9 +22,10 @@ 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 end -end \ No newline at end of file +end diff --git a/db/schema.rb b/db/schema.rb index ee82797..6736fc4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" diff --git a/db/seeds.rb b/db/seeds.rb index 684ce7b..d58c6f0 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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!