Renamed job associations for operator and costumer

This commit is contained in:
2024-10-02 09:04:17 +02:00
parent 5237ab9af6
commit e2cf5bb19e
9 changed files with 23 additions and 26 deletions

View File

@@ -1,8 +1,8 @@
class Job < ApplicationRecord
attr_accessor :current_user
belongs_to :costumer, class_name: "User", optional: true, counter_cache: :jobs_as_costumer_count, inverse_of: :jobs_as_costumer
belongs_to :operator, class_name: "User", optional: true, counter_cache: :jobs_as_operator_count, inverse_of: :jobs_as_operator
belongs_to :costumer, class_name: "User", optional: true, counter_cache: :costumer_jobs_count, inverse_of: :costumer_jobs
belongs_to :operator, class_name: "User", optional: true, counter_cache: :operator_jobs_count, inverse_of: :operator_jobs
belongs_to :creator, class_name: "User", optional: true, counter_cache: :created_jobs_count, inverse_of: :created_jobs
belongs_to :cashier, class_name: "User", optional: true, counter_cache: :cashed_jobs_count, inverse_of: :cashed_jobs

View File

@@ -1,8 +1,8 @@
class User < ApplicationRecord
has_secure_password
# has_many :jobs
has_many :jobs_as_costumer, foreign_key: :costumer_id, class_name: "Job"
has_many :jobs_as_operator, foreign_key: :operator_id, class_name: "Job"
has_many :costumer_jobs, foreign_key: :costumer_id, class_name: "Job"
has_many :operator_jobs, foreign_key: :operator_id, class_name: "Job"
has_many :created_jobs, foreign_key: :creator_id, class_name: "Job"
has_many :cashed_jobs, foreign_key: :cashier_id, class_name: "Job"
@@ -45,7 +45,7 @@ class User < ApplicationRecord
end
def self.ransackable_attributes(auth_object = nil)
[ "created_at", "email", "firstname", "id", "jobs_as_costumer_count", "jobs_as_operator_count", "lastname", "role", "verified", "name" ]
[ "created_at", "email", "firstname", "id", "costumer_jobs_count", "operator_jobs_count", "lastname", "role", "verified", "name" ]
end
def self.ransackable_associations(auth_object = nil)

View File

@@ -8,8 +8,8 @@
<p>E-Mail Verifiziert:
<%= icon bool_icon(user.verified), class: "icon #{user.verified ? "text-green-600" : "text-red-600"}" %></p>
<p><%= user.created_at %></p>
<p>Druckaufträge als Kunde: <%= @user.jobs_as_costumer.size %></p>
<p>davon abgebrochen: <%= @user.jobs_as_costumer.canceled.size %></p>
<p>Druckaufträge als Operator: <%= @user.jobs_as_operator.size %></p>
<p>Druckaufträge als Kunde: <%= @user.costumer_jobs.size %></p>
<p>davon abgebrochen: <%= @user.costumer_jobs.canceled.size %></p>
<p>Druckaufträge als Operator: <%= @user.operator_jobs.size %></p>
<p>Druckaufträge kassiert: <%= @user.cashed_jobs.size %></p>
</div>

View File

@@ -74,7 +74,7 @@
<th class="min-w-24 p-2 py-3 text-left"><%= sort_link(@q, :firstname, "Vorname") %></th>
<th class="min-w-24 p-2 py-3 text-left"><%= sort_link(@q, :lastname, "Nachname") %></th>
<th class="p-2 py-3 text-left"><%= sort_link(@q, :email, "E-Mail-Adresse") %></th>
<th class="w-1 p-2 py-3 text-right text-nowrap"><%= sort_link(@q, :jobs_as_costumer_count, "# Jobs") %></th>
<th class="w-1 p-2 py-3 text-right text-nowrap"><%= sort_link(@q, :costumer_jobs_count, "# Jobs") %></th>
<th class="w-1 p-2 py-3 text-center text-nowrap"><%= sort_link(@q, :created_at, "Registriert am") %></th>
<th class="w-1 p-2 py-3 text-center"><%= sort_link(@q, :role, "Rolle") %></th>
</tr>

View File

@@ -21,7 +21,7 @@
</tr>
</thead>
<tbody id='jobs' class="divide-y divivde-gray-300">
<%= render partial: "jobs/job_tr", collection: @user.created_jobs.order(created_at: :desc).limit(10), as: :job, locals: { no_actions: true } %>
<%= render partial: "jobs/job_tr", collection: @user.costumer_jobs.order(created_at: :desc).limit(10), as: :job, locals: { no_actions: true } %>
</tbody>
</table>
</div>

View File

@@ -22,17 +22,17 @@
<h2 class="p-1 text-lg font-bold border-b-2 border-hsrm-red">Aufgegebene Druckaufträge</h2>
<p>
Aufgegebene Druckaufträge
<%= current_user.jobs_as_costumer.size %>
<%= current_user.costumer_jobs.size %>
</p>
<p>
Abgebrochene Druckaufgräge
<%= current_user.jobs_as_costumer.canceled.size %>
<%= current_user.costumer_jobs.canceled.size %>
</p>
<% if is_admin_or_operator? %>
<h2 class="p-1 text-lg font-bold border-b-2 border-hsrm-red">Bearbeitete Druckaufträge</h2>
<p>
Gedruckte Druckaufträge
<%= current_user.jobs_as_operator.paid.size %>
<%= current_user.operator_jobs.paid.size %>
</p>
<% end %>
<h2 class="p-1 text-lg font-bold border-b-2 border-hsrm-red">Actions</h2>

View File

@@ -10,8 +10,8 @@ class CreateUsers < ActiveRecord::Migration[7.2]
t.boolean :verified, null: false, default: false
t.integer :jobs_as_costumer_count, default: 0
t.integer :jobs_as_operator_count, default: 0
t.integer :costumer_jobs_count, default: 0
t.integer :operator_jobs_count, default: 0
t.integer :created_jobs_count, default: 0
t.integer :cashed_jobs_count, default: 0

4
db/schema.rb generated
View File

@@ -90,8 +90,8 @@ ActiveRecord::Schema[7.2].define(version: 2024_08_26_144016) do
t.string "lastname"
t.string "role", default: "user"
t.boolean "verified", default: false, null: false
t.integer "jobs_as_costumer_count", default: 0
t.integer "jobs_as_operator_count", default: 0
t.integer "costumer_jobs_count", default: 0
t.integer "operator_jobs_count", default: 0
t.integer "created_jobs_count", default: 0
t.integer "cashed_jobs_count", default: 0
t.datetime "created_at", null: false

View File

@@ -30,9 +30,8 @@ students = []
lastname = Faker::Name.unique.last_name
# created_at = Faker::Time.backward(days: 60, period: :day)
created_at = Faker::Time.between_dates(from: Date.today - 60, to: Date.today - 30, period: :day)
email="#{firstname}.#{lastname}@student.hs-rm.de".downcase.gsub('ö', 'oe').gsub('ä', 'ae').gsub('ü', 'ue').gsub('ß', 'ss')
puts "Create Student:" + email
email.delete(" ")
email=I18n.transliterate "#{firstname}.#{lastname}@student.hs-rm.de"
puts "Create Student: " + email
students << User.new(email: email, firstname: firstname, lastname: lastname, password_digest: BCrypt::Password.create("password"), verified: true, created_at: created_at)
students.last.save!
end
@@ -43,9 +42,8 @@ end
lastname = Faker::Name.unique.last_name
created_at = Faker::Time.backward(days: 60, period: :day)
# created_at = Faker::Time.between_dates(from: Date.today - 60, to: Date.today, period: :day)
email="#{firstname}.#{lastname}@student.hs-rm.de".downcase.gsub('ö', 'oe').gsub('ä', 'ae').gsub('ü', 'ue').gsub('ß', 'ss')
email.delete(" ")
puts "Create Student:" + email
email=I18n.transliterate "#{firstname}.#{lastname}@student.hs-rm.de"
puts "Create Student: " + email
User.new(email: email, firstname: firstname, lastname: lastname, password_digest: BCrypt::Password.create("password"), verified: true, created_at: created_at).save!
end
@@ -55,9 +53,8 @@ end
lastname = Faker::Name.unique.last_name
created_at = Faker::Time.backward(days: 60, period: :day)
# created_at = Faker::Time.between_dates(from: Date.today - 60, to: Date.today, period: :day)
email="#{firstname}.#{lastname}@student.hs-rm.de".downcase.gsub('ö', 'oe').gsub('ä', 'ae').gsub('ü', 'ue').gsub('ß', 'ss')
email.delete(" ")
puts "Create Student:" + email
email=I18n.transliterate "#{firstname}.#{lastname}@student.hs-rm.de"
puts "Create Student: " + email
User.new(email: email, firstname: firstname, lastname: lastname, password_digest: BCrypt::Password.create("password"), verified: false, created_at: created_at).save!
end