From 2f26983f6a86dc747a8598a9661149588ac808b9 Mon Sep 17 00:00:00 2001 From: Christoph Marzell Date: Tue, 18 Nov 2025 09:45:27 +0100 Subject: [PATCH] add total time --- app/controllers/entries_controller.rb | 28 ++++++++++++++------------- app/views/entries/index.html.erb | 7 ++++++- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/app/controllers/entries_controller.rb b/app/controllers/entries_controller.rb index 1e6fb76..57f17dc 100644 --- a/app/controllers/entries_controller.rb +++ b/app/controllers/entries_controller.rb @@ -3,11 +3,15 @@ class EntriesController < ApplicationController before_action :set_entry, only: %i[edit update destroy stop_timer] def index - @entries = current_user.entries.order(date: :desc) + @entries = current_user.entries.order(date: :desc) @running_entry = current_user.entries.find_by(end_time: nil, beschreibung: "Timer") # Gesamtzeit in Minuten @total_minutes = @entries.sum { |e| e.hours.to_i * 60 + e.minutes.to_i } + @total_minutes_praktikum_prop = @entries.where(praktikums_typ: Entry::PRAKTIKUMSTYPEN[0], entry_art: Entry::ENTRY_ARTEN[0]).sum { |e| e.hours.to_i * 60 + e.minutes.to_i } + + @total_minutes_praktikum_fach = @entries.where(praktikums_typ: Entry::PRAKTIKUMSTYPEN[1], entry_art: Entry::ENTRY_ARTEN[0]).sum { |e| e.hours.to_i * 60 + e.minutes.to_i } + # Gesamtbetrag der Kilometerpauschale @total_kilometer_pauschale = @entries.sum(&:kilometer_pauschale) @@ -36,7 +40,6 @@ class EntriesController < ApplicationController @selbsterfahrungskosten_by_year = Entry.total_selbsterfahrungskosten_by_year(current_user) @allekosten_by_year = Entry.total_semesterkosten_by_year(current_user) - # Voraussichtliches Ende je Kombination basierend auf weekly_target_matrix # @estimated_end_by_typ_art = {} @@ -65,7 +68,7 @@ class EntriesController < ApplicationController typ = params[:typ] art = params[:art] - @entry = current_user.entries.create!(start_time: Time.current, beschreibung: "Timer" , praktikums_typ:typ, entry_art: art) + @entry = current_user.entries.create!(start_time: Time.current, beschreibung: "Timer", praktikums_typ: typ, entry_art: art) redirect_to entries_path, notice: "Timer gestartet" end @@ -73,13 +76,11 @@ class EntriesController < ApplicationController def stop_timer #@entry = current_user.entries.where(end_time: nil).order(start_time: :desc).first if @entry - @entry.end_time = Time.current + @entry.end_time = Time.current @entry.lunch_break_minutes = 30 if ActiveModel::Type::Boolean.new.cast(params[:lunch_break]) - - - total_minutes = @entry.total_minutes_including_break - @entry.hours = total_minutes / 60 + total_minutes = @entry.total_minutes_including_break + @entry.hours = total_minutes / 60 @entry.minutes = total_minutes % 60 @entry.save! @@ -147,18 +148,19 @@ class EntriesController < ApplicationController # In Hash-Struktur für die View umwandeln @report = {} rows.each do |r| - month = r.attributes["month"].to_date - total = r.attributes["total_minutes"].to_i + month = r.attributes["month"].to_date + total = r.attributes["total_minutes"].to_i typ_art = [r.praktikums_typ, r.entry_art] - @report[month] ||= {} + @report[month] ||= {} @report[month][typ_art] = { total_minutes: total, - hours: total / 60, - minutes: total % 60 + hours: total / 60, + minutes: total % 60 } end end + private def set_entry diff --git a/app/views/entries/index.html.erb b/app/views/entries/index.html.erb index 149e801..3effc83 100644 --- a/app/views/entries/index.html.erb +++ b/app/views/entries/index.html.erb @@ -52,7 +52,12 @@
🕒 Gesamtzeit
-

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

+

Total: <%= @total_minutes / 60 %> <%= @total_minutes % 60 %> min

+

Propädeutikum: <%= @total_minutes_praktikum_prop / 60 %> <%= @total_minutes % 60 %> min

+

Fachspezifikum: <%= @total_minutes_praktikum_fach / 60 %> <%= @total_minutes % 60 %> min

+ + +