diff --git a/app/controllers/leagues_controller.rb b/app/controllers/leagues_controller.rb index c4c0657..cfeb30f 100644 --- a/app/controllers/leagues_controller.rb +++ b/app/controllers/leagues_controller.rb @@ -901,14 +901,16 @@ def remove_future_games end def rainout_games - @todays_games = @league.games.where(:game_time.gte => Date.today.beginning_of_day, :game_time.lte => Date.today.end_of_day ) - @todays_fields = {} + @next_game_date = @league.games.where(:game_time.gte => Time.now).order_by(game_time: 'asc').first.game_time.to_date + + @games = @league.games.where(:game_time.gte => @next_game_date.beginning_of_day, :game_time.lte => @next_game_date.end_of_day ) + @fields = {} @field_game_count = {} - @todays_games.each do |g| + @games.each do |g| fsid = g.field_site._id.to_s - @todays_fields[fsid] ||= g.field_site + @fields[fsid] ||= g.field_site @field_game_count[fsid] ||= 0 @field_game_count[fsid] += 1 @@ -924,6 +926,8 @@ def process_rainout # Create job, queue jobs jobs = [] + rainout_date = Date.parse(params[:rainout_date]) + params[:fieldsite_ids].each do |fsid| fs = FieldSite.find(fsid) unless fs.present? @@ -931,10 +935,10 @@ def process_rainout return end - GameCancellationWorker.perform_async(@league._id.to_s, fsid, Date.today.beginning_of_day.to_i, Date.today.end_of_day.to_i, current_user._id.to_s, params[:notify]) + GameCancellationWorker.perform_async(@league._id.to_s, fsid, rainout_date.beginning_of_day.to_i, rainout_date.end_of_day.to_i, current_user._id.to_s, params[:notify]) end - redirect_to league_path(@league), notice: "We've started processing cancellations for those sites. It may take a few minutes for them all to be sent." + redirect_to league_path(@league), notice: "We've started processing cancellations for those sites for #{rainout_date}. It may take a few minutes for them all to be sent." end def missing_spirit_reports diff --git a/app/views/leagues/rainout_games.html.haml b/app/views/leagues/rainout_games.html.haml index 7ab2cbc..3e9a22a 100644 --- a/app/views/leagues/rainout_games.html.haml +++ b/app/views/leagues/rainout_games.html.haml @@ -1,14 +1,17 @@ - content_for :title, @league.name = render :partial => '/pageheader', :locals => {subtitle: nil, breadcrumbs: {'Leagues' => leagues_path, @league.name => league_path(@league), 'Rainout Games' => nil}} -- if @todays_games.count > 0 +%H1 Rainouts for #{@next_game_date.strftime('%A, %B %-d, %Y')} + +- if @games.count > 0 =form_tag process_rainout_league_path(@league), class: 'form' do + %input{type: 'hidden', name: "rainout_date", value: @next_game_date} .row .span4.offset2 %h3 Fields to Rain Out: .control-group .controls - - @todays_fields.each do |id, fs| + - @fields.each do |id, fs| %label.checkbox =check_box_tag 'fieldsite_ids[]', id #{fs.name} (#{@field_game_count[id]} games) diff --git a/app/workers/game_cancellation_worker.rb b/app/workers/game_cancellation_worker.rb index 6ffeca8..342db20 100644 --- a/app/workers/game_cancellation_worker.rb +++ b/app/workers/game_cancellation_worker.rb @@ -17,7 +17,7 @@ def perform(league_id, fieldsite_id, start_ts, end_ts, cancelling_user_id, notif new_score_report = { reporter_id: user._id, - report_time: Time.now, + report_time: 1.minute.ago, reporter_ip: '0.0.0.4', rainout: true, forfeit: false @@ -52,7 +52,7 @@ def perform(league_id, fieldsite_id, start_ts, end_ts, cancelling_user_id, notif end game_date = Time.at(start_ts).strftime('%a, %b %e') - text_message = "Bad news! Your AFDC games at #{@fieldsite.name} are canceled for today (#{game_date})." + text_message = "Bad news! Your AFDC games at #{@fieldsite.name} are canceled for (#{game_date})." player_list.each do |user_id, p| notify_user(p, text_message, start_ts)