app/controllers/meeting_results_controller.rb
# Allows editing of the current Meeting results passages, according to the
# current_user and its managed affiliations.
#
# To be reachable this action, requires that the current user is one of
# the existing Team managers (indipendently from current season).
#
# The action then proceeds to fill a list of editable passages, one for
# each MIR of the teams managed by the current user.
#
# If no passage row is existing for the corresponding associated MIR
# found, a button to add a new row will be rendered instead.
#
# The actual correlated update action is performed via API/v2/remote_edit/ AJAX call.
#
# === Parameters:
# - id: Meeting id for which the Passages must be edited
#
Allows editing of the current Meeting results passages, according to the
current_user and its managed affiliations.

To be reachable this action, requires that the current user is one of
the existing Team managers (indipendently from current season).

The action then proceeds to fill a list of editable passages, one for
each MIR of the teams managed by the current user.

If no passage row is existing for the corresponding associated MIR
found, a button to add a new row will be rendered instead.

The actual correlated update action is performed via API/v2/remote_edit/ AJAX call.

Meeting id for which the Passages must be edited
Allows editing of the current Meeting results passages according to the current_user and its managed affiliations . To be reachable this action requires that the current user is one of the existing Team managers ( indipendently from current season ) . The action then proceeds to fill a list of editable passages one for each MIR of the teams managed by the current user . If no passage row is existing for the corresponding associated MIR found a button to add a new row will be rendered instead . The actual correlated update action is performed via API / v2 / remote_edit / AJAX call . Meeting id for which the Passages must be edited
def edit_passages
    @managed_teams = current_user
      .team_managers
      .joins( :team_affiliation )
      .where( ['team_affiliations.season_id = ?', @meeting.season_id] )
      .map{ |tm| tm.team }
      .uniq
    @managed_team_ids = @managed_teams.map{ |team| team.id }
    @editable_stuff = MeetingIndividualResult
        .joins( meeting_program: [meeting_event: [:event_type, meeting_session: :pool_type]]  )
        .where( [
          'meeting_sessions.meeting_id = ? AND (meeting_individual_results.team_id IN (?)) AND (event_types.length_in_meters > pool_types.length_in_meters)',
          @meeting.id, @managed_team_ids
        ] )
        .order('meeting_sessions.session_order, meeting_events.event_order, meeting_individual_results.is_disqualified, meeting_individual_results.minutes DESC, meeting_individual_results.seconds DESC, meeting_individual_results.hundreds DESC' )
        .includes( :passages )
        .to_a
        .map{ |mir| { mir => mir.passages } }
  end
def edit_passages @managed_teams = current_user . team_managers . joins ( :team_affiliation ) . where ( [ 'team_affiliations.season_id = ?' , @meeting . season_id ] ) . map { | tm | tm . team } . uniq @managed_team_ids = @managed_teams . map { | team | team . id } @editable_stuff = MeetingIndividualResult . joins ( meeting_program : [ meeting_event : [ :event_type , meeting_session : :pool_type ] ] ) . where ( [ 'meeting_sessions.meeting_id = ? AND (meeting_individual_results.team_id IN (?)) AND (event_types.length_in_meters > pool_types.length_in_meters)' , @meeting . id , @managed_team_ids ] ) . order ( 'meeting_sessions.session_order, meeting_events.event_order, meeting_individual_results.is_disqualified, meeting_individual_results.minutes DESC, meeting_individual_results.seconds DESC, meeting_individual_results.hundreds DESC' ) . includes ( :passages ) . to_a . map { | mir | { mir => mir . passages } } end
Allows editing of the current Meeting results passages, according to the
current_user and its managed affiliations.
Allows editing of the current Meeting results passages according to the current_user and its managed affiliations .
# Collect the list of managed Teams: # Leega: Managed teams are always referred to the meeting season  # Collect the list of available/editable Passages, for each available MIR # for the managed affiliations by the current user. # The "editable stuff" is returned as an ordered array of Hash, where each # Hash item has as key the related MIR and as value its list of passages. #    @editable_stuff = @meeting.meeting_individual_results.unscope(:order) #        .joins( meeting_session: :pool_type, meeting_event: :event_type ) #        .where( [ #          '(meeting_individual_results.team_id IN (?)) AND (event_types.length_in_meters > pool_types.length_in_meters)', #          @managed_team_ids #        ] ) #        .sort_by_event_and_timing #        .includes( :passages ) #        .to_a #        .map{ |mir| { mir => mir.passages } } #        .includes( :passages, [meeting_program: [meeting_event: [:event_type, meeting_session: :pool_type]]] ) #        .order('meeting_sessions.session_order, meeting_events.event_order').order( :is_disqualified, minutes: :DESC, seconds: :DESC, hundreds: :DESC ) # DEBUG #    puts "\r\n\r\n--- @editable_stuff: ---\r\n#{ @editable_stuff.inspect }\r\n" # TODO Use a dedicated DAO class instead of this ugly Hash # TODO # Should order by start-list. # If no start-list present should use timing #if @meeting.has_start_list #  @editable_stuff.sort{ |mir_n, mir_p| MeetingEntry.where( badge_id: mir_n.keys.first.badge_id, meeting_program_id: mir_n.keys.first.meeting_program_id ).first.get_timing <=> MeetingEntry.where( badge_id: mir_p.keys.first.badge_id, meeting_program_id: mir_n.keys.first.meeting_program_id ).first.get_timing } #end