From 4d98f709ed5c81cca48d3f9251009ed3dfa1b57a Mon Sep 17 00:00:00 2001 From: Christoph Marzell Date: Sun, 8 Feb 2026 09:08:48 +0100 Subject: [PATCH] add dashboard --- app/controllers/dashboards_controller.rb | 29 +++++++++++++++ app/views/dashboards/_summary_tiles.html.erb | 36 ++++++++++++++++++ app/views/dashboards/show.html.erb | 39 ++++++++++++++++++++ config/routes.rb | 2 +- 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 app/controllers/dashboards_controller.rb create mode 100644 app/views/dashboards/_summary_tiles.html.erb create mode 100644 app/views/dashboards/show.html.erb diff --git a/app/controllers/dashboards_controller.rb b/app/controllers/dashboards_controller.rb new file mode 100644 index 0000000..aa8f360 --- /dev/null +++ b/app/controllers/dashboards_controller.rb @@ -0,0 +1,29 @@ +# app/controllers/dashboards_controller.rb +class DashboardsController < ApplicationController + def show + @entries = current_user.entries.order(date: :desc) + + valid_entries = @entries.select { |e| e.date.present? } + + @report = valid_entries.group_by { |e| e.date.beginning_of_month } + .transform_values do |entries| + entries.group_by { |e| [e.praktikums_typ, e.entry_art] } + .transform_values do |subset| + minutes = subset.sum(&:total_minutes) + { hours: minutes / 60, minutes: minutes % 60 } + end + end + + @monthly_minutes_chart_data = @report.transform_keys { |date| date.strftime("%b") } + .transform_values do |groups| + groups.values.sum { |data| data[:hours] * 60 + data[:minutes] } + end + + @monthly_targets = Hash.new(1500) # z.B. 25h im Monat als Ziel → 1500min + + @total_minutes = @entries.sum(&:total_minutes) + @last_entry = @entries.first + @completed_percent = ((@total_minutes.to_f / 10000) * 100).round(1) + @remaining_total = [10000 - @total_minutes, 0].max + end +end diff --git a/app/views/dashboards/_summary_tiles.html.erb b/app/views/dashboards/_summary_tiles.html.erb new file mode 100644 index 0000000..79ca1b8 --- /dev/null +++ b/app/views/dashboards/_summary_tiles.html.erb @@ -0,0 +1,36 @@ + +
+
+
+
🕒 Gesamtzeit
+

<%= @total_minutes / 60 %>h <%= @total_minutes % 60 %>min

+
+
+
+ +
+
+
+
🚧 Offen
+

<%= @remaining_total / 60 %>h

+
+
+
+ +
+
+
+
✅ Erledigt
+

<%= @completed_percent %>%

+
+
+
+ +
+
+
+
📅 Letzter Eintrag
+

<%= l(@last_entry.date, format: :long) if @last_entry %>

+
+
+
diff --git a/app/views/dashboards/show.html.erb b/app/views/dashboards/show.html.erb new file mode 100644 index 0000000..da88090 --- /dev/null +++ b/app/views/dashboards/show.html.erb @@ -0,0 +1,39 @@ +

📊 Dashboard

+ + +
+ <%= render partial: 'dashboards/summary_tiles' %> +
+ + +
+
+
📈 Monatsverlauf
+ <%= column_chart @monthly_minutes_chart_data, height: "250px", colors: ["#0d6efd"] %> +
+
+ + +
+ <% @report.each do |month, groups| %> + <% total_minutes = groups.values.map { |data| (data[:hours] * 60 + data[:minutes]) }.sum %> + <% total_hours = total_minutes / 60 %> + <% rest_min = total_minutes % 60 %> + <% percent = ((total_minutes.to_f / @monthly_targets[month]) * 100).round rescue 0 %> + +
+
<%= month.strftime("%B %Y") %>
+
+

⏱️ <%= total_hours %>h <%= rest_min %>min

+

🎯 Ziel: <%= @monthly_targets[month] / 60 %>h

+
+
+ <%= percent %>% +
+
+
+
+ <% end %> +
diff --git a/config/routes.rb b/config/routes.rb index 409701e..efceb2f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,7 @@ Rails.application.routes.draw do get "/calendar/week/:year/:week", to: "calendar#week", as: :calendar_week resources :mileage_rates, only: [:index, :new, :create, :edit, :update] - + resource :dashboard, only: [:show] resources :entries do post :start_timer, on: :collection