<commit_before>class MentorsController < ApplicationController
  load_and_authorize_resource
  include CrudActions
  include ManageSchedules # edit_schedules & update_schedules

  def index
    # a prototyped mentor is submitted with each index query. if the prototype
    # is not present, it is built here with default values
    params[:mentor] ||= {}
    params[:mentor][:inactive] = '0' if params[:mentor][:inactive].nil?

    # mentors are filtered by the criteria above
    last_selected_coach = params[:mentor][:filter_by_coach_id]
    last_selected_meeting_day = params[:mentor][:filter_by_meeting_day]
    if params[:mentor][:filter_by_coach_id].to_i > 0
      @mentors = @mentors.joins(:admins).where('kids.admin_id = ?', params[:mentor][:filter_by_coach_id].to_i).uniq
      params[:mentor][:filter_by_coach_id] = nil
    end
    if params[:mentor][:filter_by_meeting_day].to_i > -1
      @mentors = @mentors.joins(:kids).where('kids.meeting_day = ?', params[:mentor][:filter_by_meeting_day]).uniq
      params[:mentor][:filter_by_meeting_day] = nil
    end
    @mentors = @mentors.where(mentor_params.to_h.delete_if { |_key, val| val.blank? })
    params[:mentor][:filter_by_coach_id] = last_selected_coach
    params[:mentor][:filter_by_meeting_day] = last_selected_meeting_day

    # provide a prototype for the filter form
    @mentor = Mentor.new(mentor_params)


    if current_user.is_a?(Admin) && 'xlsx' == params[:format]
      return render xlsx: 'index'
    # when only one record is present, show it immediately. this is not for
    # admins, since they could have no chance to alter their filter settings in
    # some cases
    elsif !current_user.is_a?(Admin) && (1 == @mentors.count)
      redirect_to @mentors.first
    else
      respond_with @mentors
    end
  end<commit_msg>Change controlling of mentor filters<commit_after>class MentorsController < ApplicationController
  load_and_authorize_resource
  include CrudActions
  include ManageSchedules # edit_schedules & update_schedules

  def index
    # a prototyped mentor is submitted with each index query. if the prototype
    # is not present, it is built here with default values
    params[:mentor] ||= {}
    params[:mentor][:inactive] = '0' if params[:mentor][:inactive].nil?

    # mentors are filtered by the criteria above
    last_selected_coach = params[:mentor][:filter_by_coach_id]
    last_selected_meeting_day = params[:mentor][:filter_by_meeting_day]
    unless params[:mentor][:filter_by_coach_id].blank?
      @mentors = @mentors.joins(:admins).where('kids.admin_id = ?', params[:mentor][:filter_by_coach_id].to_i).uniq
      params[:mentor][:filter_by_coach_id] = nil
    end
    unless params[:mentor][:filter_by_meeting_day].blank?
      @mentors = @mentors.joins(:kids).where('kids.meeting_day = ?', params[:mentor][:filter_by_meeting_day].to_i).uniq
      params[:mentor][:filter_by_meeting_day] = nil
    end
    @mentors = @mentors.where(mentor_params.to_h.delete_if { |_key, val| val.blank? })
    params[:mentor][:filter_by_coach_id] = last_selected_coach
    params[:mentor][:filter_by_meeting_day] = last_selected_meeting_day

    # provide a prototype for the filter form
    @mentor = Mentor.new(mentor_params)


    if current_user.is_a?(Admin) && 'xlsx' == params[:format]
      return render xlsx: 'index'
    # when only one record is present, show it immediately. this is not for
    # admins, since they could have no chance to alter their filter settings in
    # some cases
    elsif !current_user.is_a?(Admin) && (1 == @mentors.count)
      redirect_to @mentors.first
    else
      respond_with @mentors
    end
  end
{'fraction_non_alphanumeric': 0.1102880658436214, 'fraction_numerical': 0.0016460905349794238, 'mean_word_length': 4.353891336270191, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '958423', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1209, 'n_words': 267}