diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 96d4125..e0a9b96 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -16,3 +16,71 @@ *= require_tree . *= require_self */ +.bg-purple { + background-color: #6f42c1 !important; + color: white !important; +} + +.calendar-table th, +.calendar-table td { + min-width: 120px; + height: 100px; + vertical-align: top; +} + +.calendar-table td .badge { + font-size: 0.85em; +} +.calendar-table td { + vertical-align: top; + padding: 4px; + height: 130px; + width: 14.28%; +} + +.day-box { + border-radius: 6px; + padding: 4px; + height: 100%; + display: flex; + flex-direction: column; +} + +.day-header { + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 4px; +} + +.day-number { + font-weight: 600; + font-size: 0.9rem; +} + +.day-add { + padding: 0 6px; + font-size: 0.75rem; +} + +.day-entries { + flex-grow: 1; + overflow-y: auto; + display: flex; + flex-direction: column; + gap: 4px; +} + +.day-entry { + background: #f8f9fa; + border-radius: 4px; + padding: 3px 5px; + font-size: 0.75rem; + display: flex; + align-items: center; + gap: 4px; +} + +.day-entry:hover { + background: #e9ecef; +} diff --git a/app/controllers/calendar_controller.rb b/app/controllers/calendar_controller.rb new file mode 100644 index 0000000..1b9e4fc --- /dev/null +++ b/app/controllers/calendar_controller.rb @@ -0,0 +1,64 @@ +class CalendarController < ApplicationController + before_action :authenticate_user! + + def month + @year = params[:year].to_i + @month = params[:month].to_i + + while @month < 1 + @month += 12 + @year -= 1 + end + while @month > 12 + @month -= 12 + @year += 1 + end + + first_of_month = Date.new(@year, @month, 1) + last_of_month = first_of_month.end_of_month + + @filter_typ = params[:typ] + @filter_art = params[:art] + + @entries = current_user.entries + .where(date: first_of_month..last_of_month) + @entries = @entries.where(praktikums_typ: @filter_typ) if @filter_typ.present? + @entries = @entries.where(entry_art: @filter_art) if @filter_art.present? + @entries = @entries.group_by { |e| e.date.to_date } + + + puts @entries + @days = (first_of_month..last_of_month).to_a + end + + def week + @year = params[:year].to_i + @week = params[:week].to_i + + while @month < 1 + @month += 12 + @year -= 1 + end + while @month > 12 + @month -= 12 + @year += 1 + end + + first = Date.commercial(@year, @week, 1) + last = Date.commercial(@year, @week, 7) + + @filter_typ = params[:typ] + @filter_art = params[:art] + + @entries = current_user.entries + .where(date: first..last) + @entries = @entries.where(praktikums_typ: @filter_typ) if @filter_typ.present? + @entries = @entries.where(entry_art: @filter_art) if @filter_art.present? + @entries = @entries.group_by{ |e| e.date.to_date } + + + + + @days = (first..last).to_a + end +end diff --git a/app/controllers/entries_controller.rb b/app/controllers/entries_controller.rb index 2807f86..f8e94be 100644 --- a/app/controllers/entries_controller.rb +++ b/app/controllers/entries_controller.rb @@ -224,6 +224,7 @@ class EntriesController < ApplicationController rows.each do |r| month = r.attributes["month"].to_date total = r.attributes["total_minutes"].to_i + next if total.zero? typ_art = [r.praktikums_typ, r.entry_art] @report[month] ||= {} diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..b0a134f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,16 @@ module ApplicationHelper + def color_class_for(entry) + case entry.entry_art + when "Praktikum" + "bg-primary text-white" + when "Selbsterfahrung" + "bg-purple text-white" + when "Supervision" + "bg-warning text-dark" + when "Fortbildung" + "bg-success text-white" + else + "bg-secondary text-white" + end + end end diff --git a/app/views/calendar/month.html.erb b/app/views/calendar/month.html.erb new file mode 100644 index 0000000..a3340bc --- /dev/null +++ b/app/views/calendar/month.html.erb @@ -0,0 +1,110 @@ +
| <%= day %> | + <% end %> +
|---|
|
+
+ <% if date %>
+
+
+ <% end %>
+
+ <%= date.day %>
+
+ <%= link_to "+",
+ new_entry_path(date: date),
+ class: "btn btn-sm btn-success day-add",
+ title: "Eintrag hinzufügen",
+ onclick: "event.stopPropagation();" %>
+
+
+
+ <% (@entries[date.to_date] || []).each do |entry| %>
+ <%= link_to edit_entry_path(entry),
+ class: "day-entry text-decoration-none",
+ onclick: "event.stopPropagation();" do %>
+
+ <%= entry.entry_art.capitalize %>
+
+
+ <%= entry.hours %>h <%= entry.minutes %>min
+
+ <% end %>
+ <% end %>
+
+ |
+
+ <% end %>
+
Keine Einträge
+ <% end %> +