Browse Source

add erledigt

main
Christoph Marzell 1 month ago
parent
commit
159f8c30d7
  1. 45
      app/controllers/entries_controller.rb
  2. 3
      app/views/entries/index.html.erb

45
app/controllers/entries_controller.rb

@ -24,54 +24,49 @@ class EntriesController < ApplicationController
# Verbleibende Minuten je Kombination
@remaining_minutes_matrix = {}
@spent_minutes_matrix = {}
@time_by_typ_art.each do |typ, arts|
@remaining_minutes_matrix[typ] ||= {}
@spent_minutes_matrix[typ] ||= {}
arts.each do |art, spent_minutes|
target = current_user.required_hours_matrix.dig(typ, art).to_i * 60
remaining = [target - spent_minutes, 0].max
@remaining_minutes_matrix[typ][art] = remaining
@spent_minutes_matrix[typ][art] = spent_minutes
end
end
@completion_percent_by_typ_art = {}
@progress_chart_data = {}
@progress_chart_data = {}
@progress_colors = {}
User::PRAKTIKUMSTYPEN.product(User::ENTRY_ARTEN).each do |typ, art|
total_required = current_user.required_hours_matrix.to_h.dig(typ, art).to_f
total_required = current_user.required_hours_matrix.to_h.dig(typ, art).to_f
remaining_minutes = @remaining_minutes_matrix.dig(typ, art).to_i
required_minutes = (total_required * 60).to_i
entries_exist = current_user.entries.where(praktikums_typ: typ, entry_art: art).exists?
required_minutes = (total_required * 60).to_i
entries_exist = current_user.entries.where(praktikums_typ: typ, entry_art: art).exists?
if total_required > 0 && entries_exist
done_minutes = required_minutes - remaining_minutes
percent = (done_minutes / required_minutes.to_f * 100).round
percent = 100 if percent > 100
@completion_percent_by_typ_art[[typ, art]] = percent
done_minutes = required_minutes - remaining_minutes
percent = (done_minutes / required_minutes.to_f * 100).round
percent = 100 if percent > 100
@completion_percent_by_typ_art[[typ, art]] = percent
@progress_chart_data["#{typ.capitalize}#{art}"] = percent
else
percent = 0
@completion_percent_by_typ_art[[typ, art]] = percent
percent = 0
@completion_percent_by_typ_art[[typ, art]] = percent
@progress_chart_data["#{typ.capitalize}#{art}"] = percent
end
@progress_colors["#{typ.capitalize}#{art}"] = if percent < 50
'#007bff' # Blau
elsif percent < 90
'#28a745' # Grün
else
'#dc3545' # Rot
end
'#007bff' # Blau
elsif percent < 90
'#28a745' # Grün
else
'#dc3545' # Rot
end
end
@total_kilometer_costs_by_year = Entry.total_kilometer_cost_by_year(current_user)
@fortbildungskosten_by_year = Entry.total_fortbildungskosten_by_year(current_user)
@ -79,8 +74,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 = {}

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

@ -26,6 +26,7 @@
<th>Typ</th>
<th>Art</th>
<th>Verbleibend</th>
<th>Erledigt</th>
<th>Soll (h)</th>
<th>Wöchentlich</th>
<th>Vorauss. Ende</th>
@ -36,6 +37,7 @@
<% ["propädeutikum", "fachspezifikum"].each do |typ| %>
<% ["Praktikum", "Selbsterfahrung", "Supervision"].each do |art| %>
<% remaining = @remaining_minutes_matrix.dig(typ, art) %>
<% spent = @spent_minutes_matrix.dig(typ, art) %>
<% soll = current_user.required_hours_matrix.dig(typ, art) %>
<% weekly = current_user.weekly_target_matrix.dig(typ, art) %>
<% ende = @estimated_end_by_typ_art.dig(typ, art) %>
@ -45,6 +47,7 @@
<td><%= typ.capitalize %></td>
<td><%= art.capitalize %></td>
<td><%= remaining ? "#{remaining / 60} h #{remaining % 60} min" : "—" %></td>
<td><%= spent ? "#{spent / 60} h #{spent % 60} min" : "—" %></td>
<td><%= soll || "—" %> h</td>
<td><%= weekly || "—" %> h/Woche</td>
<td><%= ende.present? ? ende.strftime("%d.%m.%Y") : "—" %></td>

Loading…
Cancel
Save