Browse Source

fix view

main
Christoph Marzell 1 month ago
parent
commit
454dee523e
  1. 17
      app/controllers/calendar_controller.rb
  2. 7
      app/views/calendar/month.html.erb

17
app/controllers/calendar_controller.rb

@ -17,18 +17,19 @@ class CalendarController < ApplicationController
first_of_month = Date.new(@year, @month, 1) first_of_month = Date.new(@year, @month, 1)
last_of_month = first_of_month.end_of_month last_of_month = first_of_month.end_of_month
start_date = first_of_month - (first_of_month.cwday - 1)
end_date = last_of_month + (7 - last_of_month.cwday)
@filter_typ = params[:typ] @filter_typ = params[:typ]
@filter_art = params[:art] @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 }
entries_scope = current_user.entries.where(date: start_date..end_date)
entries_scope = entries_scope.where(praktikums_typ: @filter_typ) if @filter_typ.present?
entries_scope = entries_scope.where(entry_art: @filter_art) if @filter_art.present?
@entries = entries_scope.group_by { |e| e.date.to_date }
puts @entries
@days = (first_of_month..last_of_month).to_a
@days = (start_date..end_date).to_a
end end
def week def week
@ -47,6 +48,8 @@ class CalendarController < ApplicationController
first = Date.commercial(@year, @week, 1) first = Date.commercial(@year, @week, 1)
last = Date.commercial(@year, @week, 7) last = Date.commercial(@year, @week, 7)
@filter_typ = params[:typ] @filter_typ = params[:typ]
@filter_art = params[:art] @filter_art = params[:art]

7
app/views/calendar/month.html.erb

@ -23,11 +23,11 @@
<table class="table table-bordered calendar-table"> <table class="table table-bordered calendar-table">
<thead class="table-light"> <thead class="table-light">
<tr>
<% Date::ABBR_DAYNAMES.each do |day| %>
<% day_names = I18n.t("date.abbr_day_names") %>
<% monday_first = day_names.rotate(1) %>
<% monday_first.each do |day| %>
<th><%= day %></th> <th><%= day %></th>
<% end %> <% end %>
</tr>
</thead> </thead>
<tbody> <tbody>
<% weeks = @days.in_groups_of(7, nil) %> <% weeks = @days.in_groups_of(7, nil) %>
@ -36,6 +36,7 @@
<% week.each do |date| %> <% week.each do |date| %>
<td class="day-cell <td class="day-cell
<%= 'bg-light' if date.blank? %> <%= 'bg-light' if date.blank? %>
<%= 'outside-month' if date.month != @month %>
<%= 'today' if date == Date.current %>" <%= 'today' if date == Date.current %>"
data-date="<%= date %>" data-date="<%= date %>"
data-label="<%= date&.strftime('%d.%m.%Y') %>"> data-label="<%= date&.strftime('%d.%m.%Y') %>">

Loading…
Cancel
Save