diff --git a/app/models/job.rb b/app/models/job.rb index 321e8c3..b1e2345 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -16,6 +16,7 @@ class Job < ApplicationRecord before_save :update_status_changed_at, if: :will_save_change_to_status? before_save :set_cost_qm before_save :calc_cost, if: :printed_pages_changes? + before_validation :set_costumer_infos # 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 @@ -163,4 +164,9 @@ class Job < ApplicationRecord calc_cost save end + + def set_costumer_infos + self.costumer_firstname = costumer.firstname if self.costumer_firstname.nil? + self.costumer_lastname = costumer.lastname if self.costumer_lastname.nil? + end end diff --git a/app/views/operator/jobs/_job.html.erb b/app/views/operator/jobs/_job.html.erb index f5fb21c..8ae1d50 100644 --- a/app/views/operator/jobs/_job.html.erb +++ b/app/views/operator/jobs/_job.html.erb @@ -7,7 +7,7 @@ Operator ID: <%= job.operator_id %> <% if job.operator %> - (<%= job.operator.name %>) + - <%= job.operator.name %> (<%= job.operator.email %>) <% else %> - <% end %> @@ -16,7 +16,7 @@ Costumer ID: <%= job.costumer_id %> <% if job.costumer %> - (<%= job.costumer.name %>) + - <%= job.costumer.name %> (<%= job.costumer.email %>) <% else %> - <% end %> diff --git a/app/views/operator/jobs/show.html.erb b/app/views/operator/jobs/show.html.erb index d0feebb..80a6bd2 100644 --- a/app/views/operator/jobs/show.html.erb +++ b/app/views/operator/jobs/show.html.erb @@ -1,4 +1,4 @@ -
+
<% if notice.present? %>

<%= notice %>

diff --git a/db/seeds.rb b/db/seeds.rb index 8c07ca8..82527b7 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -17,8 +17,8 @@ User.create!(email: "maximilian.lasser@hs-rm.de", firstname: "Max", lastname: "L # Students students = [] 5.times do - firstname = Faker::Name.unique.first_name - lastname = Faker::Name.unique.last_name + firstname = Faker::Name.unique.first_name.delete(" ") + lastname = Faker::Name.unique.last_name.delete(" ") students << User.new(email: firstname + "." + lastname + "@student.hs-rm.de", firstname: firstname, lastname: lastname, password_digest: BCrypt::Password.create("password"), verified: true) students.last.save! end @@ -29,10 +29,8 @@ end 'DasNächsteMalGeheIchWoAndersHin.pdf' ].shuffle.each do |pdf| status = %i[open open open open open printing pickup paid canceled].sample - job = Job.new(costumer_firstname: Faker::Name.unique.first_name, costumer_lastname: Faker::Name.unique.last_name, - costumer_id: students[rand(0...4)].id, - # number_of_plans_a0: a0, number_of_plans_a1: a1, number_of_plans_a2: a2, number_of_plans_a3: a3, - status:, privacy_policy_accepted: true) + job = Job.new(status:, privacy_policy_accepted: true) job.pdf = File.open(Rails.root.join('db/pdfs/', pdf)) + job.costumer = students[rand(0...4)] job.save! end