Added Search function for items and fixed javascript controller
This commit is contained in:
@@ -8,28 +8,25 @@
|
||||
<% end %>
|
||||
|
||||
<div class="w-full space-y-6">
|
||||
<!-- Beschreibungskarte -->
|
||||
<!-- Beschreibungskarte der Kategorie -->
|
||||
<div class="bg-white border border-gray-200 rounded-xl p-6 shadow-sm">
|
||||
<h2 class="text-sm font-bold text-gray-400 uppercase tracking-wider">Beschreibung</h2>
|
||||
<p class="text-sm text-gray-600 mt-1 leading-relaxed"><%= @category.description.presence || "Keine Beschreibung hinterlegt." %></p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<!-- 1. Gleiche Suchleiste laden (CSV-Export bleibt hier deaktiviert!) -->
|
||||
<!-- 1. Suchleiste steht außerhalb des Frames (CSV-Export hier auf 'false') -->
|
||||
<%= render "items/search_bar", show_csv: false %>
|
||||
|
||||
<!-- 2. Artikelliste laden -->
|
||||
<% if @items.any? %>
|
||||
<%= render "items/list", items: @items %>
|
||||
<% else %>
|
||||
<div class="text-center py-16 text-gray-400 bg-white border border-gray-200 rounded-xl shadow-sm">
|
||||
<svg class="mx-auto h-12 w-12 text-gray-300" 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>
|
||||
<p class="text-sm mt-3 font-medium">Bisher sind keine Inventargegenstände erfasst.</p>
|
||||
<p class="text-xs text-gray-400 mt-1">Klicke oben rechts auf "Artikel hinzufügen", um das erste Gerät einzubuchen.</p>
|
||||
</div>
|
||||
|
||||
<!-- 2. NUR DAS LIST-PARTIAL WIRD IN DEN FRAME GEPAKT -->
|
||||
<%= turbo_frame_tag "items_list_frame" do %>
|
||||
<% if @items.any? %>
|
||||
<%= render "items/list", items: @items %>
|
||||
<% else %>
|
||||
<div class="text-center py-12 text-gray-400 bg-white border border-gray-200 rounded-xl shadow-sm">
|
||||
<p class="text-sm">Keine passenden Artikel in dieser Kategorie gefunden.</p>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
<div class="bg-white border border-gray-200 rounded-xl shadow-sm overflow-hidden">
|
||||
|
||||
|
||||
<!-- ========================================================================= -->
|
||||
<!-- 1. HANDY-ANSICHT: OPTIMIERTE INVENTAR-CARDS (md:hidden) -->
|
||||
<!-- ========================================================================= -->
|
||||
<div class="block md:hidden divide-y divide-gray-200 bg-white">
|
||||
<% items.each do |item| %>
|
||||
<div class="p-4 space-y-3 hover:bg-gray-50/50 transition">
|
||||
|
||||
|
||||
<!-- Zeile 1: Name, Kategorie & die markante Sticker-ID Plakette -->
|
||||
<div class="flex justify-between items-start gap-3">
|
||||
<div class="min-w-0">
|
||||
<h4 class="font-bold text-gray-900 text-sm leading-snug truncate"><%= item.name %></h4>
|
||||
<p class="text-xs text-gray-500 font-medium mt-0.5"><%= item.category.name %></p>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Rechte Box für ID und den optimal platzierten Preis direkt darunter -->
|
||||
<div class="flex flex-col items-end gap-1.5 shrink-0">
|
||||
<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-wider">
|
||||
@@ -58,10 +58,17 @@
|
||||
|
||||
<!-- Aktions-Icons -->
|
||||
<div class="flex items-center gap-1 shrink-0">
|
||||
<%= link_to item_path(item), class: "p-2 text-gray-500 hover:text-blue-600 hover:bg-blue-50 rounded-lg border border-gray-200 bg-white shadow-sm" do %>
|
||||
<!-- DETAILS BUTTON mit _top Ausbruch -->
|
||||
<%= 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" 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), class: "p-2 text-gray-500 hover:text-amber-600 hover:bg-amber-50 rounded-lg border border-gray-200 bg-white shadow-sm" do %>
|
||||
|
||||
<!-- BEARBEITEN BUTTON mit _top Ausbruch -->
|
||||
<%= 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" 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>
|
||||
@@ -103,23 +110,33 @@
|
||||
<span class="inline-flex items-center py-0.5 px-2 rounded-full text-xs font-medium bg-amber-50 text-amber-800 border border-amber-200">📦 Im Hauptlager</span>
|
||||
<% end %>
|
||||
</td>
|
||||
|
||||
|
||||
<!-- STICKER-ID ALS BADGE (Jetzt auch in der Desktop-Tabelle markant) -->
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<span class="inline-flex items-center font-mono font-bold text-xs text-white bg-blue-600 px-2 py-0.5 rounded shadow-sm tracking-wider">
|
||||
#<%= item.sticker_id %>
|
||||
</span>
|
||||
</td>
|
||||
|
||||
|
||||
<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>
|
||||
<!-- In der Schleife der Desktop-Tabelle (_list.html.erb) -->
|
||||
<td class="px-6 py-4 whitespace-nowrap text-end font-medium text-xs">
|
||||
<div class="flex items-center justify-end gap-2">
|
||||
<%= link_to item_path(item), class: "p-1.5 text-gray-500 hover:text-blue-600 hover:bg-blue-50 rounded-lg transition-colors border border-transparent hover:border-blue-100", title: "Details anzeigen" do %>
|
||||
<!-- DETAILS ICON mit _top Ausbruch -->
|
||||
<%= link_to item_path(item),
|
||||
data: { turbo_frame: "_top" },
|
||||
class: "p-1.5 text-gray-500 hover:text-blue-600 hover:bg-blue-50 rounded-lg transition-colors border border-transparent hover:border-blue-100",
|
||||
title: "Details anzeigen" do %>
|
||||
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke-width="1.5" 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), class: "p-1.5 text-gray-500 hover:text-amber-600 hover:bg-amber-50 rounded-lg transition-colors border border-transparent hover:border-amber-100", title: "Artikel bearbeiten" do %>
|
||||
|
||||
<!-- BEARBEITEN ICON mit _top Ausbruch -->
|
||||
<%= link_to edit_item_path(item),
|
||||
data: { turbo_frame: "_top" },
|
||||
class: "p-1.5 text-gray-500 hover:text-amber-600 hover:bg-amber-50 rounded-lg transition-colors border border-transparent hover:border-amber-100",
|
||||
title: "Artikel bearbeiten" do %>
|
||||
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke-width="1.5" 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>
|
||||
|
||||
@@ -1,11 +1,48 @@
|
||||
<div class="bg-white border border-gray-200 rounded-xl shadow-sm p-4 bg-gray-200 flex flex-col sm:flex-row gap-3 justify-between items-center mb-6">
|
||||
|
||||
<!-- Das universelle Suchfeld -->
|
||||
<div class="relative w-full sm:max-w-xs">
|
||||
<input type="text" placeholder="Artikel, SKU oder Besitzer..." class="py-2 px-3 pl-9 block w-full border border-gray-300 rounded-lg text-sm bg-white focus:border-blue-500 focus:ring-blue-500">
|
||||
<%# Wenn dem Partial keine feste URL übergeben wurde, nutzt es automatisch die aktuelle Browser-URL %>
|
||||
<% form_url = local_assigns[:url] || request.fullpath %>
|
||||
|
||||
<%= form_with(url: form_url, method: :get,
|
||||
data: { controller: "search-form", turbo_frame: "items_list_frame" },
|
||||
class: "w-full bg-white border border-gray-200 rounded-xl shadow-sm p-4 bg-gray-50 flex flex-col sm:flex-row gap-3 justify-between items-center mb-6") do |form| %>
|
||||
|
||||
<!-- DAS SUCHFELD (Jetzt zusätzlich an den Scanner-Controller gekoppelt) -->
|
||||
<div data-controller="scanner" class="relative w-full sm:flex-1">
|
||||
<%= form.text_field :query,
|
||||
value: params[:query],
|
||||
placeholder: "Artikel, SKU, SN oder ID...",
|
||||
data: { action: "input->search-form#submit", scanner_target: "input" },
|
||||
class: "py-2 px-3 pl-9 pr-10 block w-full border border-gray-300 rounded-lg text-sm bg-white focus:border-blue-500 focus:ring-blue-500" %>
|
||||
|
||||
<!-- Linkes Icon: Lupe -->
|
||||
<div class="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none">
|
||||
<!-- Heroicon: magnifying-glass -->
|
||||
<svg class="h-4 w-4 text-gray-400" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.637 10.637z" /></svg>
|
||||
<svg class="h-4 w-4 text-gray-400" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.637 10.637z" />
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<!-- RECHTES ICON IM FELD: Der neue QR-Code-Scanner Button -->
|
||||
<button type="button"
|
||||
data-action="click->scanner#startCamera"
|
||||
class="absolute inset-y-0 right-0 flex items-center pr-3 text-gray-400 hover:text-blue-600 transition-colors"
|
||||
title="QR-Code scannen">
|
||||
<!-- Heroicon: qr-code -->
|
||||
<svg class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M3.75 4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125v2.25c0 .621-.504 1.125-1.125 1.125h-2.25A1.125 1.125 0 0 1 3.75 7.125v-2.25ZM3.75 14.625c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125v2.25c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 0 1-1.125-1.125v-2.25ZM14.625 4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125v2.25c0 .621-.504 1.125-1.125 1.125h-2.25c-.621 0-1.125-.504-1.125-1.125v-2.25ZM11.25 3.75a.75.75 0 0 1 .75.75v2.25a.75.75 0 0 1-1.5 0V4.5a.75.75 0 0 1 .75-.75ZM4.5 11.25a.75.75 0 0 1 .75-.75h2.25a.75.75 0 0 1 0 1.5H5.25a.75.75 0 0 1-.75-.75ZM11.25 10.5a.75.75 0 0 1 .75.75v2.25a.75.75 0 0 1-1.5 0v-2.25a.75.75 0 0 1 .75-.75ZM10.5 18.75a.75.75 0 0 1 .75-.75h2.25a.75.75 0 0 1 0 1.5h-2.25a.75.75 0 0 1-.75-.75ZM18.75 10.5a.75.75 0 0 1 .75.75v2.25a.75.75 0 0 1-1.5 0v-2.25a.75.75 0 0 1 .75-.75ZM14.625 14.625c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125v2.25c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 0 1-1.125-1.125v-2.25ZM18.75 4.5a.75.75 0 0 1 .75-.75h.75c.621 0 1.125.504 1.125 1.125V5.25a.75.75 0 0 1-1.5 0V4.5h-.375a.75.75 0 0 1-.75-.75ZM19.5 18.75a.75.75 0 0 1 .75-.75h.375V17.25a.75.75 0 0 1 1.5 0v1.5c0 .621-.504 1.125-1.125 1.125h-1.5a.75.75 0 0 1-.75-.75ZM4.5 19.5v-.375a.75.75 0 0 1 1.5 0v.375h.375a.75.75 0 0 1 0 1.5h-1.5A1.125 1.125 0 0 1 3.75 19.5Z" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<!-- (HINWEIS: Hier im Untergrund muss noch dein HTML-Modal für die Kamera-Vorschau liegen, falls das nicht global eingebunden ist) -->
|
||||
<div data-scanner-target="modal" class="hidden fixed inset-0 bg-gray-900/60 z-50 flex items-center justify-center p-4 backdrop-blur-sm">
|
||||
<div class="bg-white rounded-2xl max-w-md w-full p-6 space-y-4 shadow-xl border border-gray-100">
|
||||
<div class="flex justify-between items-center">
|
||||
<h3 class="text-sm font-bold text-gray-800 uppercase tracking-wide">Inventar-Sticker scannen</h3>
|
||||
<button type="button" data-action="click->scanner#stopCamera" class="p-1 text-gray-400 hover:text-gray-600 rounded-lg">
|
||||
<svg class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" /></svg>
|
||||
</button>
|
||||
</div>
|
||||
<div id="search-reader" data-scanner-target="preview" class="w-full aspect-square rounded-xl overflow-hidden border border-gray-200 bg-gray-50"></div>
|
||||
<p class="text-xs text-gray-500 text-center">Halte den QR-Code des Geräts ruhig in den Scan-Rahmen.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -19,7 +56,7 @@
|
||||
<span>CSV</span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
|
||||
<!-- Universeller Filter-Button -->
|
||||
<button class="py-2 px-3 border border-gray-300 rounded-lg text-sm font-medium bg-white text-gray-700 hover:bg-gray-50 flex items-center gap-1.5 shadow-sm transition">
|
||||
<!-- Heroicon: funnel -->
|
||||
@@ -28,4 +65,4 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -1,35 +1,6 @@
|
||||
<!-- <%# content_for :title, "Items" %>
|
||||
|
||||
<div class="w-full">
|
||||
<% if notice.present? %>
|
||||
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-md inline-block" id="notice"><%= notice %></p>
|
||||
<% end %>
|
||||
|
||||
<div class="flex justify-between items-center">
|
||||
<h1 class="font-bold text-4xl">Items</h1>
|
||||
<%= link_to "New item", new_item_path, class: "rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white block font-medium" %>
|
||||
</div>
|
||||
|
||||
<div id="items" class="min-w-full divide-y divide-gray-200 space-y-5">
|
||||
<% if @items.any? %>
|
||||
<% @items.each do |item| %>
|
||||
<div class="flex flex-col sm:flex-row justify-between items-center pb-5 sm:pb-0">
|
||||
<%#= render item %>
|
||||
<div class="w-full sm:w-auto flex flex-col sm:flex-row space-x-2 space-y-2">
|
||||
<%= link_to "Show", item, class: "w-full sm:w-auto text-center rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
|
||||
<%= link_to "Edit", edit_item_path(item), class: "w-full sm:w-auto text-center rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
|
||||
<%= button_to "Destroy", item, method: :delete, class: "w-full sm:w-auto rounded-md px-3.5 py-2.5 text-white bg-red-600 hover:bg-red-500 font-medium cursor-pointer", data: { turbo_confirm: "Are you sure?" } %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<p class="text-center my-10">No items found.</p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>-->
|
||||
|
||||
<% content_for :title, "Gesamtbestand" %>
|
||||
|
||||
<!-- OBERE AKTIONSLISTE -->
|
||||
<% content_for :top_bar_actions do %>
|
||||
<%= link_to new_item_path, class: "py-2 px-4 text-sm font-semibold rounded-lg bg-blue-600 text-white hover:bg-blue-700 flex items-center gap-1.5 shadow-sm 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="M12 4.5v15m7.5-7.5h-15" /></svg>
|
||||
@@ -38,23 +9,17 @@
|
||||
<% end %>
|
||||
|
||||
<div class="w-full space-y-4">
|
||||
<!-- 1. Suchleiste laden (mit aktiviertem CSV-Export) -->
|
||||
<!-- 1. Die Suchleiste steht AUSSERHALB des Frames. Sie wird beim Tippen nicht neu geladen! -->
|
||||
<%= render "items/search_bar", show_csv: true %>
|
||||
|
||||
<!-- 2. Artikelliste laden -->
|
||||
<% if @items.any? %>
|
||||
<%= render "items/list", items: @items %>
|
||||
<% else %>
|
||||
<div class="text-center py-16 text-gray-400 bg-white border border-gray-200 rounded-xl shadow-sm">
|
||||
<svg class="mx-auto h-12 w-12 text-gray-300" 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>
|
||||
<p class="text-sm mt-3 font-medium">Bisher sind keine Inventargegenstände erfasst.</p>
|
||||
<p class="text-xs text-gray-400 mt-1">Klicke oben rechts auf "Artikel hinzufügen", um das erste Gerät einzubuchen.</p>
|
||||
</div>
|
||||
<!-- 2. NUR DIE LISTE WIRD IN DEN TURBO-FRAME GEPAKT -->
|
||||
<%= turbo_frame_tag "items_list_frame" do %>
|
||||
<% if @items.any? %>
|
||||
<%= render "items/list", items: @items %>
|
||||
<% else %>
|
||||
<div class="text-center py-16 text-gray-400 bg-white border border-gray-200 rounded-xl shadow-sm">
|
||||
<p class="text-sm font-medium">Keine passenden Inventargegenstände gefunden.</p>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user