You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.4 KiB
64 lines
1.4 KiB
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
|