diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb new file mode 100644 index 0000000..a0b18a9 --- /dev/null +++ b/app/controllers/rooms_controller.rb @@ -0,0 +1,97 @@ +class RoomsController < ApplicationController + before_action :set_room, only: %i[ show edit update destroy ] + + # GET /rooms or /rooms.json + # 1. Übersicht aller Räume (Kacheldesign) + def index + @rooms = Room.all.order( + Room.arel_table[:building].asc.nulls_last, + Room.arel_table[:floor].asc.nulls_last, + :name + # :building, :floor, :name + ) + + # NEU: Filtert die Räume live nach Name, Gebäude oder Etage + if params[:query].present? + query_str = "%#{params[:query]}%" + @rooms = @rooms.where( + "rooms.name LIKE :q OR rooms.building LIKE :q OR rooms.floor LIKE :q", + q: query_str + ) + end + end + + # GET /rooms/1 or /rooms/1.json + # 2. Detailansicht eines Raums mit integrierter Live-Suche für dessen Inventar + def show + # Basis-Abfrage: Alle Items dieses Raums laden + @items = @room.items.includes(:category, :user).order(created_at: :desc) + + # Wenn in der Suchleiste getippt wird, filtert der Controller live + if params[:query].present? + query_str = "%#{params[:query]}%" + @items = @items.where( + "items.name LIKE :q OR items.sku LIKE :q OR items.serial_number LIKE :q OR items.sticker_id LIKE :q", + q: query_str + ) + end + end + + # GET /rooms/new + def new + @room = Room.new + end + + # GET /rooms/1/edit + def edit + end + + # POST /rooms or /rooms.json + def create + @room = Room.new(room_params) + + respond_to do |format| + if @room.save + format.html { redirect_to @room, notice: "Room was successfully created." } + format.json { render :show, status: :created, location: @room } + else + format.html { render :new, status: :unprocessable_content } + format.json { render json: @room.errors, status: :unprocessable_content } + end + end + end + + # PATCH/PUT /rooms/1 or /rooms/1.json + def update + respond_to do |format| + if @room.update(room_params) + format.html { redirect_to @room, notice: "Room was successfully updated.", status: :see_other } + format.json { render :show, status: :ok, location: @room } + else + format.html { render :edit, status: :unprocessable_content } + format.json { render json: @room.errors, status: :unprocessable_content } + end + end + end + + # DELETE /rooms/1 or /rooms/1.json + def destroy + @room.destroy! + + respond_to do |format| + format.html { redirect_to rooms_path, notice: "Room was successfully destroyed.", status: :see_other } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_room + @room = Room.find(params.expect(:id)) + end + + def room_params + # :description wurde hier restlos entfernt + params.require(:room).permit(:name, :building, :floor) + end +end diff --git a/app/helpers/rooms_helper.rb b/app/helpers/rooms_helper.rb new file mode 100644 index 0000000..1d0f4c7 --- /dev/null +++ b/app/helpers/rooms_helper.rb @@ -0,0 +1,2 @@ +module RoomsHelper +end diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index 89bbe90..0341a98 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -1,134 +1,205 @@ -<% content_for :title, "Dashboard Übersicht" %> +<% content_for :title, "Dashboard" %>
Objekte im System
-Gesamtbestand
+Registrierte Unikate
+Aktuell im Lager
-Kategorien
+Geräte-Typen
+Gesamtwert Inventar
-Räume & Büros
+Erfasste Standorte
+<%= item.name %>
-+ +
|
+
+ <%= link_to item_path(item), class: "shrink-0 transition hover:scale-105 active:scale-95 block" do %>
+
+ #<%= item.sticker_id %>
+
+ <% end %>
+
+
+ <%= link_to item_path(item), class: "font-bold text-gray-900 hover:text-blue-600 hover:underline inline leading-tight" do %>
+ <%= item.name %>
+ <% end %>
+ <%= item.category.name %>
+
+ |
+
<% if item.user.present? %>
- 👤 <%= item.user.name %>
+
+
+ <%= item.user.name %>
+
<% elsif item.room.present? %>
- 📍 <%= item.room.name_with_building %>
+ <%= link_to room_path item.room do %>
+
+
+ <%= item.room.name %>
+
+ <% end %>
<% else %>
- 📦 Im Hauptlager
+
+
+ Hauptlager
+
<% end %>
-
-
-
-
- <%= time_ago_in_words(item.created_at) %>
-
-
- <% end %>
+ |
+ + <%= time_ago_in_words(item.created_at) %> + | +
- <%= link_to log.item.name, item_path(log.item), class: "hover:text-blue-600 transition" %> -
-- <% if log.user.present? %> - 👤 <%= log.user.name %> - <% elsif log.room.present? %> - 📍 <%= log.room.name_with_building %> - <% else %> - 📦 Ins Hauptlager gelegt - <% end %> -
-|
+
+ <%= link_to item_path(log.item), class: "shrink-0 transition hover:scale-105 active:scale-95 block" do %>
+
+ #<%= log.item.sticker_id %>
+
+ <% end %>
+
+
+ <% if log.item.present? %>
+ <%= link_to item_path(log.item), class: "font-bold text-gray-900 hover:text-blue-600 hover:underline inline leading-tight" do %>
+ <%= log.item.name %>
+ <% end %>
+ <% else %>
+ Gelöschter Artikel
+ <% end %>
+
+
+
+ <% if log.user.present? %>
+
+
+ <%= log.user.name %> zugewiesen
+
+ <% elsif log.room.present? %>
+ <%= link_to room_path log.room do %>
+
+
+ In <%= log.room.name %> platziert
+
+ <% end %>
+ <% else %>
+
+
+ Hauptlager zurückgebracht
+
+ <% end %>
+
+ |
+ + <%= time_ago_in_words(log.assigned_at) %> + | +
<%= item.category.name %>
+ <%= link_to item_path(item), data: { turbo_frame: "_top" }, class: "font-black text-gray-900 hover:text-blue-600 text-base leading-tight block truncate" do %> + <%= item.name %> + <% end %>+ <%= room.new_record? ? "Definiere einen neuen physischen Standort für deine Inventargegenstände." : "Aktualisiere die Standortbezeichnung oder die Etage." %> +
+In diesem Raum gelistete Artikel verlieren ihren Standort und werden automatisch ins Hauptlager umgebucht.
+| Raum | +Gebäudeteil | +Etage | +Aktiver Bestand | +Aktionen | +
|---|---|---|---|---|
|
+
+
+
+ <%= room.name %>
+ |
+ <%= room.building %> | +<%= room.floor %> | ++ + <%= room.items.count %> <%= room.items.count == 1 ? "Gerät" : "Geräte" %> + + | +
+
+
+
+ <%= link_to room_path(room), data: { turbo_frame: "_top" },
+ class: "p-2.5 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",
+ title: "Inventar öffnen" do %>
+
+ <% end %>
+
+
+ <%= link_to edit_room_path(room), data: { turbo_frame: "_top" },
+ class: "p-2.5 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",
+ title: "Bearbeiten" do %>
+
+ <% end %>
+
+ |
+
Keine passenden Gebäude oder Büros gefunden.
+Gebäude
+<%= @room.building %>
+Stockwerk / Etage
+<%= @room.floor %>
+Keine passenden Artikel an diesem Standort gefunden.
+