<commit_before>class GroupsController < ApplicationController
  before_filter :auth_user!
  autocomplete :user, :full_name, full: true
  autocomplete :group, :name, { full: true }

  def autocomplete_group_name
    term = params[:term].downcase
    neighborhood = Group.neighborhoods[params[:neighborhood].gsub("^", " ")] || "all"
    if neighborhood == "all"
      groups = Group.active.where('lower(name) LIKE ?', "%#{term}%").order(:name).all
    else
      groups = Group.active.where('neighborhood = ? AND lower(name) LIKE ?', neighborhood, "%#{term}%").order(:name).all
    end
    render json: groups.map { |g| {id: g.id, label: g.name, value: g.name} }
  end

  # TODO(Shimmy): Only display this page if the user is logged in
  def index
    # TODO(Shimmy):Make scopes for these
    @groups = Group.all
    @neighborhoods = Group.neighborhoods.keys
    my = params[:format]
    if my.nil?
      @all = "selected = \"selected\"".html_safe
      @my = "".html_safe
    else
      @my = "selected = \"selected\"".html_safe
      @all = "".html_safe
    end
  end

  def my_index
    @groups = UserGroup.where(user: current_user).map(&:group)
  end

  def show
    @post = Post.new
    @reply = Reply.new
    @group = Group.friendly.find(params[:id])
    @posts = @group.posts.where(event_id: nil).order_by_created_at
    @event_id = nil
    @group_id = @group.id
    @neighborhood = @group.neighborhood
  end

  def new
    if current_user
      if params.key?(:group_param)
        @group = Group.new(params[:group_param].permit(:name, :description, :neighborhood))
      else
        @group = Group.new
      end
      @neighborhoods = Group.neighborhoods.keys
      @allnames = Group.all.map(&:name)
      render action: "new", notice: "Sample notice"
    else
      redirect_to new_user_session_path, notice: "You are not logged in."
    end
  end

  # When User creates group, create a UserGroup with is_leader: true
  def create<commit_msg>user_group nil groups<commit_after>class GroupsController < ApplicationController
  before_filter :auth_user!
  autocomplete :user, :full_name, full: true
  autocomplete :group, :name, { full: true }

  def autocomplete_group_name
    term = params[:term].downcase
    neighborhood = Group.neighborhoods[params[:neighborhood].gsub("^", " ")] || "all"
    if neighborhood == "all"
      groups = Group.active.where('lower(name) LIKE ?', "%#{term}%").order(:name).all
    else
      groups = Group.active.where('neighborhood = ? AND lower(name) LIKE ?', neighborhood, "%#{term}%").order(:name).all
    end
    render json: groups.map { |g| {id: g.id, label: g.name, value: g.name} }
  end

  # TODO(Shimmy): Only display this page if the user is logged in
  def index
    # TODO(Shimmy):Make scopes for these
    @groups = Group.all
    @neighborhoods = Group.neighborhoods.keys
    my = params[:format]
    if my.nil?
      @all = "selected = \"selected\"".html_safe
      @my = "".html_safe
    else
      @my = "selected = \"selected\"".html_safe
      @all = "".html_safe
    end
  end

  def my_index
    @groups = UserGroup.where(user: current_user).map(&:group).compact
  end

  def show
    @post = Post.new
    @reply = Reply.new
    @group = Group.friendly.find(params[:id])
    @posts = @group.posts.where(event_id: nil).order_by_created_at
    @event_id = nil
    @group_id = @group.id
    @neighborhood = @group.neighborhood
  end

  def new
    if current_user
      if params.key?(:group_param)
        @group = Group.new(params[:group_param].permit(:name, :description, :neighborhood))
      else
        @group = Group.new
      end
      @neighborhoods = Group.neighborhoods.keys
      @allnames = Group.all.map(&:name)
      render action: "new", notice: "Sample notice"
    else
      redirect_to new_user_session_path, notice: "You are not logged in."
    end
  end

  # When User creates group, create a UserGroup with is_leader: true
  def create
{'fraction_non_alphanumeric': 0.1324655436447167, 'fraction_numerical': 0.0, 'mean_word_length': 3.1252631578947367, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2215128', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1261, 'n_words': 317}