<commit_before># frozen_string_literal: true

class ReviewersController < ApplicationController
  def index
    filter_params = params.permit(reviewer_filter: %i[state track_id])
    @reviewer_filter = ReviewerFilter.new(filter_params)
    @tracks = @conference.tracks
    @states = resource_class.state_machine.states.map(&:name)
    @reviewers = @reviewer_filter.apply(Reviewer)
                                 .for_conference(@conference)
                                 .joins(:user)
                                 .order('first_name, last_name')
                                 .includes(user: [:reviews], accepted_preferences: [], conference: [])
    @reviewer_batch = ReviewerBatch.new(conference: @conference)
    @previous_reviewers = resource_class
                          .where('conference_id != ? and user_id not in (?) and state = ?',
                                 @conference.id, @reviewers.map(&:user_id), :accepted)
                          .includes(user: [:reviews], conference: []).group_by(&:user)
    @reviewer = resource_class.new(conference: @conference)
    respond_to do |format|
      format.html
    end
  end

  def create
    reviewer = new_reviewer
    if reviewer.try(:save)
      message = t('flash.reviewer.create.success')
      reviewer = ReviewerJsonBuilder.new(reviewer).to_json

      respond_to do |format|
        format.json do
          render json: {
            message: message,
            reviewer: reviewer
          }.to_json, status: :created
        end
      end
    else
      message = t('flash.reviewer.create.failure', username: reviewer.try(:user_username))
      respond_to do |format|
        format.json { render json: message, status: :bad_request }<commit_msg>Fixing condition to show history of reviewers in reviewer invitation page<commit_after># frozen_string_literal: true

class ReviewersController < ApplicationController
  def index
    filter_params = params.permit(reviewer_filter: %i[state track_id])
    @reviewer_filter = ReviewerFilter.new(filter_params)
    @tracks = @conference.tracks
    @states = resource_class.state_machine.states.map(&:name)
    @reviewers = @reviewer_filter.apply(Reviewer)
                                 .for_conference(@conference)
                                 .joins(:user)
                                 .order('first_name, last_name')
                                 .includes(user: [:reviews], accepted_preferences: [], conference: [])
    @reviewer_batch = ReviewerBatch.new(conference: @conference)
    query = resource_class
            .where('conference_id != ? and state = ?',
                   @conference.id, :accepted)
    unless @reviewers.empty?
      query = query.where('user_id not in (?)', @reviewers.map(&:user_id))
    end
    @previous_reviewers = query
                          .includes(user: [:reviews], conference: []).group_by(&:user)
    @reviewer = resource_class.new(conference: @conference)
    respond_to do |format|
      format.html
    end
  end

  def create
    reviewer = new_reviewer
    if reviewer.try(:save)
      message = t('flash.reviewer.create.success')
      reviewer = ReviewerJsonBuilder.new(reviewer).to_json

      respond_to do |format|
        format.json do
          render json: {
            message: message,
            reviewer: reviewer
          }.to_json, status: :created
        end
      end
    else
      message = t('flash.reviewer.create.failure', username: reviewer.try(:user_username))
      respond_to do |format|
        format.json { render json: message, status: :bad_request }
{'fraction_non_alphanumeric': 0.10391061452513967, 'fraction_numerical': 0.0, 'mean_word_length': 2.2974217311233884, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1199374', 'n_tokens_mistral': 1014, 'n_tokens_neox': 992, 'n_words': 207}