app/controllers/meeting_reservations_controller.rb
# Prepares the PDF print-out for the event and relay reservations for the current
# meeting.
#
# == Params:
# id: the meeting id to be processed
#
# == Implied parameters:
# current_user:  user must be logged-in and either be a team-manager or have an
#                associated swimmer (must be a "goggler").
#                (when also a team-manager, the whole matrix of rows should be editable)
#
Prepares the PDF print-out for the event and relay reservations for the current
meeting.

the meeting id to be processed

Implied parameters:
current_user:  user must be logged-in and either be a team-manager or have an
associated swimmer (must be a "goggler").
(when also a team-manager, the whole matrix of rows should be editable)
Prepares the PDF print - out for the event and relay reservations for the current meeting . the meeting id to be processed Implied parameters : current_user : user must be logged - in and either be a team - manager or have an associated swimmer ( must be a " goggler " ) . ( when also a team - manager the whole matrix of rows should be editable )
def printout_event_sheet()
    @events = @meeting.meeting_events
        .joins(:meeting_session, :event_type)
        .includes(:meeting_session, :event_type)
        .order('meeting_sessions.session_order, event_order')
        .to_a
    @reservations_events = {}
    @reservations_relays = {}
    @events.each do |event|
      if event.event_type.is_a_relay
        @reservations_relays[ event.id ] = MeetingRelayReservation.where(
          meeting_event_id: event.id,
          team_id: @team.id,
          is_doing_this:    true
        ).joins(:swimmer, meeting_event: [:meeting_session, :event_type])
          .includes(:swimmer, meeting_event: [:meeting_session, :event_type])
          .order('meeting_sessions.session_order, meeting_events.event_order')
          .to_a
      else
        @reservations_events[ event.id ] = MeetingEventReservation.where(
          meeting_event_id: event.id,
          team_id: @team.id,
          is_doing_this:    true
        ).joins(:category_type, swimmer: [:gender_type], meeting_event: [:meeting_session, :event_type])
          .includes(:category_type, swimmer: [:gender_type], meeting_event: [:meeting_session, :event_type])
          .order('meeting_sessions.session_order, meeting_events.event_order, category_types.code, gender_types.code')
          .to_a
      end
    end
    all_swimmer_ids = ( @reservations_events.values + @reservations_relays.values )
      .flatten
      .map{ |res| res.swimmer_id }
      .uniq
    @meeting_reservations = MeetingReservation.where(
      meeting_id:    @meeting.id,
      team_id:       @team_affiliation ? @team_affiliation.team_id : @team.id,
      is_not_coming: false,
      swimmer_id:    all_swimmer_ids
    ).joins(:swimmer).includes(:swimmer)
    if all_swimmer_ids.size > 0
      base_filename = "#{I18n.t('meeting_reservation.event_sheet_basefilename')}_#{@meeting.code}"
      filename = create_unique_filename( base_filename ) + '.pdf'
      options = {
        report_title:         I18n.t('meeting_reservation.event_sheet_title'),
        meta_info_subject:    'passages collection model sheet printout',
        meta_info_keywords:   "Goggles, #{base_filename}'",
        meeting:              @meeting,
        team:                 @team,
        events:               @events,
        meeting_reservations: @meeting_reservations,
        reservations_events:  @reservations_events,
        reservations_relays:  @reservations_relays
      }
      send_data(                                    
          PassagesCollectSheetLayout.render( options ),
          type: 'application/pdf',
          filename: filename
      )
    else
      flash[:error] = I18n.t(:no_detail_to_process)
      redirect_to( meetings_current_path() ) and return
    end
  end
def printout_event_sheet ( ) @events = @meeting . meeting_events . joins ( :meeting_session , :event_type ) . includes ( :meeting_session , :event_type ) . order ( 'meeting_sessions.session_order, event_order' ) . to_a @reservations_events = { } @reservations_relays = { } @events . each do | event | if event . event_type . is_a_relay @reservations_relays [ event . id ] = MeetingRelayReservation . where ( meeting_event_id : event . id , team_id : @team . id , is_doing_this : true ) . joins ( :swimmer , meeting_event : [ :meeting_session , :event_type ] ) . includes ( :swimmer , meeting_event : [ :meeting_session , :event_type ] ) . order ( 'meeting_sessions.session_order, meeting_events.event_order' ) . to_a else @reservations_events [ event . id ] = MeetingEventReservation . where ( meeting_event_id : event . id , team_id : @team . id , is_doing_this : true ) . joins ( :category_type , swimmer : [ :gender_type ] , meeting_event : [ :meeting_session , :event_type ] ) . includes ( :category_type , swimmer : [ :gender_type ] , meeting_event : [ :meeting_session , :event_type ] ) . order ( 'meeting_sessions.session_order, meeting_events.event_order, category_types.code, gender_types.code' ) . to_a end end all_swimmer_ids = ( @reservations_events . values + @reservations_relays . values ) . flatten . map { | res | res . swimmer_id } . uniq @meeting_reservations = MeetingReservation . where ( meeting_id : @meeting . id , team_id : @team_affiliation ? @team_affiliation . team_id : @team . id , is_not_coming : false , swimmer_id : all_swimmer_ids ) . joins ( :swimmer ) . includes ( :swimmer ) if all_swimmer_ids . size > 0 base_filename = "#{I18n.t('meeting_reservation.event_sheet_basefilename')}_#{@meeting.code}" filename = create_unique_filename ( base_filename ) + '.pdf' options = { report_title : I18n . t ( 'meeting_reservation.event_sheet_title' ) , meta_info_subject : 'passages collection model sheet printout' , meta_info_keywords : "Goggles, #{base_filename}'" , meeting : @meeting , team : @team , events : @events , meeting_reservations : @meeting_reservations , reservations_events : @reservations_events , reservations_relays : @reservations_relays } send_data ( PassagesCollectSheetLayout . render ( options ) , type : 'application/pdf' , filename : filename ) else flash [ :error ] = I18n . t ( :no_detail_to_process ) redirect_to ( meetings_current_path ( ) ) and return end end
Prepares the PDF print-out for the event and relay reservations for the current
meeting.
Prepares the PDF print - out for the event and relay reservations for the current meeting .
# DEBUG #    logger.debug "\r\n\r\n!! ------ #{self.class.name}#printout_event_sheet -----" #    logger.debug "> #{params.inspect}" # Collect all events for this Meeting, respecting session and event order: # Collect all available event (both ind. and relays) reservations: # DEBUG #    puts "\r\n#- printout_event_sheet: Team: #{ @team.id }, meeting: #{ @meeting.id }, TA: #{ @team_affiliation.id }" # *** RELAYS *** # TODO WE NEED A DIFFERENT LAYOUT FOR THE RELAYS # *** EVENTS *** # Collect all related swimmer reservations (to gather also notes): # DEBUG # puts "---------------" # puts "all_swimmer_ids: #{ all_swimmer_ids.inspect }" # puts "@events:" # @events.each{ |ev| puts ev.inspect } # puts "---------------" # puts "- available @meeting_reservations tot...: #{ @meeting_reservations.count }" # puts "- available @reservations_events subarrays tot....: #{ @reservations_events.count }" # puts "- available @reservations_relays subarrays tot....: #{ @reservations_relays.count }" # logger.debug "---------------" # logger.debug "@meeting_reservations:" # @meeting_reservations.each{ |r| logger.debug r.inspect } # logger.debug "---------------" # logger.debug "@reservations_events hash:" # @reservations_events.values.each_with_index do |re, idx| # logger.debug( "\r\nEvent #{idx+1}, tot.: #{re.count}" ) # logger.debug( re.inspect ) # end # logger.debug "---------------" # logger.debug "@reservations_relays hash:" # @reservations_relays.values.each_with_index do |re, idx| # logger.debug( "\r\nEvent #{idx+1}, tot.: #{re.count}" ) # logger.debug( re.inspect ) # end # logger.debug "---------------" # Prepare the printout only if there's actually someone going to this Meeting: # (No redirect if there's no data) # == OPTIONS setup + RENDERING phase == # == Render layout & send data: # XXX [Steve, 20180704] Use-case example that forces a redirect during PDF printout of the event sheet: #     TeamManager #9 (Simone DelRio) w/ Meeting ID 16106 (for example), w/ 0 MER reserved rows.