diff --git a/app/models/category.rb b/app/models/category.rb index 6803530..c80d111 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -2,4 +2,19 @@ class Category < ApplicationRecord has_many :items, dependent: :restrict_with_error validates :name, presence: true, uniqueness: true + + # 1. Zählt Artikel im Hauptlager (weder User noch Raum zugewiesen) + def items_in_storage_count + items.where(user_id: nil, room_id: nil).count + end + + # 2. Zählt Artikel, die bei Mitarbeitern im Umlauf sind + def items_with_users_count + items.where.not(user_id: nil).count + end + + # 3. Zählt Artikel, die fest in Räumen verbaut sind + def items_in_rooms_count + items.where.not(room_id: nil).count + end end diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb index 2cfbbb3..19532ea 100644 --- a/app/views/categories/index.html.erb +++ b/app/views/categories/index.html.erb @@ -1,44 +1,80 @@ - - -<% content_for :title, "Kategorien" %> +<% content_for :title, "Kategorien & Typen" %>
- - <% content_for :top_bar_actions do %> - <%= link_to new_category_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 %> - - Kategorie erstellen - <% end %> + + <% if @categories.any? %> + +
+ <% @categories.each do |category| %> +
+ + +
+
+ +
+ + + +
+
+

<%= category.name %>

+ Gesamt: <%= category.items.count %> +
+
+ + +
+ + +
+ + + + + + <%= category.items_in_storage_count %> +
+ + +
+ + + + + + <%= category.items_with_users_count %> +
+ + +
+ + + + + + + <%= category.items_in_rooms_count %> +
+ +
+
+ + +
+ <%= link_to category_path(category), class: "text-blue-600 hover:text-blue-700 transition" do %> + Liste öffnen → + <% end %> + <%= link_to "Bearbeiten", edit_category_path(category), class: "text-gray-400 hover:text-gray-600 transition" %> +
+ +
+ <% end %> +
+ <% else %> +
+

Bisher sind keine Kategorien hinterlegt.

+
<% end %> - -
- <% @categories.each do |category| %> -
-
-
-
- - -
- - - <%= category.items.count %> <%= category.items.count == 1 ? "Objekt" : "Objekte" %> - -
-

<%= category.name %>

-

<%= category.description.presence || "Keine Beschreibung hinterlegt." %>

-
- -
- - <%= link_to "Bearbeiten", edit_category_path(category), class: "text-gray-500 hover:text-gray-700 transition" %> - - <%= link_to category_path(category), class: "text-blue-600 hover:text-blue-800 flex items-center gap-0.5 transition" do %> - Artikel ansehen → - <% end %> -
-
- <% end %> -