From fd3149b13f990a64640022f3f93f8a86f882a185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20B=C3=B6hm?= Date: Sat, 30 May 2026 01:45:23 +0200 Subject: [PATCH] Added condition badge in show and removed in_use --- app/models/item.rb | 3 +-- app/views/items/show.html.erb | 18 ++++++++++++------ app/views/layouts/_badge.html.erb | 23 ++++++++++++++++------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/app/models/item.rb b/app/models/item.rb index 1b05f5e..2e6b144 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -112,9 +112,8 @@ class Item < ApplicationRecord 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 + condition end private diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb index 4bc3822..e594c06 100644 --- a/app/views/items/show.html.erb +++ b/app/views/items/show.html.erb @@ -15,18 +15,22 @@ --> -<% content_for :title, "Artikel-Details: #{@item.name}" %> +<% content_for :title, "Artikel-Details" %> <% content_for :top_bar_actions do %>
<%= link_to items_path, class: "py-2 px-3 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 flex items-center gap-1.5 shadow-sm transition" do %> - Zurück + <% end %> <%= link_to edit_item_path(@item), class: "py-2 px-3 text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 rounded-lg flex items-center gap-1.5 shadow-sm transition" do %> - Bearbeiten + <% end %>
<% end %> @@ -42,9 +46,11 @@

<%= @item.name %>

- - <%= @item.category.name %> - + +
+ <%= render "layouts/badge", type: @item.condition_badge_type %> + <%= render "layouts/badge", type: :category, label: @item.category.name %> +

diff --git a/app/views/layouts/_badge.html.erb b/app/views/layouts/_badge.html.erb index 365a08b..3921d28 100644 --- a/app/views/layouts/_badge.html.erb +++ b/app/views/layouts/_badge.html.erb @@ -1,11 +1,12 @@ <% - # optons: class = overide css class - # label = overide label - # icon_type = choose one of the given icons. - # icon_svg = costum svg icon + # options: class = override css class + # label = override label + # icon_type = choose one of the given icons. + # icon_svg = custom svg icon # 1. Standard-Design festlegen (Fallback) css = local_assigns[:class] || "" + type = local_assigns[:type] || "" # 2. Icons als Strings definieren icon_user = '' @@ -13,11 +14,12 @@ icon_storage = '' icon_in_use = '' icon_new = '' - icon_as_new = '' + icon_as_new = '' icon_used = '' icon_heavy = '' icon_defective = '' icon_unknown = '' + icon_category = '' # 3. Logik-Weiche für Farben, Standard-Icons und Standard-Labels case type.to_s @@ -42,12 +44,19 @@ 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") + when "category" + css, computed_icon, computed_label = "bg-blue-50 text-blue-800 border-blue-200", icon_category, "" 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 = local_assigns[:icon_svg].present? ? local_assigns[:icon_svg] : computed_icon.to_s.html_safe + final_icon = if local_assigns[:icon_svg].present? + local_assigns[:icon_svg] + elsif local_assigns[:icon_type].present? + local_assigns[:icon_type] + else + computed_icon.to_s.html_safe + end %>