Added condition for items and started with localize
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -63,6 +63,23 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-1.5">
|
||||
<!-- Rails schreibt das Label automatisch über die de.yml -->
|
||||
<%= form.label :condition, Item.human_attribute_name(:condition), class: "block text-sm font-semibold text-gray-700" %>
|
||||
<div class="relative">
|
||||
<!-- PURE RAILS KONVENTION: Sicher, verständlich und stabil -->
|
||||
<%= 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" %>
|
||||
|
||||
<!-- Kleiner Custom-Pfeil rechts -->
|
||||
<div class="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none text-gray-400">
|
||||
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M19.5 8.25l-7.5 7.5-7.5-7.5" /></svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="border-gray-200">
|
||||
|
||||
<!-- ========================================================================= -->
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
<div class="bg-white border border-gray-200 rounded-xl shadow-sm overflow-hidden">
|
||||
|
||||
<!-- ========================================================================= -->
|
||||
<!-- 1. MOBIL-ANSICHT: TEXTE BÜNDIG ZUM ARTIKELNAMEN & VERTIKALE BUTTONS -->
|
||||
<!-- ========================================================================= -->
|
||||
<!-- 1. MOBIL-ANSICHT: OPTIMIERT MIT REINEM CODESYMBOL & ZUSTANDS-BADGES -->
|
||||
<!-- ========================================================================= -->
|
||||
<div class="block md:hidden divide-y divide-gray-200 bg-white">
|
||||
<% items.each do |item| %>
|
||||
<div class="p-4 hover:bg-gray-50/50 transition flex items-center justify-between gap-4">
|
||||
|
||||
<!-- LINKER BEREICH: STRUKTURIERTER INHALT -->
|
||||
<!-- LINKER BEREICH: TEXTE BÜNDIG ZUM ARTIKELNAMEN FLUCHTEND -->
|
||||
<div class="flex-1 min-w-0 flex items-start gap-3">
|
||||
|
||||
<!-- Das ID-Badge steht als sauberer, fester Anker ganz links -->
|
||||
@@ -17,7 +16,7 @@
|
||||
</span>
|
||||
<% end %>
|
||||
|
||||
<!-- DIESER CONTAINER ERZWINGT DIE BÜNDIGKEIT UNTER DEM NAMEN -->
|
||||
<!-- TEXT-CONTAINER: ALLES FLUCHTET PERFEKT LINKSBÜNDIG UNTER DEM NAMEN -->
|
||||
<div class="flex-1 min-w-0 space-y-2">
|
||||
|
||||
<!-- Zeile 1: Fetter Artikelname -->
|
||||
@@ -27,33 +26,27 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<!-- Zeile 2: Kategorie & SKU (Jetzt perfekt bündig unter dem Namen!) -->
|
||||
<div class="flex items-center gap-2 text-xs font-medium text-gray-500 font-mono">
|
||||
<!-- Zeile 2: Kategorie, SKU & Seriennummer (SN) als kompakte Kette -->
|
||||
<div class="flex items-center flex-wrap gap-x-2 gap-y-0.5 text-xs font-medium text-gray-500 font-mono">
|
||||
<span class="font-sans font-bold text-gray-400"><%= item.category.name %></span>
|
||||
<span class="text-gray-300">•</span>
|
||||
<span>SKU: <span class="text-gray-700 font-bold"><%= item.sku %></span></span>
|
||||
<span>SKU: <span class="text-gray-700 font-bold"><%= item.sku.presence || "—" %></span></span>
|
||||
<span class="text-gray-300">•</span>
|
||||
<span>SN: <span class="text-gray-700 font-bold"><%= item.serial_number.presence || "—" %></span></span>
|
||||
</div>
|
||||
|
||||
<!-- Zeile 3: Das Standort-Badge (Ebenfalls perfekt bündig unter dem Namen) -->
|
||||
<div class="pt-0.5">
|
||||
<% if item.user.present? %>
|
||||
<span class="inline-flex items-center gap-1.5 text-xs font-bold bg-green-50 text-green-800 px-2.5 py-1 rounded-md border border-green-200 shadow-sm">
|
||||
<svg class="h-3.5 w-3.5 text-green-600 shrink-0" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M15.75 6a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0ZM4.501 20.118a7.5 7.5 0 1 1 14.998 0A17.933 17.933 0 0 1 12 21.75c-2.676 0-5.216-.584-7.499-1.632Z" /></svg>
|
||||
<%= item.user.name %>
|
||||
</span>
|
||||
<% elsif item.room.present? %>
|
||||
<span class="inline-flex items-center gap-1.5 text-xs font-bold bg-blue-50 text-blue-800 px-2.5 py-1 rounded-md border border-blue-200 shadow-sm">
|
||||
<svg class="h-3.5 w-3.5 text-blue-600 shrink-0" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M15 10.5a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" /><path stroke-linecap="round" stroke-linejoin="round" d="M19.5 10.5c0 7.142-7.5 11.25-7.5 11.25s-7.5-4.108-7.5-11.25a7.5 7.5 0 1 1 15 0Z" /></svg>
|
||||
<%= item.room.name %>
|
||||
</span>
|
||||
<% else %>
|
||||
<span class="inline-flex items-center gap-1.5 text-xs font-bold bg-amber-50 text-amber-900 px-2.5 py-1 rounded-md border border-amber-200 shadow-sm">
|
||||
<svg class="h-3.5 w-3.5 text-amber-600 shrink-0" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M21 7.5l-9-5.25L3 7.5m18 0l-9 5.25m9-5.25v9l-9 5.25M3 7.5l9 5.25M3 7.5v9l5.25 3.03M12 12.75v9" /></svg>
|
||||
Hauptlager
|
||||
</span>
|
||||
<% end %>
|
||||
<!-- Zeile 3: Das ultimativ schlanke, automatisierte Badge-Duo im Mobil-Layout -->
|
||||
<div class="flex items-center flex-wrap gap-2 pt-0.5">
|
||||
|
||||
<!-- A: Standort-Badge (Label wird manuell übergeben, da dynamischer Personen-/Raumname) -->
|
||||
<%= render "layouts/badge", type: item.location_badge_type, label: item.location_badge_label(short_room: true) %>
|
||||
|
||||
<!-- B: Zustands-Badge (Vollautomatisch! Text und Icon kommen direkt aus dem Typen) -->
|
||||
<%= render "layouts/badge", type: item.condition_badge_type %>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -71,103 +64,74 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<!-- ========================================================================= -->
|
||||
<!-- 2. DESKTOP-ANSICHT: STICKY-TABELLE (hidden md:block) -->
|
||||
<!-- ========================================================================= -->
|
||||
<div class="hidden md:block overflow-x-auto max-h-[calc(100vh-12rem)]">
|
||||
<table class="min-w-full divide-y divide-gray-200 text-sm">
|
||||
<thead class="bg-gray-50 sticky top-0 z-20 shadow-[0_1px_0_0_rgba(229,231,235,1)]">
|
||||
<tr>
|
||||
<th scope="col" class="px-6 py-3 text-start font-semibold text-gray-500 uppercase tracking-wider">Artikel / Details</th>
|
||||
<th scope="col" class="px-6 py-3 text-start font-semibold text-gray-500 uppercase tracking-wider">SN</th>
|
||||
<th scope="col" class="px-6 py-3 text-start font-semibold text-gray-500 uppercase tracking-wider">Standort / Inhaber</th>
|
||||
<th scope="col" class="px-6 py-3 text-start font-semibold text-gray-500 uppercase tracking-wider">Sticker-ID</th>
|
||||
<th scope="col" class="px-6 py-3 text-end font-semibold text-gray-500 uppercase tracking-wider">Wert</th>
|
||||
<th scope="col" class="px-6 py-3 text-end font-semibold text-gray-500 uppercase tracking-wider">Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-200 bg-white">
|
||||
<% items.each do |item| %>
|
||||
<tr class="hover:bg-gray-50/50 transition">
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<div class="font-semibold text-gray-900"><%= item.name %></div>
|
||||
<div class="text-xs text-gray-400">SKU: <%= item.sku %> • <%= item.category.name %></div>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap font-mono text-xs text-gray-600"><%= item.serial_number %></td>
|
||||
<!-- Spalte 3: Inhaber-Weiche mit markanten Badges (Desktop Tabelle) -->
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm">
|
||||
<% if item.user.present? %>
|
||||
<span class="inline-flex items-center gap-1.5 text-gray-900 font-semibold bg-green-50 text-green-800 px-2.5 py-1 rounded-md border border-green-200 shadow-sm">
|
||||
<!-- Heroicon: user -->
|
||||
<svg class="h-4 w-4 text-green-600 shrink-0" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 6a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0ZM4.501 20.118a7.5 7.5 0 0 1 14.998 0A17.933 17.933 0 0 1 12 21.75c-2.676 0-5.216-.584-7.499-1.632Z" />
|
||||
</svg>
|
||||
<%= item.user.name %>
|
||||
</span>
|
||||
<% elsif item.room.present? %>
|
||||
<span class="inline-flex items-center gap-1.5 text-gray-900 font-semibold bg-blue-50 text-blue-800 px-2.5 py-1 rounded-md border border-blue-200 shadow-sm">
|
||||
<!-- Heroicon: map-pin -->
|
||||
<svg class="h-4 w-4 text-blue-600 shrink-0" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M15 10.5a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" />
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 10.5c0 7.142-7.5 11.25-7.5 11.25s-7.5-4.108-7.5-11.25a7.5 7.5 0 1 1 15 0Z" />
|
||||
</svg>
|
||||
<%= item.room.name_with_building %>
|
||||
</span>
|
||||
<% else %>
|
||||
<span class="inline-flex items-center gap-1.5 text-amber-900 font-semibold bg-amber-50 text-amber-800 px-2.5 py-1 rounded-md border border-amber-200 shadow-sm">
|
||||
<!-- Heroicon: cube / box -->
|
||||
<svg class="h-4 w-4 text-amber-600 shrink-0" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M21 7.5l-9-5.25L3 7.5m18 0l-9 5.25m9-5.25v9l-9 5.25M3 7.5l9 5.25M3 7.5v9l5.25 3.03M12 12.75v9" />
|
||||
</svg>
|
||||
Hauptlager
|
||||
</span>
|
||||
|
||||
<!-- ========================================================================= -->
|
||||
<!-- 2. DESKTOP-ANSICHT: STICKY-TABELLE (Ab md:) -->
|
||||
<!-- ========================================================================= -->
|
||||
<div class="hidden md:block overflow-x-auto max-h-[calc(100vh-12rem)]">
|
||||
<table class="min-w-full divide-y divide-gray-200 text-sm">
|
||||
<thead class="bg-gray-50 sticky top-0 z-20 shadow-[0_1px_0_0_rgba(229,231,235,1)]">
|
||||
<tr>
|
||||
<th scope="col" class="px-6 py-3 text-start font-semibold text-gray-500 uppercase tracking-wider w-24">Sticker-ID</th>
|
||||
<th scope="col" class="px-6 py-3 text-start font-semibold text-gray-500 uppercase tracking-wider">Artikeldetails</th>
|
||||
<th scope="col" class="px-6 py-3 text-start font-semibold text-gray-500 uppercase tracking-wider">Aktueller Standort</th>
|
||||
<th scope="col" class="px-6 py-3 text-center font-semibold text-gray-500 uppercase tracking-wider w-36">Zustand</th>
|
||||
<th scope="col" class="px-6 py-3 text-end font-semibold text-gray-500 uppercase tracking-wider w-24">Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-200 bg-white">
|
||||
<% items.each do |item| %>
|
||||
<tr class="hover:bg-gray-50/50 transition">
|
||||
|
||||
<!-- Spalte 1: Verlinktes Sticker-ID-Badge -->
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<%= link_to item_path(item), data: { turbo_frame: "_top" }, class: "inline-block transition hover:scale-105" do %>
|
||||
<span class="inline-flex items-center font-mono font-black text-xs text-white bg-blue-600 px-2.5 py-1 rounded-md shadow-sm tracking-widest">
|
||||
#<%= item.sticker_id %>
|
||||
</span>
|
||||
<% end %>
|
||||
</td>
|
||||
|
||||
<!-- Spalte 2: Artikelname, Kategorie, SKU & SN direkt darunter im Block -->
|
||||
<td class="px-6 py-4 max-w-[280px] sm:max-w-[350px]">
|
||||
<div class="min-w-0 whitespace-normal break-words leading-tight space-y-1">
|
||||
<%= link_to item_path(item), data: { turbo_frame: "_top" }, class: "font-bold text-gray-900 hover:text-blue-600 hover:underline inline" do %>
|
||||
<%= item.name %>
|
||||
<% end %>
|
||||
</td>
|
||||
|
||||
<!-- STICKER-ID ALS BADGE (Jetzt auch in der Desktop-Tabelle markant) -->
|
||||
<!-- Erste Tabellenspalte der Desktop-Schleife -->
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<%= link_to item_path(item), data: { turbo_frame: "_top" }, class: "inline-block transition hover:scale-105" do %>
|
||||
<span class="inline-flex items-center font-mono font-black text-xs text-white bg-blue-600 px-2.5 py-1 rounded-md shadow-sm tracking-widest">
|
||||
#<%= item.sticker_id %>
|
||||
</span>
|
||||
<% end %>
|
||||
|
||||
<td class="px-6 py-4 whitespace-nowrap text-end font-medium text-gray-900">
|
||||
<%= number_to_currency(item.price, unit: "€", separator: ",", delimiter: ".", format: "%n %u") %>
|
||||
</td>
|
||||
<!-- Letzte Spalte der Desktop-Tabelle in app/views/items/_list.html.erb -->
|
||||
<td class="px-6 py-4 whitespace-nowrap text-end font-medium text-xs w-24 shrink-0">
|
||||
<!-- Mit 'justify-end' fluchten die echten Button-Boxen perfekt bündig rechts -->
|
||||
<div class="flex items-center justify-end gap-2">
|
||||
|
||||
<!-- DETAILS BUTTON (Weißes Button-Design mit feinem Rahmen & Schatten) -->
|
||||
<%= link_to item_path(item),
|
||||
data: { turbo_frame: "_top" },
|
||||
class: "p-2 text-gray-500 hover:text-blue-600 hover:bg-blue-50 rounded-lg border border-gray-200 bg-white shadow-sm flex items-center justify-center transition",
|
||||
title: "Details anzeigen" do %>
|
||||
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M2.036 12.322a1.012 1.012 0 0 1 0-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178Z" />
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" />
|
||||
</svg>
|
||||
<% end %>
|
||||
|
||||
<!-- BEARBEITEN BUTTON (Weißes Button-Design mit feinem Rahmen & Schatten) -->
|
||||
<%= link_to edit_item_path(item),
|
||||
data: { turbo_frame: "_top" },
|
||||
class: "p-2 text-gray-500 hover:text-amber-600 hover:bg-amber-50 rounded-lg border border-gray-200 bg-white shadow-sm flex items-center justify-center transition",
|
||||
title: "Artikel bearbeiten" do %>
|
||||
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10" />
|
||||
</svg>
|
||||
<% end %>
|
||||
|
||||
<span class="block text-[10px] text-gray-400 font-medium"><%= item.category.name %></span>
|
||||
|
||||
<div class="flex items-center gap-2 text-[10px] font-mono text-gray-500 pt-0.5">
|
||||
<span>SKU: <span class="text-gray-700 font-semibold"><%= item.sku.presence || "—" %></span></span>
|
||||
<span class="text-gray-300">•</span>
|
||||
<span>SN: <span class="text-gray-700 font-semibold"><%= item.serial_number.presence || "—" %></span></span>
|
||||
</div>
|
||||
</td>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- Spalte 3: Aktueller Standort (Desktop Tabelle - Voller Name übergeben) -->
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<%= render "layouts/badge", type: item.location_badge_type, label: item.location_badge_label(short_room: false) %>
|
||||
</td>
|
||||
|
||||
<!-- Spalte 4: Zustand (Desktop Tabelle - VOLLAUTOMATISCH!) -->
|
||||
<td class="px-6 py-4 whitespace-nowrap text-center">
|
||||
<%= render "layouts/badge", type: item.condition_badge_type %>
|
||||
</td>
|
||||
|
||||
<!-- Spalte 5: Aktionen -->
|
||||
<td class="px-6 py-4 whitespace-nowrap text-end font-medium text-xs w-24 shrink-0">
|
||||
<div class="flex items-center justify-end gap-2">
|
||||
<%= link_to item_path(item), data: { turbo_frame: "_top" }, class: "p-2 text-gray-500 hover:text-blue-600 hover:bg-blue-50 rounded-lg border border-gray-200 bg-white shadow-sm flex items-center justify-center transition" do %>
|
||||
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M2.036 12.322a1.012 1.012 0 0 1 0-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178Z" /><path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" /></svg>
|
||||
<% end %>
|
||||
<%= link_to edit_item_path(item), data: { turbo_frame: "_top" }, class: "p-2 text-gray-500 hover:text-amber-600 hover:bg-amber-50 rounded-lg border border-gray-200 bg-white shadow-sm flex items-center justify-center transition" do %>
|
||||
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10" /></svg>
|
||||
<% end %>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
56
app/views/layouts/_badge.html.erb
Normal file
56
app/views/layouts/_badge.html.erb
Normal file
@@ -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 = '<svg class="h-3.5 w-3.5 text-green-600 shrink-0" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M15.75 6a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0ZM4.501 20.118a7.5 7.5 0 0 1 14.998 0A17.933 17.933 0 0 1 12 21.75c-2.676 0-5.216-.584-7.499-1.632Z" /></svg>'
|
||||
icon_room = '<svg class="h-3.5 w-3.5 text-blue-600 shrink-0" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M15 10.5a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" /><path stroke-linecap="round" stroke-linejoin="round" d="M19.5 10.5c0 7.142-7.5 11.25-7.5 11.25s-7.5-4.108-7.5-11.25a7.5 7.5 0 1 1 15 0Z" /></svg>'
|
||||
icon_storage = '<svg class="h-3.5 w-3.5 text-amber-600 shrink-0" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M21 7.5l-9-5.25L3 7.5m18 0l-9 5.25m9-5.25v9l-9 5.25M3 7.5l9 5.25M3 7.5v9l5.25 3.03M12 12.75v9" /></svg>'
|
||||
icon_in_use = '<svg class="h-3.5 w-3.5 text-gray-400 shrink-0" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M7.5 21 3 16.5m0 0L7.5 12M3 16.5h13.5m0-13.5L21 7.5m0 0L16.5 12M21 7.5H7.5" /></svg>'
|
||||
icon_new = '<svg class="h-3.5 w-3.5 text-green-600 shrink-0" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M9.813 15.904 9 21l-.813-5.096L3.096 15 8 14.187 8.813 9l.813 5.187L15 15l-5.187.904ZM18 5.25l-.45 1.8-.45-1.8-1.8-.45 1.8-.45.45-1.8.45 1.8 1.8.45-1.8.45ZM21.75 9.75l-.3.9-.3-.9-.9-.3.9-.3.3-.9.3.9.9.3-.9.3Z" /></svg>'
|
||||
icon_as_new = '<svg class="h-3.5 w-3.5 text-emerald-600 shrink-0" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M6.633 10.25c.896 0 1.7-.393 2.287-1.011l3.34-3.52c.536-.565 1.433-.317 1.62.428l1.042 4.161h4.582a2.25 2.25 0 0 1 2.478l-.997 8.475A2.25 2.25 0 0 1 18.522 23H6.633a2.25 2.25 0 0 1-2.228-1.889L2.83 11.913A2.25 2.25 0 0 1 5.058 9.5h1.575c-.21 0-.422.02-.63.06l-.002.008ZM6.633 10.25V23" /></svg>'
|
||||
icon_used = '<svg class="h-3.5 w-3.5 text-yellow-600 shrink-0" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5" /></svg>'
|
||||
icon_heavy = '<svg class="h-3.5 w-3.5 text-orange-600 shrink-0" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M11.42 15.17 17.25 21A2.65 2.65 0 1 0 21 17.25l-5.83-5.83m0 0a2.65 2.65 0 1 1-3.75-3.75 2.65 2.65 0 0 1 3.75 3.75Zm-5.83 5.83a2.65 2.65 0 1 1-3.75-3.75 2.65 2.65 0 0 1 3.75 3.75M21 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0ZM18.75 7a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0ZM16.5 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0Z" /></svg>'
|
||||
icon_defective = '<svg class="h-3.5 w-3.5 text-red-600 shrink-0" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z" /></svg>'
|
||||
icon_unknown = '<svg class="h-3.5 w-3.5 text-gray-300 shrink-0" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M9.879 7.519c1.171-1.025 3.071-1.025 4.242 0 1.172 1.025 1.172 2.687 0 3.712-.203.179-.43.326-.67.442-.745.361-1.45.999-1.45 1.827v.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9 5.25h.008v.008H12v-.008Z" /></svg>'
|
||||
|
||||
# 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
|
||||
%>
|
||||
|
||||
<span class="inline-flex items-center gap-1.5 py-1 px-2.5 rounded-md text-xs font-semibold shadow-sm border <%= css %> ">
|
||||
<%= final_icon if final_icon.present? %>
|
||||
<%= final_label %>
|
||||
</span>
|
||||
Reference in New Issue
Block a user