Added condition for items and started with localize
Some checks failed
CI / scan_ruby (push) Has been cancelled
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
CI / system-test (push) Has been cancelled

This commit is contained in:
2026-05-28 22:28:13 +02:00
parent edf3886b94
commit 9e18b233d9
10 changed files with 242 additions and 125 deletions

View File

@@ -6,6 +6,15 @@ class Item < ApplicationRecord
# ohne dass dafür Spalten in der Datenbank existieren müssen.
attr_accessor :user_name, :room_name
enum :condition, {
unknown: "unknown",
new_item: "new_item",
as_new: "as_new",
used: "used",
heavily_used: "heavily_used",
defective: "defective"
}
belongs_to :category
belongs_to :user, optional: true # Optional, falls im Raum oder Lager
belongs_to :room, optional: true # Optional, falls beim User oder Lager
@@ -71,6 +80,43 @@ class Item < ApplicationRecord
end
end
# Holt die saubere Übersetzung vollautomatisch über die Rails-Konvention
# In app/models/item.rb
def human_condition
# Holt den nackten String-Wert direkt aus der Spalte
current_condition = self[:condition]
return nil if current_condition.blank?
Item.human_attribute_name("conditions.#{current_condition}")
end
# 1. Ermittelt den abstrakten Standort-Typen für das Badge
def location_badge_type
if user_id.present?
"user"
elsif room_id.present?
"room"
else
"storage"
end
end
# 2. Liefert den passenden Text für das Standort-Badge
def location_badge_label(short_room: false)
if user.present?
user.name
elsif room.present?
short_room ? room.name : room.name_with_building
else
"Hauptlager"
end
end
# 3. Ermittelt den abstrakten Zustands-Typen für das Badge (Berücksichtigt deinen Umlauf)
def condition_badge_type
(user_id.present? || room_id.present?) ? "in_use" : condition
end
private
def either_user_or_room