<commit_before>class FundingBucketsController < OrganizationAwareController
  # before_action :set_funding_template, only: [:show, :edit, :update, :destroy]

  add_breadcrumb "Home", :root_path

  before_action :set_funding_bucket, only: [:show, :edit, :update, :edit_bucket_app, :update_bucket_app, :destroy_bucket_app]
  before_action :check_filter,      :only => [:index, :show, :new, :edit, :new_bucket_app, :edit_bucket_app]

  INDEX_KEY_LIST_VAR    = "funding_buckets_key_list_cache_var"

  # GET /buckets
  def index

    if params[:my_funds]
      authorize! :my_funds, FundingBucket

      add_breadcrumb 'Funding Programs', funding_sources_path
      add_breadcrumb 'My Funds', funding_buckets_path(my_funds: 1)
    else
      authorize! :read, FundingBucket

      add_breadcrumb 'Funding Programs', funding_sources_path
      add_breadcrumb 'Templates', funding_templates_path
      add_breadcrumb 'Buckets', funding_buckets_path
    end



    # Start to set up the query
    conditions  = []
    values      = []

    if params[:agency_id].present?
      @searched_agency_id =  params[:agency_id]
    end
    if params[:fiscal_year].present?
      @searched_fiscal_year =  params[:fiscal_year]
    end
    if params[:funds_available].present?
      @show_funds_available_only =  params[:funds_available]
    end
    if params[:searched_template].present?
      @searched_template = params[:searched_template]
    end

    # this is a search of the owner not a search on the eligibility
    # a search on the eligiblity follows the overall system filter -- not set for a super manager
    if @searched_agency_id.blank?
      if params[:my_funds]
        conditions << 'owner_id IN (?)'
        # should use organization list but organizations that the user actually belongs to
        # so bpt can see all orgs but only belong to BPT
        # transit agencies obviously belongs to all their transit agencies
        values << (current_user.organizations.ids & @organization_list)
      end
    else
      agency_filter_id = @searched_agency_id.to_i
      conditions << 'owner_id = ?'
      values << agency_filter_id
    end

    unless @searched_fiscal_year.blank?
      fiscal_year_filter = @searched_fiscal_year.to_i
      conditions << 'fiscal_year = ?'
      values << fiscal_year_filter
    end

    unless @searched_template.nil?
      funding_template_id = @searched_template.to_i
      conditions << 'funding_template_id = ?'
      values << funding_template_id
    end

    if @show_funds_available_only
      conditions << 'budget_amount > budget_committed'
    end

    # on My Funds - templates must be ones you are eligible for
    # on buckets index page you can search by template
    #if params[:my_funds]
      #@templates = FundingTemplate.joins(:organizations).where('funding_templates.owner_id = ? AND funding_templates_organizations.organization_id IN (?)', FundingSourceType.find_by(name: 'State').id, @organization_list)
      #buckets = FundingBucket.where('(funding_template_id IN (?) OR owner_id IN (?))',templates.ids, @organization_list)
      #@buckets = buckets.where(conditions.join(' AND '), *values)
    #end

    conditions << 'active = true'

    @buckets = FundingBucket.where(conditions.join(' AND '), *values)

    if params[:my_funds]
      @organizations = Organization.where('organization_type_id = 1 OR id IN (?)', @organization_list).pluck(:name, :id)
    else
      @organizations =  Organization.where(id: @organization_list).pluck(:name, :id)
      @templates =  FundingTemplate.all.pluck(:name, :id)
    end


    # cache the set of object keys in case we need them later
    cache_list(@buckets, INDEX_KEY_LIST_VAR)

    respond_to do |format|
      format.html # index.html.erb
      format.json { render :json => @buckets }
    end
  end<commit_msg>set variables for filter dropdown collections on funding_buckets#index<commit_after>class FundingBucketsController < OrganizationAwareController
  # before_action :set_funding_template, only: [:show, :edit, :update, :destroy]

  add_breadcrumb "Home", :root_path

  before_action :set_funding_bucket, only: [:show, :edit, :update, :edit_bucket_app, :update_bucket_app, :destroy_bucket_app]
  before_action :check_filter,      :only => [:index, :show, :new, :edit, :new_bucket_app, :edit_bucket_app]

  INDEX_KEY_LIST_VAR    = "funding_buckets_key_list_cache_var"

  # GET /buckets
  def index

    if params[:my_funds]
      authorize! :my_funds, FundingBucket

      add_breadcrumb 'Funding Programs', funding_sources_path
      add_breadcrumb 'My Funds', funding_buckets_path(my_funds: 1)
    else
      authorize! :read, FundingBucket

      add_breadcrumb 'Funding Programs', funding_sources_path
      add_breadcrumb 'Templates', funding_templates_path
      add_breadcrumb 'Buckets', funding_buckets_path

      @templates =  FundingTemplate.all.pluck(:name, :id)
    end

    @organizations = Organization.where(id: @organization_list).pluck(:name, :id)

    # Start to set up the query
    conditions  = []
    values      = []

    if params[:agency_id].present?
      @searched_agency_id =  params[:agency_id]
    end
    if params[:fiscal_year].present?
      @searched_fiscal_year =  params[:fiscal_year]
    end
    if params[:funds_available].present?
      @show_funds_available_only =  params[:funds_available]
    end
    if params[:searched_template].present?
      @searched_template = params[:searched_template]
    end

    # this is a search of the owner not a search on the eligibility
    # a search on the eligiblity follows the overall system filter -- not set for a super manager
    if @searched_agency_id.blank?
      if params[:my_funds]
        conditions << 'owner_id IN (?)'
        # should use organization list but organizations that the user actually belongs to
        # so bpt can see all orgs but only belong to BPT
        # transit agencies obviously belongs to all their transit agencies
        values << (current_user.organizations.ids & @organization_list)
      end
    else
      agency_filter_id = @searched_agency_id.to_i
      conditions << 'owner_id = ?'
      values << agency_filter_id
    end

    unless @searched_fiscal_year.blank?
      fiscal_year_filter = @searched_fiscal_year.to_i
      conditions << 'fiscal_year = ?'
      values << fiscal_year_filter
    end

    unless @searched_template.nil?
      funding_template_id = @searched_template.to_i
      conditions << 'funding_template_id = ?'
      values << funding_template_id
    end

    if @show_funds_available_only
      conditions << 'budget_amount > budget_committed'
    end

    # on My Funds - templates must be ones you are eligible for
    # on buckets index page you can search by template
    #if params[:my_funds]
      #@templates = FundingTemplate.joins(:organizations).where('funding_templates.owner_id = ? AND funding_templates_organizations.organization_id IN (?)', FundingSourceType.find_by(name: 'State').id, @organization_list)
      #buckets = FundingBucket.where('(funding_template_id IN (?) OR owner_id IN (?))',templates.ids, @organization_list)
      #@buckets = buckets.where(conditions.join(' AND '), *values)
    #end

    conditions << 'active = true'

    @buckets = FundingBucket.where(conditions.join(' AND '), *values)


    # cache the set of object keys in case we need them later
    cache_list(@buckets, INDEX_KEY_LIST_VAR)

    respond_to do |format|
      format.html # index.html.erb
      format.json { render :json => @buckets }
    end
  end
{'fraction_non_alphanumeric': 0.09164671455174249, 'fraction_numerical': 0.0003990422984836393, 'mean_word_length': 3.6157151626764885, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 9, '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': '2641417', 'n_tokens_mistral': 2444, 'n_tokens_neox': 2314, 'n_words': 578}