diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 927d1fa..fd37611 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -125,6 +125,6 @@ class ItemsController < ApplicationController def item_params # 'user_name' und 'room_name' müssen in die Strong Parameters aufgenommen werden! - params.require(:item).permit(:name, :sku, :sticker_id, :serial_number, :price, :notes, :category_id, :user_id, :room_id, :user_name, :room_name) + params.require(:item).permit(:name, :sku, :sticker_id, :serial_number, :price, :notes, :category_id, :user_id, :room_id, :user_name, :room_name, :condition) end end diff --git a/app/models/item.rb b/app/models/item.rb index 09c6909..1b05f5e 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -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 diff --git a/app/views/items/_form.html.erb b/app/views/items/_form.html.erb index 08f258c..86b47c3 100644 --- a/app/views/items/_form.html.erb +++ b/app/views/items/_form.html.erb @@ -63,6 +63,23 @@ +
+ + <%= form.label :condition, Item.human_attribute_name(:condition), class: "block text-sm font-semibold text-gray-700" %> +
+ + <%= form.select :condition, + Item.conditions.keys.map { |cond| [Item.human_attribute_name("conditions.#{cond}"), cond] }, + {}, + class: "py-2.5 px-3 block w-full border border-gray-300 rounded-lg text-sm bg-gray-50/50 focus:border-blue-500 focus:ring-blue-500 appearance-none pr-10" %> + + +
+ +
+
+
+
diff --git a/app/views/items/_list.html.erb b/app/views/items/_list.html.erb index b4f7cd0..778e1a0 100644 --- a/app/views/items/_list.html.erb +++ b/app/views/items/_list.html.erb @@ -1,13 +1,12 @@
- - - + +
<% items.each do |item| %>
- +
@@ -17,7 +16,7 @@ <% end %> - +
@@ -27,33 +26,27 @@ <% end %>
- -
+ +
<%= item.category.name %> - SKU: <%= item.sku %> + SKU: <%= item.sku.presence || "—" %> + + SN: <%= item.serial_number.presence || "—" %>
- -
- <% if item.user.present? %> - - - <%= item.user.name %> - - <% elsif item.room.present? %> - - - <%= item.room.name %> - - <% else %> - - - Hauptlager - - <% end %> + +
+ + + <%= render "layouts/badge", type: item.location_badge_type, label: item.location_badge_label(short_room: true) %> + + + <%= render "layouts/badge", type: item.condition_badge_type %> +
+
@@ -71,103 +64,74 @@ <% end %>
- - - - diff --git a/app/views/layouts/_badge.html.erb b/app/views/layouts/_badge.html.erb new file mode 100644 index 0000000..b688fa0 --- /dev/null +++ b/app/views/layouts/_badge.html.erb @@ -0,0 +1,56 @@ +<% + # optons: class = overide css class + # label = overide label + # icon_type = choose one of the given icons. + # icon_svg = costum svg icon + + # 1. Standard-Design festlegen (Fallback) + css = local_assigns[:class] || "" + + # 2. Icons als Strings definieren + icon_user = '' + icon_room = '' + icon_storage = '' + icon_in_use = '' + icon_new = '' + icon_as_new = '' + icon_used = '' + icon_heavy = '' + icon_defective = '' + icon_unknown = '' + + # 3. Logik-Weiche für Farben, Standard-Icons und Standard-Labels + case type.to_s + when "storage" + css, computed_icon, computed_label = "bg-amber-50 text-amber-800 border-amber-200", icon_storage, "Hauptlager" + when "user" + css, computed_icon, computed_label = "bg-green-50 text-green-800 border-green-200", icon_user, "" + when "room" + css, computed_icon, computed_label = "bg-blue-50 text-blue-800 border-blue-200", icon_room, "" + when "in_use" + css, computed_icon, computed_label = "bg-gray-100 text-gray-600 border-gray-200", icon_in_use, "In Benutzung" + when "new_item" + css, computed_icon, computed_label = "bg-green-50 text-green-700 border-green-200", icon_new, Item.human_attribute_name("conditions.new_item") + when "as_new" + css, computed_icon, computed_label = "bg-emerald-50 text-emerald-700 border-emerald-200", icon_as_new, Item.human_attribute_name("conditions.as_new") + when "used" + css, computed_icon, computed_label = "bg-yellow-50 text-yellow-700 border-yellow-200", icon_used, Item.human_attribute_name("conditions.used") + when "heavily_used" + css, computed_icon, computed_label = "bg-orange-50 text-orange-700 border-orange-200", icon_heavy, Item.human_attribute_name("conditions.heavily_used") + when "defective" + css, computed_icon, computed_label = "bg-red-50 text-red-700 border-red-200", icon_defective, Item.human_attribute_name("conditions.defective") + css += " animate-pulse font-bold" + when "unknown" + css, computed_icon, computed_label = "bg-gray-50 text-gray-400 border-gray-100", icon_unknown, Item.human_attribute_name("conditions.unknown") + end + + # 4. Optionale Variablen-Überlagerung von außen (Falls manuell übergeben) + final_label = local_assigns[:label].presence || computed_label + final_icon = local_assigns[:icon_type].present? ? local_assigns[:icon_type] : computed_icon.to_s.html_safe + final_icon = lcoal_assigns[:icon_svg].present? ? local_assigns[:icon_svg] : computed_icon.to_s.html_safe +%> + + + <%= final_icon if final_icon.present? %> + <%= final_label %> + diff --git a/config/application.rb b/config/application.rb index 3ea0a6b..25a2058 100644 --- a/config/application.rb +++ b/config/application.rb @@ -16,6 +16,12 @@ module Vault171 # Common ones are `templates`, `generators`, or `middleware`, for example. config.autoload_lib(ignore: %w[assets tasks]) + # Setzt die Standard-Sprache der App dauerhaft auf Deutsch + config.i18n.default_locale = :de + + # Erlaubt Rails, auch Unterordner in locales zu durchsuchen + config.i18n.available_locales = [ :de, :en ] + # Configuration for the application, engines, and railties goes here. # # These settings can be overridden in specific environments using the files diff --git a/config/locales/de.yml b/config/locales/de.yml new file mode 100644 index 0000000..4a7a053 --- /dev/null +++ b/config/locales/de.yml @@ -0,0 +1,12 @@ +de: + activerecord: + attributes: + item: + condition: "Zustand bei Einlagerung" + item/conditions: + unknown: "Unbekannt" + new_item: "Neu" + as_new: "Neuwertig" + used: "Gebraucht" + heavily_used: "Stark Gebraucht" + defective: "Defekt" \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 6c349ae..c4faa47 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -28,4 +28,14 @@ # enabled: "ON" en: - hello: "Hello world" + activerecord: + attributes: + item: + condition: "Condition upon storage" + conditions: + unknown: "Unknown" + new_item: "New" + as_new: "Like New" + used: "Used" + heavily_used: "Heavily Used" + defective: "Defective" diff --git a/db/migrate/20260528181506_add_condition_to_items.rb b/db/migrate/20260528181506_add_condition_to_items.rb new file mode 100644 index 0000000..91fc7af --- /dev/null +++ b/db/migrate/20260528181506_add_condition_to_items.rb @@ -0,0 +1,5 @@ +class AddConditionToItems < ActiveRecord::Migration[8.1] +def change + add_column :items, :condition, :string, default: "unknown", null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 0e12cd1..d0a708f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.1].define(version: 2026_05_21_125254) do +ActiveRecord::Schema[8.1].define(version: 2026_05_28_181506) do create_table "assignment_logs", force: :cascade do |t| t.datetime "assigned_at" t.datetime "created_at", null: false @@ -50,6 +50,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_05_21_125254) do create_table "items", force: :cascade do |t| t.integer "category_id" + t.string "condition", default: "unknown", null: false t.datetime "created_at", null: false t.string "name" t.text "notes"