Created
February 26, 2016 11:01
-
-
Save mosinski/55cefacb9c9bcb0c2ca0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def index | |
puts '!!!!!!' | |
if current_user.sportsman? | |
@time_range = Date.today.at_beginning_of_month-6.days..Date.today.at_end_of_month+6.days | |
@trainings = Training.includes(:trainings_executions).where(start_date: @time_range, trainings_executions: {sportsman_id: current_user.id}).order(:start_time) | |
else | |
date = params[:start_date] ? params[:start_date].to_date : Date.today | |
@time_range = date.at_beginning_of_week..date.at_end_of_week | |
@training = Training.new | |
if current_user.coach? | |
@sportsmen = User.includes(:groups, :unread_comments).where(role: User.roles[:sportsman], groups: {id: current_user.groups.ids}).order(:name) | |
@groups = current_user.groups | |
else | |
@sportsmen = User.includes(:unread_comments).where(role: User.roles[:sportsman]).order(:name) | |
@groups = Group.all | |
end | |
@locations = Location.all | |
@trainings = Training.includes(:trainings_executions).where(start_date: @time_range, trainings_executions: {sportsman_id: @sportsmen.ids}).order(:start_time) | |
end | |
puts '!!!!!!' | |
trainings_executions_ids = @trainings.map {|t| t.trainings_executions.ids}.flatten.uniq | |
puts trainings_executions_ids.inspect | |
unread_comments_training = current_user.unread_comments.where(assignment_status: Comment.assignment_statuses[:training], trainings_execution_id: trainings_executions_ids) | |
unread_comments_day = current_user.unread_comments.where(assignment_status: Comment.assignment_statuses[:day], assigned_day: @time_range) | |
@unread_comments = unread_comments_day.concat(unread_comments_training) | |
comments = Comment.arel_table | |
@comments = Comment.where(comments[:assigned_day].in(@time_range).or(comments[:trainings_execution_id].in(trainings_executions_ids))).select(:assigned_day, :start_date) | |
puts @comments.inspect | |
respond_to do |format| | |
format.html { render current_user.dashboard } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment