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 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_art = params[:art] 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 } @days = (start_date..end_date).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