Browse Source

add total time

main
Christoph Marzell 3 weeks ago
parent
commit
2f26983f6a
  1. 28
      app/controllers/entries_controller.rb
  2. 7
      app/views/entries/index.html.erb

28
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

7
app/views/entries/index.html.erb

@ -52,7 +52,12 @@
<div class="col rounded border shadow-sm p-3">
<h5>🕒 Gesamtzeit</h5>
<p><strong><%= @total_minutes / 60 %> h <%= @total_minutes % 60 %> min</strong></p>
<p><strong>Total: <%= @total_minutes / 60 %> <%= @total_minutes % 60 %> min</strong></p>
<p>Propädeutikum: <%= @total_minutes_praktikum_prop / 60 %> <%= @total_minutes % 60 %> min</strong></p>
<p>Fachspezifikum: <%= @total_minutes_praktikum_fach / 60 %> <%= @total_minutes % 60 %> min</strong></p>
</div>
</div>

Loading…
Cancel
Save